亚洲国产精品成人无码区,公天天吃我奶躁我的比视频,亚洲国产欧美视频亚洲国产精品一区二区成人片不卡,天天躁日日躁狠狠躁视频2021,起视碰看97视频在线少妇久久久久久人妻无码, 芒果乱码一线二线三线新区 ,亚洲熟妇无码AⅤ不卡在线播放,人妻少妇乱子伦无码专区

400-800-9385
網(wǎng)站建設(shè)資訊詳細

商城網(wǎng)站對接paypal支付接口

發(fā)表日期:2023-07-18 17:18:05   作者來源:劉紅旺   瀏覽:2063   標(biāo)簽:商城網(wǎng)站建設(shè)    
第一步申請賬號:

1.注冊paypal開發(fā)者賬號  
 

paypal支付


 
2.創(chuàng)建自己的應(yīng)用
live:是上線模式
sendbox:沙盒模式

創(chuàng)建應(yīng)用
 

paypal沙盒
 

 

 

 


 
3. 獲取client id和 client secret

 獲取密鑰
 
4.創(chuàng)建支付訂單
 
初始化參數(shù)
   public function _initialize()
    {
        parent::_initialize();
        $PaymentModel = new PaymentModel();
       
        $config = $PaymentModel->getCacheClass('paypal');
        //dump($config);exit;
        if(empty($config)) {
            echo '支付參數(shù)未配置!';
            exit();
        } else {
            $this->clientId =   $config['app_id'];
            $this->clientSecret = $config['app_key'];
        }
       
        $request = Request::instance();
        $base_url = $request->domain();
 
        $this->accept_url = $base_url.'/paypal/callback';//回調(diào)地址
     
       
        $this->PayPal = new ApiContext(
            new OAuthTokenCredential(
                $this->clientId,
                $this->clientSecret
            )
        );
       // 如果是沙盒測試環(huán)境不設(shè)置,請注釋掉
        $this->PayPal->setConfig(
            array(
              'mode' => 'live',
            )
        );
    }
 
生成訂單并且跳轉(zhuǎn)到paypal
 public function pay($product, $price, $shipping = 0, $description,$currency)
    {
        $paypal = $this->PayPal;
 
        $total = $price + $shipping;//總價
 
        $payer = new Payer();
        $payer->setPaymentMethod('paypal');
 
        $item = new Item();
        $item->setName($product)->setCurrency($currency)->setQuantity(1)->setPrice($price);
 
        $itemList = new ItemList();
        $itemList->setItems([$item]);
 
        $details = new Details();
        $details->setShipping($shipping)->setSubtotal($price);
 
        $amount = new Amount();
        $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
 
        $transaction = new Transaction();
        $transaction->setAmount($amount)->setItemList($itemList)->setDescription($description)->setInvoiceNumber(uniqid());
 
        $redirectUrls = new RedirectUrls();
        // $redirectUrls->setReturnUrl(self::accept_url . '?success=true')->setCancelUrl(self::accept_url . '/?success=false');
        $redirectUrls->setReturnUrl($this->accept_url .'?success=true')->setCancelUrl($this->accept_url .'?success=false');
 
        $payment = new Payment();
        $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]);
        try {
            $payment->create($paypal);
        } catch (PayPalConnectionException $e) {
            echo $e->getData();
            die();
        }
 
        $approvalUrl = $payment->getApprovalLink();
        //echo $approvalUrl;
        $this->redirect($approvalUrl);
        //header("Location:{$approvalUrl}");
    }
 
 
 /**
     * 回調(diào)
     */
    public function callback()
    {
        // 修改訂單狀態(tài)
        $success = trim($_GET['success']);
 
        if ($success == 'false' && !isset($_GET['paymentId']) && !isset($_GET['PayerID'])) {
           $this->error('Cancal Pay!!', 'member/order');
        }
 
        $paymentId = trim($_GET['paymentId']);
        $PayerID = trim($_GET['PayerID']);
 
        if (!isset($success, $paymentId, $PayerID)) {
            echo 'Failure to pay。';
            exit();
        }
 
        if ((bool)$_GET['success'] === 'false') {
            echo 'Failure to pay,payment ID【' . $paymentId . '】,Payer ID【' . $PayerID . '】';
            exit();
        }
 
        $payment = Payment::get($paymentId, $this->PayPal);
 
        $execute = new PaymentExecution();
 
        $execute->setPayerId($PayerID);
 
        try {
            $data = $payment->execute($execute, $this->PayPal);
           
            $data_arr = $data->toArray();
           
         
            $order_no = $data_arr['transactions'][0]['description'];
            $total_money = $data_arr['transactions'][0]['amount']['total'];
            // 實例化訂單模型
            $model = $this->getOrderModel($order_no, OrderTypeEnum::MASTER);
            // 訂單信息
            $order = $model->getOrderInfo();
            if(empty($order)){
               echo 'Order not exist';
            }
            $update_data['transaction_id'] = $paymentId;
           
           
            $status = $model->onPaySuccess(PayTypeEnum::PAYPAL, $update_data);
            if ($status == false) {
                echo $model->getError();
            }
        } catch (Exception $e) {
            $this->error('Pay Error!', 'member/order');
           
            //echo $e . ',支付失敗,支付ID【' . $paymentId . '】,支付人ID【' . $PayerID . '】';
            //exit();
        }
}
       
       
 
 
跳轉(zhuǎn)成功后,登入選擇支付卡號就可以了

商城支付
 
如沒特殊注明,文章均為方維網(wǎng)絡(luò)原創(chuàng),轉(zhuǎn)載請注明來自http://www.oulysa.com/news/6831.html
相關(guān)網(wǎng)站設(shè)計案例
亚洲综合伊人色一区| 国产9i精品女同一区二区| 国产成人综合亚洲av第一页| 真实国产乱子伦高清对白直播| 精品动漫在线一区二区在线| 欧美日韩精品一区二区在线播放| 清纯唯美亚洲综合欧美色| 亚洲视频中文字幕| 亚洲中文字幕无码永久免弗| 久久婷婷五月综合色精品 | 亚洲欧美日韩另类小说| 国产在线精品观看免费观看| 国产欧美日韩综合视频在线观看| AⅤ毛片手机免播放器| 国产一区二区内射最近更新| 日韩精品一区二区三区中文| 久久亚洲精品国产av| 露脸国产自产拍在线观看| 久久国产亚洲观看| 一级黄色网站免费在线观看| 亚洲欧美二区绝色浪潮性色| 久久久久国产精品人妻AⅤ麻豆| 在线看片免费人成视久网| 国产成人无码精品一区在线观看| 久久久无码精品亚洲日韩链接| 中文字幕一区二区AⅤ无码| 亚洲成A∨人片在线观看不卡| 国产成人精品手机在线观看| 日韩精品一区二区三区中文| 国产在线精品一区亚洲毛片免费一级| 国产区综合精品国产www| 亚洲最大的黄色网站Av| 强被迫伦姧惨叫在线视频| 亚洲国产精品悠悠久久琪琪| 亚洲国产精品专区久久综合播放网站| a级情欲片在线观看| 男女激情爽爽爽无限看片的视频| 亚洲精品无码国产123| 亚洲AV午夜成人片精品网站| 亚洲天码中文字幕第一页| 亚洲中文精品久久久久久|