Esempio n. 1
0
 /**
  * @param bool $asArray
  * @return array|\idarex\pingppyii2\CodeAutoCompletion\Charge
  */
 public function getCharge($asArray = false)
 {
     if ($asArray) {
         return $this->_charge->__toArray(true);
     } else {
         return $this->_charge->__toStdObject();
     }
 }
Esempio n. 2
0
 public function pay($runValidation = true)
 {
     if ($runValidation && !$this->validate()) {
         return false;
     }
     if ($this->_order->status !== Order::STATUS_UNPAID) {
         return false;
     }
     require_once Yii::getAlias('@vendor') . "/pingplusplus/pingpp-php/init.php";
     \Pingpp\Pingpp::setApiKey(Yii::$app->params['pingpp.apiKey']);
     try {
         $extra = [];
         switch ($this->channel) {
             case self::CHANNEL_ALIPAY_WAP:
                 $extra = ['success_url' => Yii::$app->request->hostInfo . '/#/order/detail/' . $this->_order->id, 'cancel_url' => Yii::$app->request->hostInfo . '/#/order/pay/' . $this->_order->id];
                 break;
             case self::CHANNEL_WX_PUB:
                 Yii::$app->session->open();
                 $extra = ['open_id' => Yii::$app->session['wechatOpenid']];
                 break;
             case self::CHANNEL_ALIPAY_PC_DIRECT:
                 $extra = ['success_url' => Yii::$app->request->hostInfo . '/#/order/detail/' . $this->_order->id];
                 break;
             default:
                 throw new InvalidValueException('支付渠道错误!');
         }
         $ch = \Pingpp\Charge::create(['subject' => '笑e购订单', 'body' => '笑e购(xiaoego.com)订单,订单号:' . $this->_order->order_sn, 'amount' => bcmul($this->_order->real_fee, 100), 'order_no' => $this->_order->order_sn, 'currency' => 'cny', 'extra' => $extra, 'channel' => $this->channel, 'client_ip' => Yii::$app->request->userIP, 'time_expire' => $this->_order->timeout + 1800, 'app' => ['id' => Yii::$app->params['pingpp.appId']], 'description' => mb_strlen($this->_order->description, 'UTF-8') <= 255 ? $this->_order->description : substr($this->_order->description, 0, 253) . '……']);
         return $ch;
     } catch (\Exception $e) {
         throw $e;
     }
 }
Esempio n. 3
0
 /**
  * @return bool|\Pingpp\Charge|CodeAutoCompletion\Charge
  * @throws \Exception
  */
 public function create()
 {
     if ($this->validate()) {
         $data = \Pingpp\Charge::create(['order_no' => $this->order_no, 'amount' => $this->amount, 'app' => ['id' => $this->getComponent()->appId], 'channel' => $this->channel, 'currency' => $this->currency, 'client_ip' => $this->client_ip, 'subject' => $this->subject, 'body' => $this->body, 'extra' => $this->extra]);
         return $data;
     }
     return false;
 }
Esempio n. 4
0
 /**
  * 创建订单,并返回charge对象
  *
  * @param string $tradeId 当前的交易ID,这里是支付的ID
  * @param int	$amount	交易金额,单位:分
  * @param string $channel 交易方式, alipay, upacp, wx
  *
  * @return object 一段可以被Json序列化的对象
  */
 public function createCharge($tradeId, $amount, $channel, $subject, $body, $desc)
 {
     //$ip = $_SERVER['HTTP_REMOTEIP'];
     $ip = $_SERVER['REMOTE_ADDR'];
     $conf = $this->getConf();
     $charge = \Pingpp\Charge::create(array('order_no' => $tradeId, 'amount' => $amount, 'app' => array('id' => $conf['appid']), 'channel' => $channel, 'currency' => 'cny', 'client_ip' => $ip, 'subject' => $subject, 'body' => $body, 'description' => $desc));
     return $charge->__toStdObject();
 }
