srmklive/paypal支付授权无需立即捕获

问题描述 投票:0回答:1

我正在尝试在我的 laravel 应用程序中设置 paypal 付款授权,以便卖家可以选择在他的 paypal 业务仪表板上查看报价并拒绝付款,而不是立即收到完整付款并不必要地收取交易费如果他不想收到资金,则使用 paypal。

我使用 srmklive/paypal 包来处理 paypal 付款方式,现在我的代码可以立即捕获用户的订单确认。这些东西在 Stripe 上设置起来要容易得多……

这是我当前在结帐控制器中的贝宝代码部分:

if ($request->input('payment_option') === 'paypal'){
            $provider = new PayPalClient();
            $provider->setApiCredentials(config('paypal'));
            // $provider->setCurrency('EUR');
            $paypalToken = $provider->getAccessToken();

            $response = $provider->createOrder([
                "intent" => "CAPTURE",
                "application_context" => [
                    "return_url" => route('payment.success'),
                    "cancel_url" => route('payment.cancel'),
                ],
                "purchase_units" => [
                    [
                        'description' => "Globus Transfers - " . strtoupper($vehicle) . " taxi transfer reservation from $departureLocationName to $destinationLocationName.",
                        "amount" => [
                            "currency_code" => "EUR",
                            "value" => $price
                        ],
                        
                    ]
                ]
            ]);

            if(isset($response['id']) && $response['id'] != 'null') {
                // Store the order ID in the session
                session(['paypal_order_id' => $response['id']]);

                foreach($response['links'] as $link){
                    if($link['rel'] === 'approve'){
                        return redirect()->away($link['href']);
                    }
                }
            } else {
                return redirect()->route('payment.cancel');
            }

这是我在PaymentController中的成功方法:

if($routeAndReservationData['payment_option'] === 'paypal'){
            $provider = new PayPalClient();
            $provider->setApiCredentials(config('paypal'));
            $paypalToken = $provider->getAccessToken();
            $orderId = session('paypal_order_id');
            $response = $provider->showOrderDetails($request->token);
            // Capture the payment
            $captureResponse = $provider->capturePaymentOrder($orderId);


            if(isset($captureResponse['status']) && $captureResponse['status'] == 'COMPLETED'){
                // Update the reservation with the PayPal transaction ID
                $reservation->update(['paypal_order_id' => $orderId]);
                // Send confirmation email to the user
                Mail::to($routeAndReservationData['email'])->send(new UserReservationCreation($routeAndReservationData));
                Mail::to('[email protected]')->send(new CompanyReservationCreation($routeAndReservationData));
                session()->flush();
                return view('payment.success');
            } else {
                return view('payment.cancel');
            }

我需要使用什么方法来实现所描述的功能?

laravel paypal
1个回答
0
投票

我正在尝试在我的 laravel 应用程序中设置 paypal 付款授权,以便卖家可以选择查看报价并拒绝付款

...

“意图”=>“捕获”,

使用

"intent" => "AUTHORIZE"
来表示该行为。

有关更多详细信息,请参阅:授权付款并稍后获取资金。 (有关成为合作伙伴以及使用purchase_units.payee对象指定接收者的信息不适用于与接收者自己的API凭证的第一方集成。)

© www.soinside.com 2019 - 2024. All rights reserved.