#hamzaig

1 messages ยท Page 1 of 1 (latest)

lethal onyxBOT
gloomy gust
#

hey there, what have you done so far and what is causing you trouble?

quartz jungle
#

how can i create a priceid for the subsciption as every month 20$ flat fee and 0.87$ per request

#

can you help me?

gloomy gust
#

Learn how to charge customers based on how much they use your product or service.

Learn about common pricing models and how to create them.

quartz jungle
#

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

gloomy gust
#

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'

quartz jungle
#

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

gloomy gust
#

There is no react code for that, you'd create that price on your backend server or in thw dashboard

quartz jungle
#

how can in the dashboard

gloomy gust
#

choose your product (or create one)

#

(click the "dashboard" tab)

#

You can either create a Product or select an existing product and create a Price

quartz jungle
#

this is the same scenario

#

but i had a problem to get priceId

gloomy gust
#

What do you mean you have a problem getting the price ID?

quartz jungle
#

yes how can i create price id for the same scenario

gloomy gust
quartz jungle
#

api steps

#

is it ok only confirm?

gloomy gust
#

That looks like what you described, yes, though using 88c instead of 87, but your choice there

quartz jungle
#

ok thanks

quartz jungle
#

there is one more problem with this when i apply it them it is not charged currntly

#

i want first 20$ charge immediately

mystic tapir
#

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?

quartz jungle
#

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

mystic tapir
#

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.

quartz jungle
#

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

mystic tapir
#

Can you share the ID of a request where you created a Subscription and don't think it immediately processed a payment?

quartz jungle
#

ok one second

mystic tapir
#

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

quartz jungle
#

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

mystic tapir
#

Thank you, I'm working on pulling those up.

quartz jungle
#

sure i am waiting

mystic tapir
#

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.

quartz jungle
#

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

mystic tapir
#

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]
  },
],```
quartz jungle
#

ok one more question

mystic tapir
#

Sure

quartz jungle
#

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

mystic tapir
#

Is this an endpoint that you built?

quartz jungle
#

pasha

#

?

mystic tapir
#

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 Customer
  • await stripe.customers.update - updates a Customer object
  • await stripe.invoices.retrieve - retrieves an Invoice object
quartz jungle
#

thank you

#

can you describe that expand: ['latest_invoice.payment_intent', 'pending_setup_intent'],

mystic tapir
quartz jungle
#

thank you

mystic tapir
#

Happy to help!