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

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

外貿(mào)獨(dú)立站商城之Stripe境外支付接口對(duì)接

發(fā)表日期:2022-01-12 15:07:05   作者來源:劉紅旺   瀏覽:3635   標(biāo)簽:外貿(mào)獨(dú)立站商城    Stripe境外支付    
外貿(mào)獨(dú)立站是做外貿(mào)的公司自己開設(shè)的獨(dú)立品牌商城,主要區(qū)別于商城平臺(tái)如亞馬遜、阿里巴巴等,優(yōu)點(diǎn)是自己的地盤自己說了算,缺點(diǎn)是需要自己推廣引流,適合有一定品牌的商家。

大部分外貿(mào)公司都是兩者都做,從商品平臺(tái)推廣獲客,然后把流量引入自己的品牌商城,打造自己的私域流量商城。

Stripe支付公司是由一對(duì)來自愛爾蘭的天才兄弟Collison Brothers一手創(chuàng)辦的,他們表示隨著美國(guó)最大的民營(yíng)金融科技公司進(jìn)入小企業(yè)貸款領(lǐng)域,新一輪融資使其價(jià)值增加了一半以上。
KlipC分析稱,Stripe的商業(yè)模式主要是梳理目前有的支付方式,將不同的支付方式打包成一套SDK接口,通過整體接入,降低用戶的接入成本,以收取手續(xù)費(fèi)或者服務(wù)盈利。目前在金融行業(yè),很多公司已經(jīng)采用了Stripe的支付通道,比起傳統(tǒng)通道,Stripe效率更高,成本更低。
 

支付工具份額

第一步:安裝類庫
composer require stripe/stripe-php
 
第二步后臺(tái)控制器:
 function create (){
      
        \Stripe\Stripe::setApiKey($this->clientSecret);//私鑰
        try {
            $jsonStr = file_get_contents('php://input');
            $jsonObj = json_decode($jsonStr);//獲取頁面參數(shù)
            $arr=object_array($jsonObj);//轉(zhuǎn)換為數(shù)組
            $order_id=$arr['items'][0]['order_id'];//訂單單號(hào)
            $order = db('order')->where('order_id', $order_id)->find();//查找訂單
            //訂單是否存在和支付狀態(tài)
            if(empty($order)) {
                echo "can't find order!";
                exit();
            }
             if($order['pay_status'] == 20) {
                echo  'The order was paid!';
                exit();
            }
            
            $request = Request::instance();
            $base_url = $request->domain();//獲取網(wǎng)址
            $time=time();
            //判斷支付訂單是不是已經(jīng)生成
            if(!$order['stripe_pay'] || $time-$order['stripe_time']>30*60){
                $currency_list = ExchangeRateModel::getFront();
                $currency = $currency_list['code'];
                $total_amount_currency =  $order['pay_price'];
                $paymentIntent = \Stripe\PaymentIntent::create([
                    'amount' =>  $total_amount_currency*100,//訂單金額
                    'currency' => $currency,
                    'automatic_payment_methods' => [
                        'enabled' => true,
                    ],
                ]);
                $output = [
                    'clientSecret' => $paymentIntent->client_secret,
                ];
                 
                $transaction=explode('_secret_',$paymentIntent->client_secret);//記錄生成的支付單號(hào),單號(hào)后面會(huì)加‘單號(hào)_secret_安全碼’
                $transaction_id=$transaction[0];
                db('order')->where('order_id',$order_id)->update(['stripe_pay' => $paymentIntent->client_secret,'stripe_time'=>$time,'transaction_id'=>$transaction_id]);//記錄單號(hào)
            }else{
                $output = [
                    'clientSecret' => $order['stripe_pay'],
                ];
 
            }
            // Create a PaymentIntent with amount and currency
       
          
            echo json_encode($output);
        } catch (Error $e) {
            http_response_code(500);
            echo json_encode(['error' => $e->getMessage()]);
        }
    }
 
 
