Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento 2: How to change Payment Action Method on the fly in Paypal Express

I have already created Paypal/Developer/Sandbox Account. Already got API Credentials.

Downloaded PHP SDK http://paypal.github.io/PayPal-PHP-SDK/

Referring: https://developer.paypal.com/docs/api/

https://devtools-paypal.com/guide/expresscheckout/php?interactive=ON&env=sandbox

I have already done Sandbox One Transaction with Authorize Method using my PHP Script.

What i have to achieve. I need to get Authorize Payments, Convert "Authorize" payments to "Capture/Sale" Method & Notify Customer & Admin As well.

How to get Authorization Id?

By referring above document i need to use 3 Web Services

  • Get details of an authorized payment
  • Capture an authorized payment
  • Get details of a captured payment

Already have Transaction ID of "Authorize" Payment.

Please provide the steps to follow & if any example already available then please share

Need to integrate this functionality in Magento 2

[UPDATE]

I have changed my API Sandbox Credentials in PHP SDK in PayPal-PHP-SDK-master\sample\bootstrap.php file.

From sample/payments/AuthorizePayment.php i will get Authorized Payment with ID: PAY-0TV39791XXX02404VK7XD32I & it works fine.

When i input my Transaction Id it gives

{"name":"INVALID_RESOURCE_ID","message":"Requested resource ID was not found.","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#INVALID_RESOURCE_ID","debug_id":"1f2b08ce88633"}

My Sandbox Transaction Id is 3AA32794KF48247AA. So question is how to convert your Transaction Id in to Payment Id?

https://magento.stackexchange.com/questions/138579/magento-2-change-paypal-action-method-on-the-fly

Below is the reply from Paypal

Transaction id can be generated after REST API execute payment, Classic API [NVP/SOAP] DoEC API or normal button payment completion. It will never work to reverse the search to find the Payment Id.

like image 955
Jackson Avatar asked Nov 09 '22 08:11

Jackson


1 Answers

If you have paymentId, you can get details of authorized payment in this way:

$payment = Payment::get( $paymentId, $apiContext );

For all propeties of payment class take a look this - Payment.php

To change Sandbox/API Credentials edit the bootstrap.php in your project.

UPDATE

You don't need to use AuthorizePayment.php. Istead, do the following:

  1. Create payment and get the url for authorization (your website side).
  2. Print the url for authorization (your website side).
  3. Cutomer follow the authorization url and go to PayPal and authorize the payment (PayPal side).
  4. PayPal returns customer to your website with the paymentId (PayPal side).
  5. Grab the paymentId and execute the payment (your website side).
like image 74
Ivnhal Avatar answered Nov 14 '22 23:11

Ivnhal