#pozzworth_code
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1257295461073682465
đ Have more to share? Add details, code, screenshots, videos, etc. below.
const processPayment = async (req, res) => {
try {
const { customerId, price, currency, paymentMethodId, providerCustomerId, providerDefaultPaymentMethodId } = req.body;
if (!providerCustomerId) {
return res.status(400).json({ error: 'Provider customer ID is missing' });
}
// Calculate total deduction (Stripe fee + platform fee)
// const totalDeductionPercentage = 0.20; // 20%
// const totalDeductionAmount = price * totalDeductionPercentage;
// Calculate the amount to transfer to the Express account (80% of the total payment amount)
const stripeFeePercentage = 0.029; // 2.9%
const stripeFeeFixed = 0.30; // $0.30
const stripeFeeAmount = (price * stripeFeePercentage) + stripeFeeFixed;
const platformFeePercentage = 0.0499; // 4.99%
const platformFeeFixed = 0.99; // $0.99
const platformFeeAmount = (price * platformFeePercentage) + platformFeeFixed;
// Calculate amount for Express account
const expressAmount = price - platformFeeAmount - stripeFeeAmount;
const roundedExpressAmount = Math.round(expressAmount)
console.log('Amount for Express account:', roundedExpressAmount);
console.log('Platform fee amount:', platformFeeAmount);
console.log('Stripe fee amount:', stripeFeeAmount);
// Create a payment intent or perform payment directly
let paymentIntent;
if (providerDefaultPaymentMethodId) {
paymentIntent = await stripe.paymentIntents.create({
customer: customerId,
amount: price, // Replace with the actual amount in cents
currency: currency, // Replace with the desired currency
payment_method: paymentMethodId,
confirm: true,
transfer_data: {
// amount: roundedExpressAmount,
destination: providerCustomerId
},
application_fee_amount: Math.round(platformFeeAmount), // Platform fee amount in cents
return_url: `https://samtroyer.com`
});
}
it seems to be trasnferring the full amount of the payment minus the stripe fee and mostly disregarding the amount to keep for the platform
But I see that it's commented out: // amount: roundedExpressAmount,
What do you mean by "full amount of the payment minus the stripe fee"? How it's different from "the amount to keep for the platform"?
right, i think it should not be that. i was trying a different method to see if it would work but it did not really
say someone is booking a class at $5, and Stripe on any payments takes 2.9% + 30 cents, that's always happening
in my case i'm trying to hold a percentage of the earnings and then pass what remains on to the person receiving money for the class
I totally understand that. You can use both transfer_data.amount: total - application_fee or application_fee_amount: application_fee, and calculate the application_fee however you prefer.
that didn't work when i tried it
Payment error: StripeInvalidRequestError: You may not provide the application_fee_amount parameter
and the transfer_data[amount] parameter simultaneously. They are mutually exclusive.
at StripeError.generate (C:\Users\Sam Troyer\Desktop\ym-user\yogamatt\server\node_modules\stripe\cjs\Error.js:10:20)
Why do you provide both of them?
oh nevermind, i thought that's what you were telling me to do