#Sarvesh -Collect then Transfer

1 messages ยท Page 1 of 1 (latest)

white maple
rancid imp
#

ok

#

req_cUSQJKBokl1yTY

#

{
"error": {
"message": "You must update your Connect branding settings with business name, icon, brand color in order to create an account link. You can set the missing fields at https://dashboard.stripe.com/settings/connect",
"type": "invalid_request_error"
}
}

white maple
#

thanks for sharing, taking a look

strange plover
#

I think the error is self explanatory @rancid imp and tells you exactly the next step, do you have a specific concern?

rancid imp
#

yes, while creating account i need to do it from api call or from the stripe UI in test mode i need to fill it only once?

#

for every account creation Connect branding settings with business name, icon, brand color etc needs to setup from api call?

#

$account = $stripe->accounts->create([
'country' => 'US',
'type' => 'express',
'business_type' => 'company',
'business_profile' => ['url' => 'https://www.w3schools.com/'],
]);

    if(!empty($account) && isset($account->id)) {
        $accountLinks = $stripe->accountLinks->create(
            [
              'account' => $account->id,
              'refresh_url' => 'https://02c9-103-80-116-218.in.ngrok.io/refreshdata',
              'return_url' => 'https://02c9-103-80-116-218.in.ngrok.io/returndata',
              'type' => 'account_onboarding',
            ]
          );
    }
strange plover
#

when the users sign up they have to see the name of your business and a page with "Sign up for Sarvesh's Marketplace" and your company logo; you set that up once, in your platform settings.

rancid imp
#

ok, so once i finished this one type setup with my brand above code will work and return me the account link?

strange plover
#

it should, you can try it out

rancid imp
#

ok, I will update you in few minutes, thanks

#

yes, I received the account link and completed the steps for the connected account registrations and I can see it in Connected accounts with status Enabled
But after completion of process, its redirected back to my URL with empty array()
https://02c9-103-80-116-218.in.ngrok.io/returndata

#

is it correct or I should get all info of newly registered account in the response to save on my side?

strange plover
#

its redirected back to my URL with empty array()
we redirect the browser to your URL, as a GET request, so there's no POST data, yes

#

I think there's an ?account=acct_xxx in the URL when we redirect to you(you can check in test mode), your script can try to read that, then call the API to retrieve the Account object(https://stripe.com/docs/api/accounts/retrieve) and do what you need to do.

rancid imp
#

ok, I will try again

strange plover
#

perhaps I was wrong then. Either way , you get an account.updated webhook event. You should also be able to authenticate the user from your own cookies and look up the account ID you saved for them when you created their account.

rancid imp
#

So i need to add Webhooks in test mode for "Events on your account" and "Events on connected accounts" ?

gray stump
#

Hi! I'm taking over this thread.

rancid imp
gray stump
#

If you want to listen to account.updated event from your connected accounts, then yes you need to create a connect webhook endpoint on your platform.

#

mentioned while creating account?
You mean when creating an account link?

rancid imp
#

yes, will this refresh / return url does not get any info back from stripe?

gray stump
rancid imp
#

return_url
REQUIRED
The URL that the user will be redirected to upon leaving or completing the linked flow.
so it does not return any data with it so this URL will be the same url from the account link is clicked?

gray stump
#

I just tested and yes, we redirect exactly to the return_url (no data is sent).

rancid imp
#

ok fine

#

so once I am back to return url and connected account it is created then which step I need to do for get some money from customer and transfer portion of it to service provider?

#

We recommend using Stripe Checkout, a prebuilt Stripe-hosted page, to accept payments. ?

gray stump
#

And in general we recommend using Checkout Sessions to accept payments.

rancid imp
#

ok checking

#

I have done following now by Creating separate charges and transfers manually at code level by taking last created connected account id from the Stripe UI

    Stripe::setApiKey(config('services.stripe.stripeSecret'));
    $method = PaymentMethod::create([
        'type' => 'card',
        'card' => [
          'number' => '4242424242424242',
          'exp_month' => 12,
          'exp_year' => 34,
          'cvc' => '314',
        ],
    ]);
    $paymentIntent = PaymentIntent::create([
        'payment_method_types' => ['card'],
        'payment_method' => $method->id,
        'amount' => 800,
        'currency' => 'gbp',//'usd',
        'transfer_group' => 'testorder10',
        'confirm' => true,
    ]);

sleep(3);
$transfer = Transfer::create([
'amount' => 100,
'currency' => 'gbp',//'usd',
'destination' => 'acct_1LezxvPSK0cme62N', //'acct_1LefCPPSLfI3YlCp', // config('services.stripe.stripeHostAccount'),
'transfer_group' => 'testorder10',
]);

But I am getting error as
You have insufficient funds in your Stripe account. One likely reason you have insufficient funds is that your funds are automatically being paid out; try enabling manual payouts by going to https://dashboard.stripe.com/account/payouts.

#

what is wrong with above code / steps?

gray stump
rancid imp
#

ok, so I need to pass "source_transaction" => "{CHARGE_ID}",
from where i will get this {CHARGE_ID} ?

#

from PaymentIntent response?

#

