Karem
Karem

Reputation: 18123

Express Checkout for Paypal, why three methods to complete a payment?

I dont get it.

As of my knowledge currently, there is three must-have methods in order to complete a complete transaction.

  1. SetExpressCheckout Makes sense, I create a payment with the items in it and all, then redirect the user to the redirecturi i receive in the response.

  2. GetExpressCheckoutDetails This method should be on the url that is specified on the returnurl from the SetExpressCheckout. By getting the TOKEN that comes from paypal and use it for calling this method, we can get Payer ID, that we will use to call the final method DoExpressCheckoutPayment

  3. DoExpressCheckoutPayment This method requires a TOKEN and PAYER ID that we now both have. It also requires the Payment and the payment items, to really complete the transaction.

Now my questions are:

  1. On my returnurl, I am calling both GetExpressCheckoutDetails and then DoExpressCheckoutPayment. Now - can I always go out from that everything is correct and the transaction WILL go through when calling these two? I am thinking, maybe Paypal doesnt continue to the returnurl if the user has insufficient funds ?

  2. Why do we need to specify the payment items all again in DoExpressCheckoutPayment ? When we already did it in SetExpressCheckout?

I am so used to other payment gateways that simply have an initiation of the payment -> redirect to payment gateway -> complete. Where they then make an callback when the transaction is really completed and then I can set the order to completed and deliver items to the user.

I hope someone can clarify things up for me, once and for all (there's so many similiar questions regarding this)

Update

$DECPFields = array(
                    'token' => $_GET['token'],                              // Required.  A timestamped token, the value of which was returned by a previous SetExpressCheckout call.
                    'payerid' => $_GET['PayerID'],                          // Required.  Unique PayPal customer id of the payer.  Returned by GetExpressCheckoutDetails, or if you used SKIPDETAILS it's returned in the URL back to your RETURNURL.
                    'returnfmfdetails' => '1',                  // Flag to indiciate whether you want the results returned by Fraud Management Filters or not.  1 or 0.                         'allowedpaymentmethod' => 'InstantPaymentOnly',                 // The payment method type. Specify the value InstantPaymentOnly.
                    'buttonsource' => '',                       // ID code for use by third-party apps to identify transactions in PayPal. 
                    'USESESSIONPAYMENTDETAILS' => '1'
                );

$PayPalRequest = array(
                       'DECPFields' => $DECPFields
                       );

$decp = $PayPal -> DoExpressCheckoutPayment($PayPalRequest);

This is the request/response

Array
(
    [TIMESTAMP] => 2014-04-13T00:14:26Z
    [CORRELATIONID] => 7f6dd4f8798aa
    [ACK] => Failure
    [VERSION] => 112.0
    [BUILD] => 10567876
    [L_ERRORCODE0] => 10400
    [L_SHORTMESSAGE0] => Transaction refused because of an invalid argument. See additional error messages for details.
    [L_LONGMESSAGE0] => Order total is missing.
    [L_SEVERITYCODE0] => Error
    [ERRORS] => Array
        (
            [0] => Array
                (
                    [L_ERRORCODE] => 10400
                    [L_SHORTMESSAGE] => Transaction refused because of an invalid argument. See additional error messages for details.
                    [L_LONGMESSAGE] => Order total is missing.
                    [L_SEVERITYCODE] => Error
                )

        )

    [PAYMENTS] => Array
        (
        )

Upvotes: 0

Views: 1026

Answers (1)

Drew Angell
Drew Angell

Reputation: 26056

What you explained about other payment gateways is essentially what PayPal Payments Standard is. A very basic HTML form that sends the user over to the gateway where they sign in or enter cc details to complete the payment and it's done. Then you could setup IPN to receive data about that transaction and automate post-processing tasks like you mentioned.

Express Checkout is more advanced. It uses the actual API's and provides a lot more freedom to integrate things exactly how you want to suit your needs.

First, GetExpressCheckoutDetails is optional. When you call SetExpressCheckout and then redirect to PayPal you can use the "useraction" parameter on that redirect URL to change the experience. If you use useraction=commit then two things will happen.

  • The button on the PayPal review page will change from "Continue" to "Pay"
  • The PayerID will be returned as a URL parameter when PayPal sends the user back to your site. This allows you to skip straight to DoExpressCheckoutPayment if you want to.

As part of that feature, you can also setup a callback that communicates with PayPal's review page. Their review page will POST the buyer's shipping address and item details back to your script. Your script can take that data, calculate shipping options with it, and return the shipping and tax details back to the PayPal review page. The PayPal page updates a drop down list that gets populated with the results your script returns so the user can complete the entire order using the PayPal review and you don't need to build another review on your own site.

As for DoExpressCheckoutPayment, if you include the USESESSIONPAYMENTDETAILS parameter in that request it will use the details you sent with SetExpressCheckout so you don't have to include it all again.

Something could indeed go wrong with GECD and DECP, so you always want to run through error handling and log accordingly. There are instances where the funding that was chosen on the PayPal page doesn't work, and PayPal actually builds in a way to circle back around and handle that based on a particular error code you'd get back.

Hope that helps!

Upvotes: 1

Related Questions