7
votes

I'm trying to use PayPal REST API instead of PayPal Classic API but it seems that the REST API is lacking two features that the Classic API has:

  1. immediate payment: when the user goes to PayPal page show him a "Pay now" button instead of a "Continue" button and "You’re almost done. You will confirm your payment on ..." phrase.
  2. no shipping address: avoid asking the user to confirm his shipping address while on PayPal page (in Classic API is done with NOSHIPPING=1 parameter, if I remember well)

So my question is: is it possibile do perform an immediate payment without asking for shipping address using REST API? Do I have to go back to Classic API?

I provide here a little more informations about how I'm using the PayPal REST API. I'm using the PayPal REST Java SDK. This is a sample request:

{
  "intent": "sale",
  "payer": {
    "payment_method": "paypal"
  },
  "transactions": [
    {
      "amount": {
        "currency": "USD",
        "total": "5",
        "details": {
          "subtotal": "5"
        }
      },
      "description": "This is the payment transaction description.",
      "item_list": {
        "items": [
          {
            "quantity": "1",
            "name": "Item 1",
            "price": "5",
            "currency": "USD"
          }
        ]
      }
    }
  ],
  "redirect_urls": {
    "return_url": "http://XXX/handlePayment.jsp?guid\u003dXXX",
    "cancel_url": "http://XXX/cancelPayment.jsp?guid\u003dXXX"
  }
}

And its response:

{
    "id": "XXX",
    "create_time": "2014-06-29T08:52:55Z",
    "update_time": "2014-06-29T08:52:55Z",
    "state": "created",
    "intent": "sale",
    "payer": {
        "payment_method": "paypal",
        "payer_info": {
            "shipping_address": {}
        }
    },
    "transactions": [
        {
            "amount": {
                "total": "5.00",
                "currency": "USD",
                "details": {
                    "subtotal": "5.00"
                }
            },
            "description": "This is the payment transaction description.",
            "item_list": {
                "items": [
                    {
                        "name": "Item 1",
                        "price": "5.00",
                        "currency": "USD",
                        "quantity": "1"
                    }
                ]
            }
        }
    ],
    "links": [
        {
            "href": "https://api.sandbox.paypal.com/v1/payments/payment/XXX",
            "rel": "self",
            "method": "GET"
        },
        {
            "href": "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=XXX",
            "rel": "approval_url",
            "method": "REDIRECT"
        },
        {
            "href": "https://api.sandbox.paypal.com/v1/payments/payment/XXX/execute",
            "rel": "execute",
            "method": "POST"
        }
    ]
}
6

6 Answers

6
votes

While delving through the REST API I came across this

I believe this means you don't have to go about creating any "Profiles" as such, and can just pass them along with the payment call...

Further explanation as requested :)

Below is an example of passing PayPal experience parameters along with a particular payment call using the Client-side JS method for Express checkout.

        payment: function(data, actions) {
        return actions.payment.create({
            payment: {
                transactions: [
                    {
                        amount: { total: '1.00', currency: 'USD' }
                    }
                ]
            },

            experience: {
                input_fields: {
                    no_shipping: 1
                }
            }
        });
    },

Hope that makes enough sense to you guys! :)

3
votes

Unfortunately, the REST API is still a long ways behind the Classic API with features it provides. These features you mentioned are things I've seen come up quite a bit, and to my knowledge they are not yet available with the REST services.

I personally have stuck with Classic as they provide everything and I really see no advantage to using REST myself. If you happen to be working with PHP (which I always do) you may be interested in my class library for PayPal. It makes all of the Classic API calls very quick and easy for you, and it's available on Packagist so you can use with Composer easily.

2
votes

The REST API now supports no-shipping with the Payment Experience APIs.

You need to create a web experience profile and supply no_shipping as an input field. Then use the profile ID when creating the payment.

The profile ID doesn't need to be recreated every time.

2
votes

appreciate that this post hasn't had any activity for a while but...

i hit on the exact same problem and used this post as a start point for my own question:

paypal api: take immediate payment without a shipping address

it's taken a bit of trial and error but i you can create a one off web profile with 'no_shipping' set to 1, store the id that it creates and then pass that in with future payments that don't require a shipping address.

still haven't figured out how to get rid of the 'You're almost done. You will confirm your payment on xxx.' but my payment process is a far better place than it was!

hope this helps someone out there as this no shipping issue is one that a lot of people appear to be hitting with the paypal api...

1
votes

I tried using the experience section of the API and apart from still not being able to force a locale code have been able to disable shipping and go straight to billing:

payment: {
    transactions: [{
        invoice_number: document.getElementById("ReqTxt").value,
        amount: {
            total:  document.getElementById("InvoiceAmt").innerText,
            currency: document.getElementById("Currency").innerText 
        }
    }]
},
experience: {
    input_fields: {
        no_shipping: 1
    },
    flow_config: {
        landing_page_type:'billing'
    }
}

you can also see this page. It is possible to set the user action in the flow_config section too

0
votes

For 'Pay Now' instead of 'Continue' on Paypal I use a special param in approval url:

$approvalUrl = $payment->getApprovalLink().'&useraction=commit';

Result:

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=TOKEN&useraction=commit