$ stripe apps start [18:17:37] compiled successfully 💻 Running development server on http://localhost:4242 (^C to quit) ✨ You can now preview Helloworld 1 in your Stripe account. 🌐 Press Enter to open the Stripe dashboard • デフォルトでは、顧客詳細ページのみ • 初回起動時は確認画面が表示される
◦ URLと用途を登録 • ワイルドカード(*)はサブドメインのみ • 動的なパスを持つ場合、 「https://example.com/api/」のように 「/」で終わる形で登録する • 実装詳細: https://stripe.com/docs/stripe-apps/buil d-ui#use-third-party-apis 22 JP_Stripes in サッポロ Vol.7 Stripe再入門 & アプリ開発入門 22 $ stripe apps grant url ✔ Enter a connect-src URL (to call a third-party API from your app): https://e Enter a connect-src URL (to call a third-party API from your app): https://example.com/api ✔ Enter a purpose for the grant: Processing subscription event in our SaaS ser Enter a purpose for the grant: Processing subscription event in our SaaS server ✔ Granted url https://example.com/api
stripe = require('stripe')(process.env.STRIPE_API_KEY); // Find your app's secret in your app settings page in the Developers Dashboard. const appSecret = 'absec_...'; app.post('/do_secret_stuff', (request, response) => { 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); } catch (error) { response.status(400).send(error.message); } import fetchStripeSignature from '@stripe/ui-extension-sdk/signature'; const App = ({ userContext, environment }) => { const makeRequestToMyBackend = async (endpoint, requestData) => { // By default the signature is signed with user id and account id. const signaturePayload = { user_id: userContext?.id, account_id: userContext?.account.id, }; return fetch(`https://example.com/${endpoint}/`, { method: 'POST', headers: { 'Stripe-Signature': await fetchStripeSignature(), 'Content-Type': 'application/json', }, body: JSON.stringify({ ...requestData, ...signaturePayload, }), }); }; ... }