#birdy247-connect

1 messages · Page 1 of 1 (latest)

lusty notch
#

Hi! What do you mean by "from a payment intent that was created from a cloned customer"? You mean a cloned PaymentMethod?

royal spindle
#

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

lusty notch
#

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.

royal spindle
#

yes

lusty notch
#

then yes this should work.

royal spindle
#

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

lusty notch
royal spindle
#

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

lusty notch
#

Then yes you need to make sure you use the correct value for stripeAccount

royal spindle
#

But if stripe already exisits and we have mounted a payment element

#

Can we do that?

lusty notch
#

So you want to dynamically change the value of stripeAccount?

royal spindle
#

Yes

lusty notch
#

Hum... I don't think that's possible.

royal spindle
#

I cant get the stripe.confrimPayment to work

lusty notch
#

Can you share your code?

royal spindle
#

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?

dire sandal
#

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?

royal spindle
#

Can you see the thread?

#

Its a bit annoying to type again

dire sandal
#

it would be better for me to really understand and try to help you

royal spindle
#

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

dire sandal
#

sorry for the inconvenience

royal spindle
#

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

dire sandal
#

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

royal spindle
#

Ok, but it will be the same issue no?

dire sandal
#

one step at a time

royal spindle
#

If it requires action, they will need to confirmPayment again?

dire sandal
#

just to explain what's happening here

#

you're creating a PaymentIntent using both your Platform's Account id and the Connect Account Id

royal spindle
#

PaymentIntent is created on the connected account

#

So we need to confirm it using their account no?

dire sandal
#

could you share that bit of code?

royal spindle
dire sandal
#

that's not the bit I was asking for, I need to see your backend code where you create the Payment Intent

royal spindle
#

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

dire sandal
#

how are you initializing your Stripe Account to do this $this->_createPaymentIntent?

royal spindle
#

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');
}

dire sandal
#

@royal spindle I'm trying to figure out how are you creating the PaymentIntent to begin with

royal spindle
#

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)

slate totem
#

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
royal spindle
#

what about the elements?

slate totem
#

another mistake I thnk is you shouldn't be using Elements at all in the confirmPayment

royal spindle
#

It says its mandatory

slate totem
#

yep but you shouldn't be using confirmPayment

#

you should use confirmCardPayment

royal spindle
#

Got it

slate totem
#

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

royal spindle
#

Right, so if they use google pay/apple pay, this will not work?

slate totem
#

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

royal spindle
#

Yes, i can see

#

Ok, that worked

#

Thanks for your help

#

WOrking nicely

slate totem
#

awesome!

royal spindle
#

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?

slate totem
#

yes, I believe so. It's just a card really.

royal spindle
#

Awesome

slate totem
#

the PaymentElement with the SetupIntent is what uses the GPay button

royal spindle
#

In any other flow, we use confirmPayment

slate totem
#

after that you just have the card (the PaymentMethod object) and the rest of the flow is the same

royal spindle
#

just when we have 2 connected accounts to pay

#

SO to clarfiy, would we need to change our implemntation for GPay?

royal spindle
#

?

slate totem
#

I don't think so. you can test it

royal spindle
#

ok great