#.stevenp

1 messages · Page 1 of 1 (latest)

radiant roseBOT
tardy moss
#

Hi there, you shouldn't add thing to the stripeSignature, otherwise the signature verification would fail

unreal thorn
#

ah yes, when I call it as the guide suggests here:

https://stripe.com/docs/stripe-apps/build-backend

```return fetch(https://example.com/${endpoint}/, {
method: 'POST',
headers: {
'Stripe-Signature': await fetchStripeSignature(),
'Content-Type': 'application/json',
},
// Include the account ID and user ID in the body to verify on backend.
body: JSON.stringify({
...requestData,
...signaturePayload,
}),
});

the request fails
tardy moss
#

Any error log from your server?

unreal thorn
#

It's not failing on the server it's failing in chrome

#

it never makes it to the server

#

no logs on my server, and when I remove this header it works fine

tardy moss
#

Is the endpoint accessible?

unreal thorn
#

yea

#

when I remove the header from the request it succeeds

tardy moss
#

can you share with me your exact code?

unreal thorn
#

yessir

#
mport { Box, ContextView, Inline, Link } from "@stripe/ui-extension-sdk/ui";
import type { ExtensionContextValue } from "@stripe/ui-extension-sdk/context";

import BrandIcon from "./brand_icon.svg";
import {SignInView, SettingsView} from '@stripe/ui-extension-sdk/ui';
import React, { useEffect, useState } from 'react';
import {fetchStripeSignature} from '@stripe/ui-extension-sdk/utils';

/**
 * This is a view that is rendered in the Stripe dashboard's customer detail page.
 * In stripe-app.json, this view is configured with stripe.dashboard.customer.detail viewport.
 * You can add a new view by running "stripe apps add view" from the CLI.
 */
const App = ({ userContext, environment }: ExtensionContextValue) => {
  const isUserSignedIn = false 

  const [data, setData] = useState(null);
 
  useEffect(() => {

    const fetchData = async () => {
      try {
        // just returns a 200 status
        const signaturePayload = {
          user_id: userContext?.id,
          account_id: userContext?.account.id,
        };
        const stripeSignature = await fetchStripeSignature()

        console.log(stripeSignature)
        const response = await fetch('https://cartwheel.ngrok.io/test_stripe', {
          method: 'POST',
          headers: {
            'Stripe-Signature': stripeSignature,
            'Content-Type': 'application/json',
          },
          // Include the account ID and user ID in the body to verify on backend.
          body: JSON.stringify({
            signaturePayload
          })
        });
        const result = await response.json();
        console.log(result)
        setData(result);
      } catch (error) {
        console.error('Error:', error);
      }
    };

    fetchData()
  }, []);

  return (
    <ContextView
      title="Hello world22"
      brandColor="#F6F8FA" // replace this with your brand color
      brandIcon={BrandIcon} // replace this with your brand icon
      externalLink={{
        label: "View docs",
        href: "https://stripe.com/docs/stripe-apps"
      }}
    >

<SettingsView>
      {/* Add your settings view content. */}
    </SettingsView>
...
tardy moss
#

OK, do you see any error in your browser console?

unreal thorn
#

not a particularly useful one

#

I am nearly certain the request never even makes it to my server as I have logs set up on my server and nothing is getting hit

tardy moss
#

Open your Network tab and see if it tells you more about the network error.

unreal thorn
#

I think Stripe is killing the request from the browser due to the signature not being valid

tardy moss
#

Hmm, it's a CORS error.

#

Anyway, there's a mistake that you might want to fix in your code

            signaturePayload
          })

should be

            ...signaturePayload
          })
unreal thorn
#

ah yeah good find

tardy moss
#

Does your server accept CORS requests?

unreal thorn
#

yep, thing is when the 'Stripe-Signature' Header is removed there's no CORS error, the response 200s, so I'm not sure if the CORS error is accurte

#

yessir

#

it returns a successful response without the header

tardy moss
unreal thorn
#

i've noticed on other projects chrome with show a CORS error when in reality the issue is somethign else, it's just chrome dev console not having good error logging

#

yep, i have my endpoint added there (if I didnt the request without the header wouldn't work)

tardy moss
#

did you add your endpoint to connect-src ?

unreal thorn
#
      "connect-src": [
        "https://api.chargeblast.io/",
        "https://cartwheel.ngrok.io/"
      ],

yes I have it added there, it is something very specific to the Header being passed in I think

tardy moss
#

Do you mind if I do send some post requests to your server?

unreal thorn
#

Go for it

#

So I've found another interesting observation:

 const response = await fetch('https://cartwheel.ngrok.io/test_stripe', {
          method: 'POST',
          headers: {
            'Example': 'XYZ',
            'Content-Type': 'application/json',
          },
          // Include the account ID and user ID in the body to verify on backend.
          body: JSON.stringify({
            ... signaturePayload
          })
        });

This does not work

But removing the "EXAMPLE" header works

#

it seems adding anything to the header (nothing to do with the Stripe verification part) is causing the fetch to not get made

#

When I do it from postman it works

#

So am thinking there's some middleware on the stripe dashboard thats killing it

tardy moss
#

Have you run stripe apps upload ?

unreal thorn
#

yes

#

i've done that and I'm running it via stripe apps start for a live developer experience

#

i can reupload it

tardy moss
#

Did you upload it before you set the connect-src ?

unreal thorn
#

yes

tardy moss
#

Ah, can you upload it again?

unreal thorn
#

yes will do, just seeing a small error

#

found violation for connect-src "https://api.chargeblast.io/": path cannot be empty found violation for connect-src "https://cartwheel.ngrok.io/": path cannot be empty

#

would you know how to make it like a wildcard allow?

#
    "content_security_policy": {
      "connect-src": [
        "https://api.chargeblast.io/",
        "https://cartwheel.ngrok.io/"
      ],
#

will just tuck it under a /stripe/ folder

tardy moss
#

Change it to https://cartwheel.ngrok.io/test_stripe

unreal thorn
#

give me a moment

tardy moss
#

Update the connect-src, upload the Stripe app and try again.

unreal thorn
#

Ok so I moved my endpoint instead to the above and changed the stripe frontend code to hit new endpoint, and updated connect-src. I've test app both within the stripe page direct and via stripe apps start seeing the same issue

#
        const response = await fetch('https://cartwheel.ngrok.io/stripe/test_stripe', {
          method: 'POST',
          headers: {
            'Example': 'XYZ',
            'Content-Type': 'application/json',
          },
#

this fails

#
      "connect-src": [
        "https://api.chargeblast.io/stripe/",
        "https://cartwheel.ngrok.io/stripe/"
      ],```
