Does PayPal Rest API have the classic useraction equivalent

前端 未结 2 1168
深忆病人
深忆病人 2021-01-01 04:03

Is there a way to skip the 2 step confirmation process using the PayPal REST Api?

I\'ve successfully implemented the standard process using the PayPal REST api, whic

相关标签:
2条回答
  • 2021-01-01 04:33

    This use case does exist on the REST side of things, but currently only available via the Mobile SDKs. For more details look into https://developer.paypal.com/docs/integration/mobile/make-future-payment/

    When users are paying with PayPal in web, redirection to PayPal is still necessary in the REST ecosystem.

    0 讨论(0)
  • 2021-01-01 04:41

    I had the same problem and I got an answer from the PayPal support.

    TL;DR: Just append &useraction=commit to the approval_url.

    They told me the REST API redirection URL is a regular Express Checkout redirection URL and therefore you can use the same parameter.

    If you do a payment API call like:

    curl -v https://api.sandbox.paypal.com/v1/payments/payment
    -H "Content-Type:application/json"
    -H "Authorization:Bearer ACCESS_TOKEN_HERE"
    -d '{
        "transactions": [{
            "amount": {
                "currency":"USD",
                "total":"12"
            },
            "description":"creating a payment"
        }],
        "payer": {
            "payment_method":"paypal"
        },
        "intent":"sale",
        "redirect_urls": {
            "cancel_url":"https://devtools-paypal.com/guide/pay_paypal/curl?cancel=true",
            "return_url":"https://devtools-paypal.com/guide/pay_paypal/curl?success=true"
        }
       }'
    

    You will get the following response:

    {
       "id":"PAY-XYZ",
       "create_time":"2015-02-26T15:14:27Z",
       "update_time":"2015-02-26T15:14:28Z",
       "state":"created",
       "intent":"sale",
       "payer":{
          "payment_method":"paypal",
          "payer_info":{
             "shipping_address":{
    
             }
          }
       },
       "transactions":[
          {
             "amount":{
                "total":"12.00",
                "currency":"USD",
                "details":{
                   "subtotal":"12.00"
                }
             },
             "description":"creating a payment",
             "related_resources":[
    
             ]
          }
       ],
       "links":[
          {
             "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-XYZ",
             "rel":"self",
             "method":"GET"
          },
          {
             "href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-FOOBAR",
             "rel":"approval_url",
             "method":"REDIRECT"
          },
          {
             "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-XYZ/execute",
             "rel":"execute",
             "method":"POST"
          }
       ]
    }
    

    In this response you get the approval url

    https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-FOOBAR
    

    and you just have to programmatically extend it with the parameter &useraction=commit.

    So you redirect your user to

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

    Examples are from the PayPal Developer Tools.

    0 讨论(0)
提交回复
热议问题