【发布时间】:2021-02-26 04:53:32
【问题描述】:
我一直在尝试使用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',
]);
}
我尝试了一些方法,但我不确定如何正确收取费用。
任何有关如何获得费用的帮助或想法将不胜感激。
非常感谢
【问题讨论】: