#xfechx-stripe-account option

1 messages ยท Page 1 of 1 (latest)

lone garden
#

Yes, certainly you can create a customer for a connected account. Are you having trouble with this?

violet copper
#

just need to know how to do it in code

#

yes, I couldn't add it, I got an error about the customer_id non existing

#

so I think the $customer is been created only on the platform, and not on the connected account.

lone garden
#

Can you share the request id hitting that error?

violet copper
#

$customer = \Stripe\Customer::create(['stripe_account' => $connect]);

lone garden
violet copper
#

Is that the way of doing it?

#

Or the api reference where I can see how to insert the connected account as parameter

lone garden
#

I think you'd need that in a second set of parameters, what customer details are you providing?

violet copper
#

none yet...

lone garden
#

$customer = \Stripe\Customer::create(['email' => 'test@example.com'], ['stripe_account' => $connect]);

violet copper
#

can I do that without email though?

lone garden
#

the first set of params can be empty i think, yea

#

$customer = \Stripe\Customer::create([], ['stripe_account' => $connect]);

#

try that

violet copper
#

it works... thanks.
I was trying to attach the SEPA charge to the customer added.

#

Is this possible?

#

So that the app can then charge the customer recursively?

#

(using sepa , as I notice you cannot create suscriptions with sepa as parameter on session)

#

subscriptions*

lone garden
#

Can you be more precise? I'd suggest going through the docs for SEPA and see if you encounter any specific issues

violet copper
#

yes, my problem is then afterwards attaching a payment source

#

to a customer

#

before, when making the stripe session without creating first the customer, it wasn't possible

lone garden
#

What error are you hitting? What are you trying?

violet copper
#

"message": "This PaymentMethod was previously used without being attached to a Customer or was detached from a Customer, and may not be used again.",

#

That's the error i am hitting

lone garden
#

Right, so you'd need ot have it attached to a customer instead of using directly

violet copper
#

so how do I do that?

#

is there something in the docs?

#

I am using this guide:

lone garden
#

are you doing this via checkout or a custom flow?

violet copper
#

checkout

#

under the checkout.session.completed payload, can I know if the method used was sepa_debit?

lone garden
#

If you're using checkout then you need to provide that account id when creating the session if you're using connected accounts

#

it would be in the payment_method which you can retrieve

violet copper
#

payment_method, retrieve it from where?

lone garden
#

would look like:

#
$stripe = new \Stripe\StripeClient(
  'sk_test_123'
);
$stripe->setupIntents->retrieve(
  'seti_321',
  ['expand'=>['payment_method']]
);
#

and you cna examine the type

violet copper
#

I have this

#

$intent = Stripe\SetupIntent::retrieve($event->data->object->setup_intent);

#

then how to get the payment_method from $intent?

#

So like this, finally:

#

$intent = Stripe\SetupIntent::retrieve($event->data->object->setup_intent, $connected_account, ['expand' => ['payment_method']]);

#

$payment_method = $intent->payment_method;

lone garden
#

correct, and look at the type on that payment method

violet copper
#

ok

#

ok, I am stuck in attaching the payment_method to the customer

lone garden
#

but you dont need to do that if you're using checkout, that part should happen for you

#

so i'm confused about what exactly you're trying to do

violet copper
#

I am trying to save the sepa_debit info, so that I can create a subscription to a customer using that info

#

because subscriptions don't allow sepa_debit parameter on checkout session

#

the subscription would be created manually on stripe dashboard, or through a webhook

#

asynchronously

lone garden
#

OK, and checkout is succeeding during your tests?

#

(for setup mode)

violet copper
#

yes checkout is fine

#

not sure what is setup mode

lone garden
#

mode=setup -- that's what youre using to collect sepa details via checkout, right?

violet copper
#

no... i wasn't using the mode parameter

#

so I have to use that , so that the sepa_debit info is saved oncustomer?

lone garden
#

yes -- suggest reading through the guide above again, as this is detailed there to setup future sepa payments

violet copper
#

great.

#

how do I pass metadata to a setup in checkout session?

#

with subscriptions, it's subscription_data, as a parameter of the checkout session

lone garden
#

setup_intent_data[metadata] -- same pattern ๐Ÿ™‚

lone garden
#

Is this working for you now?

violet copper
#

No

#

actually, I added the setup parameter to the checkout session, and with sepa_debit as argument, and a newly created customer (no email, as the customer will enter email in checkout page). And still no luck, the payment is there, but the customer doesn't have an attached payment source in dashboard.

sand nimbus
#

Do you have an example Session we can look at?

violet copper
#

sure, where can i find it?

#

req_pFaWX10EeieIfS

sand nimbus
#

We return ids of objects in the API everywhere, and your code should in theory know about a Session id, store it in your database, etc. Same for the customer id and related.

