#emily-connect

1 messages ยท Page 1 of 1 (latest)

arctic thistle
#

hello, thread created, go ahead

tepid iris
#

So I started out using stripe php with js to create a payment gateway, but discovered I needed to make use of Stripe Connect Standard to handle platform fees, identity verification, and for tax reasons. So when the user logs in they can now use oauth and onboard, and it saves the returned acct_stripeaccountid to the database, which is $fundraiserstripecode in my example. There's also $stripeFee which is the platform fee in my example. I don't know if it's a syntax error or what but after adding ['stripe_account' => $fundraiserstripecode] and 'payment_intent_data' => [ 'application_fee_amount' => $stripeFee, ] I'm not longer to create a checkout session.

#

My Code:

#

Here's a visual of the diff if that helps readability

#

should the acct_ prefix be included in $fundraiserstripecode or perhaps just the id itself?

#

maybe that's breaking it

#

$fundraiserstripecode = acct_123456789 for example

arctic thistle
#

1/ what error do you get back?

2/ can you share the request ID from the request you make

#

also appreciate you sharing those helpful details above^, helps draw a better picture

#

let me know about 1/ and 2/

tepid iris
#

Oh yeah this is the js:

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

<script>
var buyBtn = document.getElementById('payButton');
var responseContainer = document.getElementById('paymentResponse');
    
// Create a Checkout Session with the selected product
var createCheckoutSession = function (stripe) {
    return fetch("https://mywebsite.com/foobar.php", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
        },
        body: JSON.stringify({
            checkoutSession: 1,
        }),
    }).then(function (result) {
        return result.json();
    });
};

// Handle any errors returned from Checkout
var handleResult = function (result) {
    if (result.error) {
        responseContainer.innerHTML = '<p>'+result.error.message+'</p>';
    }
    buyBtn.disabled = false;
    buyBtn.textContent = 'Buy Now';
};

// Specify Stripe publishable key to initialize Stripe.js
var stripe = Stripe('<?php echo STRIPE_PUBLISHABLE_KEY; ?>');

buyBtn.addEventListener("click", function (evt) {
    buyBtn.disabled = true;
    buyBtn.textContent = 'Please wait...';
    
    createCheckoutSession().then(function (data) {
        if(data.sessionId){
            stripe.redirectToCheckout({
                sessionId: data.sessionId,
            }).then(handleResult);
        }else{
            handleResult(data);
        }
    });
});
</script>```
tepid iris
arctic thistle
#

rather, using the info there

#

but ah

#

you're creating Stripe.js (in your JS code) as the Platform

#

but you created the CheckoutSession as the Connect account

#

you're most likely missing this

#
var stripe = Stripe('{{PLATFORM_PUBLISHABLE_KEY}}', {
  stripeAccount: '{{CONNECTED_STRIPE_ACCOUNT_ID}}',
});

you need to also pass the same Stripe Connect acct ID to Stripe.js also

tepid iris
#

oops

#

yeah that would help

#

should the CONNECTED_STRIPE_ACCOUNT_ID include acct_ like acct_12345 or just 12345

arctic thistle
#

the full thing, the entire ID is acct_12345

#

just like PaymentMethod ID is pm_123 or Customer ID is cus_456

the prefix is part of the ID

tepid iris
#

thanks ๐Ÿ™‚

#

so I see my acct_ now:

var stripe = Stripe('pk_test_foobar, {
  stripeAccount: 'acct_foobar',
});

but it's just showing me 'Please wait...' and no longer redirecting me to the stripe gateway page as it did prior to using application_fee_amount and stripe_account. For context (from my js):

    buyBtn.disabled = true;
    buyBtn.textContent = 'Please wait...';
    
    createCheckoutSession().then(function (data) {
        if(data.sessionId){
            stripe.redirectToCheckout({
                sessionId: data.sessionId,
            }).then(handleResult);
        }else{
            handleResult(data);
        }
    });
});```
arctic thistle
#

let's start here

#

pls answer these questions to help narrow down

#

1/ server-side, are you creating a CheckoutSession successfully

#

do you get a CheckoutSession obj back in yoru server-side response

#

I'll move on to 2/ depending on the answer

tepid iris
#

@arctic thistle I removed payment_intent_data because there was a syntax issue, but now there's a new problem. Without using connect the stripe gateway loads, but if I add:

var stripe = Stripe('<?php echo STRIPE_PUBLISHABLE_KEY; ?>', {
  stripeAccount: '<?php echo $fundraiserstripecode; ?>',
});```

and append ```        ],['stripe_account' => $fundraiserstripecode]); ``` with stripe_account I get:

```TEST
Something went wrong
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.

