Can't capture order, loop on action-required

AlinM
Contributor
Contributor

Hi,

 

I'm trying to implement Orders API v2 and I can't capture the order.

 

I create the order with intent = CAPTURE, user_action = PAY_NOW and payment_method_preference = IMMEDIATE_PAYMENT_REQUIRED.

 

Then I redirect the user to payer-action, I pay (on sandbox), then I'm redirected back to return_url where I'm supposed to capture the order.

Here I call orders endpoint in order to get full order details and if status is "APPROVED" and intent is "CAPTURE" I proceed to capture the order by posting the payload below to the capture link I receive. The server replies with PAYER_ACTION_REQUIRED and another payer-action (checkoutnow) link and here starts the loop; I go again to checkoutnow and so on.

 

 

 

 

{"payment_source":{"paypal":{"email_address":"mymail","experience_context":{"user_action":"PAY_NOW","return_url":"mysite/callback\/paypal_v2","cancel_url":"mysite/callback\/paypal_v2"}}}}

 

 

 

 

Initially I tried to capture the order without sending any payload, as there aren't any required fields for this endpoint, but it replies with the error below:

 

 

 

{"name":"INVALID_REQUEST","message":"Request is not well-formed, syntactically incorrect, or violates schema.","debug_id":"a8d16e5ecc4a7","details":[{"field":"/","location":"body","issue":"MALFORMED_REQUEST_JSON","description":"The request JSON is not well formed."}],"links":[{"href":"https://developer.paypal.com/docs/api/orders/v2/#error-MALFORMED_REQUEST_JSON","rel":"information_link","encType":"application/json"}]}

 

 


Can you please guide me how should I capture an order? I'm stuck.

Login to Me Too
4 REPLIES 4

Kavyar
Moderator
Moderator

Good day @AlinM 

 

Thank you for posting to the PayPal community.

 

I am writing to address the error you have been experiencing with invalid requests in the body. This error usually occurs when an invalid JSON request is sent.

 

To provide you with more information, please use the following link:  https://developer.paypal.com/api/rest/reference/orders/v2/errors/#link-captureorder

 

In order to help you capture order details, please make sure that you correctly pass the order ID and token. Additionally, if you want to send a request body, please ensure that the request is valid.

 

For more detailed guidance, please refer to the provided link: https://developer.paypal.com/docs/api/orders/v2/#orders_capture!path=payment_source&t=request

 

I would like to suggest that you try again.

 

If you are still experiencing issues, please create an MTS ticket via the following URL  - https://www.paypal-support.com/s/?language=en_US  .Please ensure that you provide detailed information and error details when submitting the ticket.

 

Sincerely,

Kavya

PayPal MTS

 

If this post or any other was helpful, please enrich the community by giving kudos or accepting it as a solution.

Login to Me Too

AlinM
Contributor
Contributor

Thank you for replying.

Indeed I wasn't sending [] (empty square brackets) but empty string. My curl framework wasn't sending empty JSON (empty brackets) when the request was POST and there was no data to be sent.

 

Another problem was the currency. I was testing with EUR and the merchant account was, somehow, accepting only USD. I don't think I've seen anywhere written this info into the docs. I had to figure it out after days of debugging.

 

So, for further developers: make sure you send [] even if the request is empty POST and check your currency. The PayPal payment page will let you pay with any other currency, but when you'll try to capture the order you'll receive another "payer-action" response with "checkoutnow" link which will lead you into a loop.

 

Thank you!

Login to Me Too

eckosneekz
Contributor
Contributor

I have the same issue but not understanding the first part.

 

I am sending this based off your recomendation, an empty [].

 

axios.post(captureURL, [], {
   headers: {
      "PayPal-Request-Id": "7b92603e-77ed-4896-8e78-5dea2050476a",
       Authorization: `Bearer ${token}`,
   },
});

 

Initially I was sending this:

 

const capture_payload = JSON.stringify({
  payment_source: {
    experience_context: {
      return_url: "https://example.com/returnUrl",
      cancel_url: "https://example.com/cancelUrl",
    },
  },
});
 
axios.post(captureURL, capture_payload, {
   headers: {
      "Content-Type": "application/json",
      "PayPal-Request-Id": "7b92603e-77ed-4896-8e78-5dea2050476a",
       Authorization: `Bearer ${token}`,
   },
});

 

With the JSON payload results in PAYER_ACTION_REQUIRED.

 

Sending [] results in an error INVALID_REQUEST.  

Login to Me Too

Here-to-help
Contributor
Contributor

Hi @eckosneekz , Payer_action_required means that payer hasn't approved the payment/order request yet. You can capture the payment/order once it's approved. 

Login to Me Too

Haven't Found your Answer?

It happens. Hit the "Login to Ask the community" button to create a question for the PayPal community.