#rehan_error

1 messages ยท Page 1 of 1 (latest)

iron spokeBOT
#

๐Ÿ‘‹ 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.

chilly geyserBOT
sly pasture
#

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.

torn frost
#

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

sly pasture
#

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.

torn frost
#

i didnt understand can you give me the updatedd code>

#

?

sly pasture
#

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

torn frost
#

docs are realy confusing for me can you give me the code ?

sly pasture
#

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

torn frost
#

const charge = await stripe.charges.create({
amount: 1099,
currency: 'usd',
source: 'tok_visa',
});

will this work?

sly pasture
#

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.

torn frost
#

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>

#

?

sly pasture
#

Looks good, what do you see when you run that?

torn frost
#

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

sly pasture
#

Any time!

torn frost
#

will this balance will be avaiale in my test account?

sly pasture
torn frost
#

can i see it in the stripe dashboard?

sly pasture
#

Maybe? We focus on helping developers leverage our API, I'm not as familiar with the dashboard side of these flows.

torn frost
#

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?

sly pasture
#

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
#

An error is thrown because you don't have a sufficient usd balance to cover that Transfer.

sly pasture
#

What about it, what are you trying to ask?

torn frost
#

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

sly pasture
#

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

torn frost
sly pasture
#

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.

torn frost
# sly pasture I'm still not sure I understand what you're trying to ask. Those Event types wi...

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

sly pasture
#

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)

torn frost
#

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?

sly pasture
torn frost
#

what do you mean when i accept payment thourgh stirpe checkout page in usd
it will be conveted into cad?

sly pasture
#

Yup

torn frost
#

oh i see

sly pasture
#

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.

torn frost
#

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

sly pasture
#

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?

torn frost
#

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??

sly pasture
#

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

torn frost
#

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?

sly pasture
#

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.

torn frost
#

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?

sly pasture
#

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.

torn frost
#

let me check i haven't run it.

sly pasture
#

Like if job.stripeSessionId is the ID of a Checkout Session, then no it won't work.

torn frost
#

yes it is

sly pasture
torn frost
#

pi_3Q5ofpRvOCLWc0jZ1dXSJcXp
are you talking about this id?

sly pasture
#

That is the ID of a Payment Intent. You can tell by the pi_ prefix.

iron spokeBOT
torn frost
#

not able to understand what do you means

sly pasture
#

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.

torn frost
#

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);
    }
}
rigid umbra
#

Hello! I'm taking over and catching up...

torn frost
#

sure Rubeus

rigid umbra
#

So your current goal is to get the exchange rate used, correct?

torn frost
#

yes

rigid umbra
#

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?

torn frost
#

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>

rigid umbra
#

You would need to run it to find out. We can't provide code reviews here.

torn frost
#

okay let me run it

rigid umbra
#

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.

torn frost
rigid umbra
#

Okay, you'll need to add funds to your available balance with the test card indicated in the error message.

torn frost
#

see the balance is avaialbe

rigid umbra
torn frost
#

req_2bfZHJCzoZRSns

rigid umbra
#

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.

torn frost
#

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?

rigid umbra
#

To clarify, you want to make sure the Transfer to the connected account succeeded?

torn frost
#

yes

rigid umbra
#

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.

torn frost
#

// if there is payout update the status of the job
if(payout){
await Job.findByIdAndUpdate(jobId, { 'paymentInfo.payout': 'completed' }, { new: true });
}