To confirm the subscription payment flow

Hi @Bryan-Square , So, pls confirm me this, what I am doing is this whenever I get an invoice.updated webhook, I look for subscription_id in it then I fetch the API response from retrieve_susbcription method using that subscription_id, then I look for the invoices array in the response and then take the latest invoice in the array (which appears to be the first one i.e. [0]th index in the array), then I check the status of that invoice and if it is not PAID, I act accordingly, is it the right flow, I am currently listening for subcription.updated and invoice.updated webhook events for the payment confirmation. I am looking for the invoice arrays as it appears there can be versions of a single invoice so I am looking for the latest version (that should be the one associated in the array, right?)

You can just take the invoice_id from the webhook event and call the Invoices API to get the status of the invoice without calling the Subscriptions API. :slight_smile:

Hi @Bryan-Square , thanks for responding, so it seems the invoice array in the api response for retrive_subscription doesn’t always contains the latest version of the invoice so then i cant really rely on that so this is the flow i am adapting from now on, pls confirm this
We extract the following fields from the webhook payload:

  • Invoice ID

  • Subscription ID

  • Version number

  • Invoice status

  1. If the invoice status is DRAFT, we ignore the webhook completely and do nothing.
  2. Using the Subscription ID, we look up the corresponding subscription record in our database.
  3. If we do not find a matching subscription record, we ignore the webhook.
  4. If the Invoice ID in the webhook is different from the Invoice ID currently stored in our database:
    • We update the stored Invoice ID.

    • We update our db accordingly.

  5. If the Invoice ID is the same as the one already stored:
    • We compare the webhook’s version number with the version number stored in our database.

    • If the webhook version is newer (greater than the stored version), we update the metadata and invoice status.

    • If the webhook version is the same or older, we ignore the webhook.

@Bryan-Square pls reply and confirm me on this