Page MenuHomePhabricator

Implement PayPal EC DoExpressCheckoutPayment in SmashPig
Closed, ResolvedPublic4 Estimated Story Points

Description

Method on payment provider: approvePayment

Doc link: https://developer.paypal.com/api/nvp-soap/do-express-checkout-payment-nvp/

Params to send in our implementation: (TODO finish mapping where all the values come from)
'USER', (from account params)
'PWD', (from account params)
'VERSION' => 204,
'METHOD' => 'DoExpressCheckoutPayment',
'TOKEN' => $params['payment_token'],
'PAYERID' => $params['processor_contact_id'],
'PAYMENTREQUEST_0_AMT',
'PAYMENTREQUEST_0_CURRENCYCODE',
'PAYMENTREQUEST_0_CUSTOM',
'PAYMENTREQUEST_0_DESC' => $params['description'],
'PAYMENTREQUEST_0_INVNUM',
'PAYMENTREQUEST_0_ITEMAMT', // FIXME: Not clear why this is required.
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
'PAYMENTREQUEST_0_PAYMENTREASON' => 'None',

Error mapping:
PAYMENTINFO_0_ERRORCODE element of response should have value 0 for success
value 10412 should map to ErrorCode::DUPLICATE_ORDER_ID

Event Timeline

Dwisehaupt set the point value for this task to 4.Oct 7 2022, 4:21 PM

Gonna move this out of sprint for now and pick up T318759: Implement PayPal EC SetExpressCheckout in SmashPig which I think is the one we want next

Change 845045 had a related patch set uploaded (by Jgleeson; author: Jgleeson):

[wikimedia/fundraising/SmashPig@master] WIP: Implement PayPal EC DoExpressCheckoutPayment API call

https://gerrit.wikimedia.org/r/845045

Test instructions

There are a few ways to test this patch and get the necessary values needed to call the GetExpressCheckoutDetails API method. Here's the quickest way:

1, Open up DonationInterface/paypal_ec_gateway/paypal_express.adapter.php and jump to line 618. You should see code that looks like the following:

$this->addRequestData( $requestData );
$resultData = $this->do_transaction( 'GetExpressCheckoutDetails' );

Change this to

$this->addRequestData( $requestData );
/** DEBUG CODE. DELETE AFTER USE  */
var_dump($requestValues);exit;
/** END OF DEBUG CODE */
$resultData = $this->do_transaction( 'GetExpressCheckoutDetails' );

We just add the line var_dump($requestValues);exit; in between the existing code lines.

2, Put through a normal Paypal donation locally (note: remember the amount for later)

3, You should now see a prematurely exited array dump with a bunch of request values, these are the values needed to call the DoExpressCheckoutPayment API method

For example, after adding the debug code and trying out a donation, I see the following:

array (size=5)
  'title' => string 'Special:PaypalExpressGatewayResult' (length=34)
  'order_id' => string '15182.1' (length=7)
  'wmf_token' => string '916c2bef399600e5bbccc3faf3451509+\' (length=34)
  'token' => string 'EC-3HX397483P386493S' (length=20)
  'PayerID' => string 'FLJLQ2GV38E4Y' (length=13)

If you see this, great, you can now use the values above to run the newly added DoExpressCheckoutPayment maintenance script

4, Checkout this patch on smashpig

5, Connect in to the container using docker-compose exec smashpig bash

6, Run cd /srv/smashpig/

7, Now it's time to call the new maintenance script using the values you captured from your previous donation attempt.

8, Run php PaymentProviders/PayPal/Maintenance/DoExpressCheckoutPayment.php $token $PayerID $order_id $amount replacing the variables with the request values you got from the debug output. Note: the amount isn't included in the request values, you need to remember that. All the other required params should be there.

You should end up with parameters that look something like this php PaymentProviders/PayPal/Maintenance/DoExpressCheckoutPayment.php EC-3HX397483P386493S FLJLQ2GV38E4Y 15182.1 25.00

9, Run that final command using the required parameters, and if all goes well, you should see something like:

2022-11-03T14:40:14+00:00 [DEBUG  ] {SmashPig-DoExpressCheckoutPayment::SPCID-0691958305} Successful request
2022-11-03T14:40:14+00:00 [DEBUG  ] {SmashPig-DoExpressCheckoutPayment::SPCID-0691958305} Response from API call: {"body":"TOKEN=EC%2d3HX397483P386493S&SUCCESSPAGEREDIRECTREQUESTED=false&TIMESTAMP=2022%2d11%2d03T14%3a40%3a14Z&CORRELATIONID=ef4e37e87b6d7&ACK=Success&VERSION=204&BUILD=57853092&INSURANCEOPTIONSELECTED=false&SHIPPINGOPTIONISDEFAULT=false&PAYMENTINFO_0_TRANSACTIONID=6BP189448J588054R&PAYMENTINFO_0_TRANSACTIONTYPE=expresscheckout&PAYMENTINFO_0_PAYMENTTYPE=instant&PAYMENTINFO_0_ORDERTIME=2022%2d11%2d03T14%3a40%3a12Z&PAYMENTINFO_0_AMT=25%2e00&PAYMENTINFO_0_FEEAMT=1%2e36&PAYMENTINFO_0_TAXAMT=0%2e00&PAYMENTINFO_0_CURRENCYCODE=USD&PAYMENTINFO_0_PAYMENTSTATUS=Completed&PAYMENTINFO_0_PENDINGREASON=None&PAYMENTINFO_0_REASONCODE=None&PAYMENTINFO_0_PROTECTIONELIGIBILITY=Eligible&PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE=ItemNotReceivedEligible%2cUnauthorizedPaymentEligible&PAYMENTINFO_0_SELLERPAYPALACCOUNTID=fr%2dtech%2dfacilitator%40wikimedia%2eorg&PAYMENTINFO_0_SECUREMERCHANTACCOUNTID=XBAQ9CSARUZ7J&PAYMENTINFO_0_ERRORCODE=0&PAYMENTINFO_0_ACK=Success","headers":{"Content-Type":"text\/plain; charset=utf-8","Content-Length":"943","Connection":"keep-alive","Server":"nginx\/1.14.0 (Ubuntu)","Date":"Thu, 03 Nov 2022 14:40:14 GMT","Cache-Control":"max-age=0, no-cache, no-store, must-revalidate","Paypal-Debug-Id":"ef4e37e87b6d7","X-Paypal-Operation-Name":"DoExpressCheckoutPayment","Strict-Transport-Security":"max-age=31536000; includeSubDomains"},"status":200}
SmashPig\PaymentProviders\Responses\ApprovePaymentResponse Object
(
    [errors:protected] => Array
        (
        )

    [validationErrors:protected] => Array
        (
        )

    [rawResponse:protected] => Array
        (
            [TOKEN] => EC-3HX397483P386493S
            [SUCCESSPAGEREDIRECTREQUESTED] => false
            [TIMESTAMP] => 2022-11-03T14:40:14Z
            [CORRELATIONID] => ef4e37e87b6d7
            [ACK] => Success
            [VERSION] => 204
            [BUILD] => 57853092
            [INSURANCEOPTIONSELECTED] => false
            [SHIPPINGOPTIONISDEFAULT] => false
            [PAYMENTINFO_0_TRANSACTIONID] => 6BP189448J588054R
            [PAYMENTINFO_0_TRANSACTIONTYPE] => expresscheckout
            [PAYMENTINFO_0_PAYMENTTYPE] => instant
            [PAYMENTINFO_0_ORDERTIME] => 2022-11-03T14:40:12Z
            [PAYMENTINFO_0_AMT] => 25.00
            [PAYMENTINFO_0_FEEAMT] => 1.36
            [PAYMENTINFO_0_TAXAMT] => 0.00
            [PAYMENTINFO_0_CURRENCYCODE] => USD
            [PAYMENTINFO_0_PAYMENTSTATUS] => Completed
            [PAYMENTINFO_0_PENDINGREASON] => None
            [PAYMENTINFO_0_REASONCODE] => None
            [PAYMENTINFO_0_PROTECTIONELIGIBILITY] => Eligible
            [PAYMENTINFO_0_PROTECTIONELIGIBILITYTYPE] => ItemNotReceivedEligible,UnauthorizedPaymentEligible
            [PAYMENTINFO_0_SELLERPAYPALACCOUNTID] => fr-tech-facilitator@wikimedia.org
            [PAYMENTINFO_0_SECUREMERCHANTACCOUNTID] => XBAQ9CSARUZ7J
            [PAYMENTINFO_0_ERRORCODE] => 0
            [PAYMENTINFO_0_ACK] => Success
        )

    [gateway_txn_id:protected] => 6BP189448J588054R
    [status:protected] => complete
    [rawStatus:protected] => Success
    [successful:protected] => 1
    [timeTaken:protected] => 
)

Reach out if that above doesn't work!

Note: Don't forget to remove the debug code you added!
Another Note: You could also capture the request info by setting a breakpoint at line 618 of DonationInterface/paypal_ec_gateway/paypal_express.adapter.php and using xdebug. Either way would work fine to get the initial required info.

Change 845045 merged by jenkins-bot:

[wikimedia/fundraising/SmashPig@master] Implement PayPal EC DoExpressCheckoutPayment API call

https://gerrit.wikimedia.org/r/845045

Change 854581 had a related patch set uploaded (by Jgleeson; author: Jgleeson):

[wikimedia/fundraising/SmashPig@master] Update PayPal EC approvePayment/doExpressCheckoutPayment status mapping to handle all available status messages

https://gerrit.wikimedia.org/r/854581

Change 855060 had a related patch set uploaded (by Jgleeson; author: Jgleeson):

[wikimedia/fundraising/SmashPig@master] Add tests for Paypal Express implementation

https://gerrit.wikimedia.org/r/855060

Change 855060 merged by Wfan:

[wikimedia/fundraising/SmashPig@master] Add test for Paypal Express API

https://gerrit.wikimedia.org/r/855060

Change 855749 had a related patch set uploaded (by Jgleeson; author: Jgleeson):

[wikimedia/fundraising/SmashPig@master] Add Paypal EC PaymentProvider Tests

https://gerrit.wikimedia.org/r/855749

Change 854581 merged by jenkins-bot:

[wikimedia/fundraising/SmashPig@master] Update PayPal EC approvePayment/doExpressCheckoutPayment status mapping.

https://gerrit.wikimedia.org/r/854581

Change 855749 merged by jenkins-bot:

[wikimedia/fundraising/SmashPig@master] Add Paypal EC PaymentProvider Tests

https://gerrit.wikimedia.org/r/855749

XenoRyet set Final Story Points to 4.