#xfechx-stripe-account option
1 messages ยท Page 1 of 1 (latest)
Yes, certainly you can create a customer for a connected account. Are you having trouble with this?
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.
Can you share the request id hitting that error?
$customer = \Stripe\Customer::create(['stripe_account' => $connect]);
Is that the way of doing it?
Or the api reference where I can see how to insert the connected account as parameter
I think you'd need that in a second set of parameters, what customer details are you providing?
none yet...
$customer = \Stripe\Customer::create(['email' => 'test@example.com'], ['stripe_account' => $connect]);
can I do that without email though?
the first set of params can be empty i think, yea
$customer = \Stripe\Customer::create([], ['stripe_account' => $connect]);
try that
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*
Can you be more precise? I'd suggest going through the docs for SEPA and see if you encounter any specific issues
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
What error are you hitting? What are you trying?
"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
Right, so you'd need ot have it attached to a customer instead of using directly
are you doing this via checkout or a custom flow?
checkout
under the checkout.session.completed payload, can I know if the method used was sepa_debit?
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
payment_method, retrieve it from where?
from the setup_intent that was used: https://stripe.com/docs/api/checkout/sessions/object?lang=php#checkout_session_object-setup_intent
so I'd suggest you retrieve the setup intent and expand the payment_method
https://stripe.com/docs/api/expanding_objects
would look like:
$stripe = new \Stripe\StripeClient(
'sk_test_123'
);
$stripe->setupIntents->retrieve(
'seti_321',
['expand'=>['payment_method']]
);
and you cna examine the type
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;
correct, and look at the type on that payment method
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
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
no... i wasn't using the mode parameter
so I have to use that , so that the sepa_debit info is saved oncustomer?
yes -- suggest reading through the guide above again, as this is detailed there to setup future sepa payments
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
Is this working for you now?
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.
Do you have an example Session we can look at?
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?
yes
why isn't it saved when the customer enters SEPA data
do I need to manually saave it in the webhook?
Just to clarify: you do know that this is not a subscription and it's only a one-time payment right?
because that is already setup in my code
What you want is to set payment_intent_data[setup_future_usage] https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-setup_future_usage
that indicates that you don't want to just accept a payment, you also want to charge them again later. And if you do that we'll attach the PaymentMethod \
So, in this case, I will need setup future usage and application fee
also, is it setup_intent_data, or payment_intent_data ?
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
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
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?
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.
yep then do setup IMO, way easier/cleaner
and start the subscription after that step
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...
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.
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;
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
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(
yeah it's the client/service approach: https://github.com/stripe/stripe-php/wiki/Migration-to-StripeClient-and-services-in-7.33.0
not sure why always in my code, just used functions to assign key but never had created a stripe object
ahh wow
ok
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
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
so the php library, yes?
stripe-php yes
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
$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
I know. it already works like that in my code somehow
and with the new way you do
$session = $stripe->checkout->sessions->retrieve(
$event->data->object->id,
[], // no params
['stripe_account' => $connected_account]
);
$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?
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?
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
thanks @sand nimbus
@lone garden ok, still working on it
I can't seem to add metadata to a session?
$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
can you share the session or request id?
if you replace 'metadata' => array(...) with 'metadata' => ['key1'=>'val1', ...] does that work?
how can i find the request id
i have this?
cs_test_a1mMg5ndMnW3qDrZB0D9wlAhFIlQazJL8H7mrWfmsDBs2ybfzTX0FpGfNr
that'll work, thanks
yea here check out this request in your logs: https://dashboard.stripe.com/test/logs/req_I6ZeAIC32bNyoz
we only get metadata within the payment_intent_data, not at the top level for the session itself.
I see...
I need to retrieve the metadata value, so I cannot do it with the checkout session?
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
OK, now I sent a request but it says payment incomplete?
i am still unable to send metadata
Yes, you need to go through checkout to complete the payment
?
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
can you share the new session? do your new logs show the metadata coming through?
can you share the full session create request snippet?
still no meta data here: https://dashboard.stripe.com/test/logs/req_cb2TPVZeAc8YXw
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,
so you need to debug why it fails. start simple:
'metadata' => [
'test'=>'test',
]
and comment out the other lines, the check your logs: https://dashboard.stripe.com/test/logs
then re-enabled a few other values, try again
what do you mean? YOu'd need to examine your logs for other session creation requests
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?
If you're in subscription mode, sure: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-application_fee_percent
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
(and making a Connect request)
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
can you rephrase that?
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
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
Hmmm but the setup doesn't take any charge at all, correct?
Ok yes, I have to make some tests first
Thanks
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?
ah, yep, looks like it's going through now: https://dashboard.stripe.com/test/logs/req_LnpvBglMhZDLDD
the request failed related to the application fees you were asking about, but the metadata is there ๐
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]
);
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
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
);
can you share the SetupIntent ID, the PaymentMethod ID and the Customer ID?
evt_1Jcd2d4wpi0cDPtefAFd87tx
that would be an Event ID, can you share the request ID that you made which returned the error?
Just look for it in https://dashboard.stripe.com/test/logs
req_EeTz4wLiyxvOvY
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