How to Associate PayPal Subscriptions with User Information in FastAPI using IPN and Webhooks?

I am working on implementing PayPal subscription payments for my website, which is built using FastAPI as the backend. My goal is to track and identify users who have subscribed by clicking on the subscribe button.
Challenges: I’ve tried using PayPal’s IPN (Instant Payment Notification) and webhooks, but I’m struggling to understand how to update my database with the user’s subscription information after they’ve successfully made the payment.

I attempted to modify the PayPal button to include additional data, but I’m not receiving the same values from the IPN or webhooks. How can I ensure that the data I send with the button is correctly linked to the user who completed the payment and subscription?

In the JSON where the subscription is created, add a custom_id parameter with a value that identifies the user or profile it should be associated with.

That value will be returned in future webhooks related to that subscription. In particular you should subscribe to the event PAYMENT.SALE.COMPLETED, calculate and update the subscription’s good-through date every time you receive that event.

Leave a Comment