Use last subscription created at time as a subscription generation number

This commit is contained in:
Ehren Kret
2021-10-14 12:06:19 -05:00
parent c0837104cd
commit 8b8c6237be
2 changed files with 12 additions and 7 deletions

View File

@@ -305,11 +305,12 @@ public class SubscriptionController {
}
if (record.subscriptionId == null) {
long lastSubscriptionCreatedAt = record.subscriptionCreatedAt != null ? record.subscriptionCreatedAt.getEpochSecond() : 0;
// we don't have one yet so create it and then record the subscription id
//
// this relies on stripe's idempotency key to avoid creating more than one subscription if the client
// retries this request
return stripeManager.createSubscription(record.customerId, priceConfiguration.getId(), level)
return stripeManager.createSubscription(record.customerId, priceConfiguration.getId(), level, lastSubscriptionCreatedAt)
.thenCompose(subscription -> subscriptionManager.subscriptionCreated(
requestData.subscriberUser, subscription.getId(), requestData.now, level)
.thenApply(unused -> subscription));