Search code examples
node.jspaypalpaypal-sandboxpaypal-subscriptions

Subscription plan not updating after revising with PayPal API in sandbox environment


I am attempting to update a subscription plan using the PayPal API in a sandbox environment. After successfully revising the subscription plan and receiving a positive response, I fetch the subscription details again. However, the retrieved subscription still displays the old plan ID instead of the updated one. I have waited for some time to allow for potential delays in the update process, but the issue persists. I have thoroughly checked my code and ensured that the revision request and subsequent fetch request are correctly implemented. Are there any known limitations or additional steps I should consider when updating subscription plans with the PayPal API in a sandbox environment?

Revising the subscription plan:

const updateSubscriptionPlan = async () => {
  try {
    // Code to obtain PayPal token and define planId and apiUrl

    const updatedSubscriptionResponse = await axios.post(
      apiUrl,
      { plan_id: planId },
      { headers: headers }
    );

    // Console log the updatedSubscriptionResponse.data
  } catch (error) {
    // Handle errors
  }
};

Fetching the subscription details:

const getSubscriptionDetails = async () => {
  try {
    // Code to obtain PayPal token and define apiUrl

    const updatedSubscriptionResponse = await axios.get(
      apiUrl,
      { headers: headers }
    );

    // Console log the updatedSubscriptionResponse.data
  } catch (error) {
    // Handle errors
  }
};

Note: I have verified that the subscription ID used in the endpoint URL is correct, and I am using a sandbox environment. I have also reviewed the response data from the revision request and confirmed that the plan ID update was successful. Despite this, the updated plan ID is not reflected when fetching the subscription details again. Any insights or suggestions on how to troubleshoot this issue would be greatly appreciated. Thank you.


Solution

  • The payer has not approved the new plan, therefore the change has not taken effect.

    See the Subscriptions documentation:

    Subscriptions using PayPal require the user to login and re-consent to the change using the approve HATEOS URL returned in the response. If re-consent is not done or if it fails, the subscription continues to be billed on the existing plan.

    The JS SDK paypal.Buttons createSubscription callback can be used instead of a redirect for this approval. Have the callback (optionally fetch and) return the subscription ID.