Track subscription id through renewal

  • Olle Haerstedt
  • Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 11 months ago - 7 years 11 months ago #81625 by Olle Haerstedt
Track subscription id through renewal was created by Olle Haerstedt
Hi,

We want to connect each subscription with a "key", which is used to enable various features on another site. For example, we can have:

- Subscription A is connected to K1
- Subscription B is connected to K2

When a subscription is renewed, the key will also be extended. To be able to do this, we have to track the subscription id. The problem is, for each payment, a new subscription is created. If subscriptions A and B are of the same plan/type, is it possible to know at payment which one is which?

I looked at the $row value and it has some fields that might be useful. Unfortunately, they are all empty at renewal.

'from_subscription_id' => '0',
'subscription_id' => '',
'from_plan_id' => '0',

Regards
Olle

Edit: I found field "subscription_code", which seems to be unique for each subscription, and can be used to pair one subscription to our "key". Is this correct?
Last edit: 7 years 11 months ago by Olle Haerstedt.

Please Log in or Create an account to join the conversation.

More
7 years 11 months ago #81655 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Track subscription id through renewal
Hi Olle

1. Yes, I think you can use the subscription_code as the key

2. When someone renews the subscription, the system will create a new subscription record. For that record, you would know the user_id and the plan_id, so you can query the database for the first subscription record of that user, check the subscription_code from that first record and extends it. I think it should work (or maybe I mis-undertood your requirement)

Tuan

Please Log in or Create an account to join the conversation.

  • Olle Haerstedt
  • Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 11 months ago #81671 by Olle Haerstedt
Replied by Olle Haerstedt on topic Track subscription id through renewal
Hi,

Thanks for your answer!

About 2, it was my understanding (when I looked at the database) that subscription_code is always the same, even for updated subscriptions? So there would be no need to query for the first record. Correct?

Regards
Olle

Please Log in or Create an account to join the conversation.

More
7 years 11 months ago #81754 by Tuan Pham Ngoc
Replied by Tuan Pham Ngoc on topic Track subscription id through renewal
Hi Olle

That's not correct. Each record has it own subscription_code (it is a random string). So you could not use that string to query the first record.

Regards,

Tuan

Please Log in or Create an account to join the conversation.

  • Olle Haerstedt
  • Topic Author
  • Offline
  • New Member
  • New Member
More
7 years 11 months ago - 7 years 11 months ago #81771 by Olle Haerstedt
Replied by Olle Haerstedt on topic Track subscription id through renewal

Tuan Pham Ngoc wrote: 2. When someone renews the subscription, the system will create a new subscription record. For that record, you would know the user_id and the plan_id, so you can query the database for the first subscription record of that user, check the subscription_code from that first record and extends it. I think it should work (or maybe I misunderstood your requirement)


This solution will not work if a user can have multiple subscription. I'm still looking for a away to uniquely identify a subscription through renewals.

Olle

Edit: Maybe the best solution is to create a new column in the osmembership_subscriber table, to use as identifier? Then it can be accessed and updated through a plugin. What to you think?

Edit 2: I realized that subscription_id (using profile id from Paypal) is unique together with user_id, so I will use that to track subscriptions.
Last edit: 7 years 11 months ago by Olle Haerstedt. Reason: Added solution

Please Log in or Create an account to join the conversation.