#

ah nice looking

#

Okay so your latest ask here is why the Customer doesn't have a PaymentMethod?

violet copper
#

yes

#

why isn't it saved when the customer enters SEPA data

#

do I need to manually saave it in the webhook?

sand nimbus
#

Just to clarify: you do know that this is not a subscription and it's only a one-time payment right?

violet copper
#

because that is already setup in my code

sand nimbus
violet copper
#

So, in this case, I will need setup future usage and application fee

#

also, is it setup_intent_data, or payment_intent_data ?

sand nimbus
#

setup_intent_data is for mode setup, payment_intent_data is for mode payment and subscription_data is for mode subscription

#

so which one to use depends on what you are doing

violet copper
#

req_e97MgXjsUMTcno

#

OK, so subscription mode I cannot use SEPA

#

setup and payment, I can use SEPA

#

which one is best for keeping the payment method on the customer?

#

I sent payment_intent_data, with 'setup' mode.

#

I added the setup_future_usage parameter

sand nimbus
#

Both work, it's really up to you for what you are trying to do. I assume you want a payment upfront and then you'll start a subscription async for next month?

violet copper
#

Yes, or if possible just a SEPA and subscription right away

#

but afaik it's not possible

#

this is ONLY for SEPA method

#

for cards, etc I already have a working solution since a while

#

but here in Europe many people do subscriptions with SEPA

#

What I was thinking is to do the first charge, then create a subscription on the backend (webhook) for that customer, using that payment method.

sand nimbus
#

yep then do setup IMO, way easier/cleaner

#

and start the subscription after that step

violet copper
#

I did a setup , but I cannot see how to retrieve the customer payment method

#

the customer doesnt have the payment method attached to it, on the dashboard

#

I'm here, but it's very brief...

sand nimbus
#

what does "i'm here but it's very brief" mean? I'm sorry you really need to provide a lot more specific details as you go

#

explain what you're seeing, provide detailed example ids, what you see in the API, what you see in the Dashboard, etc.

violet copper
#

in that example, they use the stripe object to obtain it

#

I have the following:

#

$intent = \Stripe\SetupIntent::retrieve($event->data->object->setup_intent, $connected_account, ['expand' => ['payment_method']]);
$payment_method = $intent->payment_method;
$payment_method_type = $payment_method->type;

sand nimbus
#

The setup mode does not attach the PaymentMethod automatically and it's expected, you have to attach it yourself. so yes the code you shared above is what you'd need

violet copper
#

and the last step, which I cannot find

#

attach.., Do I need a stripe object for that?

#

or does customer have a function

#

to attach

#

like with update source.. ?

#