Esempio n. 5
0
 /**
  * 重新支付
  * @return string
  * @author zhengqian@dajiayao.cc
  */
 public function rePay()
 {
     $buyerId = $this->buyerId;
     $wxUser = Buyer::find($buyerId)->wxUser;
     if (!$wxUser) {
         return RestHelp::encodeResult(24000, "user illegality");
     }
     $inputData = $this->inputData->all();
     $validator = Validator::make($inputData, ['orderNumber' => 'required']);
     if ($validator->fails()) {
         return RestHelp::parametersIllegal($validator->messages()->first());
     }
     $objOrder = Order::where('order_number', $inputData['orderNumber'])->first();
     $objShop = Shop::find($objOrder->shop_id);
     if (!$objShop) {
         return RestHelp::encodeResult(21000, sprintf("shop short id %s not found in db", $objOrder->shop_id));
     }
     //查找价格
     $itemTotal = $objOrder->item_total;
     $grandTotal = $objOrder->grand_total;
     $payment = new Payment();
     $payment->serial_number = OrderHelper::getPaymentSerialNumber(1);
     $payment->payment_number = '';
     $payment->order_id = $objOrder->id;
     $payment->order_number = $inputData['orderNumber'];
     $payment->buyer_id = $buyerId;
     $payment->amount = $itemTotal;
     $payment->channel = Payment::PAYMENT_CHANNEL_PXX;
     $payment->type = Payment::PAYMENT_TYPE_WX;
     $payment->status = Order::PAY_STATUS_NO;
     $payment->save();
     $subject = '';
     //32
     $body = '';
     //128
     foreach ($objOrder->orderItems as $orderItem) {
         $subject .= $orderItem->items->title . "*" . $orderItem->items->spec . "*" . $orderItem->quantity . ",";
         $body .= $orderItem->items->title . $orderItem->items->spec . $orderItem->quantity;
     }
     try {
         \Pingpp\Pingpp::setApiKey('sk_live_3dKEivmziedjzitFhaHL7gYF');
         $ch = \Pingpp\Charge::create(array('order_no' => $payment->serial_number, 'app' => array('id' => 'app_XTOW5SXTWLGCGKef'), 'channel' => 'wx_pub', 'amount' => $grandTotal * 100, 'client_ip' => $this->inputData->ip(), 'currency' => 'cny', 'subject' => mb_substr($subject, 0, 32), 'body' => mb_substr($body, 0, 128), 'extra' => array('open_id' => $wxUser->openid)));
     } catch (\Exception $e) {
         return RestHelp::encodeResult(22003, $e->getMessage(), ['orderNum' => $inputData['orderNumber']]);
     }
     //写入paytmentLOg
     $paymentLog = new PaymentLog();
     $paymentLog->payment_id = $payment->id;
     $paymentLog->channel = Payment::PAYMENT_CHANNEL_PXX;
     $paymentLog->request_data = $ch;
     $paymentLog->respond_data = '';
     $paymentLog->save();
     //保存支付流水号
     $payment->payment_number = json_decode($ch)->id;
     $payment->save();
     return RestHelp::success(['orderNumber' => $inputData['orderNumber'], 'paymentNumber' => $payment->serial_number, 'charge' => json_decode($ch, true)]);
 }
Esempio n. 6
0
 /**
  * @param $channel
  * @param $orderno
  * @param $amount
  * @param array $others
  * @param array|null $extra
  * @return Charge
  */
 public function create($channel, $orderno, $amount, array $others = array(), array $extra = null)
 {
     $config = array('channel' => $channel, 'order_no' => $orderno, 'amount' => $amount);
     if ($extra) {
         $config['extra'] = $extra;
     }
     $config = array_merge($config, $others, $this->config);
     $charge = Charge::create($config);
     return $charge;
 }
Esempio n. 7
0
 /**
  * Show the form for creating a new resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function pay()
 {
     \Pingpp\Pingpp::setApiKey('sk_test_urT4i5iPOCiHPmj5K0uLO0GK');
     $res = \Pingpp\Charge::create(array('order_no' => '0123456789', 'amount' => '100', 'app' => array('id' => 'app_9iLSeP8Oi5SGznbj'), 'channel' => 'upacp_pc', 'currency' => 'cny', 'client_ip' => '127.0.0.1', 'subject' => 'Your Subject', 'body' => 'Your Body', 'extra' => array('success_url' => 'http://www.jindanlan.com/')));
     \Debugbar::info($res);
     $content = $res;
     $status = 200;
     $value = "text/json";
     return response($content, $status)->header('Content-Type', $value);
 }
 private static function connectionCheck()
 {
     try {
         \Pingpp\Pingpp::setApiKey(static::$apiKey);
         \Pingpp\Charge::retrieve(static::$exampleChargeId);
     } catch (Exception $e) {
         if ($e instanceof \Pingpp\Error\ApiConnection) {
             throw $e;
         }
     }
 }
 /**
  * @author : Comer
  * @date   : 2015/4/20 16:20
  *
  * @desc     通过charge的ID查询支付状态
  * @param
  * @return   null
  */
 public function getPaystateById($chargeId)
 {
     //引入ping++类库文件
     require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/pingpp-php-master/init.php';
     \Pingpp\Pingpp::setApiKey(C('MYLINE_KEY'));
     $Charge = \Pingpp\Charge::retrieve($chargeId);
     $input_data = json_decode($Charge, true);
     if ($input_data['object'] == 'charge' && $input_data['paid'] == true) {
         return true;
     } else {
         if ($input_data['object'] == 'charge' && $input_data['paid'] == false) {
             return false;
         }
     }
 }