"charges": {
"object": "list",
"data": [
{
"id": "ch_3Lf0dxALTlZ8nxc301jqGGiv",
"object": "charge",
"amount": 800,

so the charge_id: ch_3Lf0dxALTlZ8nxc301jqGGiv ?

gray stump
#

Exactly.

rancid imp
#

ok, trying again

#

now previous error gone and got new one
The currency of source_transaction's balance transaction (usd) must be the same as the transfer currency (gbp)

#

now it works after make usd at both places

#

now i can see in platform account it receives
$8.00USD Succeeded
and in connected account shows balance of $1.02
but as per above code I transferred amount 100 so $1 so how it changes to $1.02?

gray stump
#

now it works after make usd at both places
Great!

#

but as per above code I transferred amount 100 so $1 so how it changes to $1.02?
I'm not sure I follow. Can you share the PaymentIntent ID?

rancid imp
#

yes

#

{
"id": "pi_3Lf0dxALTlZ8nxc30c7euzaT",
"object": "payment_intent",

gray stump
#

So this is a PI for $8. Then you did a transfer for this PI? Can you share its ID?

rancid imp
#

{
"id": "tr_3Lf0t1ALTlZ8nxc31rrOTMvw",
"object": "transfer",

#

maybe Default currency
GBP
so it convets $1 to 1.2 gbp?

gray stump
#

Thanks. This is a transfer for $1. But yes like you said it then gets converted to the default currency of the connected account to GBP

rancid imp
#

hmm but still why it is 1.2? it should be 0.85 gbp right?

gray stump
#

Where do you see 1.2? Can you share a screenshot or object ID?

rancid imp
gray stump
#

I just checked the balance of your connected account (acct_1LezxvPSK0cme62N), and it's only 0.85 GBP. So what you see in the dashboard might be rounding error.

rancid imp
#

hmm ok

#

Here is our workflow on the website

  1. Our website is platform for events so website owner will register on strip and create account will be say OwnerAccount
  2. There will be different event hosts who will register on site and to host/publish events
  3. So we will create connected host accounts under OwnerAccount using owners Stripe Secret key
  4. We will create account link for HostAccount and ask him to complete stripe registration steps so he will get added under connected account
  5. Host will create some paid events and participants will register for it by paying online
  6. Then from the registration amount e.g. $10, Owner should get $2 and host should get $7 and remaining say $1 will be processing fee of stripe

Will this get covered with the workflow which I have completed just now right?

rancid imp
#

there?

thorn cradle
#

Hi ๐Ÿ‘‹ I'm jumping in as my teammate needed to step away, please bear with me a moment while I catch up on the context here.

rancid imp
#

sure, thanks

thorn cradle
#

Just making sure I'm following your flow correctly, because it sounds like something that isn't supported, are you planning to create Connected Accounts from your Platform and then create Connected Accounts for your Connected Accounts?

rancid imp
#

ok, I will repeat the workflow

  1. our website will be event hosting platform and website owner will have stripe account
  2. using that stipe account secret key, we will create connected accounts via apis
    $stripe->accounts->create()
    $stripe->accountLinks->create()
    and then we will redirect user to account links where he will complete his registration and add the bank details etc.
  3. Then we will need to get the newly created connected account id somehow via stripe apis. For now I have hardcoded it by coping it from stripe UI.
  4. So that I will call further apis
    PaymentIntent::create() and
    Transfer::create()
    with
    'destination' => 'acct_1LezxvPSK0cme62N',
    "source_transaction" => $paymentIntent->charges->data[0]->id,
#

So from event registration fee say $10 then our web platform we keep $2 and transfer $7 to event host company and $1 may be processing fee of stripe

#

will this get achieved from above api calls?

#

event hoster will create events on web platform and event participient will pay fee of it which we need to distribute in webplatform $2 and event hosts $7

#

is this correct?

thorn cradle
#

Yes, that looks right

rancid imp
#

'destination' => 'acct_1LezxvPSK0cme62N', I have hardcoded so how I will get it from the api?

thorn cradle
#

The ID of the created account is returned in the response provided to the creation request.

rancid imp
#

yes, but in return url redirects to page without any data.
so I think the flow will get cut off there?

thorn cradle
#

I'm not sure I follow, the Account is being created by your backend so the frontend redirect doesn't seem relevant unless I'm overlooking something.

rancid imp
#

no, the account creation and connected account link will be done from the frontend itself

#

via api calls

thorn cradle
#

It shouldn't be if you're using your secret key.

#

If you transmit your secret key to your frontend code, then everyone accessing your frontend could access your secret key and make requests for your account.

rancid imp
#

no it will be done in php side so it will not get disclosed to anyone

#

server side

#

frontend/ backend => client / server ?

thorn cradle
#

Yeah

#

So if you have the Account ID server-side, why does a client-side redirect impact the availability of that information? If it does, then it sounds like you'll need to add some sort of persistency layer to hold that information.

rancid imp
#

ok, is there any api which can return the last created connected account?

#

just to cross check

thorn cradle
#

You can list all connected accounts:
https://stripe.com/docs/api/accounts/list
Our list endpoints return objects ordered from most recently created to oldest.

If you rely on that approach though, it seems like your flow wouldn't be able to handle multiple accounts in parallel.

rancid imp
#

i see ok

#

so I need to handle it from server side only from the response of connected account creation and process paymentIntent and transfer create calls

#

right?

#

ignore the redirect url? But if the connected account links - steps do not complete or any wrong data provided by the event hosts then how to stop process further and call refresh url again?

#

any webhooks will help in this case?

thorn cradle
#

Yes, you should listen for webhook events to know when the connected account is ready before attempting to process a payment for them.
https://stripe.com/docs/connect/webhooks

You'll want to use a Connect webhook endpoint to listen for events from your connected account, and listen for account.updated events.

rancid imp
#

perfect. I will opt for it