Search code examples
laravelpaypallaravel-8paypal-sandbox

PayPal Laravel Integrarion CheckOutStatus = PayentActionNotIntiated


I'm working on project where i need to integrate PayPal for Payments. I've Integrated PayPal in Laravel 8 by help of: https://devnote.in/how-to-integrate-paypal-payment-gateway-with-laravel/

Everything is working perfect. But I can not able to see transaction in my sandbox activity Tab so I debugged the code what i found in response is

"CHECKOUTSTATUS" => "PaymentActionNotInitiated"

What I think is wrong is this

$response = $provider->setExpressCheckout($data);
$response = $provider->setExpressCheckout($data, true);

Here is my response after payment

"TOKEN" => "EC-2X484972KX015750V"
"BILLINGAGREEMENTACCEPTEDSTATUS" => "1"
"CHECKOUTSTATUS" => "PaymentActionNotInitiated"
"TIMESTAMP" => "2021-08-25T08:46:25Z"
"CORRELATIONID" => "45064f9f5ee81"
"ACK" => "Success"
"VERSION" => "123"
"BUILD" => "55938276"
"EMAIL" => "sb-8dekq7353673@personal.example.com"
"PAYERID" => "9U9985S7EREYQ"
"PAYERSTATUS" => "verified"
"FIRSTNAME" => "John"
"LASTNAME" => "Doe"
"COUNTRYCODE" => "US"
"ADDRESSSTATUS" => "Confirmed"
"CURRENCYCODE" => "USD"
"AMT" => "30.00"
"ITEMAMT" => "30.00"
"SHIPPINGAMT" => "0.00"
"HANDLINGAMT" => "0.00"
"TAXAMT" => "0.00"
"DESC" => "Your order #EL/21-22/7 Invoice"
"INVNUM" => "EL/21-22/7"
"INSURANCEAMT" => "0.00"
"SHIPDISCAMT" => "0.00"
"INSURANCEOPTIONOFFERED" => "false"
"L_NAME0" => "Prem"
"L_QTY0" => "1"
"L_TAXAMT0" => "0.00"
"L_AMT0" => "30.00"
"L_DESC0" => "Order No: EL/21-22/7 ORDER SUMMARY- aosdno"
"PAYMENTREQUEST_0_CURRENCYCODE" => "USD"
"PAYMENTREQUEST_0_AMT" => "30.00"
"PAYMENTREQUEST_0_ITEMAMT" => "30.00"
"PAYMENTREQUEST_0_SHIPPINGAMT" => "0.00"
"PAYMENTREQUEST_0_HANDLINGAMT" => "0.00"
"PAYMENTREQUEST_0_TAXAMT" => "0.00"
"PAYMENTREQUEST_0_DESC" => "Your order #EL/21-22/7 Invoice"
"PAYMENTREQUEST_0_INVNUM" => "EL/21-22/7"
"PAYMENTREQUEST_0_INSURANCEAMT" => "0.00"
"PAYMENTREQUEST_0_SHIPDISCAMT" => "0.00"
"PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID" => "sb-nicfx7337505@business.example.com"
"PAYMENTREQUEST_0_INSURANCEOPTIONOFFERED" => "false"
"L_PAYMENTREQUEST_0_NAME0" => "Prem"
"L_PAYMENTREQUEST_0_QTY0" => "1"
"L_PAYMENTREQUEST_0_TAXAMT0" => "0.00"
"L_PAYMENTREQUEST_0_AMT0" => "30.00"
"L_PAYMENTREQUEST_0_DESC0" => "Order No: EL/21-22/7 ORDER SUMMARY- aosdno"
"PAYMENTREQUESTINFO_0_ERRORCODE" => "0"

Solution

  • With that EC API, when the buyer returns to your site, you are expected to display a final order review page for which the final approval action will then trigger the DoExpressCheckoutPayment API call (using the EC token and PayerID from the url query string that was returned with) to create a PayPal transaction. Based on the response you are to display a thank you/success message--or error message about not being able to process the payment. No transaction is created until you call DoExpressCheckoutPayment.

    Regardless, this integration you are attempting is with the classic EC API which is several generations old (about 15 years old). You should not be using this old API for any new integration, that guide you are following is quite old and should be disregarded.


    Instead, follow the current Set up standard payments guide and make 2 routes on your server, one for 'Create Order' and one for 'Capture Order', documented here. Both routes should return only JSON data (no HTML or text). Inside the 2nd route, when the capture API is successful you should store its resulting payment details in your database (particularly purchase_units[0].payments.captures[0].id, which is the PayPal transaction ID) and perform any necessary business logic (such as sending confirmation emails or reserving product) immediately before forwarding your return JSON to the frontend caller.

    Pair those 2 routes with the frontend approval flow: https://developer.paypal.com/demo/checkout/#/pattern/server