Esempio n. 10
0
<?php

/* *
 * Ping++ Server SDK
 * 说明:
 * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写, 并非一定要使用该代码。
 * 该代码仅供学习和研究 Ping++ SDK 使用,只是提供一个参考。
 */
require_once dirname(__FILE__) . '/../init.php';
\Pingpp\Pingpp::setApiKey('YOUR-KEY');
$ch = \Pingpp\Charge::retrieve('CHARGE_ID');
$ch->refunds->create(array('amount' => 10, 'description' => 'Your Descripton'));
Esempio n. 11
0
//ping++ part

//\Pingpp\Pingpp::setApiKey('sk_test_SSarLCPCi5eHanrLCOeH0ar5'); //测试key
\Pingpp\Pingpp::setApiKey('sk_live_GWD8WLDqbTOSqb9er5W9CGi5'); //真实key
$channel = strtolower("wx_pub");
$extra = array('open_id' => $t_openid);

try {
    $ch = \Pingpp\Charge::create(
        array(
            'subject'   => '2015中国企业家年会'.$subject,
            'body'      => $t_name.':'.$t_phone.':'.$t_address,
            'amount'    => $amount,
            'order_no'  => $orderNo,
            'currency'  => 'cny',
            'extra'     => $extra,
            'channel'   => $channel,
            'client_ip' => $_SERVER['REMOTE_ADDR'],
            'app'       => array('id' => 'app_90iv9CinvL40yDWT'),
            'time_expire' => $expire_time
        )
    );

    echo '"charge":'.$ch.'}';
} catch (\Pingpp\Error\Base $e) {
    header('Status: ' . $e->getHttpStatus());
    echo($e->getHttpBody());
}


mysqli_close($con);
Esempio n. 12
0
$orderNo = substr(md5(time()), 0, 12);
//$extra 在使用某些渠道的时候,需要填入相应的参数,其它渠道则是 array() .具体见以下代码或者官网中的文档。其他渠道时可以传空值也可以不传。
$extra = array();
switch ($channel) {
    case 'alipay_wap':
        $extra = array('success_url' => 'http://www.yourdomain.com/success', 'cancel_url' => 'http://www.yourdomain.com/cancel');
        break;
    case 'upmp_wap':
        $extra = array('result_url' => 'http://www.yourdomain.com/result?code=');
        break;
    case 'bfb_wap':
        $extra = array('result_url' => 'http://www.yourdomain.com/result?code=');
        break;
    case 'upacp_wap':
        $extra = array('result_url' => 'http://www.yourdomain.com/result?code=');
        break;
    case 'wx_pub':
        $extra = array('open_id' => 'Openid');
        break;
    case 'wx_pub_qr':
        $extra = array('product_id' => 'Productid');
        break;
}
\Pingpp\Pingpp::setApiKey('YOUR-KEY');
try {
    $ch = \Pingpp\Charge::create(array("subject" => "Your Subject", "body" => "Your Body", "amount" => $amount, "order_no" => $orderNo, "currency" => "cny", "extra" => $extra, "channel" => $channel, "client_ip" => $_SERVER["REMOTE_ADDR"], "app" => array("id" => "YOUR-APP-ID")));
    echo $ch;
} catch (\Pingpp\Error\Base $e) {
    header('Status: ' . $e->getHttpStatus());
    echo $e->getHttpBody();
}
Esempio n. 13
0
<?php

/* *
 * Ping++ Server SDK
 * 说明:
 * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写, 并非一定要使用该代码。
 * 该代码仅供学习和研究 Ping++ SDK 使用,只是提供一个参考。
 */
