#tymm
1 messages ยท Page 1 of 1 (latest)
Hi there, can you tell me how you apply a coupon?
paramsBuilder.setCoupon(couponCode); where paramsBuilder is of class SubscriptionCreateParams.Builder
then Subscription.create(paramsBuilder.build())
Ok, so you apply the coupon on the subscription itself.
yes the coupon will be applied to the invoices generated by the subscription, including invoice items that you are adding to
i could set coupon to the items instead? if so how do i do that? im curently adding items into subscription using this method
paramsBuilder.addItem(
SubscriptionCreateParams.Item
.builder()
.setPrice(item.getKey())
.setQuantity(item.getValue())
.build()
);
https://stripe.com/docs/api/invoiceitems/create#create_invoiceitem-discounts-coupon yes you can apply a coupon for this invoice item only
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
i cannot use invoice. i have to set things like proration date, backdate startdate, prorations, etc
and also i have all other stuffs built using subscriptions already
i want to be able to apply coupon to a subscription, at the same time also able to add a one time fee to the subscription and not get affected by the coupon
you can't really, we don't support per-item discounts on Subscriptions today unfortunately, it's a known gap but the functionality was only implemented for one-off invoices and hasn't been prioritised to expand to subs . Make sure to write to https://support.stripe.com/?contact=true to raise feature requests for the team
without that, what is probably best is to add negative invoice items to the Subscription in order to apply discounts of an amount you calculate, instead of coupons.
are we able to charge a one time arbitrary amount to a subscription?
in several ways yes.
https://stripe.com/docs/billing/invoices/subscription#adding-upcoming-invoice-items is that what you mean?
what i meant was i want to charge an extra amount on the fly , after reverse-calculating the amount of one time fee that would be charged after applying a coupon. i saw this api, seems promising, am still testing it.
if(coupon != null){
charge = charge / (coupon.getPercentOff().doubleValue() / 100);
}
paramsBuilder.addAddInvoiceItem(
SubscriptionCreateParams.AddInvoiceItem.builder()
.setPriceData(SubscriptionCreateParams.AddInvoiceItem.PriceData.builder()
.setCurrency("myr")
.setProduct("Service Charge")
.setUnitAmount(charge.longValue())
.setTaxBehavior(SubscriptionCreateParams.AddInvoiceItem.PriceData.TaxBehavior.INCLUSIVE)
.build()
)
.build()
);
adding an invoice item will incorporate it into the next Invoice on the subscription. Or you can force the next invoice by updating the subscription with billing_cycle_anchor:"now" ; or you can create a separate one-off invoice for the customer with the item; or you can charge the customer's card directly with a PaymentIntent
ok it seems like the setProduct() is meant for a productid is it possible to charge something without a product?
you can pass amount/currency directly instead of using a Price/Product (we just try to discourage that because we want you to have your product catalogue on Stripe)
adding an invoice item will incorporate it into the next Invoice on the subscription.
i have tested this and i saw that the subsequent invoice doesnt have the service charge.
first invoice :in_1NfIs8LouXJU4FDJqtWvig3k
next month invoice :in_1NfItmLouXJU4FDJo9mnMlwQ
looks like this is only available for invoice api, so i dont think i can use that. ๐
you can though
i have tested this and i saw that the subsequent invoice doesnt have the service charge.
adding an invoice item with https://stripe.com/docs/billing/invoices/subscription#adding-upcoming-invoice-items is a one-time thing, it adds one item, and that one item is pulled into one future invoice. Maybe that wasn't clear? but you also never mentioned to me that you wanted anything recurring here, you just said 'charge a one time arbitrary amount to a subscription?' which is exactly what this is and what happened ๐
ah maybe i misunderstood what u meant by next invoice.
yes, this one-time behavior is exactly what i want, minus the part where a MYR 1 service charge became MYR 0.5 due to a 50% off coupon being applied.
this is also why i said i planned to "reverse-calculate" the service charge manually, so that i would add a MYR 2 service charge and after the coupon is being calculated, the final service charge would theorically be MYR 1
minus the part where a MYR 1 service charge became MYR 0.5 due to a 50% off coupon being applied.
coupons apply to the entire Subscription Invoice, (as I said earlier, per-item discounts are not supported today)
so yeah, you can make the item 2 MYR instead I suppose so it nets out to the correct amount.
can i actually use this on a subscription? i want the service charge and the subscription be in one transaction tho,
can i actually use this on a subscription?
it adds an invoice item to the Customer and that item is charged in the next Invoice for the customer, e.g. in the next Subscription Invoice they have
so I don't understand the question, of course you can use it with a Subscription, you just did exactly that in the test you showed me
i want the service charge and the subscription be in one transaction tho
not sure what a 'transaction' means here, but like an Invoice with 100 items is only charging the customer's card once(for the total), not 100 times
because i dont see setamount being one of the function that i can call in the snippet i've shown earlier
probably because we removed it from the Java SDK for the reasons I mentioned earlier of us wanting you to have a product catalogue
sorry, I know that's annoying but it's a policy that we have, we don't remove things from the API but sometimes we deprecate them from the SDKs to make them less discoverable/nudge people towards the integrations we want
you can still pass it using .putExtraParam("amount", "4242") on the Param Builder class
would this invoice item that i add persist in the subsequent invoices for the subscription? if i were to add the extra charges this way
no, it's one time
you can add it each month, technically; like listen to the invoice.upcoming event and add it then. But then why don't you simply add it as a normal recurring Product/Price to the Subscription? I think you need to take a step back and think over things
no, one time is what i want, just making sure
because after looking at the docs i cannot understand how to use it still
so programmatically i would create the subscription first, then create an invoice item that links to the subscription ?
right now i would create a subscription, and from there i get the invoice object. do i add the one time charge there?
Hi! I'm taking over from my colleague. Please, give me a moment to catch up.
Just to summarise, you want to add a one-time item to an upcoming Invoice? Or charge the Customer outside of their normal billing cycle?
i want to add a one-time charge onto a subscription when im creating the subscription
the subscription can have prorations, backdate and also coupon. the one-time charge should not be affected by those settings
add_invoice_items is a parameter for this: https://stripe.com/docs/api/subscriptions/create#create_subscription-add_invoice_items
It adds the provided items only to the first Invoice.
the one-time charge amount would be halved if i apply a 50% off coupon to the subscription. i do not want that
ok let me try
ok it works
๐
but it would be too tedious to add all the other products one by one except for the service charge product that i do not want to add. is there a "excluding" feature on stripe?
else i think i could make a script to call to api then
You can generate the Coupon on the spot via API when the Subscription is created, and only include the items from Subscription.
thanks
Happy to help!