tardy moss
#

I thought I asked you to change it to https://cartwheel.ngrok.io/test_stripe ?

#

Wait

#

it doesn't matter

#

Did you run stripe apps upload ? was the upload sucessful?

unreal thorn
#

It shouldn't matter, i just thought I was being clever to make it under a subfolder

#

yes the upload was successful

#

also, I had a connect-src error before, when i didnt have the endpoint/folder there, the request failed even without a random header on it

#

so I don't think that's it

tardy moss
#

Can you remove the Example header and use Stripe-Signature instead?

unreal thorn
#

done, it is still the same issue

#

would it help if i send the exact curl request?

tardy moss
#

Can you try increment the version number in stripe-app.json and upload it again?

unreal thorn
#

yes

tardy moss
#

Still the same error?

unreal thorn
#

give me a sec, seem to be having a different isuee

#

weird, it gets past this error when i do stripe apps start

#

but when i do stripe apps upload this is a new error and nothing is loading

tardy moss
#

You mean you get error in browser console when running stripe apps upload ?

unreal thorn
#

When I run the app via stripe app upload now nothing is loading in the UI of the drawer, but when I do stripe apps start, it loads the UI correctly, just fails on this web request

#

so it hits an error way earlier in the lifecycle on stripe app upload compared to stripe apps start

#

This is the same app, just with stripe apps start instead

tardy moss
#

Close the browser, run stripe login to login to your Stripe account, and then run stripe apps start

unreal thorn
#

ok now im getting the error i was getting before, but i will bet if i try stripe apps upload nothing will work

tardy moss
#

So still the same CORS error?

unreal thorn
#

yes

tardy moss
#

That's very strange

#

Hmm, can you create new Stripe app and upload the same code?

unreal thorn
#

ok - how do I delete the stripe app?

radiant roseBOT
unreal thorn
#

i made a second one but now my account is quite bugged

#

i cant delete the old one and i have two of the same app and am getting duplicate console logs

tardy moss
unreal thorn
#

yes that worked ty

#

do i really need this header on the request?

#

can i just pass in on the body?

clear bough
#

No, needs to be in the header to verify the request in your backend

#

I suggest fixing your CORS configuration in your backend server to permit that header

unreal thorn
#

I dont think it has anything to do w/ my server because when i make a request with a random header in it, it also is blocked

#

and the request succeeds from postman

unreal thorn
clear bough
unreal thorn
#

this is my stripe-app.json

{
  "id": "com.chargeblast.helloworld2",
  "version": "0.0.5",
  "name": "Helloworld2",
  "icon": "",
  "permissions": [
    {
      "permission": "event_read",
      "purpose": "Allows reading event data from users who have installed the app"
    },
    {
      "permission": "dispute_read",
      "purpose": "Allows reading event data from users who have installed the app"
    },
    {
      "permission": "dispute_write",
      "purpose": "Allows reading event data from users who have installed the app"
    },
    {
      "permission": "charge_read",
      "purpose": "Allows reading event data from users who have installed the app"
    },
    {
      "permission": "webhook_read",
      "purpose": "Allows reading event data from users who have installed the app"
    }
  ],
  "ui_extension": {
    "views": [
      {
        "viewport": "stripe.dashboard.drawer.default",
        "component": "App"
      }
    ],
    "content_security_policy": {
      "connect-src": [
        "https://api.chargeblast.io/stripe/",
        "https://cartwheel.ngrok.io/stripe/"
      ],
      "image-src": [
        "https://images.example.com/one_image.jpg",
        "https://images.example.com/a_whole_subdirectory/"
      ],
      "purpose": "These URLs allow the app to contact [YOUR APP] for creating shipping details and loading images of shipping partner logos"
    }
  },
  "allowed_redirect_uris": [
    "https://api.chargeblast.io/callback_stripe",
    "https://cartwheel.ngrok.io/callback_stripe"
  ]
}
#

I

#

I'm not sure what you mean by manifest.json - do you mean for my backend?

#

I'm not using node on the backend

clear bough
unreal thorn
#
  const sig = request.headers['stripe-signature'];
  // Retrieve user id and account id from the request body
  const payload = JSON.stringify({
    user_id: request.body['user_id'],
    account_id: request.body['account_id']
  });
  try {
    // Verify the payload and signature from the request with the app secret.
    stripe.webhooks.signature.verifyHeader(payload, sig, appSecret);
#

this is example code of what i should do on the backend

#

cant i just pull the signature from the body instead?

clear bough
#

I suspect ngrok is the issue here

#

It's probably blocking any of the non-standard HTTP headers (i.e. Stripe-Signature)

unreal thorn
#

get same error when i try a different url

#

if i go right to the api instead of ngrok