/**
  * query all warehouse addresses
  * @params $resultFormat string objectList or arrayList
  * @return array
  */
 public static function queryAll($resultFormat = 'objectList')
 {
     $curl = PilipayCurl::instance();
     $result = $curl->get(PilipayConfig::getWarehouseAddressListUrl());
     if (empty($result)) {
         return array();
     }
     $json = json_decode($result, true);
     if (empty($json)) {
         return false;
     }
     if ($resultFormat !== 'objectList') {
         return $json;
     }
     $addressList = array();
     foreach ($json as $item) {
         $addressList[] = new PilipayWarehouseAddress($item);
     }
     return $addressList;
 }
예제 #2
0
 /**
  * query all available currencies from pilibaba
  * @param string $resultFormat objectList | stringList
  * @return array
  */
 public static function queryAll($resultFormat = 'objectList')
 {
     $curl = PilipayCurl::instance();
     $result = $curl->get(PilipayConfig::getWarehouseAddressListUrl());
     if (empty($result)) {
         return array();
     }
     $json = json_decode($result, true);
     if (empty($json)) {
         return array();
     }
     if ($resultFormat !== 'objectList') {
         return $json;
     }
     $currencies = array();
     foreach ($json as $currencyCode) {
         $currencies[] = new PilipayCurrency(array('code' => $currencyCode));
     }
     return $currencies;
 }
예제 #3
0
 /**
  * Get the barcode's Picture URL
  * -- this barcode should be print on the cover of package before shipping, so that our warehouse could easily match the package.
  * 获取条形码的图片URL
  * -- 在邮寄前, 这个条形码应该打印到包裹的包装上, 以便我们的中转仓库识别包裹.
  * @return string the barcode's Picture URL
  */
 public function getBarcodePicUrl()
 {
     return PilipayConfig::getBarcodeUrl() . '?' . http_build_query(array('merchantNo' => $this->merchantNO, 'orderNo' => $this->orderNo));
 }
