#hamzaig
1 messages ยท Page 1 of 1 (latest)
hey there, what have you done so far and what is causing you trouble?
how can i create a priceid for the subsciption as every month 20$ flat fee and 0.87$ per request
can you help me?
You can read about modeling a bit here: https://stripe.com/docs/billing/subscriptions/usage-based#product-modeling
and here: https://stripe.com/docs/products-prices/pricing-models#model-usage-based-pricing-on-stripe
What you're asking about is putting in a flat fee in the first (possible only) tier as shown here:
https://stripe.com/docs/products-prices/pricing-models#adding-flat-fees
I dont Understand the documentation can you only tell me how to create the priceId for that the customer charged with $20 montly and allowed 20 requests monthly and after that it will be charged 0.87 per request
There is example just above for all server languages:https://stripe.com/docs/products-prices/pricing-models#graduated-pricing
What client do you use?
You'd set the first tier to have flat_amount=2000 with unit_amount=0 and up_to=20 then your second tier is flat_amount=0 with unit_amount=87 and up_to='inf'
i am using reactjs
if you can create write the react code for the price id i am very thankful to you
or you can define the process on dashboard
First time i am using the stripe
There is no react code for that, you'd create that price on your backend server or in thw dashboard
how can in the dashboard
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
choose your product (or create one)
then set up the price as described here: https://stripe.com/docs/products-prices/pricing-models#model-usage-based-pricing-on-stripe
(click the "dashboard" tab)
You can either create a Product or select an existing product and create a Price
What do you mean you have a problem getting the price ID?
yes how can i create price id for the same scenario
Using the steps here, either following the API or Dashboard steps
That looks like what you described, yes, though using 88c instead of 87, but your choice there
ok thanks
there is one more problem with this when i apply it them it is not charged currntly
i want first 20$ charge immediately
Hi there ๐ my teammate needed to step away, but I can assist. Taking a quick look at the conversation so far, am I understanding correctly that you're working with metered prices?
yes i am working with metered pricing
i want to create product like that
i created that but i think it is working fine but it is not charging immediately
Thank you for that clarification! Metered prices will always bill in arrears (at the end of the billing period) rather than at the beginning.
If you want to bill at the beginning of the billing period for a flat price, then you will need to use a non-metered price for that portion. Though that will limit some of your integration paths as you'll then have multiple items in the Subscription.
so it is bad approch or not
i had create another price in the product
then can any problem with that
but in which the example that is shared in github it used only one priceid in the code
Can you share the ID of a request where you created a Subscription and don't think it immediately processed a payment?
That does look like a zero-dollar Invoice, but could you share the ID of the request that created that Subscription so I can take a closer look at what values were provided as part of that request?
https://support.stripe.com/questions/finding-the-id-for-an-api-request
Find help and support for Stripe. Our support center provides answers on all types of situations, including account information, charges and refunds, and subscriptions information. Get your questions answered and find international support for Stripe.
req_BCxpMVhTX0xPcI
req_KKAG6SpxWvHDxI
req_xn2Jt2ptuwoKZW
POST /v1/products/prod_N8jdy3epZ34ZkJ
Status
200 OK
ID
req_BCxpMVhTX0xPcI
POST /v1/prices
Status
200 OK
ID
req_KKAG6SpxWvHDxI
POST /v1/subscriptions
Status
200 OK
ID
req_xn2Jt2ptuwoKZW
i am new at stripe these are the three id's according to request
Thank you, I'm working on pulling those up.
sure i am waiting
Looking at the request to create the Subscription, I'm only seeing one Price object being provided, and that Price seems to be a metered one so the first Invoice not including a payment seems expected.
If you want to bill your customers for metered usage, and a flat fee at the beginning of the billing period, then your Subscription will need to be created with two entries in the items array. One that is mapped to a recurring, non-metered Price that represents your flat fee, with the other being your metered Price.
very thank you but i am confussing because your code example thats i have share screen shot only use one price id
// Create the subscription
const subscription = await stripe.subscriptions.create({
customer: req.body.customerId,
items: [{ price: process.env[req.body.priceId] }],
expand: ['latest_invoice.payment_intent', 'pending_setup_intent'],
});
as that
items: [{ price: process.env[req.body.priceId] }],
This line here, in it items accepts an array of objects, so you can pass in multiple items.
It would look something like:
{
price: process.env[req.body.priceId]
},
{
price: [ID_OF_NON_METERED_PRICE]
},
],```
ok one more question
Sure
app.post('/retry-invoice', async (req, res) => {
// Set the default payment method on the customer
try {
await stripe.paymentMethods.attach(req.body.paymentMethodId, {
customer: req.body.customerId,
});
await stripe.customers.update(req.body.customerId, {
invoice_settings: {
default_payment_method: req.body.paymentMethodId,
},
});
} catch (error) {
// in case card_decline error
return res
.status('402')
.send({ result: { error: { message: error.message } } });
}
const invoice = await stripe.invoices.retrieve(req.body.invoiceId, {
expand: ['payment_intent'],
});
res.send(invoice);
});
what's this endpoint meaning
retry invoice
Is this an endpoint that you built?
no this is the end point which is used in the example that are givin in the
https://stripe.com/docs/billing/subscriptions/usage-based
pasha
?
You can step through the functions that endpoint is calling to see what it is doing.
For instance, it uses the following functions:
await stripe.paymentMethods.attach- attaches a Payment Method to a Customerawait stripe.customers.update- updates a Customer objectawait stripe.invoices.retrieve- retrieves an Invoice object
thank you
can you describe that expand: ['latest_invoice.payment_intent', 'pending_setup_intent'],
That's expanding the contents of the response. If a response has the ID of an object, you can use Expand to return the object inline rather than just getting the ID. This topic is discussed in more detail in our API ref:
https://stripe.com/docs/api/expanding_objects
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
thank you
Happy to help!