Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PayPal REST API: how to do an immediate payment and without asking for shipping address

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"
        }
    ]
}
like image 864
matteo.cajani Avatar asked Jun 29 '14 09:06

matteo.cajani


Video Answer


1 Answers

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! :)

like image 85
ampedwebdev Avatar answered Nov 13 '22 22:11

ampedwebdev