Momo
Momo

Reputation: 35

Paypal API - Get the capture_id after subscription

I have a subscription button that I integrated with the Paypal API. After a subscription I get these informations:

{ orderId: "ORDERID", subscriptionId: "SUBSCRIPTIONID" }

I need to get the capture_id which is the id of the captured payment after the user subscribed.

After searching the doc and lot of chatting with chatGPT I know to get the capture_id I have to do this request:

curl -X GET https://api.paypal.com/v2/checkout/orders/<order_id> \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access_token>"

I should have the capture_id in the purchase_units fields returned by the request, but the purchase_units field I get is an empty array.

The status of my order is "APPROVED" and I need to have the status as "CAPTURED" to get the purchase_units. To do this I need to make this request:

curl -X POST https://api.paypal.com/v2/checkout/orders/<order_id>/capture \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access_token>"

But when I do that I get the error: "INTERNAL_SERVER_ERROR".

Also I don't understand why the order I get has the status "APPROVED" and not directly "CAPTURED", since when I go check on the user test account I have the payment which is done:

enter image description here

Upvotes: 0

Views: 478

Answers (1)

Preston PHX
Preston PHX

Reputation: 30402

Use the Get Subscription Details API call, and/or subscribe to the webhook PAYMENT.SALE.COMPLETED

To aid in reconciliation, add a custom_id when creating the subscription. This value will be returned in all webhook payment notifications, for both the first and future payments.

Upvotes: 1

Related Questions