How to get payout data in Stripe Connect? - javascript

I'm adding Stripe Connect to my app to send payments to the users,I need to create a payment dashboard where each user can see all the payments that were sent to them( like payment history). I've read here https://stripe.com/docs/api/payouts/create that I can retrieve list of all payouts or individual payout(by submitting payout id), but I can't find information on how to get payout data per user. For example, if I have user John Doe, I want to get all the payout information for John only with 1 API call, is it possible in Stripe Connect?

If you want to retrieve the list of payments on the connected account, you should retrieve the list of Charges using the stripeAccount header.
You can also make use of the auto-pagination built into Stripe SDKs to loop through the list.
Example
for await (const charge of stripe.charges.list({stripeAccount: 'connected_account_id'})) {
// Do something with charge
console.log(charge);
}
You may want to reach out to Stripe to check if you're eligible to use this beta where you can embed a payments dashboard component into your site : https://stripe.com/docs/connect/get-started-connect-embedded-uis

If I understand goodly your question, you want to retrieve connected accounts' payouts.
You have to know that payout api using is when you move money on your account. In the other hand, if you want to move money to any connected account you need to use transfert api.
Code
You need to know user connect account
const stripe = require('stripe')('API_KEY');
const transfers = await stripe.transfers.list({
destination: 'acct_id.....',
});

Related

Stripe - add a card for customer without payment

I have a customer that is logged into my application.
const customerId = '1234';
I want him to be able to add a card so he can use it later for purchasing items in my shop.
But theres many of possible requests and im not really sure which one should be used in such situation.
createSource();
createPaymentMethod();
createSetupIntent();
What is the proper way in Stripe to add a card by customer?
You'd use Setup Intents which will facilitate the authentication and saving of payment details to an existing Customer object. There's a guide here on how to achieve this.

How to pass existing subscription details on stripe during checkout

I’ve different subscription plan on stripe starting from Zero. When customer sign up, I’m creating a subscription with free plan by default.
In the future, customer want to upgrade the plan through checkout session, how can I pass my existing subscription details to the checkout session to update the plan tagged to the subscription ID instead of creating multiple subscriptions.
I gone through the stripe create checkout session Doc but I couldn’t find a way to pass subscription ID in checkout session.
Any help would be much appreciated
You are trying to update an existing Subscription through a CheckoutSession, that is not supported.
If a customer uses Checkout to sign up for a new Price, that creates a completely new Subscription object. You cannot pass an existing Subscription ID as Checkout cannot modify that.
You should use Checkout in mode: setup to collect card details from your customer. This setup mode only collects card details but does not charge or create a Subscription on that Customer.
Then in your server-side code after you receive the checkout.session.completed webhook event, update the existing Subscription to switch from the "free" Price to the "paid" Price: https://stripe.com/docs/api/subscriptions/update

Stripe - Refund Checkout Session

I’m trying to implement a method for my connected account owners to be able to refund charges collected via a Stripe Checkout Session.
In order to do so, I want to use the following code:
const refund = await stripe.refunds.create({
payment_intent: pi_id,
});
In order to obtain the payment_intent_id, I am listening to the checkout.session.completed webhook, and accessing data.object.payment_intent.
When I attempt to create a refund using this payment intent id, I get the No such paymentintent error from Stripe. I noticed in my Stripe test account that there is a charge ID associated with the payment, so maybe I should be using that - but I’m not sure how to retrieve that programmatically from the checkout session.
You're making the API call correctly.
“No such...” errors with Stripe are usually caused by either a mismatch in API keys (e.g. using a mixture of your test plus live keys) or by trying to access objects that exist on a different account (e.g. trying to perform an operation from your platform account on an object that was created on a connected account).

Stripe connect transfers and payouts without verification

I am trying to clarify things associated with Stripe Connect's paymentIntent and transfers endpoints. The thing is that I do think that I do not understand the flow perfectly and even do not know if I did choose the best solution for my application.
I am using the separate charges and transfers method and for the account type I did choose custom.
What I want to achieve is the following:
Get money from user A and send it to user B (user in this context is my platform user not the Stripe Account or Customer). I want to take my cut while I send the money to user B. It leads to a question, if I do need to create both the Stripe Customer and Account. And if the user B who gets the money after transfer is not acting as a company, why would I need to collect industry and other legal information from him/her just to make payout?
What I did:
First of all I do create Stipe Customer and Account for my platform users. Then I:
Create PaymentIntent to take money from (Stripe Customer A). Includes the Stripe fees
Create Transfer of the PaymentIntent and transfer it to (Stripe Account B).
Now I want to create payout of the transferred money. Do I have to trigger the payout endpoint for this case?
The 3 last steps in code:
Create paymentIntent
const paymentIntent = {description, amount, currency, customer_id, transfer_group, payment_method, confirmation_method: 'manual', confirm: true};
const response = await stripe.paymentIntents.create(paymentIntent);
Create transfer
const transfer = { amount, currency, destination: destinationAccount, transfer_group };
const response = await stripe.transfers.create(transfer);
stripe.paymentIntents.confirm(response.client_secret, {payment_method: response.payment_method})
Now money is taken from Customer A and transferred to Account B but I have no idea what legal information I need from my platform users to be able to create payouts? All my Stripe accounts/customers did accept the tos_acceptance also while adding a new source. None of my platform users are industry nor a company. They are individuals doing their things.
To follow the flow which you mentioned you need to create stripe Connect account for each of your customer B. As you need to do payouts to there bank accounts they need to be completely verified by stripe this shows legal information required for verification as per country
Though your end users are individuals you need to completely prove them for authenticity as you are involving them in legal fund transfer and making there sub-merchant accounts.
And you don't have to trigger the payout end point as it is automatically handled by stripe and you can also change it either you want to do payout weekly/daily/monthly etc and also set for custom payouts from dashboard settings.

Pusher with multi-database companies

I'm trying to figure out what's the best approach to use Pusher in my application.
My app consists in a normal website where users log in
Each user is connected to a company
Each company has its own database
So, I need my app to allow the send of regular messages and notifications (like popups) to people that only belong to the company signed for.
Doubts/problems:
If I create a channel called notifications and send events to it, all users (no matter what company) will receive it
If I set up some sort of token associated to the company won't work because some notifications/messages should only be sent to a restrict users
In my previous project I associated a token to the company because there was no activity between users only a "show-off" of what PHP was doing (within a loop) in each company, something like:
PHP:
$this->pusher->trigger($company_pusher_token, 'feedback', $data);
JS:
var token = $('#company_pusher_token').val();
var channel = pusher.subscribe(token);
channel.bind('feedback', function(data)
{
alert('working..');
});
So, how should I proceed to accomplish what I'm looking for?
It looks like you are going in the right direction.
The channel name would always start with the company unique prefix. If only a subset of users of that company should be notified then combine the prefix with the group ID.
Channels:
"notifications": send to all companies, all clients
"<company-token>-notifications": send to all clients from a given company
"<company-token>-<group-id>-notifications": send to all clients from a group within a given company
By the way if you want to make sure your customers can't bind to another company's channel make sure either the company token is not guessable, or use the "private-" prefix to let you control the authorization on the subscription of channels.

Categories