#arsani-sinout_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/1221919220535656468
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- arsani-sinout_api, 5 hours ago, 11 messages
- arsani-sinout_api, 6 hours ago, 3 messages
- arsani-sinout_api, 6 days ago, 12 messages
Can you double check that:
- The full API key was copied correctly in to Postman
- There isn't extra whitespace around your key
I am not sure if Postman trims whitespace but I suspect not
Sure , one sec
Just checked , and both are already correct
Is it relates to the key being test ?
Yes, that error should only relate to the key. If it was the right key but the wrong customer we would have an error about the customer
Should i use the Publishable key instead of the secret key ?
Secret key for creating customers, the public key only has read access and only to certain data on your account
I dont quite understand , which key should i be using then ?
Your secret key is the right one for this call. It looks like the secret key that you used for that successful call is similar to the one you used for this one. Trying to see if I can get more insight in to what was wrong with that second call
Yes , please
Maybe the header ?
๐ stepping in for my teammate.
I deleted your last message since you shared the full string of your test secret key.
Yes , thanks for that
Since this is a public channel, I recommend rolling your key. I looked through our logs and, while the key you used in Postman ends in the same characters/letters as the key you used with some Python code earlier today, the key is slightly different
I'm not sure if perhaps you accidentally added some characters somewhere in the middle of that key but they don't match
"Just did, but nothing changed" - what does this mean exactly?
I did reroll the key , but still getting the same response
Just retried my python code and it worked
Dont know how is that possible
Not sure how you rolled it/if you opted to expire at a later time
What do you mean by reroll it ?
Also , how do i charge a customer using their existing balance and how to i charge them to add to their balance ?
What parts of the documentation will i find this in ?
I recommend rolling the key that ends in WE by following these steps:
https://docs.stripe.com/keys#rolling-keys
Also , how do i charge a customer using their existing balance and how to i charge them to add to their balance ?
Are you referring to a customer credit balance? https://docs.stripe.com/billing/customer/balance
url = f"https://api.stripe.com/v1/customers/{CustomerID}/balance_transactions"
data = {
"amount": RechargeAmount,
"currency": "usd",
"customer": CustomerID,
"payment_method": "customer_balance",
}
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
data = response.json()
Just used this python , but it gave bad request
Any suggestions ?
What are you trying to do exactly?
To charge the customer
Are you following a specific guide/doc?
This doesn't look correct. I'm not sure why you're using customer and payment_method in the body of your request.
I removed them ,but still getting bad access
Can you share the ID of the customer you're working with? If you make a get call to retrieve that customer, do they have a balance?
req_W7ouUegbzLSTgh
They dont , i want to recharge their balance then charge them from their balance
Got it. I think there's a misunderstanding. By "recharge their balance", do you mean you want to give them a credit because you overcharged them or want to reduce the amount they need to pay later?
What's your ultimate goal here?
So , my ultimate goal is to charge them from the credit (balance) they already have, if this credit (balance) falls under a certain threshold , i charge their card to recharge their credit (balance)
So here , i am trying to recharge their balance , then charge them by deducting from their balance
Any thoughts ?
I still don't quite follow what you're trying to do.
charge them from the credit (balance) they already have
How do you want them to accumulate this balance? Like, do you plan on having them pay for this amount?
Say my customer will pay 5000 , this is their balance
Whenever they buy something (say for 50) , i deduct the 50 from the 5000
If their balance falls below 10 , i add 4990 to make it 5000 agin
So these are the 2 API request i want to acheive
1- recharge their balance
2- charge them (by deductng from their balance)
Got it. The customer balance is not what you think it is. If you want to charge customers for the 5000, you'll need to create a PaymentIntent with the appropriate amount so that customer pays you that amount. You'll need to keep track of any "credits" they have on your end and charge them again by creating another PaymentIntent for the right amount when they deplete their credits/when they fall below a threshold
Okay so 2 questions:
1- how to make a PaymentIntent
2- how to creat an API request to credit them (deduct from their balance) ?
For # 1, I recommend starting here: https://docs.stripe.com/payments/payment-intents
And our payments quickstart here: https://docs.stripe.com/checkout/quickstart
For # 2, you'll need to keep track of this yourself. I'm assuming you want to charge customers the 5000, have these funds to into your Stripe balance, and then charge the customer again at a later time, correct? You'll need to keep track of when you need to charge them again and what amount.
I am trying to do this using python , so what is the API endpoint to check the customer's "balance" (or the remaining from the 5000 in this case) ?
I'm not sure we're understanding each other. When a customer pays 5000, is your goal to use Stripe to charge them the full amount immediately?
I am using Stripe to do several things
1- check for the balance (remaining from 5000)
2- deduct from this balance
Let's focus on your example flow:
Say my customer will pay 5000 , this is their balance
Whenever they buy something (say for 50) , i deduct the 50 from the 5000
If their balance falls below 10 , i add 4990 to make it 5000 agin
3- recharge the balance
Sure
1- read the balance of the customer (remaining from 5000)
2- deduct 5 from the 5000 (balance or what is remaining)
3- on a certain condition based on step 1 , recharge the 5000
I think you're still lost. Let's try another approach. When is money being transferred from the customer to your Stripe account's balance?
when the balance fall below a threshold , also this money is saved as the customer's balance that i deduct from it whenever a payment is needed
Is the balance we're talking about the same as credit balance ?
No, I don't think we're talking about the same thing. Can you answer this question: when is money being transferred from the customer to your Stripe account's balance?
when the balance fall below a threshold
I dont want in my own balance , this is what i am talking about , i want it as the customer's balance on my Stripe
Is that considered a subscription ?
I need to understand in order to talk to you in the right terminaology
i want it as the customer's balance on my Stripe
I don't understand what you mean by this. When exactly do you want a customer to pay?
I want him to have a balance not to pay and thats it , i want them to have a balance that i deduct from it whenever a paymenet is done
I am talking about my customers prepaying
If customers prepay, you'll create a PaymentIntent for the full amount they're prepaying. This full amount is charged to their credit card (or whatever other payment method they choose when paying) and the full amount is transferred to your Stripe account's balance.
If your goal is to allow the customer to do different things on your app up to the amount they prepaid, you will need to keep track of this activity. Then, when they "use up" the activity that covers the amount they prepaid, you can create another PaymentIntent for the next amount they should pay. Does that make sense?
Meaning that i can never know how much of the 5000 have they "used up" in a certain point of time ?
Because i think Stripe has this option
I think that's where there's a misunderstanding. There's a concept of "usage" on Stripe (with Subscriptions) but we don't calculate this. Users are responsible for reporting usage data to us
So how do subscriptions work ? in steps ?
I recommend starting here:
https://docs.stripe.com/billing/subscriptions/usage-based/pricing-models
https://docs.stripe.com/billing/subscriptions/usage-based/recording-usage
I recommend creating a few usage-based prices and Subscriptions in test mode and using test clocks to play with billing cycles: https://docs.stripe.com/billing/testing/test-clocks
Testing this out will give you an idea of what's possible in Stripe and if this fits with the flow you have in mind
If you have any questions as you test, you can come back here and share with us specific examples of what you've tried and what you're trying to achieve
So i just succeeded in doing what i want using credit balance and invoices , but using the GUI
Can you help me develop APIs fo these please
Any adjustments to a customer's balance in the Dashboard doesn't result in charging the customer so I'm not quite sure what you're doing
What happens when i adjust credit balance or create an invoice ?
adjusting a customer's credit balance means they'll either see a credit on their next invoice (the invoice amount will be decreased) or a debit on their next invoice (the invoice amount will be increased). you still need to create an invoice and prompt the customer to pay that invoice
That is what i am trying to do
Can you help me technically ?
data = {
"customer": CustomerID, # ID of the customer to be billed
# Optional fields (see Stripe documentation for details):
"line_items": [
{
"amount": ChargeAmount,
"currency": "usd",
"description": "ACA call"
}
]
}
response = requests.post(url="https://api.stripe.com/v1/invoices", headers=headers, json=data)
response.raise_for_status()
invoice = response.json()
I did this now , but got bad request as a response
Hi, taking over as roadrunner_stripe needs to step away. Let me catch up
Can you share the request ID with me? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
It gives bad request so it doesnt show on stripe
Python
I recommend that you look at the API reference: https://docs.stripe.com/api/invoices/create to see an example of how you make a request to create an invoice.
You first want to create the invoice_item: https://docs.stripe.com/api/invoiceitems/create and then create the invoice.
Can you try that?
What is the specific error? Can you share that here?
bad request
It looks like you're passing the 'data' as json. Our API expects you to pass the data in form-encoded request bodies. I highly recommend that you use our official library, https://github.com/stripe/stripe-python instead. Or, you can also try to pass the 'data' in a form-encoded request
thank you , can you leave this ticket open for tomorrow ?
I'm afraid we can't leave this thread open. Feel free to come back tomorrow and fill out the form again. We're happy to help.