require dirname(__FILE__) . '/../init.php';
\Pingpp\Pingpp::setApiKey('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');
$ch = \Pingpp\Charge::retrieve('ch_a9CmfHTGGaz1urHiL8m5OiX1');
echo $ch;
Esempio n. 14
0
    case 'upacp_wap':
        $extra = array('result_url' => 'http://example.com/result');
        break;
    case 'wx_pub':
        $extra = array('open_id' => 'openidxxxxxxxxxxxx');
        break;
    case 'wx_pub_qr':
        $extra = array('product_id' => 'Productid');
        break;
    case 'yeepay_wap':
        $extra = array('product_category' => '1', 'identity_id' => 'your identity_id', 'identity_type' => 1, 'terminal_type' => 1, 'terminal_id' => 'your terminal_id', 'user_ua' => 'your user_ua', 'result_url' => 'http://example.com/result');
        break;
    case 'jdpay_wap':
        $extra = array('success_url' => 'http://example.com/success', 'fail_url' => 'http://example.com/fail', 'token' => 'dsafadsfasdfadsjuyhfnhujkijunhaf');
        break;
}
\Pingpp\Pingpp::setApiKey($api_key);
// 设置 API Key
try {
    $ch = \Pingpp\Charge::create(array('subject' => 'Your Subject', 'body' => 'Your Body', 'amount' => $amount, 'order_no' => $orderNo, 'currency' => 'cny', 'extra' => $extra, 'channel' => $channel, 'client_ip' => $_SERVER['REMOTE_ADDR'], 'app' => array('id' => $app_id)));
    echo $ch;
    // 输出 Ping++ 返回的支付凭据 Charge
} catch (\Pingpp\Error\Base $e) {
    // 捕获报错信息
    if ($e->getHttpStatus() != NULL) {
        header('Status: ' . $e->getHttpStatus());
        echo $e->getHttpBody();
    } else {
        echo $e->getMessage();
    }
}
Esempio n. 15
0
 /**
  * @param $chId
  * @return \Pingpp\Collection
  */
 protected function getRefunds($chId)
 {
     return Charge::retrieve($chId)->refunds;
 }
Esempio n. 16
0
<?php

/* *
 * Ping++ Server SDK
 * 说明:
 * 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写, 并非一定要使用该代码。
 * 该代码仅供学习和研究 Ping++ SDK 使用,只是提供一个参考。
 */
require dirname(__FILE__) . '/../init.php';
\Pingpp\Pingpp::setApiKey('sk_test_ibbTe5jLGCi5rzfH4OqPW9KC');
$ch = \Pingpp\Charge::retrieve('ch_ejbLGCCaDWjT0ijzDSybL0mT');
Esempio n. 17
0
 public function refund($chargeId, $orderprice, $description)
 {
     $charge = Charge::retrieve($chargeId);
     $charge->refunds->create(array('amount' => $orderprice, 'description' => $description));
     return $charge;
 }
Esempio n. 18
0
\Pingpp\Pingpp::setApiKey($api_key);

//配置私匙
// \Pingpp\Pingpp::setPrivateKeyPath('../rsa_private_key.pem');

//发起支付请求获取支付凭据
try {
    $ch = \Pingpp\Charge::create(
        array(
            'order_no'  => '123456232389',          //商户订单号,适配每个渠道对此参数的要求,必须在商户系统内唯一。(alipay: 1-64 位, wx: 1-32 位,bfb: 1-20 位,upacp: 8-40 位,yeepay_wap:1-50 位,jdpay_wap:1-30 位,cnp_u:8-20 位,cnp_f:8-20 位,推荐使用 8-20 位,要求数字或字母,不允许特殊字符
            'app'       => array('id' => $app_id),  //支付使用的 app 对象的 id,请登陆管理平台查看
            'channel'   => 'alipay_pc_direct',             //支付使用的第三方支付渠道
            'amount'    => 100,                     //订单总金额, 单位为对应币种的最小货币单位,例如:人民币为分(如订单总金额为 1 元,此处请填 100)
            'client_ip' => '127.0.0.1',             //发起支付请求终端的 IP 地址
            'currency'  => 'cny',                   //三位 ISO 货币代码,目前仅支持人民币 cny
            'subject'   => '电饭煲',                 //商品的标题,该参数最长为 32 个 Unicode 字符,银联全渠道(upacp/upacp_wap)限制在 32 个字节。
            'body'      => '煮饭用的',               //商品的描述信息,该参数最长为 128 个 Unicode 字符,yeepay_wap 对于该参数长度限制为 100 个 Unicode 字符。
            'extra'     => array(
                'success_url' => 'https://www.alihanniba.com/',
            ),
            'description' => 'sadfasff',            //订单附加说明,最多 255 个 Unicode 字符                                   //特定渠道发起交易时需要的额外参数以及部分渠道支付成功返回的额外参数。
        )
    );
    echo $ch;
} catch (\Pingpp\Error\Base $e) {
    header('Status: ' . $e->getHttpStatus());
    echo($e->getHttpBody());
}


