首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Omnipay从条带获取交易费

Omnipay从条带获取交易费
EN

Stack Overflow用户
提问于 2020-11-14 19:41:20
回答 1查看 171关注 0票数 0

我一直在尝试使用thephpleague/omnipay-stripe从条带退还交易费用。

我不希望退还或设置应用程序费用,但实际费用,条纹为每一笔交易。

到目前为止,我的代码如下:

代码语言:javascript
复制
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',
        ]);
    }

我已经尝试了一些东西,但我不确定如何获得正确的费用。

任何关于如何获得费用的帮助或想法都将不胜感激。

非常感谢

EN

回答 1

Stack Overflow用户

发布于 2020-11-22 09:34:58

您需要在购买成功后检索付款意向才能获得费用。我不使用Omnipay,但也许这个方法可以帮助你找到正确的方向。这就是我如何在一次收费成功后获得费用的方式使用条带API。

代码语言:javascript
复制
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;
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64833491

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档