三,前端
    <link rel="stylesheet" href="__STATIC__/css/style.css">
    <link rel="stylesheet" href="__STATIC__/css/checkout.css">
    <script src="https://js.stripe.com/v3/"></script>
    <script>
    var order_id="{$order_id}" //訂單號(hào)
    var URL="/home/Stripepay"
    var key="{$key}"
    var base_url="{$base_url}";
    </script>
    <script src="__STATIC__/js/checkout.js" defer></script>
  
 
    <form id="payment-form">
        <div id="payment-element">
          <!--Stripe.js injects the Payment Element-->
        </div>
        <button id="submit">
          <div class="spinner hidden" id="spinner"></div>
          <span id="button-text">Pay now</span>
        </button>
        <div id="payment-message" class="hidden"></div>
      </form>
 
Checout.js
     // This is your test publishable API key.
const stripe = Stripe(key);//公鑰
 
// The items the customer wants to buy
const items = [{ id: "xl-tshirt",order_id:order_id }];
 
let elements;
 
initialize();
checkStatus();
 
document
  .querySelector("#payment-form")
  .addEventListener("submit", handleSubmit);
 
// Fetches a payment intent and captures the client secret
async function initialize() {
  const { clientSecret } = await fetch(URL+"/create", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ items }),
  }).then(res => res.json()) ;
 
  elements = stripe.elements({ clientSecret });


  const paymentElement = elements.create("payment");
  paymentElement.mount("#payment-element");
}
 
async function handleSubmit(e) {
  e.preventDefault();
  setLoading(true);
  console.log(elements);
  const { error } = await stripe.confirmPayment({
    elements,
    confirmParams: {
      // Make sure to change this to your payment completion page
      return_url: base_url+URL+"/successful.html",//成功后,回跳地址
    },
  });
 
  // This point will only be reached if there is an immediate error when
  // confirming the payment. Otherwise, your customer will be redirected to
  // your `return_url`. For some payment methods like iDEAL, your customer will
  // be redirected to an intermediate site first to authorize the payment, then
  // redirected to the `return_url`.
  if (error.type === "card_error" || error.type === "validation_error") {
    showMessage(error.message);
  } else {
    showMessage("An unexpected error occured.");
  }
 
  setLoading(false);
}
 
// Fetches the payment intent status after payment submission
async function checkStatus() {
  const clientSecret = new URLSearchParams(window.location.search).get(
    "payment_intent_client_secret"
  );
 
  if (!clientSecret) {
    return;
  }
 
  const { paymentIntent } = await stripe.retrievePaymentIntent(clientSecret);
 
  switch (paymentIntent.status) {
    case "succeeded":
      showMessage("Payment succeeded!");
      break;
    case "processing":
      showMessage("Your payment is processing.");
      break;
    case "requires_payment_method":
      showMessage("Your payment was not successful, please try again.");
      break;
    default:
      showMessage("Something went wrong.");
      break;
  }
}
 
// ------- UI helpers -------
 
function showMessage(messageText) {
  const messageContainer = document.querySelector("#payment-message");
 
  messageContainer.classList.remove("hidden");
  messageContainer.textContent = messageText;
 
  setTimeout(function () {
    messageContainer.classList.add("hidden");
    messageText.textContent = "";
  }, 4000);
}
 
// Show a spinner on payment submission
function setLoading(isLoading) {
  if (isLoading) {
    // Disable the button and show a spinner
    document.querySelector("#submit").disabled = true;
    document.querySelector("#spinner").classList.remove("hidden");
    document.querySelector("#button-text").classList.add("hidden");
  } else {
    document.querySelector("#submit").disabled = false;
    document.querySelector("#spinner").classList.add("hidden");
    document.querySelector("#button-text").classList.remove("hidden");
  }
}
 
在平臺(tái)付款可以看到支付信息
 

Stripe境外支付事件


四,獲取支付狀態(tài):
webhooks

Stripe支付狀態(tài)

添加回調(diào)地址和事件
charge.succeeded-支付成功后

Stripe支付結(jié)果

 
需要密鑰
 
