#amfpaulo_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1268593557527330906
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Easiest way would probably be to create a negative amount invoice item (which will act as a credit/discount to the total): https://docs.stripe.com/api/invoiceitems/create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So there is not discount feature I have to hack the system to apply a discount ?
It looks like
What do you mean
This way will not work for me, what are other ways ?
I need to apply a discount to a invoice
A negative item involves creating a price the is negative, etc
Not true
All I need its apply a discount to the invoice also subscription
What I suggested does that
just a second let me take a look on the code
Coupons are the alternative https://docs.stripe.com/billing/subscriptions/coupons
Here are more alternatives: https://docs.stripe.com/billing/subscriptions/coupons#alternative
All this is covered in the docs
(Including my initial suggestion of negative invoice items)
this is the way I am creating the item for my subscription:
Items = new List<SubscriptionItemOptions>
{
new SubscriptionItemOptions { Price = request.PriceId }
},
Just adding another : new SubscriptionItemOptions { } to it with negative value ?
there is no property to inform a dollar value
Could you explaing how to do this ?
Hello
Taking over here
Hello hanzo
how are you doing today ?
PriceData is the field I should add a negative dollar amount ?
I'm doing well. Thanks for asking..
How can I help? I see you're trying to add a discount..
If you're trying to create an negative invoice item then you'd want to use InvoiceItems API for that: https://docs.stripe.com/api/invoiceitems/create
Lets start over, this is getting confuse
The previous support person advice me to use a negative item
Right, since you want to apply "an amount" as discount, that's the way to go
I am trying to acomplish the discount on a invoice, and I also need to apply to subscription
Invoice item have a field Amount
but subscription item do not have field amount, just priceId
it has a field PriceData, that i did not understand how to use
Is this discount one-time or recurring?
Do you want it to apply to one subscription invoice OR all invoices going forward?
its one time
its a one time thing, I have a point of sales, client ask for discount we negotiate and give unique discount one time only
You'd only create a subscription item if you want the item to be a recurring purchase
but every month, the discount will be applyind in case of amonthly subscription
Sorry I'm not sure I follow
you said it is a one-time thing but "but every month, the discount will be applyind in case of amonthly subscription"
what does that mean
I already have subscription and invoice working 100%, now the necessity to give the client a discount came along
if invoice one time only, if the purchase is a subiscription that price is $100 but I gave 10 dollar discount, so every month this client will be charged just 90
but if a product is not recurring and cost 100 and I give 10, just the time the product will cost 90
Is it making more sense now ?
so for subscriptions you want the discount to be recurring (apply every month)?
but for one-time invoices, it would be one-time discount
yes
For subscriptions:
You can create a coupon for discount amount and apply that to subscription - https://docs.stripe.com/billing/subscriptions/coupons#coupons
but I am not using that couon anyware else
Its a client specific case
when a client negotiate for discount
So there's no way to apply recurring discount to a subscription without using a coupon
You can't create a negative amount subscription item
Other option would be to create a second price (cheaper than the original price) and update the subscription to use that
Ok, So, in this case, I'll need to create coupons for every discount I give ?
I cant create second price becaue this is not standarized discount, its negotiation discount
can be 1dollar, 10, 17, etc
Yeah you'd need to create a coupon for each negotiated discount and apply that to the subscription
sorry about that, I missid this part . Ok, cool . got it
I have a last question related to invoice: Why When I pay a invoice using the Customer default card on file it takes one hour to have the invoice paid ?
On more question just to make sure I understand everything correctly for subscription discount: I create the discount coupon , then I add it to the Subscription Discounts field ?
One hour is the default invoice finalization duration: https://docs.stripe.com/billing/subscriptions/overview#invoice-lifecycle
On more question just to make sure I understand everything correctly for subscription discount: I create the discount coupon , then I add it to the Subscription Discounts field ?
Yes
cool. got it right about the subscription
About the invoice, this behavior cannot be altered? Everytime I select use card on file for client payment, it will take 1 hour?
You can use the API to finalize it manually: https://docs.stripe.com/api/invoices/finalize
We have a gym and customers are always grabbing a water or any other drink and asking us to charge the card on file, so we use a lot this feature
I am finalizing manually
this is my C# backend code:
try
{
var options = new InvoiceCreateOptions
{
Customer = request.CustomerId,
CollectionMethod = "charge_automatically",
AutoAdvance = true,
Metadata = new Dictionary<string, string> {
{ "comission", string.Join(',', request.SalesPersonIds) },
{ "discount", request.Discount.ToString() },
},
};
if (!string.IsNullOrEmpty(request.SetupIntentId))
{
var paymentMethodId = GetLastPaymentMethod(request.SetupIntentId);
UpdateDeaultPayment(request.CustomerId, paymentMethodId);
options.DefaultPaymentMethod = paymentMethodId;
}
var invoiceService = new InvoiceService();
var invoice = invoiceService.Create(options);
new InvoiceItemService().Create(new InvoiceItemCreateOptions
{
Invoice = invoice.Id,
Customer = request.CustomerId,
Price = request.PriceId,
});
invoiceService.FinalizeInvoice(invoice.Id);
return CustomResponse(new { Success = true, SubscriptionId = invoice.Id });
}
catch (StripeException e)
{
NotifyError($"Error creating Invoice! {e.Message}");
return CustomResponse();
}
Gotcha then you can try paying using the API too: https://docs.stripe.com/api/invoices/pay
I thought about that, but was awkward from my perspective. So if I use the Pay API and do: service.Pay("in_xtp...."); the system will know the invoice client and also know it has a card on file as option to pay , moreover invoice would be paid ?