/** * This method is called when the customer goes back to shop, after he made a payment. * The customer will redirected either to the order confirmation page or to an error page * @return mixed */ public function postProcess() { require_once dirname(__FILE__) . '/../../api/loader.php'; $alipay = new Alipay(); $payment_response = new PaymentResponse(); $payment_response->getPostData(); if ($payment_response->getTradeStatus() == 'TRADE_FINISHED') { $payment_response->setIdModule($this->module->id); if (!$payment_response->processResponse()) { $errors = $payment_response->getErrors(); if ($errors) { foreach ($errors as $error) { $this->errors[] = $error; } return $this->setTemplate('error.tpl'); } } if ($payment_response->getIdOrder()) { $params = array('id_cart' => $payment_response->getIdCart(), 'id_module' => $payment_response->getIdModule(), 'id_order' => $payment_response->getIdOrder(), 'key' => $payment_response->getSecureKey()); $s = $this->context->link->getModuleLink('alipay', 'confirmation', $params); Tools::redirect($s); } else { $this->context->smarty->assign($payment_response->getTplVars()); return $this->setTemplate('check_order.tpl'); } } $this->errors[] = $alipay->l('An error occured. Please contact the merchant to have more informations'); return $this->setTemplate('error.tpl'); }
/** * This method get useful payment details and assign them into the Order back-office template * @param bool|true $response * @param bool|true $params * @return int */ public function processResponse($response = true, $params = true) { $alipay = new Alipay(); if (!$response) { $this->errors[] = $alipay->l('Impossible to retrieve transaction information'); return -1; } $xmlObj = new SimpleXMLElement($response); if ($xmlObj && $xmlObj->is_success == 'T') { $this->tplVars = get_object_vars($xmlObj->response->trade); $this->tplVars['currency'] = Currency::getIdByIsoCode($params['currency']); $this->tplVars['iso_code'] = $params['currency']; $this->tplVars['amount_in_currency'] = $params['total_fee']; } else { $this->errors[] = $alipay->l('Impossible to retrieve transaction information'); return -1; } }
/** * This method checks Alipay's response regarding the refund * @param bool|true $response * @param bool|true $params * @return int */ public function processResponse($response = true, $params = true) { $alipay = new Alipay(); if (!$response) { $this->errors[] = $alipay->l('An error occurred during the process.'); return -1; } $xmlObj = new SimpleXMLElement($response); if ($xmlObj && $xmlObj->is_success == 'T') { $this->insertRefund($params); } elseif ($xmlObj && $xmlObj->is_success == 'F') { $this->errors[] = sprintf($alipay->l('An error occured during the process: %s'), $xmlObj->error); return -1; } else { $this->errors[] = $alipay->l('An error occurred during the process.'); return -1; } }
/** * This method checks data integrity * @param bool $response * @param bool $params * @return bool */ public function processResponse($response = true, $params = true) { $alipay = new Alipay(); if (!$response || !$params) { $this->errors[] = $alipay->l('An error occured. Please contact the merchant to have more informations'); return false; } $cart = new Cart((int) $this->id_cart); if (!Validate::isLoadedObject($cart)) { $this->errors[] = $alipay->l('Cannot load Cart object.'); return false; } $customer = new Customer((int) $cart->id_customer); if (!Validate::isLoadedObject($customer)) { $this->errors[] = $alipay->l('Cannot load Customer object.'); return false; } if ($customer->secure_key != $this->secure_key || !$this->compareSign()) { $this->errors[] = $alipay->l('An error occured. Please contact the merchant to have more informations'); return false; } $this->tplVars = array('id_cart' => $this->id_cart, 'id_module' => $this->id_module, 'secure_key' => $this->secure_key); return true; }