【发布时间】:2021-10-12 07:10:22
【问题描述】:
如何将此 Paypal 响应详细信息发布到数据库
我已成功使用智能按钮支付宝付款。
我能够使用控制台日志捕获响应详细信息。
现在如何使用 laravel 将响应数组发布到数据库。
待批准
onApprove: function(data, actions) {
let token = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
// This function captures the funds from the transaction.
return actions.order.capture().then(function(details) {
if(details.status == 'COMPLETED'){
return fetch('/pages/save', {
method: 'post',
headers: {
'content-type': 'application/json',
"Accept": "application/json, text-plain, */*",
"X-Requested-With": "XMLHttpRequest",
"X-CSRF-TOKEN": token
},
body: JSON.stringify({
orderId : data.orderID,
id : details.id,
status: details.status,
payerEmail: details.payer.email_address,
})
})
.then(status)
.then(function(response){
// redirect to the completed page if paid
console.log(details)
// window.location.href = '/pages/sucess';
})
.catch(function(error) {
// redirect to failed page if internal error occurs
window.location.href = '/pages/fail?reason=internalFailure';
});
}else{
window.location.href = '/pages/fail?reason=failedToCapture';
}
});
},
Laravel 路线
Route::get('pages/sucess', [App\Http\Controllers\OrderController::class, 'sucess'])->name('pages.sucess');
输出
{
"id": "9S369747UW261581G",
"intent": "CAPTURE",
"status": "COMPLETED",
"purchase_units": [
{
"reference_id": "default",
"amount": {
"currency_code": "USD",
"value": "0.50"
},
"shipping": {
"name": {
"full_name": "John Doe"
},
},
"payments": {
"captures": [
{
"id": "5DS42883V93959154",
"status": "COMPLETED",
"amount": {
"currency_code": "USD",
"value": "0.50"
},
}
]
}
}
],
}
如何捕获 PayPal 响应详细信息并将相同的详细信息转储到 Laravel 控制器,以便将其保存到数据库中?
【问题讨论】: