Exemple #1
0
 /**
  * This method is used to render the payment button,
  * Take care if the button should be displayed or not.
  */
 public function hookPayment($params)
 {
     include_once _PS_MODULE_DIR_ . 'alipay/api/loader.php';
     $currency_id = $params['cart']->id_currency;
     $currency = new Currency((int) $currency_id);
     $cart = new Cart($params['cart']->id);
     if (!ValidateCore::isLoadedObject($cart)) {
         return false;
     }
     if (in_array($currency->iso_code, $this->limited_currencies) == false) {
         return false;
     }
     $service = Configuration::get('ALIPAY_SERVICE_PAYMENT');
     $credentials = AlipayTools::getCredentials($service, false);
     $alipayapi = new AlipayApi($credentials);
     $alipayapi->setReturnUrl($this->getReturnUrl($cart->secure_key, $cart->id));
     $alipayapi->setNotifyUrl($this->getNotifyUrl($cart->secure_key, $cart->id));
     $alipayapi->setCharset('UTF-8');
     date_default_timezone_set('Asia/Hong_Kong');
     $payment_request = new PaymentRequest();
     $payment_request->setCurrency($currency->iso_code);
     $payment_request->setPartnerTransactionId(date('YmdHis') . $cart->id);
     $payment_request->setGoodsDescription($this->getGoodsDescription());
     $payment_request->setGoodsName($this->getGoodsName($cart->id));
     $payment_request->setOrderGmtCreate(date('Y-m-d H:i:s'));
     $payment_request->setOrderValidTime(21600);
     $payment_request->setTotalFee($cart->getOrderTotal());
     $alipayapi->prepareRequest($payment_request);
     $url = $alipayapi->createUrl();
     $this->smarty->assign(array('module_dir' => $this->_path, 'alipay_payment_url' => $url));
     return $this->display(__FILE__, 'views/templates/hook/payment.tpl');
 }