Back```
#

both connect standard and my account are set to test mode and I'm using the pk_ and sk_ test keys

languid kraken
#

Hello ๐Ÿ‘‹ catching up here, hmunoz had to step out for a bit.

tepid iris
languid kraken
#

Are you using that same account when creating and retrieving the Checkout Session?

tepid iris
#

$fundraiserstripecode contains the same account id yes

languid kraken
#

Do you have the ID for the Checkout Session?

tepid iris
#

acct_foobar

#

sure let me provide it in a moment

languid kraken
#

Are you actually passing in the string acct_foobar in the StripeAccount header?

tepid iris
#

i'll double check thanks

languid kraken
#

Have you double checked that '<?php echo $fundraiserstripecode; ?>' resolves to acct_1K7Q5TJe1kqgTKOi as you are expecting?

tepid iris
#

maybe I'm confusing this so I see 1JVP8uHhaDPa8eVP within my pk_ do I need the pk_ and sk_ of all linked accounts as well?

#

or just the acct_ to make a charge on a linked accounts behalf

#

I'm using my stripe keys to make a charge on behalf of an acct_ with stripe standard

languid kraken
#

You do not need their keys, just to pass their account ID in as the header as outlined in the docs

tepid iris
#

then I'm making a mistake and I'll investigate sorry my skills are quite novice compared to the rest of discord

#

when I var_dump $fundraiserstripecode in both instances (js and in the php) they're both the same

languid kraken
#

You are totally fine, we are happy to help.

tepid iris
#

thank you

languid kraken
#

So actually, it looks like you can skip some of the client side code to make this easier.

#

At the moment you are sending data from your server to your client and calling redirectToCheckout there. You can actually just have the server send back a 302 redirect message to the Checkout Session's url

tepid iris
#

you sorted everything out for me I appreciate it

#

I just want to confirm one thing

#
            'payment_intent_data' => [
                'application_fee_amount' => $stripeFee,
              ], ```
#

does ordering matter with payment_intent_data?

#

I put it after mode

#

otherwise everything is resolved

charred thunder
#

Hi there ๐Ÿ‘‹ getting caught up on the thread, and I'm thrilled to hear my teammates advice has helped!

#

No, the order of parameters shouldn't matter.

tepid iris
#

the level of support is surreal I wish all companies had this

#

have a great holiday thanks

#

you can lock the thread

charred thunder
#

Thank you, hope you enjoy your holiday season as well!

tepid iris
#

Hey there,

So after adding application_fee_amount and stripe_account (php) and stripe_account to (js) I can process charges on other peoples acct_'s with stripe connect standard successfully, but I'm having issues fetching the checkout session, unless I revert the previous changes (then it works again).

'success_url' => STRIPE_SUCCESS_URL.'checkout_id={CHECKOUT_SESSION_ID}',

        try { 
$checkout_session = \Stripe\Checkout\Session::retrieve([
    'id' => $session_id,
    'expand' => [
        'line_items'
    ],
]);```

Does the stripe_account need to be specified somewhere in \Stripe\checkout\Session::retrieve or perhaps it's another issue? Here is my code (I tried to remove unrelated things and trim it down).
#

Code if this helps:

languid kraken
#

If you are creating the Checkout Session with the other account, then you will also need to retrieve it from that account

tepid iris
#
    'id' => $session_id,
    'expand' => [
        'line_items'
    ],
],['stripe_account' => $fundraiserstripecode]); ```
#

like this?

#

doesn't seem to be working guess not

languid kraken
#

So how are you creating the Checkout Session?

languid kraken
#

So yes, if you create it with the account header, you should retrieve it with the same account header

#

What error do you see when you make that retrieve call with that account header?

arctic thistle
#

stepping in

#

@tepid iris please share context of what isn't working for you

tepid iris
#

Alright so I pinpointed it to this. It's unable to retrieve the payment intent (No such payment_intent) because it's lacking the correct stripe_account:

            // Retrieve the details of a PaymentIntent 
            try { 
                $intent = \Stripe\PaymentIntent::retrieve($checkout_session->payment_intent); 
            } catch (\Stripe\Exception\ApiErrorException $e) { 
                $api_error = $e->getMessage(); 
            } 
             
            // Retrieves the details of customer 
            try { 
                // Create the PaymentIntent 
                $customer = \Stripe\Customer::retrieve($checkout_session->customer); 
            } catch (\Stripe\Exception\ApiErrorException $e) { 
                $api_error = $e->getMessage(); 
            } ```

How do I specify ['stripe_account' => $fundraiserstripecode] in ```\Stripe\PaymentIntent::retrieve($checkout_session->payment_intent); ``` and ```\Stripe\Customer::retrieve($checkout_session->customer); ```.
arctic thistle
#

all Stripe API requests support the Stripe-Account header, not sure off hand the PHP syntax but you have to pass a second array with stripe_account in it like shown here: https://stripe.com/docs/connect/authentication#stripe-account-header

so try

\Stripe\PaymentIntent::retrieve(
  $checkout_session->payment_intent,
  ['stripe_account' => 'acct_123'] 
); 

you'll have to fix my snippet to pass in your $fundraiserstripecode variable

tepid iris
#

i'll give that a shot thank you for the snippet!

#

@arctic thistle everything seems good now thank you have a great day

#

you can close this thread