外貿(mào)獨立站是做外貿(mào)的公司自己開設的獨立品牌商城,主要區(qū)別于商城平臺如亞馬遜、阿里巴巴等,優(yōu)點是自己的地盤自己說了算,缺點是需要自己推廣引流,適合有一定品牌的商家。
大部分外貿(mào)公司都是兩者都做,從商品平臺推廣獲客,然后把流量引入自己的品牌商城,打造自己的私域流量商城。
Stripe支付公司是由一對來自愛爾蘭的天才兄弟Collison Brothers一手創(chuàng)辦的,他們表示隨著美國大的民營金融科技公司進入小企業(yè)貸款領域,新一輪融資使其價值增加了一半以上。
KlipC分析稱,Stripe的商業(yè)模式主要是梳理目前有的支付方式,將不同的支付方式打包成一套SDK接口,通過整體接入,降低用戶的接入成本,以收取手續(xù)費或者服務盈利。目前在金融行業(yè),很多公司已經(jīng)采用了Stripe的支付通道,比起傳統(tǒng)通道,Stripe效率更高,成本更低。
第一步:安裝類庫
composer require stripe/stripe-php
第二步后臺控制器:
functioncreate(){
\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'];//訂單單號
$order=db('order')->where('order_id',$order_id)->find();//查找訂單
//訂單是否存在和支付狀態(tài)
if(empty($order)){
echo"can'tfindorder!";
exit();
}
if($order['pay_status']==20){
echo'Theorderwaspaid!';
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);//記錄生成的支付單號,單號后面會加‘單號_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()]);
}
}
三,前端