在这里只说一下stripe的使用,其他visa,PayPal都大同小异。
支付文档这里有:https://stripe.com/docs/payments
直接贴一下对接代码,自己琢磨一下
Credit CardPay// 在线支付
var url = "/order/stripePay";
var handler = StripeCheckout.configure({
key: js_stripe_key,//参数规定的秘钥key。需自己申请
image: 'https://stripe.com/img/documentation/checkout/marketplace.png',
locale: 'auto',
email: email,
allowRememberMe: false,
token: function (token) {
// You can access the token ID with `token.id`.
// Get the token ID to your server-side code for use.
data.token_id = token.id;
//stripe规定参数
data.stripe_currency = js_stripe_currency;
//币种RMB
data.stripe_amount = totalmoney;
//价格$.ajax({
type: 'POST',
url: url,
data: data,
dataType: "json",
beforeSend: function (XMLHttpRequest) {
$(".mask_layer").show()
}, success: function (data) {
if (data.code == '200') {
alert('pay success');
} else {
alert('pay fail');
}
}, complete: function (XMLHttpRequest, textStatus) {
$(".mask_layer").hide()
}, error: function (XMLHttpRequest, textStatus) {
}
});
}
});
// Open Checkout with further options:
handler.open({
name: '',
description: '',
currency: js_stripe_currency, //币种
amount: totalmoney//金额,需要*100的,
});
// Close Checkout on page navigation:
window.addEventListener('popstate', function () {
handler.close();
});
【laravel|国际支付对接,信用卡支付对接,stripe的使用】最后是php的服务端代码,一般写处理逻辑
// 此处为在线支付
try {
Stripe::setApiKey(env('STRIPE_KEY'));
$charge = Charge::create([
'amount' => $request->stripe_amount,
'currency' => $request->stripe_currency,
'source' => $request->token_id,
]);
if (json_decode($charge, true)['status'] != 'succeeded') {return response()->json(['code' => 403, 'message' => 'Order Failed']);
} else {
DB::update('update order_list set pay_type = ? where id = ?',[1,$result]);
}
} catch (Exception $exception) {
return response()->json(['code' => 404, 'message' => 'Order Failed']);
}
brother~~~~~