Paypal Finalize Subscription
POST
/api/payments/paypal/finalize
const url = 'https://example.com/api/payments/paypal/finalize';const options = {method: 'POST'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://example.com/api/payments/paypal/finalizeFinalize a PayPal subscription created client-side via Smart Buttons.
Expects JSON body: { “subscription_id”: “I-XXXX” } Flow:
- Exchange client credentials for access token
- GET subscription details from PayPal Billing Subscriptions API
- Validate custom_id correlation (custom_id == “<user_id>:<package_id>” or startswith user_id)
- Map PayPal plan_id back to internal package id (reverse PAYPAL_PLANS mapping)
- Upsert subscription (status active/pending) so polling & UI can reflect state while awaiting webhooks Returns normalized status snapshot.
Responses
Section titled “Responses”Successful Response
Media typeapplication/json
Examplegenerated
example