예제 #4
0
 /**
  * 结账页面, 验证购物车
  *
  * @param $context Context
  */
 public function performValidation($context)
 {
     $cart = $context->cart;
     if ($cart->id_customer == 0 || $cart->id_address_delivery == 0 || $cart->id_address_invoice == 0 || !$this->active) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     // Check that this payment option is still available in case the customer changed his address
     // just before the end of the checkout process
     $authorized = false;
     foreach (Module::getPaymentModules() as $module) {
         if ($module['name'] == 'pilipay') {
             $authorized = true;
             break;
         }
     }
     if (!$authorized) {
         die($this->l('This payment method is not available.', 'validation'));
     }
     $customer = new Customer($cart->id_customer);
     if (!Validate::isLoadedObject($customer)) {
         Tools::redirect('index.php?controller=order&step=1');
     }
     $currency = $context->currency;
     $total = (double) $cart->getOrderTotal(true, Cart::BOTH);
     // 修改订单状态为待从pilibaba支付 validateOrder method save an order to database.
     $this->validateOrder($cart->id, Configuration::get(self::OS_AWAITING), $total, $this->displayName, null, null, (int) $currency->id, false, $customer->secure_key);
     // 支付完成后的回调URL
     $paidCallbackUrl = $this->context->link->getModuleLink($this->name, 'result', [], true);
     $pageUrl = self::getHttpHost() . __PS_BASE_URI__ . 'index.php?controller=history';
     $order = new Order($this->currentOrder);
     $pilibabaWarehouseId = Tools::getValue(self::PILIPAY_WAREHOUSES, Configuration::get(self::PILIPAY_WAREHOUSES));
     if ($pilibabaWarehouseId != '999') {
         // not direct
         //以下几行代码用来修改订单地址到 pilibaba warehouse。
         $id_address = $this->newAddress($order);
         $sql = 'UPDATE `' . _DB_PREFIX_ . 'orders` 
                    SET `id_address_delivery` =' . (int) $id_address . ',`id_address_invoice` = ' . (int) $id_address . '
                    WHERE id_order=' . (int) $this->currentOrder;
         Db::getInstance()->execute($sql);
     }
     if (!Validate::isLoadedObject($order)) {
         die($this->l('This order is invalid.', 'pilipay'));
     }
     try {
         // create an order
         if ($this->testmode == '1') {
             PilipayConfig::setUseProductionEnv(false);
             $pilipayOrder = new PilipayOrder();
             $pilipayOrder->merchantNo = pSQL('0210000202');
             $pilipayOrder->appSecret = pSQL('cbkmqa1s');
         } else {
             $pilipayOrder = new PilipayOrder();
             $pilipayOrder->merchantNo = pSQL($this->merchantNo);
             $pilipayOrder->appSecret = pSQL($this->appSecret);
         }
         $pilipayOrder->currencyType = pSQL($this->getAbbrOfCurrency($currency));
         $pilipayOrder->orderNo = pSQL($order->id);
         $pilipayOrder->orderAmount = $total;
         $pilipayOrder->orderTime = date('Y-m-d H:i:s');
         $pilipayOrder->pageUrl = pSQL($pageUrl);
         //self::_getHttpHost() . '/index.php?controller=history';
         $pilipayOrder->serverUrl = pSQL($paidCallbackUrl);
         $pilipayOrder->redirectUrl = pSQL($pageUrl);
         $pilipayOrder->shipper = $order->total_shipping_tax_incl;
         $totalProductVatTax = 0;
         // create a good
         foreach ($order->getProducts() as $product) {
             $price = $product['product_price'];
             $price_wt = $product['product_price_wt'];
             $totalProductVatTax += $price_wt - $price;
             $productObj = new Product($product['product_id']);
             $productUrl = $context->link->getProductLink($productObj);
             $productPictureUrl = null;
             if (!empty($product['image'])) {
                 $img = $product['image'];
                 if ($img instanceof Image) {
                     $productPictureUrl = $context->link->getImageLink($img->id_image, $img->id_image);
                 }
             }
             $pilipayGood = new PilipayGood();
             $product['product_name'] = pSQL($product['product_name']);
             $pilipayGood->name = $product['product_name'] . (isset($product['attributes']) ? ' - ' . $product['attributes'] : '');
             $pilipayGood->attr = '';
             $pilipayGood->category = '';
             $pilipayGood->pictureUrl = pSQL($productPictureUrl);
             $pilipayGood->price = $price_wt;
             $pilipayGood->productUrl = pSQL($productUrl);
             $pilipayGood->productId = pSQL($product['product_id']);
             $pilipayGood->quantity = $product['product_quantity'];
             $pilipayGood->weight = $product['product_weight'];
             $pilipayGood->weightUnit = 'kg';
             // default kg for presta shop.
             $pilipayGood->width = 0;
             // 10: cm -> mm
             $pilipayGood->height = 0;
             // 10: cm -> mm
             $pilipayGood->length = 0;
             // 10: cm -> mm
             // add the good to order
             $pilipayOrder->addGood($pilipayGood);
         }
         $pilipayOrder->tax = min(0, $cart->getOrderTotal(true) - $cart->getOrderTotal(false) - ($order->total_shipping_tax_incl - $order->total_shipping_tax_excl) - $totalProductVatTax);
         echo $pilipayOrder->renderSubmitForm();
         die;
     } catch (PilipayError $e) {
         self::log("error", $e->getMessage() . PHP_EOL . $e->getTraceAsString());
         die($e->getMessage());
     } catch (Exception $e) {
         self::log("error", $e->getMessage() . PHP_EOL . $e->getTraceAsString());
         die($e->getMessage());
     }
 }
예제 #5
0
 /**
  * Set whether to use production env.
  * 设置是否使用生产环境
  * @param bool|true $isProduction
  */
 public static function setUseProductionEnv($isProduction = true)
 {
     self::$useProductionEnv = $isProduction;
 }
예제 #6
0
 /**
  * Get the barcode's Picture URL
  * -- this barcode should be print on the cover of package before shipping, so that our warehouse could easily match the package.
  * 获取条形码的图片URL
  * -- 在邮寄前, 这个条形码应该打印到包裹的包装上, 以便我们的中转仓库识别包裹.
  * @return string the barcode's Picture URL
  */
 public function getBarcodePicUrl()
 {
     if (!$this->merchantNo) {
         throw new PilipayError(PilipayError::REQUIRED_ARGUMENT_NO_EXIST, array('name' => 'merchantNo', 'value' => $this->merchantNo));
     }
     if (!$this->orderNo) {
         throw new PilipayError(PilipayError::REQUIRED_ARGUMENT_NO_EXIST, array('name' => 'orderNo', 'value' => $this->orderNo));
     }
     return PilipayConfig::getBarcodeUrl() . '?' . http_build_query(array('merchantNo' => $this->merchantNo, 'orderNo' => $this->orderNo));
 }