Esempio n. 19
0
 /**
  * 生成订单
  * @return string
  * @author zhengqian@dajiayao.cc
  */
 public function create()
 {
     //        $inputData = $this->inputData->all();
     $buyerId = $this->buyerId;
     $wxUser = Buyer::find($buyerId)->wxUser;
     if (!$wxUser) {
         return RestHelp::encodeResult(24000, "user illegality");
     }
     $inputData = json_decode(file_get_contents("php://input"), true);
     $validator = Validator::make($inputData, ['shopShortId' => 'required', 'items' => 'required', 'deliverAddressId' => 'required', 'paymentType' => 'required', "shopType" => '', 'orderNumber' => '', "isAnonymous" => 'required|Boolean']);
     if ($validator->fails()) {
         return RestHelp::parametersIllegal($validator->messages()->first());
     }
     if (!isset($inputData['items']) or !is_array($inputData['items'])) {
         return RestHelp::encodeResult(23003, 'item must be array');
     }
     $objShop = Shop::getShopByShort($inputData['shopShortId']);
     if (!$objShop) {
         return RestHelp::encodeResult(21000, sprintf("shop short id %s not found in db", $inputData['shopShortId']));
     }
     $deliver = BuyerAddress::find($inputData['deliverAddressId']);
     if (!$deliver) {
         return RestHelp::encodeResult(23001, sprintf("deliver address id: %s not found in db", $inputData['deliverAddressId']));
     }
     if (!isset($inputData['orderNumber'])) {
         $orderNumber = OrderHelper::getOrderSerialNumber();
     } else {
         $orderNumber = $inputData['orderNumber'];
     }
     $deliverAddressId = $inputData['deliverAddressId'];
     $shopId = $objShop->id;
     $itemTotal = 0;
     $postageFlag = 0;
     $shelfItems = $objShop->getItemsOnShelf();
     //检查商品合法性、库存等等
     foreach ($inputData['items'] as $item) {
         if (!array_key_exists('id', $item) or !array_key_exists('count', $item)) {
             return RestHelp::encodeResult(23005, "items not correct");
         }
         $objItem = Item::find($item['id']);
         $itemTotal += $objItem->price * $item['count'];
         if ($objItem->postage_type == Item::POSTAGE_TYPE_BUYER) {
             $postageFlag++;
         }
         if ($objItem->sale_status == Item::SALE_STATUS_NO) {
             return RestHelp::encodeResult(23006, sprintf("%s已停售", $objItem->title));
         }
         if ($objItem->shelf_status == Item::SHELF_STATUS_NO or !array_key_exists($objItem->id, $shelfItems)) {
             return RestHelp::encodeResult(23006, sprintf("%s已下架", $objItem->title));
         }
         //库存
         if ($objItem->stock < $item['count']) {
             return RestHelp::encodeResult(23006, sprintf("%s库存不足", $objItem->title));
         }
     }
     $postage = $postageFlag ? $this->settingService->getSettingByKey(Setting::KEY_ORDER_POSTAGE)->value : 0;
     $grandTotal = $itemTotal + $postage;
     $sessionTotal = WxUserKv::getValue(Buyer::find($this->buyerId)->wxUser->id, WxUserKv::BUYER_CHECK_PRICE);
     if ((string) $sessionTotal != (string) $grandTotal) {
         return RestHelp::encodeResult(22002, "illegal operation");
     }
     $discount = 0;
     $orderType = Order::PAYMENT_TYPE_WX;
     //如果传入了订单号
     if (isset($inputData['orderNumber'])) {
         //update
         $objOrder = Order::where('order_number', $inputData['orderNumber'])->first();
         if (!$objOrder) {
             return RestHelp::encodeResult(22001, "the order not found");
         }
         //new
         try {
             $orderId = $this->orderService->update($objOrder, $itemTotal, $grandTotal, $discount, $grandTotal - $discount, $inputData['isAnonymous'] ? 1 : 0, $postage, $orderType, $deliverAddressId);
         } catch (\Exception $e) {
             return RestHelp::encodeResult(23004, $e->getMessage());
         }
     } else {
         //new
         try {
             $orderId = $this->orderService->create($orderNumber, $shopId, $this->buyerId, $itemTotal, $grandTotal, $discount, $grandTotal - $discount, $postage, $orderType, $deliverAddressId, $inputData['isAnonymous'] ? 1 : 0, null, null);
         } catch (\Exception $e) {
             return RestHelp::encodeResult(23004, $e->getMessage());
         }
         //减少库存
         $commissonTotal = 0;
         foreach ($inputData['items'] as $item) {
             $objItem = Item::find($item['id']);
             $objItem->stock -= $item['count'];
             $objItem->save();
             //计算挨个佣金
             $commissonTotal += $objItem->commission * $item['count'];
         }
         //生成佣金表数据
         $commisson = OrderCommission::firstOrNew(['order_id' => $orderId]);
         $commisson->amount = $objShop->is_direct_sale == 'Y' ? 0 : $commissonTotal;
         $commisson->status = OrderCommission::STATUS_UNCONFIRMED;
         $commisson->save();
         //生成seller commisson
         $sellerCommission = SellerCommission::firstOrNew(['order_id' => $orderId, 'seller_id' => $objShop->seller_id]);
         $sellerCommission->amount = $objShop->is_direct_sale == 'Y' ? 0 : $commissonTotal;
         $sellerCommission->status = SellerCommission::STATUS_UNCONFIRMED;
         $sellerCommission->save();
     }
     $subject = '';
     //32
     $body = '';
     //128
     $itemIdList = \DB::table('order_items')->where('order_id', $orderId)->lists('item_id');
     foreach ($inputData['items'] as $item) {
         if (isset($inputData['orderNumber'])) {
             $orderItem = OrderItem::where('order_id', $orderId)->where('item_id', $item['id'])->first();
             $quantity = $orderItem ? $orderItem->quantity : 0;
             $count = $item['count'];
             $balance = $count - $quantity;
             $objItem = Item::find($item['id']);
             $objItem->stock -= $balance;
             $objItem->save();
             OrderItem::where('order_id', $orderId)->where('item_id', $item['id'])->forceDelete();
             //如果支付失败,返回修改删除了某个商品,则恢复库存 Step 1  @author zhengqian
             foreach ($itemIdList as $k => $itid) {
                 if ($item['id'] == $itid) {
                     unset($itemIdList[$k]);
                 }
             }
         }
         $orderItem = new OrderItem();
         $orderItem->order_id = $orderId;
         $orderItem->item_id = $item['id'];
         $objItem = Item::find($item['id']);
         $orderItem->name = $objItem->name;
         $subject .= $objItem->title . "*" . $objItem->spec . "*" . $objItem->{$item}['count'] . ",";
         $body .= $objItem->title . $objItem->spec . $objItem->{$item}['count'];
         $orderItem->title = $objItem->title;
         $orderItem->code = $objItem->code;
         $orderItem->barcode = $objItem->barcode;
         $orderItem->type = ItemType::find($objItem->type_id)->name;
         $orderItem->quantity = $item['count'];
         $orderItem->price = $objItem->price;
         $orderItem->item_total = $objItem->price * $item['count'];
         $commissionsRate = $this->settingService->getSettingByKey(Setting::KEY_COMMISSIONS_RATE);
         if (!$commissionsRate) {
             $commissionsRate = Setting::DEFAULT_KEY_COMMISSIONS_RATE;
         } else {
             $commissionsRate = $commissionsRate->value;
         }
         $orderItem->commission = $orderItem->item_total * $commissionsRate;
         $orderItem->save();
     }
     //如果支付失败,返回修改删除了某个商品,则恢复库存 Step 2 @author zhengqian
     if (isset($inputData['orderNumber'])) {
         foreach ($itemIdList as $itid) {
             $orderItem = OrderItem::where('order_id', $orderId)->where('item_id', $itid)->first();
             $quantity = $orderItem->quantity;
             $objItem = Item::find($itid);
             $objItem->stock += $quantity;
             $objItem->save();
             OrderItem::where('order_id', $orderId)->where('item_id', $itid)->forceDelete();
         }
     }
     $payment = new Payment();
     $payment->serial_number = OrderHelper::getPaymentSerialNumber(1);
     $payment->payment_number = '';
     $payment->order_id = $orderId;
     $payment->order_number = Order::find($orderId)->order_number;
     $payment->buyer_id = $this->buyerId;
     $payment->amount = $itemTotal;
     $payment->channel = Payment::PAYMENT_CHANNEL_PXX;
     $payment->type = Payment::PAYMENT_TYPE_WX;
     $payment->status = Order::PAY_STATUS_NO;
     $payment->save();
     try {
         \Pingpp\Pingpp::setApiKey('sk_live_3dKEivmziedjzitFhaHL7gYF');
         $ch = \Pingpp\Charge::create(array('order_no' => $payment->serial_number, 'app' => array('id' => 'app_XTOW5SXTWLGCGKef'), 'channel' => 'wx_pub', 'amount' => $sessionTotal * 100, 'client_ip' => $this->inputData->ip(), 'currency' => 'cny', 'subject' => mb_substr($subject, 0, 32), 'body' => mb_substr($body, 0, 128), 'extra' => array('open_id' => $wxUser->openid)));
     } catch (\Exception $e) {
         return RestHelp::encodeResult(22003, $e->getMessage(), ['orderNum' => $orderNumber]);
     }
     //写入paytmentLOg
     $paymentLog = new PaymentLog();
     $paymentLog->payment_id = $payment->id;
     $paymentLog->channel = Payment::PAYMENT_CHANNEL_PXX;
     $paymentLog->request_data = $ch;
     $paymentLog->respond_data = '';
     $paymentLog->save();
     //保存支付流水号
     $payment->payment_number = json_decode($ch)->id;
     $payment->save();
     return RestHelp::success(['orderNumber' => $orderNumber, 'paymentNumber' => $payment->serial_number, 'charge' => json_decode($ch, true)]);
 }
