Send money to a bank account using Stripe | Node JS - node.js

So I have this React application where users can buy gift cards online, and I'm using Stripe Payments. So far, the users can pay the money, except it will go to me(through Stripe), not to the merchant selling the Gift Cards on my app.
Is there a way with Stripe to send money to a bank account? Keep in mind that the bank account will be different for each Gift Card any users can buy.
For example, one person selling the gift cards will be the one earning the money through a different bank account than another person.
If there is a way, please tell me how to implement it, and thank you very much in advance.

I finally figured how to do this. You have to follow these steps:
1: Integrate Stripe Checkout
2: Integrate Stripe Onboarding for express accounts
These two steps are the fundamental steps in doing this.
How To Integrate Stripe Checkout:
You can get stripe checkout by using the
stripe.checkout.sessions.create
method. You can then pass in arguments like:
payment_method_types: ["card"],
locale: locale,
line_items: [
{
name: `${Name}`,
images: ["Images"],
quantity: 1,
currency: usd,
amount: price, // Keep the
// amount on the server to prevent customers
// from manipulating on client
},
],
payment_intent_data: {
transfer_data: {
destination: product.id,
},
},
success_url: `success`,
cancel_url: `cancel`,
What this will do is create a new checkout session to use.
Next Step, Onboard the businesses
All you have to do for this is to go to a URL:
const url = `https://connect.stripe.com/express/oauth/authorize?${args.toString()}
where args is this:
const state = uuid();
const args = new URLSearchParams({
state,
client_id: process.env.STRIPE_CLIENT_ID,
});
Send this data to your frontend and you will get a good looking form that onboard users and creates express accounts for them.
The basic concept is simple, you onboard the businesses, which creates a stripe account for them. Then with the checkout form, you send the money to that created stripe account. This account will automatically deliver to the businesses bank or debit account, thus making customer to merchant payments.
Here are some helpful documentation I used to solve the problem:
https://stripe.com/docs/payments/checkout
https://stripe.com/docs/payments/checkout/accept-a-payment
https://stripe.com/docs/connect
https://stripe.com/docs/connect/collect-then-transfer-guide
https://stripe.com/docs/connect/express-accounts
I hope this helps!

Related

Have one stripe connect checkout session with multiple products trigger correct payouts to multiple different connected accounts

I am building a marketplace for people to sell digital products with nextjs, firebase and firebase cloud functions. I am able to credit one account with a cart of one or multiple products by following the documentation here https://stripe.com/docs/connect/collect-then-transfer-guide. But I would say it would be important to be able to put items from different authors into your cart.
This is my code that works well for one or multiple products and one connected account.
export const checkoutSessionSingular = functions.https.onCall(async (data, context) => {
const session:any = await stripe.checkout.sessions.create({
line_items: data.line_items,
mode: "payment",
success_url: "***",
cancel_url: "***",
payment_intent_data: {
application_fee_amount: data.fee_amount,
transfer_data: {
destination: data.connectId,
},
},
});
return session;
});
I have tried putting payment data, transfer data or destination into an array, but that always breaks it.
I tried using transfers and transfer groups, but I seem to lose all the valuable data in the stripe dashboard about which product the money comes from and I can't manage to make it work properly with the very limited documentation.
I also tried using destination charges but couldn't make it work.
If something like transfer groups are the solution, I would welcome a link to a proper example implementation or something more helpful.
What should I do to just have a normal working cart for a multi vendor marketplace? I already looked at every page of their documentation 30 times. Thanks.
If you want to send the money to multiple connected accounts, then you have to use Separate Charges & Transfers. So in your case you need to:
Create the Checkout Session and collect the payment, without any application_fee_amount or transfer_data
Then manually create Transfers between your main Stripe account and the connected accounts, with this endpoint

Creating a subscription using bank account number using stripe js in node js

I have created subscription by accespting credit/debit card number, exp month, exp year and cvc from front end angular app and creating
Customer
Product
Product Price
Payment Method
Subscription
In payment method i provide following details:
async function createPaymentMethod(data) {
let body = {
type: 'card',
card: {
number: data.card?.number,
exp_month: data.card?.exp_month,
exp_year: data.card?.exp_year,
cvc: data.card?.cvc
}
};
return await stripe.paymentMethods.create(body);
}
Now i want to create payment method but want to use customer's bank account number but i am unable to find a way to do it. I want to add "type: bank_account"
Note: I am using Strip JS and Node JS. All of this I want to do on server side i.e node js
Collecting Credit Card server-side is a bad idea, since you will expose yourself to the burden on PCI-Compliance. You would want to review Stripe's Integration Security Guide. Generally you would want to use client-side SDK to collect credit card information instead.
To the question of a bank account, it depends on which specific PaymentMethod you're gonna use (which country's bank transfer?) Ie. If you are talking about ACH in the US, you should follow the ACH Guide. Similarly it will collect bank account information client-side in exchange of a token, then passing it up to your back end.

Angular/node.js Stripe Checkout Integration (1 account to facilitate payments from third party payer to third party receiver)

Man, I have been at this for some days and can't find a good solution to this. I want to use my account (via public key and private key) to facilitate payments from one account to another (nothing will be going into my account). On the front-end I have:
checkout(amount) {
const strikeCheckout = (<any>window).StripeCheckout.configure({
key: environment.PRODUCTION==='true'?stripeLiveClientId:stripeTestClientId,
locale: 'auto',
token: (stripeToken: any) => {
if(stripeToken){
console.log(stripeToken)
this.createCharge(stripeToken,amount)
}
}
});
strikeCheckout.open({
name: 'Camel Stripe',
description: 'Stripe Checkout',
amount: amount
});
}
Just a small snipet, but essentially this just captures the credit card and email and ensures it is a valid credit card and then makes a stripe token. I then pass this token to the node backend and do:
stripe.paymentIntents.create({
amount: priceInPence,
currency: 'usd',
source: stripeTokenId,
capture: false, // note that capture: false
}).then(charge => {
return res.json({ success: true, message: 'Success', result: charge })
}).catch(error => {
res.status(400).json({ success: false, status: 400, message: error });
});
//})
};
No matter how I structure it, it always end's up getting the payment to my account, the account with the public/private key. Does anyone know a way I can use this token since it has the necessary information, and send the money to another account?
You can't accept payments and move the funds into a completely different Stripe account unless you're using Connect.
To piggy back on Paul's comment, after much research on Stripe Connect I wanted to share my findings. Please note this is specific to my use case and is using angular/express.
Connect offers multi-party payments, meaning you can receive funds from 1 user, then route them into another users account. You will need a stripe connect account. After that you connect an account, aka create account. They offer 3 account types all these account types need to be
Custom: basically is if you don't want the account you're routing to to see anything stripe related, meaning it is white labeled and the user has no dashboard or view of what is going on in the background.
Standard(the one I chose): this account will have a full stripe dashboard, it has all the functionality that an account would have that you make on your own. You will get a unique account id relevant to your specific connect account environment, on their end, they will have multiple account ids depending on how many other connects they are connected to, or if it is an already existing account. You will need to use this api to get the link to have them verify information before they are integrated into your connect environment account link api
Express: they will have a slimmed down version of a dashboard, it is similar to standard with less functionality
At this point you're ready to start routing payments. I did angular on the front-end, here is an example basically this simply creates a stripeToken, which is a verification that the card data is valid. You need to pass this to a backend to make use of it, this will not create any charges.
On the backend, I used express, you use the charge api You pass the stripeToken as the source attribute. One important step is to add the stripe account id you see in your connected accounts dashboard. It should look similar to:
stripe.charges.create({
amount: priceInPence,
currency: 'usd',
source: stripeTokenId,
capture: false, // note that capture: false
},{
stripeAccount:'{{acctId}}'
})
This should be sufficient to get your payments routing to the necessary account while leveraging a simple UI checkout.
One thing to note about the charges API, this is an older API and has less functionality. For my use case (US CA only with only card payments) it is sufficient. If you have a more complicated use case, or maybe your app is for heavy prod use to many users you should look into payment intents.

Stripe adding paymentMethod to trial subscription and later validate credit card

I'm working on stripe integration with react node.js
While creating a subscription without trial, I have no issues, and all use-cases are much simple.
But, I'm trying to create free trial without collecting credit card details, later when trial expired, I would like to collect credit card details
Server side: Creating Trial Subscription without payment method:
const subscription = await stripe.subscriptions.create({
customer: customer.id,
items: [{ price: priceId }],
trial_end: expiredAt.unix(),
expand: ['latest_invoice.payment_intent'],
});
ClientSide: Later when trial expired, I would like to collect credit card details(paymentMethod), check if user action is required due to failures or 3ds and update the subscription by updating the customer's default payment_method:
const updateCustomerDefaultPaymentMethod = await stripe.customers.update(
customerId,
{
invoice_settings: {
default_payment_method: req.body.paymentMethodId,
},
}
);
How can I update the subscription to perform paymentIntent or charge the user, and return to client same subscription object with status 'in_complete' same as when creating subscription without trial_period?
Currently when running my code, I keep getting status='active' because the first invoice is in status='paid' with price of '0$'.
In the case of a free trial, creating a subscription won't result in an initial payment, and Stripe will instead create a SetupIntent under the hood for you automatically. This SetupIntent is meant to be used when collecting the customer's payment method. So at any point during the trial, the customer would need to return to your app to enter their credit card details, which you would then save using the SetupIntent:
subscription.pending_setup_intent
Confirm the SetupIntent with the collected card details
Once the payment method is setup and saved to the customer (as the default payment method for invoices) it will be used to pay for the subscription's first invoice when the trial ends. The first payment after a trial is considered an off-session payment (last FAQ), so if that payment fails Stripe will attempt to recollect the payment using the usual smart retries and dunning functionality.
In a nutshell, you need to use the SetupIntent that's created (and attached to the subscription) to save the user's payment information.

Must stripe destinations by account ids in order to make a charge

Is there anyway to make a customer be the recipient of a charge? From everything I see, it appears that the platform would have to create a stripe account for any individual that may receive charges on the platform. The following code works as long as the destination is a stripe account. Inside destination, I would like to be able to make the destination a customer instead of a stripe account, but I get errors when changing the destination[account] to destination[customer] as well as when I use a customer id in destination[account].
var arbitrary_charge = 100;
stripe.charges.create({
amount: arbitrary charge,
currency: "usd",
customer: stripe_customer_key,
destination: {
amount: .8*arbitrary_charge, //https://stripe.com/docs/connect/destination-charges
account: "acct_xxxxxxxxxxxx"
},
}).then(function(charge) {
console.log(charge)
})
There's no way to make a Customer the destination.
When developing a Platform there are two functions you're generally interested in, paying out and taking payments.
Stripe divides these functions up into separate object types: Accounts and Customers, respectively. You may have a case where you want to pay out AND take payments, in which case you'll usually want to create both a Customer and Account object for a given entity. Stripe also added a feature recently that allows you to debit from some Accounts.
to charge the customer and credit it to the connected account you have to do something like this
charge = Stripe::Charge.create({
amount: amount,
currency: "usd",
card: token.id,
description: "Charge for #{email}",
receipt_email: email,
}, {stripe_account: stripe_user_id})
stripe_user_id is the account id of the connected account of format "acct_xxxxxxxxxxxx"

Resources