Is It Possible to Detect Non-Initial Payments on a Subscription?

My client listens to incoming new order notifications via the REST API, and uses that info to send out personalized delivery urls to purchasers. We’ve run into a slight problem with subscriptions, tho: We want to only send the email on the first payment (order) of the subscription, and ignore subsequent ones (the email’s already been sent, after all).

So getting back to the subject, is there a good way to detect that programmatically? The documented “recurring”, “allow_payment”, “payment_plan” fields are all either null or absent, so even if they are related, they’re of no help.

You might need to setup a REST hook for payment.add and track the order then raise a tag for only the first instance/payment on that order.

That was my first hope, but each payment in the subscription is generating a different order id

So I believe that it’s actually the INVOICE number that is changing. Order id’s don’t change but rather, invoices are incremented by 2 each time a new one is needed to fulfill the subscription. So you may want to watch the invoice.add REST hook (see the table schema and note below):

image

I believe every renewal generates a new JobId and a new InvoiceId. You can tell if an order was created through a subscription if Job.JobRecurringId is not 0.

You can also always find the initial order of a subscription through RecurringOrder.OriginatingOrderId.