#matrix-checkout-direct-charge

1 messages · Page 1 of 1 (latest)

rough ether
#

hey ther,e sure, what are you trying currently and what isn't working like you expect?

hollow verge
#

I am trying to create a direct charge from my platform for a product that I have created in the dashboard for my connect account

#

the webpage show this error

#

The specified Checkout Session could not be found. This error is usually caused by using the wrong API key. Please make sure the API keys used to initialize Stripe.js and create the Checkout Session are test mode keys from the same account.

#

in firebase i see the following log

#

Function execution took 1195 ms, finished with status code: 200

#

I cant see and req in my stripe dashboard

rough ether
#

Are you redirecting from your server, or client-side?

hollow verge
#

here is my code

rough ether
#

if you're redirecting with stripe.js, you need to make sure you initialize stripe.js using the stripeAccount option with the account matching the stripe-account you used to create the connected checkout session

#

eg: var stripe = Stripe('pk_test_123_plat', {stripeAccount: 'account_456_connected'})

hollow verge
#

SERVER CODE
const stripeVendorAccount = 'acct_1Jpu8gFbYZoKrptz';

const session = await stripe.checkout.sessions.create(
  {
    line_items: [
      {
        // Provide the exact Price ID (e.g. pr_1234) of the product you want to sell
        price: 'price_1Js6eZFbYZoKrptzfh96WP8C',
        quantity: 1,
      },
    ],
    payment_method_types: [
      'card',
    ],
    mode: 'subscription',
    success_url: `https://google.com`,
    cancel_url: `https://yahoo.com`,
  }, {
    stripeAccount: stripeVendorAccount,
  }
);

console.log('ID  SESSION', session.id);


return {
  id: session.id,
};
#

CLIENT SIDE
<script src="https://js.stripe.com/v3/"></script>

    const checkoutButton = document.getElementById('checkout-button');
    // const createStripeCheckout = functions.httpsCallable('createStripeCheckout');
    const createStripeCheckout = httpsCallable(functions, 'createStripeCheckout');

    const stripe = Stripe('pk_test_51EpuOEKXjwYd84Q4OeeHHJmIzWklxIvZQzEeT7JOjAZx91ZRwYbJBILRjI9D3UwEu6tT7GqNM8Ne4iRpIJGPoKbP00SiByyvDH');
    checkoutButton.addEventListener('click', () => {
      console.log('CLICKED');
      createStripeCheckout()
        .then(response => {
          const sessionId = response.data.id;
          stripe.redirectToCheckout({sessionId: sessionId});
        });
    });
#

do I need write like this?

#

const stripe =
Stripe('pk_test_51EpuOEKXjwYd84Q4OeeHHJmIzWklxIvZQzEeT7JOjAZx91ZRwYbJBILRjI9D3UwEu6tT7GqNM8Ne4iRpIJGPoKbP00SiByyvDH', {stripeAccount: 'acct_1Jpu8gFbYZoKrptz'})

rough ether
#

yes, exactly, give that a whirl 🙂

hollow verge
#

ok I managed to do it

#

thanks!!!

#

do i need that if i create destination charges on_behalf_of?

#

because in my site i have multiple page, each of them is for a different connected account and i would need to initiate stripe.js multiple time...

rough ether
#

Nice, you're welcome!

#

no, with destination charges the session belongs to your platform, so neither the server create nor the stripe.js redirect needs the connected account option

#

you'll provide that in the transfer details instead

hollow verge
#

Can i ask about VAT treatment? my connected account pays 5% VAT while i pay 20%

#

ideally i would like to pay 20% on my application fee and 5% on the value of the product

#

can i achieve that with destination charges?

rough ether
#

No, taxes get applied based on the products being purchased, so i don't think anything different could be done based on the application fee you set.

hollow verge
#

so let's assume the product cost £20 and VAT is 5% = £21

#

if i charge £21 with my account it means i need to deduct the 20% VAT which means i am selling for £17.5 + 20%

#

which means i am losing money

#

is it correct?

#

if my connect account pay less VAT than me, i am losing. if they pay the same ammount it's ok

#

thinkning at direct charges, can I initiate stripe.js multiple time in my client, every time with a different connected account?

keen mesa
#

@hollow verge catching up one sec

hollow verge
#

ok

keen mesa
#

can you summarize your current question?

hollow verge
#

It seems i need to initiate stripe.js in my client with the connected account

keen mesa
#

for Direct Charges, yes
you use the stripeAccount param

hollow verge
#

this is because i want to use direct charges

#

var stripe = Stripe('pk_test_123_plat', {stripeAccount: 'account_456_connected'})

#

the question is how can i initiate it multiple time?

#

i am not very good with html and script

#

this is what i have in my index.html

#

var stripe =
Stripe('pk_test_51EpuOEKXjwYd84Q4OeeHHJmIzWklxIvZQzEeT7JOjAZx91ZRwYbJBILRjI9D3UwEu6tT7GqNM8Ne4iRpIJGPoKbP00SiByyvDH', {stripeAccount: 'acct_1Jpu8gFbYZoKrptz'})
checkoutButton.addEventListener('click', () => {
console.log('CLICKED');
createStripeCheckout()
.then(response => {
const sessionId = response.data.id;
stripe.redirectToCheckout({sessionId: sessionId});
});
});

keen mesa
#

the question is how can i initiate it multiple time?
why do you need to do that?

hollow verge
#

should i set stripe inside my addEventListener

#

because i have different connected accounts in my website

#

so if i click on button A, it is account 1

#

if i click on button B, it is connected account 2

keen mesa
#

ah so in that case, you need to just reinitialize Stripe.js and mount Elements again, you don't create multiple instances of Stripe.js, just one but reinitialize it every time the customer selects a different account

hollow verge
#

How would I do it? By calling stripe = Stripe( pk, connected-account); before console.log(CLICKED)?

keen mesa
#

yes

hollow verge
#

Ok

keen mesa
#

well

#

you do it inside your button click function

#

cause that is when you want to change the instantiation of Stripe