亚洲精品www久久久久久,国产乱码精品一区二区三,另类国产精品一区二区,国产av无码专区亚洲草草,无码日韩精品91超碰,玩弄放荡人妻少妇系列,欧洲美女黑人粗性暴交视频,一区二区三区四区五区自拍

    服務熱線 400-660-5555 (轉1)

    網站建設

    網站建設

    站內資訊
    網站建設 / 站內資訊 / 行業資訊 / 正文

    外貿獨立站商城之Stripe境外支付接口對接

    來源: All文章
    發布時間:2023-03-23 15:33:09

      外貿獨立站是做外貿的公司自己開設的獨立品牌商城,主要區別于商城平臺如亞馬遜、阿里巴巴等,優點是自己的地盤自己說了算,缺點是需要自己推廣引流,適合有一定品牌的商家。

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

      Stripe支付公司是由一對來自愛爾蘭的天才兄弟CollisonBrothers一手創辦的,他們表示隨著美國最大的民營金融科技公司進入小企業領域,新一輪融資使其價值增加了一半以上。

      KlipC分析稱,Stripe的商業模式主要是梳理目前有的支付方式,將不同的支付方式打包成一套SDK接口,通過整體接入,降低用戶的接入成本,以收取手續費或者服務盈利。目前在金融行業,很多公司已經采用了Stripe的支付通道,比起傳統通道,Stripe效率更高,成本更低。

      第一步:安裝類庫

      composerrequirestripe/stripe-ph

      第二步后臺控制器:

      functioncreate(){

      \Stripe\Stripe::setApiKey($this-clientSecret);//私鑰

      try{

      $jsonStr=file_get_contents('php://input');

      $jsonObj=json_decode($jsonStr);//獲取頁面參數

      $arr=object_array($jsonObj);//轉換為數組

      $order_id=$arr['items'][0]['order_id'];//訂單單號

      $order=db('order')-where('order_id',$order_id)-find();//查找訂單

      //訂單是否存在和支付狀態

      if(empty($order)){

      echocan'tfindorder!;

      exit();

      }

      if($order['pay_status']==20){

      echo'Theorderwaspaid!';

      exit();

      }

      $request=Request::instance();

      $base_url=$request-domain();//獲取網址

      $time=time();

      //判斷支付訂單是不是已經生成

      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);//記錄生成的支付單號,單號后面會加單號_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]);//記錄單號

      }else{

      $output=[

      'clientSecret'=$order['stripe_pay'],

      ];

      }

      //CreateaPaymentIntentwithamountandcurrency

      echojson_encode($output);

      }catch(Error$e){

      http_response_code(500);

      echojson_encode(['error'=$e-getMessage()]);

      }

      }

      三,前端

    inkrel=stylesheethref=__STATIC__/css/style.css

    inkrel=stylesheethref=__STATIC__/css/checkout.css

      scriptsrc=https://js.stripe.com/v3//script

      script

      varorder_id={$order_id}//訂單號

      varURL=/home/Stripepay

      varkey={$key}

      varbase_url={$base_url};

      /script

      scriptsrc=__STATIC__/js/checkout.jsdefer/script

      formid=payment-form

      pid=payment-element

      !--Stripe.jsinjectsthePaymentElement--

      /

      buttonid=submit

      pclass=spinnerhiddenid=spinner/

      spanid=button-textPaynow/span

      /button

      pid=payment-messageclass=hidden/

      /form

      Checout.js

      //ThisisyourtestpublishableAPIkey.

      conststripe=Stripe(key);//公鑰

      //Theitemsthecustomerwantstobuy

      constitems=[{id:xl-tshirt,order_id:order_id}];

    etelements;

      initialize();

      checkStatus();

      document

      .querySelector(#payment-form)

      .addEventListener(submit,handleSubmit);

      //Fetchesapaymentintentandcapturestheclientsecret

      asyncfunctioninitialize(){

      const{clientSecret}=awaitfetch(URL+/create,{

      method:POST,

      headers:{Content-Type:application/json},

      body:JSON.stringify({items}),

      }).then(res=res.json());

      elements=stripe.elements({clientSecret});

      constpaymentElement=elements.create(payment);

      paymentElement.mount(#payment-element);

      }

      asyncfunctionhandleSubmit(e){

      e.preventDefault();

      setLoading(true);

      console.log(elements);

      const{error}=awaitstripe.confirmPayment({

      elements,

      confirmParams:{

      //Makesuretochangethistoyourpaymentcompletionpage

      return_url:base_url+URL+/successful.html,//成功后,回跳地址

      },

      });

      //Thispointwillonlybereachedifthereisanimmediateerrorwhen

      //confirmingthepayment.Otherwise,yourcustomerwillberedirectedto

      //your`return_url`.ForsomepaymentmethodslikeiDEAL,yourcustomerwill

      //beredirectedtoanintermediatesitefirsttoauthorizethepayment,then

      //redirectedtothe`return_url`.

      if(error.type===card_error||error.type===validation_error){

      showMessage(error.message);

      }else{

      showMessage(Anunexpectederroroccured.);

      }

      setLoading(false);

      }

      //Fetchesthepaymentintentstatusafterpaymentsubmission

      asyncfunctioncheckStatus(){

      constclientSecret=newURLSearchParams(window.location.search).get(

      payment_intent_client_secret

      );

      if(!clientSecret){

      return;

      }

      const{paymentIntent}=awaitstripe.retrievePaymentIntent(clientSecret);

      switch(paymentIntent.status){

      casesucceeded:

      showMessage(Paymentsucceeded!);

      break;

      caseprocessing:

      showMessage(Yourpaymentisprocessing.);

      break;

      caserequires_payment_method:

      showMessage(Yourpaymentwasnotsuccessful,pleasetryagain.);

      break;

      default:

      showMessage(Somethingwentwrong.);

      break;

      }

      }

      //-------UIhelpers-------

      functionshowMessage(messageText){

      constmessageContainer=document.querySelector(#payment-message);

      messageContainer.classList.remove(hidden);

      messageContainer.textContent=messageText;

      setTimeout(function(){

      messageContainer.classList.add(hidden);

      messageText.textContent=;

      },4000);

      }

      //Showaspinneronpaymentsubmission

      functionsetLoading(isLoading){

      if(isLoading){

      //Disablethebuttonandshowaspinner

      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);

      }

      }

      在平臺付款可以看到支付信息

      四,獲取支付狀態:

      webhooks添加回調地址和事件

      charge.succeeded-支付成功后

      需要密鑰

      五、獲取回調信息,控制器

      publicfunctioncallback()

      {

      $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){

      //Invalidsignature

      http_response_code(400);

      exit();

      }

      }

      $log_name=notify_url.log;

      $this-log_result($log_name,'pay-start|--'.$event-data-object-paymentIntent.'--|');

      //Handletheevent

      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;

      //實例化訂單模型

      $model=$this-getOrderModel($order_no,10);

      //訂單信息

      $order=$model-getOrderInfo();

      if(empty($order)){

      echo'Ordernotexist';

      }

      $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('PayError!','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;

      //...handleothereventtypes

      default:

      $this-log_result($log_name,'pay-fail|--'.$event-type.'--|');

      echo'Receivedunknowneventtype'.$event-type;

      }

      }

    * 文章來源于網絡,如有侵權,請聯系客服刪除處理。
    在線 咨詢

    添加動力小姐姐微信

    微信 咨詢

    電話咨詢

    400-660-5555 (轉1)

    我們聯系您

    電話 咨詢
    微信掃碼關注動力小姐姐 X
    qr
    主站蜘蛛池模板: 中文字幕无码青椒影视| 最新亚洲人成网站在线观看| 亚洲色成人网站www永久四虎| 视频在线观看免费一区二区三区| 好吊妞欧美视频免费| 中文字幕无码久久精品| 久久国产免费观看精品3| 国产日韩精品中文字幕| 国产精品AV在线| 国产美女极度色诱视频WWW| 人妻三级成| 蜜桃无码一区二区三区| 国产精品入口麻豆| 久久久橹橹橹久久久久高清 | 欧美激情一区二区三区成人| 久久精品一本到99热免费| 中文字幕在线观看2025一区| 盐亭县| 中文字幕人成乱码熟女免费| 亚洲国产成人无码网站大全| 少妇高潮喷水正在播放| 亚洲无码日本| 国产国产人在线成免费视频狼人色 | 成全高清在线播放电视剧| 亚洲免费观看| 人人凹凸XX凹凸爽凹凸| 欧美精品国产综合久久| 日韩大片高清播放器| 久久99精品久久久久麻豆| 国内精品卡一卡二卡三| 精品A区| 国产精品免费久久久久影院小说| 亚洲综合久久久| 国产午夜精品福利91| 粉嫩小泬无遮挡久久久久久| 波多野结衣精品1区2区3区| 中文字幕av久久爽一区| 2020国产微拍精品一区二区| 亚洲国产精品酒店丝袜高跟| 国产精品一区二区三区黄| 日韩一区二区三区日韩精品|