#vytasbboy-payment-sheet

1 messages ยท Page 1 of 1 (latest)

static adder
#

Hey there ๐Ÿ‘‹ what seems to be the problem?

acoustic phoenix
#

I am using flutter and used to use fluyter_stripe library which i was integrating with Stripe API by creating customer, payment method, payment intent and confirming payment

#

now i have to move to new version of stripe plugin because prvious is deprectaed and new one offers Stripe sheet payments

#

i thought it would be great way to improve user experience

#

but their examples are incomplete with server side (very simple)

#

and I am not sure how correclty integrate it in my case

#

my situation is:

#

I have customer which has to pay to connected account with platform fee

#

so mu current implementation is this:

var response = await this.stripe.paymentMethods.create({
            customer: args.customerStripeAccountId,
            payment_method: args.paymentId
        }, { stripeAccount: args.spStripeAccountId });

        return await this.stripe.paymentIntents.create({
            amount: amountInCents,
            currency: args.currencyCode,
            payment_method_types: ['card'],
            receipt_email: args.customerEmail,
            payment_method: response.id,
            confirm: true,
            confirmation_method: 'automatic',
            application_fee_amount: feeAmountInCents,
            // customer: args.customerStripeAccountId,
            setup_future_usage: 'off_session',
        },
            { stripeAccount: args.spStripeAccountId }
        );

#

but new implementation should be made with ephemeralKeys

#

and i am not sure how to do this... i was trying to this like:

/* var response = await this.stripe.paymentMethods.create({
            customer: args.customerStripeAccountId,
            payment_method: args.paymentId
        }, { stripeAccount: args.spStripeAccountId }); */

        const ephemeralKey = await this.stripe.ephemeralKeys.create(
            { customer: args.customerStripeAccountId },
            {
                apiVersion: '2020-08-27',
                stripeAccount: args.spStripeAccountId,
            }
        );

        const paymentIntent = await this.stripe.paymentIntents.create({
            amount: amountInCents,
            currency: args.currencyCode,
            payment_method_types: ['card'],
            receipt_email: args.customerEmail,
            // payment_method: response.id,
            confirm: true,
            confirmation_method: 'automatic',
            application_fee_amount: feeAmountInCents,
            // customer: args.customerStripeAccountId,
            setup_future_usage: 'off_session',
        },
            { stripeAccount: args.spStripeAccountId }
        );

        return {
            paymentIntent,
            ephemeralKeySecret: ephemeralKey.secret,
        }
#

because as far as i understand payment method will be seelcted and created inside payment sheet

#

but this is not working because i get an error customer does not exists: resource error

#

i also do not know where i have to specify stripeAccount and where customer to get it working

#

as you can se in legacy i was creating payment method and assigning it to payment intent. Payment inten had stripeAccountId (connected account) and all worked..
Can you guide me how to atchieve the same with sheet?

static adder
#

Thanks for the info, please bear with me a moment while I go through it.

acoustic phoenix
#

sure

sharp gulch
#

@acoustic phoenix let's start here :

but this is not working because i get an error customer does not exists: resource error
what is the exact error message and stack trace; what is the exact code you used that resulted in that? There are 3 API calls in that backend code you shared, which one returned the error? Or was it in the frontend in the app that this error appeared?

#

also to set expectations, we don't know much about Flutter or that plugin here unfortunately, but can definitely try to help.

acoustic phoenix
#

2 calls: paymentmethod is commented

#

is i add stripeAccountId to this.stripe.ephemeralKeys.create - i get this error from it

sharp gulch
#

ok let's stop there then.

acoustic phoenix
#

if i assign customer: args.customerStripeAccountId, to await this.stripe.paymentIntents.create({ i get same error from it

#

i will give you error in a second

sharp gulch
#

it's ok, let's stop there and take it one thing at a time.

acoustic phoenix
#

message:'No such customer: 'cus_KRsyhg0xuHingr''

code:'resource_missing'

sharp gulch
#

is i add stripeAccountId to this.stripe.ephemeralKeys.create - i get this error from it
so adding stripeAccount to the call mean you execute the call on a connected account.

If you get a "no such customer" error it means that the Customer ID you passed does not exist on that connected account(meaning it probably exists on your platform).

#

that ID you pasted in the erorr message does look it exists on your platform so that is the problem!

acoustic phoenix
#

I am not sure what exsits where and what is the right way to do this. I just want client to pay and some amount is transfered to connected account and some fee is collected for platform

#

it is not complicated only when you are developer of API ๐Ÿ˜„

sharp gulch
#

yep but it's your job to implement this so you really do have to understand how Connect works in this regard and what it means for objects to exist on specific accounts, which is what I can help you with!

acoustic phoenix
#

totally agree

sharp gulch
#

so cus_KRsyhg0xuHingr exists on the platform.
There's two main options here.

#
  1. create the customer on the connected account instead.
#

it works the same as all other calls

#
let customer = await stripe.customers.create({
ย ย ย  email: "test@example.com",
} {stripeAccount:"acct_xxx"})
acoustic phoenix
#

i do not know i need to create customer on connected account because one customer can pay multiple connected accounts

sharp gulch
#

ok then maybe you want option 2. Note though it will be much more complicated

acoustic phoenix
#

i do not think first option is correct

sharp gulch
#

seems like you already implemented that

#

that's what is in your first code snippet

acoustic phoenix
#

that was i was exactly doing in legacy:

var response = await this.stripe.paymentMethods.create({
            customer: args.customerStripeAccountId,
            payment_method: args.paymentId
        }, { stripeAccount: args.spStripeAccountId });

        return await this.stripe.paymentIntents.create({
            amount: amountInCents,
            currency: args.currencyCode,
            payment_method_types: ['card'],
            receipt_email: args.customerEmail,
            payment_method: response.id,
            confirm: true,
            confirmation_method: 'automatic',
            application_fee_amount: feeAmountInCents,
            // customer: args.customerStripeAccountId,
            setup_future_usage: 'off_session',
        },
            { stripeAccount: args.spStripeAccountId }
        );


#

yes

sharp gulch
#

cool. So why are we changing it exactly?

acoustic phoenix
#

but now i am integrating with payment sheet

sharp gulch
#

because you need an ephemeral key I guess?

acoustic phoenix
#

and as far as i understand payment sheet should create payment method and so forth

sharp gulch
#

yep indeed

acoustic phoenix
#

so i do not need to create payment method.. thats a problem ๐Ÿ™‚

sharp gulch
#

unfortunately I don't think our PaymentSheet integration works very well with this concept of cloning, it might actually be impossible

#

it really only works for option 1) where you do everything on the connected account

acoustic phoenix
#

what a drawbacks with option 1?

sharp gulch
#

the problem is you need to create the ephemeral key for the Customer on the platform account, since you want to create and manage the payment methods there

#

and then you want to do the PaymentIntent on the connected account

#

and I'm pretty sure it's impossible to get that working on PaymentSheet. Sorry, our entire approach to this "cloning customers" integration really needs an overhaul and better docs, this is not really your fault.

#

the drawback with option 1 is you'd have maybe 5 customers(one on each connected account) all with the same details, instead of one "master" one on the platform, mainly.

#

also it allows the connected account to charge the customer themselves if they want(since the customer and details are stored on their account and they see it in their dashboard)

acoustic phoenix
#

if customer pays to 100 connected accounts i will have 100 customer with duplicated adat on each of them...

#

thet second thing sounds really really bad

#

so i cannot integrate sheet and have to stick with my current approach...

sharp gulch
#

it depends on the business, some businesses would want that, but yes, it is a drawback in some cases, totally agree

#

to be honest if you want this model of "master customer on the platform, clone their cards to a connected account once-off and charge there", the easiest option is to use existing integrations and not the PaymentSheet yes; the sheet is really tightly coupled to a single account and wasn't built with this cloning in mind.

acoustic phoenix
#

ok

#

thta really sad

#

because library that i use gives all out of the bocs including Apple pay and 3D security if using payment sheet

#

ok, i hope you will revise approach some time in the future and this will be possible with sheet also

#

thanks