this is somehow new for me:
$stripe->customers->update(

sand nimbus
violet copper
#

not sure why always in my code, just used functions to assign key but never had created a stripe object

#

ahh wow

#

ok

sand nimbus
#

it's way better than the old way. Otherwise you have to write

$paymentMethod = \Stripe\PaymentMethod::retrieve('pm_123');
$paymentMethod->attach(['customer' => 'cus_123']);```
#

so you have to do an extra retrieve and it's costly latency-wise

violet copper
#

so I need to download the latest Stripe?

#

or how do I update

sand nimbus
#

That change was introduced in 7.33.0 which is over a year old already, so it depends which version of stripe-php you use

#

your earlier request was on 7.27.0

#

so yeah you'd want to upgrade to the latest since it's still the same major version 7.X and no breaking changes

violet copper
#

so the php library, yes?

sand nimbus
#

stripe-php yes

violet copper
#

how do you pass connected account using the new library?

#

curently I do this:

#

$session = \Stripe\Checkout\Session::retrieve($event->data->object->id, $connected_account);

#

so for retrieving the customer in the connected account, using the stripe object

#

*client

sand nimbus
#

$session = \Stripe\Checkout\Session::retrieve($event->data->object->id, $connected_account); that should.... never work

#

$session = \Stripe\Checkout\Session::retrieve($event->data->object->id, ['stripe_account' => $connected_account]); instead

violet copper
#

I know. it already works like that in my code somehow

sand nimbus
#

and with the new way you do

$session = $stripe->checkout->sessions->retrieve(
  $event->data->object->id,
  [], // no params
  ['stripe_account' => $connected_account]
);
violet copper
#

$connected_account = array('stripe_account' => $event_json->account);

#

cool, i will try the new one

#

how to expand with new style?

#

$intent = \Stripe\SetupIntent::retrieve($event->data->object->setup_intent, $connected_account, ['expand' => ['payment_method']]);

#

same?

sand nimbus
#

not at all lol

#

expand never comes after the account id

#

Sorry, you're just mixing up concepts, it's a bit hard to follow all the questions

#
  'id' => $event->data->object->setup_intent,
  'expand' => ['payment_method'],
], [
  'stripe_account' => $connected_account
]);```
#

that's how it should work, but why are you expanding, you don't really need to?

violet copper
#

to get the payment method?

#

ah yes, sorry

#

no need to expand

sand nimbus
#

you just need the id, no need to expand

#

yep

#

I have to run but @lone garden is taking over if you have a follow up question

lone garden
#

๐Ÿ‘

#

Let me know if you hit any more bumps you can't debug through @violet copper

violet copper
#

thanks @sand nimbus

#

@lone garden ok, still working on it

#

I can't seem to add metadata to a session?

lone garden
#

where are you trying to add it?

#

you should be able to do that

violet copper
#

$session = \Stripe\Checkout\Session::create(
[
'billing_address_collection' => $zip_code_flag,
'customer_email' => $email,
'customer' => $customer_ID,
'mode'=> 'setup',
'payment_method_types' => ['sepa_debit'],
'metadata' => array(
'Invoice'=>get_the_ID(),
'Customer'=>$user->user_firstname . ' ' . $user->user_lastname,
'CustomerID'=>$user->id,
'Link'=>$permalink,
'Reference'=>get_the_title(),
'Notes'=>substr(get_the_content(), 0, 500),
'No. of Payments'=>$payments,
'Interval'=>$interval,
'Vendor' => $vendor_email,
'VendorID' => $vendor->id,
'Timestamp'=>$timestamp,
'API'=>$API,
'Affiliate'=>$affiliate_email,
'Tickets'=>$tickets,
'Test'=>$test_mode
),

#

for some reason, I am not getting the metadata on the checkout.session.completed

lone garden
#

can you share the session or request id?

#

if you replace 'metadata' => array(...) with 'metadata' => ['key1'=>'val1', ...] does that work?

violet copper
#

how can i find the request id

#

i have this?

#

cs_test_a1mMg5ndMnW3qDrZB0D9wlAhFIlQazJL8H7mrWfmsDBs2ybfzTX0FpGfNr

lone garden
#

that'll work, thanks

violet copper
#

I see...

#

I need to retrieve the metadata value, so I cannot do it with the checkout session?

lone garden
#

you can, i'm telling you its not being sent in the request

#

the snippet you showed above is not reflected in the request we receive

violet copper
#

OK, now I sent a request but it says payment incomplete?

#

i am still unable to send metadata

lone garden
#

Yes, you need to go through checkout to complete the payment

violet copper
#

?

#

yeah stripe took a bit to mark it as completed

#

i think it is because it is asynchronous

#

but the metadata i can't seem to send it

lone garden
#

can you share the new session? do your new logs show the metadata coming through?

#

can you share the full session create request snippet?

violet copper
#

I know, for some reason is not sending through

#

I have it on my code tho

#

$session = \Stripe\Checkout\Session::create(
[
'billing_address_collection' => $zip_code_flag,
'customer_email' => $email,
'customer' => $customer_ID,
'mode'=> 'setup',
'payment_method_types' => ['sepa_debit'],
'metadata' => [
'Invoice'=>get_the_ID(),
'Customer'=>$user->user_firstname . ' ' . $user->user_lastname,
'CustomerID'=>$user->id,
'Link'=>$permalink,
'Reference'=>get_the_title(),
'Notes'=>substr(get_the_content(), 0, 500),
'No. of Payments'=>$payments,
'Interval'=>$interval,
'Vendor' => $vendor_email,
'VendorID' => $vendor->id,
'Timestamp'=>$timestamp,
'API'=>$API,
'Affiliate'=>$affiliate_email,
'Tickets'=>$tickets,
'Test'=>$test_mode
],
'setup_intent_data' =>
[
'metadata' => array(
'Invoice'=>get_the_ID(),
'Customer'=>$user->user_firstname . ' ' . $user->user_lastname,

lone garden
#

then re-enabled a few other values, try again

violet copper
#

metadata still empty... ?

#

how can I check if is sending mode to setup

lone garden
#

what do you mean? YOu'd need to examine your logs for other session creation requests

violet copper
#

I know the problem

#

now i get these errors:

#

There was a problem with your transaction
Received unknown parameters: default_tax_rates, application_fee_percent, setup_future_usage

#

I cannot use application_fee_percent?

lone garden
#

(and making a Connect request)

violet copper
#

no, no subscription mode

#

setup mode

#

everything i am doing now is setup mode

#

how can I pass the application fee percentage

#

so, setup + connect

#

where is one supposed to pass the connected account to the payment method?

#

setup intent data does not receive connected account parameters?

#

sorry application fees parameters

lone garden
#

can you rephrase that?

violet copper
#

yes

#

using mode: subscripiton, you can pass application fee percent,
using mode: payment, you can pass inside payment_intent_data the application_fee_amount

#

using mode: setup, you can pass setup_intent_data, but not application_fee_amount , or application_fee_percent

lone garden
#

Correct

#

in setup mode there is no payment, so no opportunity to collect a fee

#

you would provide that application fee amount or percent when you later use the payment method to create a payment or subscription

violet copper
#

Hmmm but the setup doesn't take any charge at all, correct?

#

Ok yes, I have to make some tests first

#

Thanks

lone garden
#

Correct, setup mode is just saving payment information to use later, there's no payment

#

did you get your metadata working? was the issue really that the requests were failing for some other reason?

#

the request failed related to the application fees you were asking about, but the metadata is there ๐Ÿ™‚

violet copper
#

now I get an error about no such customer

#

$stripe = new \Stripe\StripeClient($secret_key);
$session = $stripe->checkout->sessions->retrieve(
$event->data->object->id,
[], // no params
$connected_account
);
$intent = $stripe->setupIntents->retrieve($event->data->object->setup_intent, ['expand' => ['payment_method']], $connected_account);
$payment_method = $intent->payment_method;
$payment_method_type = $payment_method->type;

          $stripe->paymentMethods->attach(
            $payment_method,
            ['customer' => $session->customer]
          );
undone void
#

hello, catching up

#

so the CheckoutSession is on the Connect account right?
and therefore, the PaymentMethod is also on the Connect account

so your request to attach the PaymentMethod should also be passing the connected_account but it isn't

violet copper
#

I am now getting no such payment method

#

$stripe = new \Stripe\StripeClient($secret_key);
$session = $stripe->checkout->sessions->retrieve(
$event->data->object->id,
[], // no params
$connected_account
);

        $intent = \Stripe\SetupIntent::retrieve([
            'id' => $event->data->object->setup_intent,
            'expand' => ['payment_method'],
          ], 
          $connected_account
          );
        $payment_method = $intent->payment_method;
        $payment_method_type = $payment_method->type;
        echo "payment method: " . $payment_method . ' --- ';
        
          $stripe->paymentMethods->attach(
            $payment_method,
            ['customer' => $session->customer],
            $connected_account
          );
undone void
#

can you share the SetupIntent ID, the PaymentMethod ID and the Customer ID?

violet copper
#

evt_1Jcd2d4wpi0cDPtefAFd87tx

undone void
violet copper
#

req_EeTz4wLiyxvOvY

undone void
#

your code passed the full PaymentMethod stringified object there
you need to pass just the PaymentMethod ID

do you see it in the request log page https://dashboard.stripe.com/test/logs/req_EeTz4wLiyxvOvY ???

Your code passed
POST /v1/payment_methods/Stripe%5CPaymentMethod+JSON%3A+%7B%0A++++%22id%22%3A+%22pm_1Jcd2c4wpi0cDPteebOkZsVu%22%2C%0A++++%22object%22%3A+%22payment_method%22%2C%0A++++%22billing_details%22%3A+%7B%0A++++++++%22address%22%3A+%7B%0A++++++++++++%22city%22%3A+%22berlin%22%2C%0A++++++++++++%22country%22%3A+%22DE%22%2C%0A++++++++++++%22line1%22%3A+%22b%22%2C%0A++++++++++++%22line2%22%3A+%22b%22%2C%0A++++++++++++%22postal_code%22%3A+%2293232%22%2C%0A++++++++++++%22state%22%3A+null%0A++++++++%7D%2C%0A++++++++%22email%22%3A+%22xfechx%40gmail.com%22%2C%0A++++++++%22name%22%3A+%22berliner%22%2C%0A++++++++%22phone%22%3A+null%0A++++%7D%2C%0A++++%22created%22%3A+1632346306%2C%0A++++%22customer%22%3A+%22cus_KHBPIORqvskqHJ%22%2C%0A++++%22livemode%22%3A+false%2C%0A++++%22metadata%22%3A+%5B%5D%2C%0A++++%22sepa_debit%22%3A+%7B%0A++++++++%22bank_code%22%3A+%2219043%22%2C%0A++++++++%22branch_code%22%3A+%22%22%2C%0A++++++++%22country%22%3A+%22AT%22%2C%0A++++++++%22fingerprint%22%3A+%22V7WHsk4zuONKVpeo%22%2C%0A++++++++%22generated_from%22%3A+%7B%0A++++++++++++%22charge%22%3A+null%2C%0A++++++++++++%22setup_attempt%22%3A+null%0A++++++++%7D%2C%0A++++++++%22last4%22%3A+%223201%22%0A++++%7D%2C%0A++++%22type%22%3A+%22sepa_debit%22%0A%7D/attach

instead of just the PaymentMethod ID like pm_123