#wiiim
1 messages ยท Page 1 of 1 (latest)
๐ How can I help?
Hey ๐ thanks for reaching out. I have a subscription model where each customer could have a custom pricing based on their personal discount.
For example:
- A user has a discount of 10%
- Creates a new subscription
- Gets a discounted price for the first invoice and each month after that too
Now I want to be able to change the personal discount of a user while they are in an active subscription. The way I want it to work is that just the next and future invoices are affected. For example if a user has a current discount of 50% and is in the middle of the period and I change it to 10%, stripe should not charge the customer some calculated amount to make up that other half of the month.
In code I use something like this:
item = SubscriptionCreateParams
.Item.builder()
.setTaxRates(List.of(stripeTaxRateKey))
.setPriceData(SubscriptionCreateParams.Item.PriceData.builder()
.setCurrency("eur")
.setProduct(stripePrice.getProduct())
.setRecurring(SubscriptionCreateParams.Item.PriceData.Recurring.builder()
.setInterval(SubscriptionCreateParams.Item.PriceData.Recurring.Interval.MONTH)
.setIntervalCount(1L)
.build())
.setUnitAmount(price)
.build())
.putMetadata("discount", String.valueOf(discount))
.build();
and attach it to this subscriptionCreateBuilder:
SubscriptionCreateParams.Builder subCreateParamsBuilder = SubscriptionCreateParams
.builder()
.setCustomer(user.getStripeCustomerId().getValue())
.setMetadata(meta).setBackdateStartDate(firstDay.atStartOfDay(ZoneOffset.UTC).toEpochSecond())
.setBillingCycleAnchor(billingCycleAnchor)
.setPaymentBehavior(SubscriptionCreateParams.PaymentBehavior.DEFAULT_INCOMPLETE)
.addAllExpand(List.of("latest_invoice.payment_intent"))
.setTransferData(SubscriptionCreateParams.TransferData.builder()
.setDestination(stripeConnectedAccount)
.build());
What's the problem you're facing?
On how to update the actual pricing because I've tried that some time earlier and it says that those prices are archived and cannot be changed.
Are you going to change to a new price or the discount amount?
Basically I want to change it to a "backend" sided custom price, no discounts/coupons used by stripe here. More or less the "unit_amount" I guess.
But I think I'll have to create a new price for that and delete the old one?
After a price is created, the amount can't be updated regardless whether it's been archived. Updating the amount of a price is not supported.
To update the subscription with new price, you may follow this guide: https://stripe.com/docs/billing/subscriptions/upgrade-downgrade
Instead of using price of new price, price_data can be used for new price
Okay so I was thinking about creating a Price with the updated "discounted" price and set the id on the price_data field on the subscription's item?
The original ask was about using price_data. price_data is an ad-hoc price that doesn't have a price created in advance (no price ID).
If the price has been created and new price ID is available, the ID should be set in price parameter.
Oh now I get it I think. So stripe uses the data from price_data on subscription creation to create the price object itself and stores it in the "price" field so when I want to update it later on I should put the id of the price I created in the "price" field?
Sorry, I may overcomplicate it haha
So stripe uses the data from price_data on subscription creation to create the price object itself and stores it in the "price" field
Yes,price_datawill create an one-time price ID and return in the response underpricefield
so when I want to update it later on I should put the id of the price I created in the "price" field?
Yes, if you use Price API to create a new price, its ID should be set underpriceparameter