[英]Omnipay Get transaction fee from stripe
我一直在嘗試使用thephpleague/omnipay-stripe
從 stripe 返回交易費用。
我不是要退還或設置申請費,而是 Stripe 為每筆交易收取的實際費用。
到目前為止,這是我的代碼:
if ($request->input('stripeToken')) {
$gateway = Omnipay::create('Stripe\PaymentIntents');
$gateway->initialize([
'apiKey' => env('STRIPE_SECRET'),
]);
$token = $request->input('stripeToken');
$paymentMethodId = $request->get('paymentMethodId');
$response = $gateway->purchase([
'amount' => session('cost'),
'currency' => env('STRIPE_CURRENCY'),
'description' => session('payment_title'),
'paymentMethod' => $paymentMethodId,
'token' => $token,
'name' => \Auth::user()->name,
'returnUrl' => route('customer.charge.stripe.return_url'),
'confirm' => true,
])->send();
if ($response->isSuccessful()) {
$arr_payment_data = $response->getData();
$data = [
'type' => session('payment_type'),
'cost' => session('cost'),
'duration' => session('duration'),
'description' => session('payment_title'),
'transaction_id' => $arr_payment_data['id'],
'status' => $arr_payment_data['status'],
'fee' => // Whatever I need to call to get fee,
'payment_details' => $arr_payment_data
];
Payments::add_payment_to_db($data);
$request->session()->forget(['cost', 'payment_title', 'duration']);
return redirect()->route('customer.dashboard')->with([
'status' => __('customer.payments.success'),
'alert' => 'success',
]);
} elseif($response->isRedirect()) {
$response->redirect();
} else {
// payment failed: display message to customer
return redirect()->back()->with([
'status' => $response->getMessage(),
'alert' => 'danger',
]);
}
我嘗試了一些方法,但不確定如何正確獲取費用。
任何有關如何獲得費用的幫助或想法將不勝感激。
非常感謝
購買成功后,您需要檢索付款意向才能獲得費用。 我不使用 Omnipay,但也許這種方法可以幫助您朝着正確的方向前進。 這是我在使用 Stripe API 收費成功后獲得費用的方式。
protected function getFeeDetails($payment_intent_id, $user)
{
Stripe::setApiKey(env('STRIPE_SECRET'));
$payment_intent = PaymentIntent::retrieve([
'id' => $payment_intent_id,
'expand' => ['charges.data.balance_transaction'],
],
[
'stripe_account' => $user->stripe_user_id
]);
return $payment_intent->charges->data[0]->balance_transaction->fee;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.