当前位置: 首页>>代码示例>>PHP>>正文


PHP Params::setKey方法代码示例

本文整理汇总了PHP中Params::setKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Params::setKey方法的具体用法?PHP Params::setKey怎么用?PHP Params::setKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Params的用法示例。


在下文中一共展示了Params::setKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generatePaymentSessionWithPaypal

 /**
  * generate payment url with paypal integration
  * @param $product
  * @param $price
  * @param $inv_number
  * @param $paypal_email
  * @param $paypal_price
  * @param $ureturn
  * @param $unotify
  * @param $ucancel
  * @param int $quantity
  * @param string $comments
  * @param string $format
  * @param string $action
  * @return array|mixed|null
  * @throws \UnexpectedValueException
  * @throws \InvalidArgumentException
  * @throws \Exception
  */
 public function generatePaymentSessionWithPaypal($product, $price, $inv_number, $paypal_email, $paypal_price, $ureturn, $unotify, $ucancel, $quantity = 1, $comments = "No comments", $format = 'json', $action = 'payment')
 {
     if (strcmp($format, 'json') != 0 && strcmp($format, 'xml') != 0) {
         throw new \InvalidArgumentException("Support only json/xml format");
     }
     if (strcmp($action, 'payment') != 0) {
         throw new \UnexpectedValueException("Unsupported action");
     }
     if (!is_string($product) || !strlen($product) > 1) {
         throw new \InvalidArgumentException("Product is not defined");
     }
     if (!is_string($unotify) || !strlen($unotify) > 1) {
         throw new \InvalidArgumentException("Notify URI is not defined");
     }
     if (!is_string($ucancel) || !strlen($ucancel) > 1) {
         throw new \InvalidArgumentException("Cancel URI is not defined");
     }
     if (!is_string($ureturn) || !strlen($ureturn) > 1) {
         throw new \InvalidArgumentException("Return URI is not defined");
     }
     if (!is_string($paypal_email) || !strlen($paypal_email) > 1) {
         throw new \InvalidArgumentException("Paypal Email is not defined");
     }
     if (!is_string($inv_number) || !strlen($inv_number) > 1) {
         throw new \InvalidArgumentException("Invoice Number is not defined");
     }
     if (!is_numeric($price)) {
         throw new \InvalidArgumentException("Price is not defined");
     }
     if (!is_numeric($paypal_price)) {
         throw new \InvalidArgumentException("Paypal Price is not defined");
     }
     if (!is_int($quantity)) {
         throw new \InvalidArgumentException("Quantity is not defined");
     }
     $params = new Params();
     $paramsbuild = $params->setKey($this->key)->setProductName($product)->setProductPrice($price)->setQuantity($quantity)->setAction($action)->setNotifyURI($unotify)->setReturnURI($ureturn)->setCancelURI($ucancel)->setComments($comments)->setInvoiceNumber($inv_number)->setPaypalAddress($paypal_email)->setPaypalPrice($paypal_price)->setFormatResult($format)->buildAsHTTPParams();
     $curl = curl_init();
     curl_setopt($curl, CURLOPT_URL, Resource::$PAYMENT);
     curl_setopt($curl, CURLOPT_POST, $params->getParamsCount());
     curl_setopt($curl, CURLOPT_POSTFIELDS, $paramsbuild);
     curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
     $resultraw = curl_exec($curl);
     if ($resultraw == false) {
         throw new \Exception("CURL error : " . curl_error($curl), curl_errno($curl));
     } else {
         $result = null;
         if (strcmp($format, 'json') == 0) {
             $result = json_decode($resultraw, true);
         } else {
             /**
              * @var \SimpleXMLElement
              */
             $resulttemp = simplexml_load_string($resultraw);
             $result = array();
             foreach ($resulttemp->children() as $child) {
                 /**
                  * @var \SimpleXMLElement $child
                  */
                 $result[$child->getName()] = (string) $child;
             }
         }
         return $result;
     }
 }
开发者ID:gamalan,项目名称:ipaymu-php,代码行数:85,代码来源:IPaymu.php


注:本文中的Params::setKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。