Esempio n. 20
0
 /**
  * [check_charge 查询支付]
  * @param  [type] $charge_id [支付id]
  * @return [type]            [description]
  */
 private function check_charge($charge_id)
 {
     try {
         $charge = \Pingpp\Charge::retrieve($charge_id);
         $charge = json_decode($charge);
         if (isset($charge->paid)) {
             if ($charge->paid) {
                 return $charge;
             }
         }
         return FALSE;
     } catch (\Pingpp\Error\Base $e) {
         return FALSE;
     }
 }
 public function promotion_pay()
 {
     $api_key = C('API_KEY');
     $api_id = C('API_ID');
     $input_data = json_decode(file_get_contents('php://input'), true);
     if (empty($input_data['channel']) || empty($input_data['amount'])) {
         echo 'channel or amount is empty';
         exit;
     }
     $channel = strtolower($input_data['channel']);
     $submission_id = $input_data['submission_id'];
     $amount = 0;
     $choice1 = $input_data['choice1'];
     if ($choice1 == '1a') {
         $amount = 3000;
     } elseif ($choice1 == '1b') {
         $amount = 8000;
     } elseif ($choice1 == '1c') {
         $amount = 12000;
     } elseif ($choice1 == '1d') {
         $amount = 18000;
     }
     $choice2 = $input_data['choice2'];
     $prices = [3000, 15000, 10000, 1000, 5000, 12000, 500, 200];
     $promotion = $choice1;
     for ($i = 0; $i < count($choice2); $i++) {
         $amount += $choice2[$i] * $prices[$i];
         $promotion .= ',' . $choice2[$i];
     }
     $amount *= 100;
     if ($_SESSION['urole'] == 2) {
         $amount = 1;
     }
     $orderNo = $input_data['order_no'];
     M('promotion')->where(array('contest_id' => C('CONTESTID'), 'user_id' => $_SESSION['uid'], 'submission_id' => $submission_id, 'promotion' => $promotion, 'price' => $amount / 100, 'ispaied' => 0))->delete();
     M('promotion')->data(array('contest_id' => C('CONTESTID'), 'user_id' => $_SESSION['uid'], 'submission_id' => $submission_id, 'promotion_code' => $orderNo, 'promotion' => $promotion, 'timestamp' => time(), 'price' => $amount / 100))->add();
     \Pingpp\Pingpp::setPrivateKeyPath('Public/rsa_private_key.pem');
     /**
      * $extra 在使用某些渠道的时候,需要填入相应的参数,其它渠道则是 array()。
      * 以下 channel 仅为部分示例,未列出的 channel 请查看文档 https://pingxx.com/document/api#api-c-new
      */
     $extra = array();
     $extra['context'] = 'promotion';
     $extra['submission_id'] = $submission_id;
     switch ($channel) {
         case 'alipay_wap':
             $extra = array('success_url' => C('SITE_PREFIX') . U('Pay/promotion_pay_success', array('submission_id' => $submission_id, 'promotion_code' => $orderNo)), 'cancel_url' => C('SITE_PREFIX') . U('Pay/promotion_pay_cancel', array('submission_id' => $submission_id, 'promotion_code' => $orderNo)));
             break;
         case 'bfb_wap':
             $extra = array('result_url' => 'http://example.com/result', 'bfb_login' => true);
             break;
         case 'upacp_wap':
             $extra = array('result_url' => 'http://example.com/result');
             break;
         case 'wx_pub':
             $extra = array('open_id' => 'openidxxxxxxxxxxxx');
             break;
         case 'wx_pub_qr':
             $extra = array('product_id' => 'Productid');
             break;
         case 'yeepay_wap':
             $extra = array('product_category' => '1', 'identity_id' => 'your identity_id', 'identity_type' => 1, 'terminal_type' => 1, 'terminal_id' => 'your terminal_id', 'user_ua' => 'your user_ua', 'result_url' => 'http://example.com/result');
             break;
         case 'jdpay_wap':
             $extra = array('success_url' => 'http://example.com/success', 'fail_url' => 'http://example.com/fail', 'token' => 'dsafadsfasdfadsjuyhfnhujkijunhaf');
             break;
     }
     $subject = '成功设计大赛作品推广 ' . $submission_id;
     \Pingpp\Pingpp::setApiKey($api_key);
     try {
         $ch = \Pingpp\Charge::create(array('subject' => $subject, 'body' => '快来支付吧', 'amount' => $amount, 'order_no' => $orderNo, 'currency' => 'cny', 'extra' => $extra, 'channel' => $channel, 'client_ip' => get_client_ip(), 'app' => array('id' => $api_id)));
         echo $ch;
     } catch (\Pingpp\Error\Base $e) {
         // 捕获报错信息
         if ($e->getHttpStatus() != NULL) {
             header('Status: ' . $e->getHttpStatus());
             echo $e->getHttpBody();
         } else {
             echo $e->getMessage();
         }
     }
 }
Esempio n. 22
0
 public function payTestOp()
 {
     \Pingpp\Pingpp::setApiKey('sk_test_vP8WX9KKG4CSmfDGCSPm1WTO');
     $extra = array();
     try {
         $ch = \Pingpp\Charge::create(array('order_no' => '123456789233', 'app' => array('id' => 'app_u1yjzHbvvLeLybbT'), 'channel' => 'alipay', 'amount' => 100, 'client_ip' => '127.0.0.1', 'currency' => 'cny', 'subject' => 'Your Subject', 'body' => 'Your Body', 'extra' => $extra));
         echo $ch;
     } catch (\Pingpp\Error\Base $e) {
         header('Status: ' . $e->getHttpStatus());
         echo $e->getHttpBody();
     }
 }
Esempio n. 23
0
 /**
  * 支付订单1
  */
 public function payOrderStep1Op()
 {
     \Pingpp\Pingpp::setApiKey('sk_test_vP8WX9KKG4CSmfDGCSPm1WTO');
     $mod_order = Model('service_yuyue_api');
     $mod_service = Model('service');
     //获取appId
     $appId = $_POST['appId'];
     $yuyueId = $_GET['yuyue_id'];
     //根据服务预约id找出记录
     $where['yuyue_id'] = $yuyueId;
     $order = $mod_order->getOne($where);
     $serviceId = $order['yuyue_service_id'];
     $service = $mod_service->getOne(array('service_id' => $serviceId));
     //取出支付订单id
     $orderId = $order['yuyue_pay_number'];
     //取出订单金额
     $amount = $service['service_now_price'] * 100;
     //取出交易名称
     $orderName = "[科研助手]" . $service['service_name'];
     //交易描述
     $orderDesc = $service['service_name'];
     //获取请求ip
     $clientIp = "";
     //获取支付方式
     $channel = $_POST['channel'];
     //        'app_u1yjzHbvvLeLybbT'
     $extra = array();
     try {
         $ch = \Pingpp\Charge::create(array('order_no' => $orderId, 'app' => array('id' => $appId), 'channel' => 'alipay', 'amount' => $amount, 'client_ip' => $clientIp, 'currency' => 'cny', 'subject' => $orderName, 'body' => $orderDesc, 'extra' => $extra));
         echo $ch;
     } catch (\Pingpp\Error\Base $e) {
         header('Status: ' . $e->getHttpStatus());
         echo $e->getHttpBody();
     }
 }
Esempio n. 24
0
 function isPaid()
 {
     $chargeId = $this->post_data->chargeId;
     try {
         $res = \Pingpp\Charge::retrieve($chargeId);
         $isPaid = $res->__toArray()['paid'];
         if ($isPaid) {
             $this->echo_msg(true);
         } else {
             $this->echo_msg(false, 'UNPAID');
         }
     } catch (Exception $e) {
         $this->echo_msg(false);
     }
 }