0

I am using https://github.com/paypal/PayPal-node-SDK. For web payments (browser), it works. But for mobile (iOS/Andriod) it does not, attempting to execute the payment gives PAYMENT_STATE_INVALID

{ [Error: Response Status : 400]
  response: 
   { name: 'PAYMENT_STATE_INVALID',
     message: 'This request is invalid due to the current state of the payment',
     information_link: 'https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID',
     debug_id: '2432d6f51f033',
     httpStatusCode: 400 },
  response_stringified: '{"name":"PAYMENT_STATE_INVALID","message":"This request is invalid due to the current state of the payment","information_link":"https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID","debug_id":"2432d6f51f033","httpStatusCode":400}',
  httpStatusCode: 400 }

The difference I notice between web and mobile are:

For web paypal returns paymentId and payerId which I can use when executing. For mobile, I only get the paymentId, so I will query the payerId by calling Paypal.

(I get payment info for the payer ID)

{ id: 'PAY-7S571696JF513951VKYCRD5Q',
  create_time: '2015-09-25T09:20:54Z',
  update_time: '2015-09-25T09:21:02Z',
  state: 'approved',
  intent: 'sale',
  payer: 
   { payment_method: 'paypal',
     status: 'VERIFIED',
     payer_info: 
      { email: '...',
        first_name: 'test',
        last_name: 'buyer',
        payer_id: 'HBT36U55GA6R8' } },
  transactions: 
   [ { amount: [Object],
       description: '...',
       related_resources: [Object] } ],
  links: 
   [ { href: 'https://api.sandbox.paypal.com/v1/payments/payment/PAY-7S571696JF513951VKYCRD5Q',
       rel: 'self',
       method: 'GET' } ],
  httpStatusCode: 200 }

Before executing the payment, for web, I notice the payment state is "created". For mobile its "approved". It seem like mobile is in a more correct state, compared to web? But fails. Why is that?


More Info Below

(Mobile Payment JSON)

{
   "id":"PAY-4A020366MP615491MKYCRYCA",
   "create_time":"2015-09-25T10:03:52Z",
   "update_time":"2015-09-25T10:03:59Z",
   "state":"approved",
   "intent":"sale",
   "payer":{
      "payment_method":"paypal",
      "status":"VERIFIED",
      "payer_info":{
         "email":"...",
         "first_name":"test",
         "last_name":"buyer",
         "payer_id":"HBT36U55GA6R8"
      }
   },
   "transactions":[
      {
         "amount":{
            "total":"40.00",
            "currency":"SGD",
            "details":{
               "subtotal":"40.00"
            }
         },
         "description":"...",
         "related_resources":[
            {
               "sale":{
                  "id":"2WD385798K879144N",
                  "create_time":"2015-09-25T10:03:52Z",
                  "update_time":"2015-09-25T10:03:59Z",
                  "amount":{
                     "total":"40.00",
                     "currency":"SGD"
                  },
                  "payment_mode":"INSTANT_TRANSFER",
                  "state":"completed",
                  "protection_eligibility":"INELIGIBLE",
                  "parent_payment":"PAY-4A020366MP615491MKYCRYCA",
                  "transaction_fee":{
                     "value":"1.86",
                     "currency":"SGD"
                  },
                  "links":[
                     {
                        "href":"https://api.sandbox.paypal.com/v1/payments/sale/2WD385798K879144N",
                        "rel":"self",
                        "method":"GET"
                     },
                     {
                        "href":"https://api.sandbox.paypal.com/v1/payments/sale/2WD385798K879144N/refund",
                        "rel":"refund",
                        "method":"POST"
                     },
                     {
                        "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-4A020366MP615491MKYCRYCA",
                        "rel":"parent_payment",
                        "method":"GET"
                     }
                  ]
               }
            }
         ]
      }
   ],
   "links":[
      {
         "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-4A020366MP615491MKYCRYCA",
         "rel":"self",
         "method":"GET"
      }
   ],
   "httpStatusCode":200
}

(Web Payment JSON)

{
   "id":"PAY-7GT16633EV511960JKYCSI6Y",
   "create_time":"2015-09-25T10:39:55Z",
   "update_time":"2015-09-25T10:39:55Z",
   "state":"created",
   "intent":"sale",
   "payer":{
      "payment_method":"paypal",
      "status":"VERIFIED",
      "payer_info":{
         "email":"...",
         "first_name":"test",
         "last_name":"buyer",
         "payer_id":"HBT36U55GA6R8",
         "shipping_address":{
            "line1":"123 Thomson Rd. ",
            "city":"Singapore",
            "postal_code":"308123",
            "country_code":"SG",
            "recipient_name":"buyer test"
         }
      }
   },
   "transactions":[
      {
         "amount":{
            "total":"20.00",
            "currency":"SGD",
            "details":{
               "subtotal":"20.00"
            }
         },
         "description":"...",
         "item_list":{
            "items":[
               {
                  "name":"X",
                  "price":"10.00",
                  "currency":"SGD",
                  "quantity":"2"
               }
            ]
         },
         "related_resources":[

         ]
      }
   ],
   "links":[
      {
         "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-7GT16633EV511960JKYCSI6Y",
         "rel":"self",
         "method":"GET"
      },
      {
         "href":"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-1MX622874M8475431",
         "rel":"approval_url",
         "method":"REDIRECT"
      },
      {
         "href":"https://api.sandbox.paypal.com/v1/payments/payment/PAY-7GT16633EV511960JKYCSI6Y/execute",
         "rel":"execute",
         "method":"POST"
      }
   ],
   "httpStatusCode":200
}

1 Answer 1

1

For the Mobile SDK, it handles the redirect and execution of the payment in the mobile application. So, you are returned with the HATEOAS links for the payment info and refund info. The transaction is already completed at that point.

For the web, you still need to redirect the customer and then execute the payment, which it sounds like you are already doing and is working okay.

TL;DR: Mobile SDK already executed the payment.

1
  • Noted. Yes, also to add I should verify the mobile payment.
    – Jiew Meng
    Sep 26, 2015 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.