skip to Main Content

I have set up Stripe Payment Request Buttons, everything is working when I manually add the stripeAccount: ‘acct_XXX…’, the payment succeeds on the dashboard for that connected account.

but when I try to put this in a const in payment_request_buttons.js:

const stripe_account_id = document.getElementById('stripe_account_id').value;

const stripe = Stripe('pk_test_XXX...'), {
  apiVersion: "2022-11-15",
  stripeAccount: stripe_account_id,
});

The hidden input:

<input id="stripe_account_id" type="hidden" value="<%= "'#{@user.stripe_account_id}'" %>"> 

I get this CORS error:

No 'Access-Control-Allow-Origin' header is present

I don’t understand what the difference is manually inputting the account compared to using const?

I have just come across this error from a stripe link in the console:

{
"error": {
"message": "You did not provide an API key. You need to 
provide your API key in the Authorization header, using 
Bearer auth (e.g. 'Authorization: Bearer YOUR_SECRET_KEY'). 
See https://stripe.com/docs/api#authentication for details, 
or we can help at https://support.stripe.com/.",
"type": "invalid_request_error"
 }
}

2

Answers


  1. Chosen as BEST ANSWER

    I have solved this error.   When passing the stripe account manually you use an apostrophe " ' " with the account number inside, but when looking at the post data to stripe you see they are removed:

    _stripe_account: acct_xxx........... 
    

    So in my ruby code i was adding the apostrophe in the value resulting in :

    value="<%= "'#{@user.stripe_account_id}'" %>">
    
    _stripe_account: 'acct_xxx...........' 
    

    being sent causing the error.   My updated ruby code without the apostrophe:

    value="<%= @user.stripe_account_id %>">
    

    This data was found in Network > wallet-config > Payload > Form Data

    This has now resolved the CORS error and is working.


  2. Can you do some loggings to check if the value of stripe_account_id is set before Stripe.js SDK initialization?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search