Learn how to transfer funds between Stripe accounts using Connect, with step-by-step setup, API code examples, and best practices for secure, compliant payments.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
How to Transfer Funds Between Stripe Accounts Using Connect
Step 1: Set Up Your Stripe Connect Platform
Before you can transfer funds between Stripe accounts, you need to set up your platform on Stripe Connect. This allows your platform to facilitate payments between connected accounts.
Step 2: Register Your Platform
Register your platform in the Stripe Dashboard by providing the required information:
Step 3: Connect User Accounts
To transfer funds, you need to connect user accounts to your platform. Here's how to create a connected account:
const stripe = require('stripe')('sk_test_YOUR_SECRET_KEY');
// Create a Standard connected account
async function createConnectedAccount() {
const account = await stripe.accounts.create({
type: 'standard',
country: 'US',
email: '[email protected]',
capabilities: {
card\_payments: {requested: true},
transfers: {requested: true}
}
});
return account;
}
For Express or Custom accounts:
// Create an Express connected account
async function createExpressAccount() {
const account = await stripe.accounts.create({
type: 'express',
country: 'US',
email: '[email protected]',
capabilities: {
card\_payments: {requested: true},
transfers: {requested: true}
},
business\_type: 'individual',
business\_profile: {
mcc: '5734', // Computer Software Stores
url: 'https://example.com'
}
});
return account;
}
Step 4: Create an Account Link or Account URL
For Standard and Express accounts, you need to redirect users to complete their onboarding:
async function createAccountLink(accountId) {
const accountLink = await stripe.accountLinks.create({
account: accountId,
refresh\_url: 'https://example.com/reauth',
return\_url: 'https://example.com/return',
type: 'account\_onboarding',
});
return accountLink.url;
}
Step 5: Transfer Funds Between Accounts
Once you have connected accounts, you can transfer funds in several ways:
Method 1: Direct Transfers
Use the Transfer API to move funds from your platform to a connected account:
async function transferToConnectedAccount(amount, destinationAccountId) {
const transfer = await stripe.transfers.create({
amount: amount, // amount in cents
currency: 'usd',
destination: destinationAccountId,
transfer_group: 'ORDER_123', // Optional for grouping related transfers
});
return transfer;
}
Method 2: Destination Charges
Create a charge and automatically split the funds:
async function createDestinationCharge(amount, customerId, destinationAccountId, applicationFeeAmount) {
const charge = await stripe.charges.create({
amount: amount, // amount in cents
currency: 'usd',
customer: customerId,
destination: {
account: destinationAccountId,
},
application_fee_amount: applicationFeeAmount, // Your platform fee in cents
});
return charge;
}
Method 3: Payment Intents with Destination
For more complex payment flows, use Payment Intents:
async function createPaymentIntentWithDestination(amount, customerId, destinationAccountId, applicationFeeAmount) {
const paymentIntent = await stripe.paymentIntents.create({
amount: amount, // amount in cents
currency: 'usd',
customer: customerId,
payment_method_types: ['card'],
transfer\_data: {
destination: destinationAccountId,
},
application_fee_amount: applicationFeeAmount, // Your platform fee in cents
});
return paymentIntent;
}
Step 6: Handle Transfers Between Connected Accounts
To transfer funds directly from one connected account to another, you'll need to:
async function transferBetweenConnectedAccounts(amount, sourceAccountId, destinationAccountId) {
// Step 1: Create a Reverse Transfer (from connected account to platform)
// You need to have the connected account's permissions to do this
const reverseTransfer = await stripe.transfers.create({
amount: amount,
currency: 'usd',
destination: 'self', // Transfer to your platform account
source_transaction: 'ch_sourceTransaction', // A charge on the source account
}, {
stripeAccount: sourceAccountId, // Execute as the source connected account
});
// Step 2: Transfer from platform to destination connected account
const forwardTransfer = await stripe.transfers.create({
amount: amount,
currency: 'usd',
destination: destinationAccountId,
source\_transaction: reverseTransfer.id, // Optional: link the transfers
});
return {
reverseTransfer,
forwardTransfer
};
}
Step 7: Implement Webhooks to Track Transfer Status
Set up webhooks to be notified when transfers complete or fail:
const express = require('express');
const app = express();
app.post('/webhook', express.raw({type: 'application/json'}), (request, response) => {
const signature = request.headers['stripe-signature'];
let event;
try {
event = stripe.webhooks.constructEvent(
request.body,
signature,
'whsec_your_webhook\_secret'
);
} catch (err) {
console.log(`⚠️ Webhook signature verification failed.`, err.message);
return response.sendStatus(400);
}
// Handle transfer events
switch (event.type) {
case 'transfer.created':
const transferCreated = event.data.object;
console.log(`Transfer of ${transferCreated.amount} created`);
break;
case 'transfer.paid':
const transferPaid = event.data.object;
console.log(`Transfer of ${transferPaid.amount} paid`);
break;
case 'transfer.failed':
const transferFailed = event.data.object;
console.log(`Transfer of ${transferFailed.amount} failed`);
break;
// ... handle other relevant events
}
response.json({received: true});
});
app.listen(8000, () => console.log('Running on port 8000'));
Step 8: Monitor and Manage Transfers
Implement monitoring and management functions for your transfers:
// Get all transfers
async function getAllTransfers() {
const transfers = await stripe.transfers.list({
limit: 100,
});
return transfers;
}
// Get a specific transfer
async function getTransfer(transferId) {
const transfer = await stripe.transfers.retrieve(transferId);
return transfer;
}
// Create a transfer reversal (refund a transfer)
async function createTransferReversal(transferId, amount) {
const reversal = await stripe.transfers.createReversal(
transferId,
{
amount: amount, // optional: if not provided, full amount is reversed
}
);
return reversal;
}
Step 9: Implement Error Handling
Proper error handling is crucial for payment systems:
async function safeTransfer(amount, destinationAccountId) {
try {
const transfer = await stripe.transfers.create({
amount: amount,
currency: 'usd',
destination: destinationAccountId,
});
return {
success: true,
transfer: transfer
};
} catch (error) {
console.error('Transfer error:', error);
return {
success: false,
error: {
message: error.message,
code: error.code,
type: error.type
}
};
}
}
Step 10: Implement Logging and Compliance
For compliance and auditability, implement proper logging:
async function loggedTransfer(amount, destinationAccountId, metadata) {
// Add detailed metadata for your records
const transferMetadata = {
...metadata,
initiated\_at: new Date().toISOString(),
initiated\_by: 'system' // or user ID
};
const transfer = await stripe.transfers.create({
amount: amount,
currency: 'usd',
destination: destinationAccountId,
metadata: transferMetadata,
});
// Log to your database or monitoring system
await logTransferToDatabase(transfer);
return transfer;
}
async function logTransferToDatabase(transfer) {
// Implementation will depend on your database
// Example using a hypothetical database client:
await db.transfers.insert({
stripe_transfer_id: transfer.id,
amount: transfer.amount,
currency: transfer.currency,
destination: transfer.destination,
created: transfer.created,
status: transfer.status,
metadata: transfer.metadata
});
}
Conclusion
Transferring funds between Stripe accounts using Connect involves setting up your platform, connecting accounts, and using Stripe's transfer APIs. Always implement proper error handling, logging, and monitoring to ensure reliable operations. Remember that different countries have different regulatory requirements, so consult Stripe's documentation for specific regional considerations.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.