五、獲取回調(diào)信息,控制器
 public function callback()
    {
        $endpoint_secret = '密鑰';//;
       
        $payload = @file_get_contents('php://input');
        $sig_header = $_SERVER['HTTP_STRIPE_SIGNATURE'];
        $event = null;
       
        if( $payload){
        try {
          
            $event = \Stripe\Webhook::constructEvent(
                $payload, $sig_header, $endpoint_secret
              );
        }catch(\Stripe\Exception\SignatureVerificationException $e) {
            // Invalid signature
            http_response_code(400);
            exit();
          }
        }
        $log_name = "notify_url.log";
        $this->log_result($log_name, 'pay-start|--'.$event->data->object->paymentIntent.'--|');
 
        // Handle the event
        switch ($event->type) {
            case 'charge.succeeded':
                $paymentIntent = $event->data->object; 
                //$payment=json_decode($paymentIntent);
                $payID=$paymentIntent->payment_intent; 
                $order_no=db('order')->where('transaction_id',$payID)->value('order_no');
                try {
                    $total_money =  $event->amount/100;
                    // 實(shí)例化訂單模型
                    $model = $this->getOrderModel($order_no, 10);
                    // 訂單信息
                    $order = $model->getOrderInfo();
                    if(empty($order)){
                       echo 'Order not exist';
                    }
                    $update_data['transaction_id'] = $payID;
                    $status = $model->onPaySuccess(20, $update_data);
                    $this->log_result($log_name, 'order_no:'.$order_no.'pay|--'.   $paymentIntent->payment_intent.'--|'.'status:'.$status);
                    if ($status == false) {
                        echo $model->getError();
                    }
                } catch (Exception $e) {
                    $this->error('Pay Error!', 'home/member/order');
                    
                    //echo $e . ',支付失敗,支付ID【' . $paymentId . '】,支付人ID【' . $PayerID . '】';
                    //exit();
                }
                
                
                break;
            case 'charge.attached':
                $paymentMethod = $event->data->object; 
                $this->log_result($log_name, 'pay-attached|--'.$event->type.'--|');
                break;
            // ... handle other event types
            default:
            $this->log_result($log_name, 'pay-fail|--'.$event->type.'--|');
            echo 'Received unknown event type '.$event->type ;
        }
    
       
 
    }
 
如沒特殊注明,文章均為方維網(wǎng)絡(luò)原創(chuàng),轉(zhuǎn)載請(qǐng)注明來自http://www.oulysa.com/news/6325.html
国产精品高潮呻吟久久av无码午夜鲁丝片| 亚洲人成网站观看在线播放| 2021AAVV年本站提供91久久精品| 免费又黄又爽a片免费看| 久久99精品久久久久久hb| 国产户外野战无码播放在线观看| 丰满少妇大叫太大太粗| 日韩精品在线观看| 精品熟人妻一区二区三区四区不卡| 久久亚洲色一区二区三区,| 亚洲欧美韩国日产综合在线| 久久婷婷五月综合97色直播| 国产凸凹视频一区二区| 天堂网www中文天堂在线| 中文字幕一级黄色电影| 精品国产免费人成在线观看| 国产成人综合久久亚洲精品| 最新日韩欧美不卡一二三区| 色噜噜综合亚洲av中文无码| 女性私人爽爽影院免费观看国产| 日韩中文字幕AV亚洲不卡在线视频| 色橹橹欧美在线观看视频高清| 国产午夜精品一区二区| 日本一区二区淫秽网| 久久久久久国产精品免费免| 亚洲区欧美区综合区自拍区| 亚洲精品无码久久久| 亚洲av中文无码乱人伦在线r| 大学生被内谢粉嫩无套| 亚洲国产天堂在线观看| 亚洲中文久久精品无码| 久久久精品国产亚洲综合久久久国产中文字幕免费| 极品新婚夜少妇真紧| 国产欧美精品在线一区二区三区| a级片在线秋霞影音先锋一区二区| 亚洲欧洲日韩一区三区四区| 中文无码人妻制服丝袜AⅤ久久| 精品久久久久中文字幕加勒比| 久久综合一区二区三区| 无码aⅴ免费中文字幕久久| 2021国产成人精品无码|