#rehan_error
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/1291476284010004521
๐ 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.
- rehan_webhooks, 6 hours ago, 41 messages
- rehan_connect-account-capabilities, 1 day ago, 90 messages
Hi ๐ is this a new integration you're building? We no longer recommend creating Charges directly, and I would advise against using this approach if this is a new integration you're building.
i am just try to add fund in my balance
i ma usyign in test mode to test everything is working
and payout to shoveller
The problem with the code you shared is that you aren't passing a Source to the source field, you're trying to pass a raw card number.
You need to change this line:
source: '4000000000000077', // Test card to add funds
and pass it an actual object rather than a test card number. That field can accept several different types of IDs as mentioned in our description of that parameter:
https://docs.stripe.com/api/charges/create#create_charge-source
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 believe it'll work if you pass it one of the Token IDs listed here:
https://docs.stripe.com/testing?testing-method=tokens#available-balance
docs are realy confusing for me can you give me the code ?
Can you help me understand what's confusing about them? I'd be happy to recommend changes to our team to make them easier to parse. Do you see the Token IDs in the section I linked to?
This value:
tok_bypassPending
const charge = await stripe.charges.create({
amount: 1099,
currency: 'usd',
source: 'tok_visa',
});
will this work?
Yes, but the funds won't be available immediately since you aren't using the tok_bypassPending to bypass the pending balance step. The Token ID I shared is the one that maps to the test card number you were using in your initial message.
const charge = await stripe.charges.create({
amount: 1099,
currency: 'usd',
source: 'tok_bypassPending', // Bypasses the pending balance step in test mode
});
is it okay now>
?
Looks good, what do you see when you run that?
Yeah it is working
message": "Funds added to balance",
"charge": {
"id": "ch_3Q5udeRvOCLWc0jZ1ArxF5KS",
"object": "charge",
"amount": 1099,
"amount_captured": 1099,
"amount_refunded": 0,
"application": null,
"application_fee": null,
"application_fee_amount": null,
"balance_transaction": "txn_3Q5udeRvOCLWc0jZ1VtRyDRC",
"billing_details": {
"address": {
"city": null,
"country": null,
"line1": null,
"line2": null,
"postal_code": null,
"state": null
Thank you Toby
really means a lot
Any time!
will this balance will be avaiale in my test account?
Yes, that is the purpose of the test cards that bypass the pending balance step. Do you see it reflected when you retrieve your balance?
https://docs.stripe.com/api/balance/balance_retrieve
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
can i see it in the stripe dashboard?
Maybe? We focus on helping developers leverage our API, I'm not as familiar with the dashboard side of these flows.
when i try to payout to shvoeller it throughs his error why?
now balance is available
"message": "Balance retrieved",
"balance": {
"object": "balance",
"available": [
{
"amount": 1375,
"currency": "cad",
"source_types": {
"card": 1375
}
}
],
"connect_reserved": [
{
"amount": 0,
"currency": "cad"
}
],
"livemode": false,
"pending": [
{
"amount": 1381,
"currency": "cad",
"source_types": {
"card": 1381
}
}
]
}
}
balance is avaialable and when i try to payout to shoveller it throughs error insufficeint balance why?
Alright, lets try to straighten out some terminology here so we're all aligned. The request you shared is trying to make a Transfer (moving funds from one Stripe account to another Stripe account) rather than a Payout (moving funds from a Stripe account's balance to their associated bank account/debit card).
Now let me see if I can spot why that error may be getting thrown.
{
"amount": 1375,
"currency": "cad",
"source_types": {
"card": 1375
}
}```
Your available balance is a `cad` balance, but your request to create a Transfer is trying to transfer a `usd` balance.
https://dashboard.stripe.com/test/logs/req_pY9oR4Ca3msYvk
Sign in to the Stripe Dashboard to manage business payments and operations in your account. Manage payments and refunds, respond to disputes and more.
An error is thrown because you don't have a sufficient usd balance to cover that Transfer.
please check this then
What about it, what are you trying to ask?
i have webhook as well
payout.paid
payout.created...
if the shvoeller completed the job we will send his payment into his account. i have implemneted webhook for htis to keep track yeah we have send money to this shoveller
I'm still not sure I understand what you're trying to ask.
Those Event types will be triggered by Payout objects:
https://docs.stripe.com/api/payouts/object
Which is a distinct object type from the Transfer that you create with this line:
const payout = await stripe.transfers.create({
https://docs.stripe.com/api/transfers/object
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
can you tell me one more thing
in my database i am storing paymeent in usd
so how can i send him in cad?
because i have payment in cad avaiable
You adjust the currency that you provide when making your request to create a Transfer. Currently you have:
const payout = await stripe.transfers.create({
amount: job.paymentInfo.amount, // Make sure the amount is in the smallest currency unit (e.g., cents)
currency: 'usd',
destination: shoveller.stripeAccountId, // Use the stripeAccountId from User model
});```
So you're telling us to transfer `usd` funds from your platform account to your connected account. If you want to transfer `cad` instead you'd adjust the value you're providing to the `currency` parameter.
You're using a Canadian Stripe account, so funds that settle on that account will settle in cad.
here i ma just asking is there any webhook event which i can listen i have transfer the payment to this shovller
one more thing that i thing i should have to tell you is that i am using stripe oauth connect. allowing shovller to connect his existing account with out platform.
and i will have there stripeaccountId which i will use to transhfer payment into his account if he earn any amount of money.
so the question is is htere nay webhyook evenet which i can listen whnerver i transhfer payment into shoveller account?
bccause i want to update the job status
There is no need to use webhook Events for Transfers. The request you make to create the Transfer provides immediate feedback on whether it succeeded.
(Unless you're using the source_transaction parameter, which I don't see in the code you provided)
when clinet post the job i'm accepting payment in usd
according to you i need to accept the payment in cad
isn't it:?
const Checkout = async (req, res) => {
try {
const { amount, jobId } = req.body; // Get jobId from request body
// Convert amount to cents
const amountInCents = amount; // Assuming amount is already in cents
// Create a checkout session with manual capture
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
{
price_data: {
currency: 'usd',
product_data: {
name: 'Cleaning Service',
},
unit_amount: amountInCents,
},
quantity: 1,
},
],
mode: 'payment',
payment_intent_data: {
capture_method: 'manual', // Authorize only, capture later
},
success_url: `http://localhost:3000/houseowner/stripeCheckout?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: 'http://localhost:3000/houseowner/stripeCheckout?canceled=true',
});
// Update the existing job with the new payment information
const updatedJob = await Job.findByIdAndUpdate(
jobId,
{
price: amountInCents,
stripeSessionId: session.id,
},
{ new: true } // Return the updated document
);
if (!updatedJob) {
return res.status(404).send({ error: "Job not found" });
}
res.json({ id: session.id });
} catch (error) {
res.status(500).send({ error: error.message });
}
};
do i need to chnage my checkout page?
You are setting usd as the presentment currency, but when the payment settles on your account it will settle in cad.
https://docs.stripe.com/currencies?presentment-currency=CA#presentment-currencies
what do you mean when i accept payment thourgh stirpe checkout page in usd
it will be conveted into cad?
Yup
oh i see
That's why the usd Charge you procesed earlier in our discussion didn't give you a usd balance to work with, instead it settled in cad and that was reflected in your available balance.
when houseoner post the job at the same time we ask him for the payment and we store payment in usd in the database.
so when the shoveller complete the job how can i send him payment in cad.
suppose the job was 30$.
how can i send the shoveller equivelelnt 30$ in cad
That is kind of up to you. Do you want to source your own exchange rates, or do you want to use the exchange rate we used?
can i repeat
30$ --> price for the job
platform charges will be 20%
and rest of money will be send to shoveller in cad
we want to use exchange rate that stirpe used
how can i do that??
Okay, if you want to use our exchange rate, then you'll need to look at the Balance Transaction object associated with the Payment Intent's Charge.
You can use the latest_charge field on the Payment Intent to find the ID of the associated Charge object:
https://docs.stripe.com/api/payment_intents/object#payment_intent_object-latest_charge
Then the balance_transaction field on the Charge object contains the ID of the associated Balance Transaction object:
https://docs.stripe.com/api/charges/object#charge_object-balance_transaction
The Balance Transaction object has an exchange_rate field where we store the exchange rate that we used if a currency conversion occurred during settlement:
https://docs.stripe.com/api/balance_transactions/object#balance_transaction_object-exchange_rate
const transferToShoveller = async (job) => {
try {
const totalAmount = job.price; // 30 USD (amount you stored)
const platformFee = 0.20 * totalAmount; // 20% platform charge
const amountForShoveller = totalAmount - platformFee; // Amount to be sent to the shoveller
// Transfer the payout to the shoveller in CAD
const payout = await stripe.transfers.create({
amount: Math.round(amountForShoveller * 100), // amount in cents (e.g., 2400 for 24.00 USD)
currency: 'cad', // Set the currency to CAD for the shoveller
destination: job.shoveller.stripeAccountId, // Use the shoveller's Stripe account ID
});
console.log('Transfer successful:', payout);
} catch (error) {
console.error('Error transferring to shoveller:', error.message);
}
};
will this code work?
Does it work when you run it? Do you see the result you're expecting?
It looks like you're using the right currency, but I don't see any currency conversion logic in there to make use of our exchange rate.
const transferToShoveller = async (job) => {
try {
const totalAmount = job.price; // 30 USD (amount you stored)
const platformFee = 0.20 * totalAmount; // 20% platform charge
const amountForShovellerUSD = totalAmount - platformFee; // Amount to be sent to the shoveller in USD
// Retrieve the Payment Intent using the stripeSessionId stored in the job
const paymentIntent = await stripe.paymentIntents.retrieve(job.stripeSessionId);
// Get the latest charge from the Payment Intent
const charge = await stripe.charges.retrieve(paymentIntent.latest_charge);
// Get the balance transaction associated with the charge
const balanceTransaction = await stripe.balanceTransactions.retrieve(charge.balance_transaction);
// Get the exchange rate used by Stripe
const exchangeRate = balanceTransaction.exchange_rate;
// Convert the amount to CAD using Stripe's exchange rate
const amountForShovellerCAD = amountForShovellerUSD * exchangeRate;
// Transfer the payout to the shoveller in CAD
const payout = await stripe.transfers.create({
amount: Math.round(amountForShovellerCAD * 100), // amount in cents (e.g., 2400 for 24.00 CAD)
currency: 'cad', // Set the currency to CAD for the shoveller
destination: job.shoveller.stripeAccountId, // Use the shoveller's Stripe account ID
});
console.log('Transfer successful:', payout);
} catch (error) {
console.error('Error transferring to shoveller:', error.message);
}
};
will this work?
Does it work when you run it? Do you see the result you're expecting?
There's a lot of variables in there that are unknown to me, so it's hard for me to say for sure.
let me check i haven't run it.
Like if job.stripeSessionId is the ID of a Checkout Session, then no it won't work.
yes it is
Then no, that won't work, and you should encounter an error when you run it.
You can't retrieve a Payment Intent using the ID of a Checkout Session. You will need to get the ID of the associated Payment Intent from the Checkout Session object's payment_intent field:
https://docs.stripe.com/api/checkout/sessions/object#checkout_session_object-payment_intent
pi_3Q5ofpRvOCLWc0jZ1dXSJcXp
are you talking about this id?
That is the ID of a Payment Intent. You can tell by the pi_ prefix.
not able to understand what do you means
I'm not sure I understand what you're trying to ask. The ID you shared, pi_3Q5ofpRvOCLWc0jZ1dXSJcXp, is the ID of a Payment Intent object.
when houseonwner post the job i store his stripesessionID and i am using webhook to soterpaymentintedID as well
if (event.type === 'checkout.session.completed') {
const session = event.data.object;
try {
// Store the paymentIntent ID and update paymentStatus
await Job.updateOne(
{ stripeSessionId: session.id },
{
$set: {
'paymentInfo.status': 'authorized',
paymentIntentId: session.payment_intent
}
}
);
console.log('Payment status updated to authorized for session:', session.id);
} catch (error) {
console.log('Error updating payment status:', error);
}
}
Hello! I'm taking over and catching up...
sure Rubeus
So your current goal is to get the exchange rate used, correct?
yes
It looks like you're on the right track, that information should be on the Balance Transaction. Are you not seeing the value you expect?
const transferToShoveller = async (job) => {
try {
const totalAmount = job.price; // 30 USD (amount you stored)
const platformFee = 0.20 * totalAmount; // 20% platform charge
const amountForShoveller = totalAmount - platformFee; // Amount to be sent to the shoveller
// Transfer the payout to the shoveller in CAD
const payout = await stripe.transfers.create({
amount: Math.round(amountForShoveller * 100), // amount in cents (e.g., 2400 for 24.00 USD)
currency: 'cad', // Set the currency to CAD for the shoveller
destination: job.shoveller.stripeAccountId, // Use the shoveller's Stripe account ID
});
console.log('Transfer successful:', payout);
} catch (error) {
console.error('Error transferring to shoveller:', error.message);
}
};
will this code work or not>
You would need to run it to find out. We can't provide code reviews here.
okay let me run it
We're also not going to run or debug your code for you.
We're happy to answer questions about the output of your code, or specific questions about particular aspects of your code though.
it througs error you insufficient balance
Okay, you'll need to add funds to your available balance with the test card indicated in the error message.
see the balance is avaialbe
Can you give me the request ID showing that error? Here's how you can find a request ID: https://support.stripe.com/questions/finding-the-id-for-an-api-request
req_2bfZHJCzoZRSns
Is that balance from your platform account or the connected account?
The balance shown in your screenshot above I mean?
I think it's probably the connected account's balance, not your platform's balance. You're trying to move money from your platform's balance to a connected account, which means your platform's available balance has to have enough funds to cover funds being moved.
issue is resolved during the transert i was multpling the payment by 100. i should not have to do this.
becuase i am already stroing amount in cents
Rubeus one more thing i need to update my database as well
marked the status to --> paid
Payout: {
id: 'tr_1Q5wM9RvOCLWc0jZaTDVL8aH',
object: 'transfer',
amount: 240,
amount_reversed: 0,
balance_transaction: 'txn_1Q5wM9RvOCLWc0jZCCRxj6Ak',
created: 1727990081,
currency: 'cad',
description: null,
destination: 'acct_1Q5jOhRruWIh6b27',
destination_payment: 'py_1Q5wM9RruWIh6b27JPZWU46r',
livemode: false,
metadata: {},
reversals: {
object: 'list',
data: [],
has_more: false,
total_count: 0,
url: '/v1/transfers/tr_1Q5wM9RvOCLWc0jZaTDVL8aH/reversals'
},
reversed: false,
source_transaction: null,
source_type: 'card',
transfer_group: null
}
is there any way i can confirm yes payemt is transet to connect acocunt and update my staus --> paid
or i need to implemnet webhook?
is there is any webhook event for this?
To clarify, you want to make sure the Transfer to the connected account succeeded?
yes
The successful response from the Transfer creation request should be all you need. A Transfer from one Stripe account to another like this happens immediately.
We do have transfer.created Events, but they're not going to tell you anything you don't already get in the response.
how can i know the response i successful
liek
if(payout.____)
which field i need to check to confirm yes transfer is succeeded
// if there is payout update the status of the job
if(payout){
await Job.findByIdAndUpdate(jobId, { 'paymentInfo.payout': 'completed' }, { new: true });
}