#birdy247-connect
1 messages · Page 1 of 1 (latest)
Hi! What do you mean by "from a payment intent that was created from a cloned customer"? You mean a cloned PaymentMethod?
We are a platform
Use case is paying to connected stripe accounts
So we create a setup intent/customer on our platform
When the setup intent is confirmed, we clone the customer on the connected account
We then create the payment intent's and pass back the secrets to the front end
We then loop through them to confirm them on the front end
So if there is a problem, the customer can fix it
When the setup intent is confirmed, we clone the customer on the connected account
So what you clone is the PaymentMethod created by the SetupIntent.
And you can use that PaymentMethod to create a PaymentIntent, and then confirm the PaymentIntent on the frontend yes.
yes
then yes this should work.
One thing I am not sure on
How we do we re-initalise stripe.js
as in the first instance, it doesnt havent an account id
but when confirming, we will have different stripe ids
How do you create the PaymentIntent? I'm guessing you use the Stripe-Account header on the backend: https://stripe.com/docs/connect/authentication#stripe-account-header
So when you confirm the PaymentIntent, you also need to use the Stripe-Account header on the frontend: https://stripe.com/docs/connect/authentication#adding-the-connected-account-id-to-a-client-side-application
stripe = new Stripe('xxxxx, {
stripeAccount: element.stripe_account_id,
apiVersion: '2020-08-27'
});
elements = stripe.elements({clientSecret: element.secret});
const paymentElement = elements.create("payment", {
terms: {
card: 'never'
}
});
paymentElement.mount("#payment-element");
const {error, paymentIntent} = await stripe.confirmPayment({
elements,
confirmParams: {
// Make sure to change this to your payment completion page
return_url: "https://somewhere.com",
},
redirect: 'if_required' //in next action
});
Thats right yes
Then yes you need to make sure you use the correct value for stripeAccount
But if stripe already exisits and we have mounted a payment element
Can we do that?
So you want to dynamically change the value of stripeAccount?
Yes
Hum... I don't think that's possible.
Can you share your code?
Its a variation of the exmaple on your website
The point of creating the setuo intent and hitting our backend works fine
I imagine its to do with a promise issue?
hi, I'm taking over for @lusty notch
could you please summarize what are you trying to do? and what's the issue you're facing?
it would be better for me to really understand and try to help you
Ok
We are a platform
Use case is paying to connected stripe accounts
So we create a setup intent/customer on our platform
When the setup intent is confirmed, we clone the customer on the connected account
We then create the payment intent's and pass back the secrets to the front end
We then loop through them to confirm them on the front end
So if there is a problem, the customer can fix it
sorry for the inconvenience
The issue we are facing is that the once we crate the paymentIntents on the connected accounts
We cant then confirm them on the front end
why not confirming directly on the backend? and using webhooks, you can listen to payment_intent.requires_action and then use that to send it to the front-end
Ok, but it will be the same issue no?
one step at a time
If it requires action, they will need to confirmPayment again?
just to explain what's happening here
you're creating a PaymentIntent using both your Platform's Account id and the Connect Account Id
PaymentIntent is created on the connected account
So we need to confirm it using their account no?
could you share that bit of code?
that's not the bit I was asking for, I need to see your backend code where you create the Payment Intent
public function createPaymentIntentOnConnectedAccountFromSetupIntent(Transaction $transaction, SetupIntent $setupIntent)
{
$paymentMethod = $setupIntent->payment_method;
$customer = $setupIntent->customer;
$invoiceItems = $this->updatePaymentStatus($transaction, true);
$transaction->setInvoiceItems($invoiceItems->toArray());
if (empty($transaction->getInvoiceItems())) {
return $transaction;
}
$tenantPaymentProvider = $transaction->getTenantPaymentProvider();
//3. Clone the payment method on the connected account
$payment_method = \Stripe\PaymentMethod::create([
'customer' => $customer,
'payment_method' => $paymentMethod,
], [
'stripe_account' => $tenantPaymentProvider->stripe_user_id,
]);
//DUPLICTE CODE - LINES 777
$paymentIntent = $this->_createPaymentIntent($transaction, $payment_method->id, $tenantPaymentProvider->stripe_user_id); //Create the payment intent
if (!$paymentIntent) { //Something has gone wrong
return $transaction;
}
$invoiceItemIds = collection($transaction->getInvoiceItems())->extract('id')->toList();
//5. Stamp the payment_intent ID on the invoices
$this->InvoiceItems->updateAll([
'payment_intent_id' => $paymentIntent->id,
'tenant_payment_provider_id' => $tenantPaymentProvider->id
], [
'id IN' => $invoiceItemIds
]);
//DUPLICTE CODE - LINES 797
//Stamp ID on invoice_items
return [
'next_action' => 'confirmPayment',
'stripe_account_id' => $transaction->getTenantPaymentProvider()->stripe_user_id,
'secret' => $paymentIntent->client_secret
];
}
I am sure its something to do with the promises
how are you initializing your Stripe Account to do this $this->_createPaymentIntent?
THats all working fine
the payment intents are being created fine
Its the code on the front end
try {
const {paymentIntent} = await stripe.confirmPayment({
elements,
confirmParams: {
return_url: "<?= Router::url(['_name' => 'invoice-items:complete'], true) ?>",
},
redirect: 'if_required' //in next action
});
} catch (e) {
console.error(e);
} finally {
console.log('We do cleanup here');
}
@royal spindle I'm trying to figure out how are you creating the PaymentIntent to begin with
THats what Im getting
In the catch
So the confirmPayment is not being hit
Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.<anonymous> (<anonymous>:1:29)
is there a page where can see this ourselves?
it's not really working to chat this way I'm afraid.
In any case, one thing I'd point out is you need two instances of Stripe for your flow.
like you need
stripe = new Stripe(platformKey)
stripeConnectedAccount = new Stripe(platformKey, {stripeAccount:"acct_xxx"} );
....
stripe.confirmSetup() // accept card on platform so you can then clone it to a connected account later
....
stripeConnectedAccount.confirmPayment() // confirm a PaymentIntent on the connected account
what about the elements?
another mistake I thnk is you shouldn't be using Elements at all in the confirmPayment
It says its mandatory
yep but you shouldn't be using confirmPayment
you should use confirmCardPayment
this version : https://stripe.com/docs/js/payment_intents/confirm_card_payment#stripe_confirm_card_payment-attached that just takes the client-secret
Got it
since you don't need to use Elements, you're not collecting a card at that point, you are just processing a payment on the PaymentIntent already created on the backend with an attached card
Right, so if they use google pay/apple pay, this will not work?
one question at a time please
I'd suggest getting this working and then looking at wallets
AFAIK it would work. But overall this flow is pretty advanced and poorly documented so it's quite a pain to build I'm afraid
awesome!
Question on wallets
I notice it says You can start accepting Google Pay payments on the web using Checkout or Elements. Using Google Pay in Checkout requires no additional configuration. For Elements, refer to our Payment Request Button or Accept a payment guides to learn how to add Google Pay to your site.
Assuming the connected account allows google pay
And they pay with google pay
will out confirmCardPayment work for this use case?
yes, I believe so. It's just a card really.
Awesome
the PaymentElement with the SetupIntent is what uses the GPay button
In any other flow, we use confirmPayment
after that you just have the card (the PaymentMethod object) and the rest of the flow is the same
just when we have 2 connected accounts to pay
SO to clarfiy, would we need to change our implemntation for GPay?
?
I don't think so. you can test it
ok great