Payment seems to be ok, but transaction not showing

MKI
Contributor
Contributor

Hi

 

I have pay button on my eshop. Customer clicks it and he is redirected to PayPal where he can seem total sum and so on. User click pay now and he is successfuly redirected back to eshop. No Error message, but money are not send/recieved.

 

My code

 

$clientId = "XXX";
        $clientSecret = "XXX";

        $environment = new ProductionEnvironment($clientId, $clientSecret);
        $client = new PayPalHttpClient($environment);

        $request = new OrdersCreateRequest();
        $request->prefer('return=representation');
        $request->body = [
                            "intent" => "CAPTURE",
                            'reference_id' => $order->id,
                            "purchase_units" => [[
                                "amount" => [
                                    "value" => $order->price,
                                    "currency_code" => $currencyCode,
                                    'breakdown'     =>
                                        [
                                            'item_total' =>
                                                [
                                                    'currency_code' => $currencyCode,
                                                    'value'         => $order->price,
                                                ],
                                        ],
                                ],
                            ]],
                            "application_context" => [
                                "cancel_url" => $this->siteUrl . "/checkout/cancel/",
                                "return_url" => $this->siteUrl . "/checkout/paid/" . $order["pay_link"],
                                'brand_name' => 'Puzzle Mania',
                                'locale' => 'en-US',
                                'user_action' => 'PAY_NOW',
                            ] 
                        ];
        try 
        {
            // Call API with your client and get a response for your call
            $response = $client->execute($request);
...

 do I someting wrong? 

Login to Me Too
3 REPLIES 3

Gabriel_PP
Moderator
Moderator

Hi @MKI 

 

Thanks for reaching out to us,

 

I am sorry to hear that.

 

Maybe the execute process is not being triggered and the order is just created but not "collected".

 

In order to execute the payments that you created you need to call the /v2/checkout/orders/{order_id}/capture method. I checked the logs and I see you are correctly creating orders but I can't see any execute call.

 

  -> execute the payment with /v2/checkout/orders/{order_id}/capture
https://developer.paypal.com/docs/api/orders/v2/#orders_capture

 

You can find at these links our guide with more details:
- https://developer.paypal.com/docs/api/orders/v2/

 

Could you please open a ticket to us: https://www.paypal-support.com/s/?language=en_US ? This way, we could verify if there's any error on our logs.

 

I hope this helps.

Thanks,

 

 

Login to Me Too

MKI
Contributor
Contributor

Ah I understand now, so when customer clicks pay now and he is redirected to eshop then this code need to be run

 

$environment = new ProductionEnvironment($clientId, $clientSecret);
            $client = new PayPalHttpClient($environment);

            Debugger::log("paypal_payment_id:" . $orderFetched["paypal_payment_id"]);
            $request = new OrdersCaptureRequest($orderFetched["paypal_payment_id"]);

            $request->prefer('return=representation');
            try 
            {
                // Call API with your client and get a response for your call
                $response = $client->execute($request);
                
                // If call returns body in response, you can get the deserialized version from the result attribute of the response
                Debugger::log($response);
            }
            catch (HttpException $ex) 
            {
                Debugger::log($ex->statusCode);
                Debugger::log($ex->getMessage());
            }
Login to Me Too

Gabriel_PP
Moderator
Moderator

Hi @MKI 

 

Thanks for your response,

 

Yes, of course this will depend on the design and logic on your Website; however the execute method, must be called in order to "complete" the payment.

 

Thanks,

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.