Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

laracoft's avatar

PayPal subscriptions schema

I handle PayPal subscriptions with the following 3 tables (buyers, transactions and subscriptions) and relations:

  • buyer hasMany transactions (transactions.buyer_id -> buyers.id)
  • transactions belongsTo 0 or 1 subscription (transactions.subscription_id -> subscriptions.id, nullable)
  • This is because some transactions such as chargebacks do not belongsTo any subscription
  • subscription hasMany transactions, e.g. monthly/annual payments until cancelled
  • What these implies is that, all subscriptions can be traced back to a buyer, i.e. buyer hasMany subscriptions
  • Currently, subscriptions does not have a buyer_id because I want to avoid a case where subscriptions.buyer_id differs from transactions.buyer_id due to bugs etc

My question is:

  1. Is not having a buyer_id in subscriptions a good practice?
  2. How do I write the buyer and subscription's model to relate to each other for the current structure? (So that it is also compatible in Nova)
  3. Anyone doing this differently and feels it is better than above?

Thank you.

0 likes
1 reply

Please or to participate in this conversation.