/**
  * @return array order data in API form
  * @throws PilipayError
  */
 public function toApiArray()
 {
     // check goods list
     if (empty($this->_goodsList)) {
         throw new PilipayError(PilipayError::REQUIRED_ARGUMENT_NO_EXIST, array('name' => 'goodsList', 'value' => Tools::jsonEncode($this->_goodsList)));
     }
     // if the orderTime is omitted, use current time
     if (empty($this->orderTime)) {
         $now = date_create('now', timezone_open('Asia/Shanghai'))->format('Y-m-d H:i:s');
         $this->orderTime = $this->orderTime ? $this->orderTime : $now;
     }
     // verify
     parent::verifyFields();
     $apiArray = array_map('strval', array('version' => $this->version, 'merchantNo' => $this->merchantNo, 'currencyType' => $this->currencyType, 'orderNo' => $this->orderNo, 'orderAmount' => (int) round($this->orderAmount * 100), 'orderTime' => $this->orderTime, 'pageUrl' => $this->pageUrl, 'serverUrl' => $this->serverUrl, 'redirectUrl' => $this->redirectUrl, 'notifyType' => $this->notifyType, 'shipper' => (int) round($this->shipper * 100), 'tax' => (int) round($this->tax * 100), 'signType' => $this->signType));
     // sign
     if ($this->signType == 'MD5') {
         // sign using MD5
         $this->signMsg = md5(implode('', $apiArray) . $this->appSecret);
         $apiArray['signMsg'] = $this->signMsg;
     } else {
         throw new PilipayError(PilipayError::INVALID_ARGUMENT, array('name' => 'signType', 'value' => $this->signType));
     }
     $apiArray['goodsList'] = urlencode(Tools::jsonEncode($this->_goodsList));
     return $apiArray;
 }
Пример #2
0
 /**
  * @return array order data in API form
  * @throws PilipayError
  */
 public function toApiArray()
 {
     // sign
     if ($this->signType == 'MD5') {
         // sign using MD5
         // not: orderAmount should be in cents
         $this->signMsg = md5($this->merchantNO . $this->orderNo . intval($this->orderAmount * 100) . $this->sendTime . $this->appSecret);
     } else {
         throw new PilipayError(PilipayError::INVALID_ARGUMENT, array('name' => 'signType', 'value' => $this->signType));
     }
     // check goods list
     if (empty($this->_goodsList)) {
         throw new PilipayError(PilipayError::REQUIRED_ARGUMENT_NO_EXIST, array('name' => 'goodsList', 'value' => json_encode($this->_goodsList)));
     }
     // verify
     parent::verifyFields();
     return array_map('strval', array('version' => $this->version, 'merchantNO' => $this->merchantNO, 'currencyType' => $this->currencyType, 'orderNo' => $this->orderNo, 'orderAmount' => intval($this->orderAmount * 100), 'orderTime' => $this->orderTime, 'sendTime' => $this->sendTime, 'pageUrl' => $this->pageUrl, 'serverUrl' => $this->serverUrl, 'shipper' => intval($this->shipper * 100), 'tax' => intval($this->tax * 100), 'signType' => $this->signType, 'signMsg' => $this->signMsg, 'goodsList' => urlencode(json_encode($this->_goodsList))));
 }
Пример #3
0
 /**
  * Convert the object into an array format required in the HTTP API
  * 转换为API中的那种array表示形式
  * @return array
  */
 public function toApiArray()
 {
     $this->pictureUrl = $this->pictureUrl ? $this->pictureUrl : self::DEFAULT_PICTURE_URL;
     parent::verifyFields();
     return array_map('strval', array('name' => $this->name, 'pictureURL' => $this->pictureUrl, 'price' => intval($this->price * 100), 'productURL' => $this->productUrl, 'productId' => $this->productId, 'quantity' => intval($this->quantity), 'weight' => intval(self::convertWeightToGram($this->weight, $this->weightUnit)), 'attr' => $this->attr, 'category' => $this->category, 'height' => $this->height, 'length' => $this->length, 'width' => $this->width));
 }