From a346297aa510db82e922945a2f8b3b2d9b80006e Mon Sep 17 00:00:00 2001 From: Kimmo Puputti Date: Wed, 29 Mar 2017 15:59:49 +0300 Subject: [PATCH] Load and setup Stripe library --- public/index.html | 5 ++++- src/config.js | 11 ++++++++++- src/index.js | 10 ++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/public/index.html b/public/index.html index 78f1dee8..958196ba 100644 --- a/public/index.html +++ b/public/index.html @@ -5,10 +5,13 @@ -
+ + + diff --git a/src/config.js b/src/config.js index 58197a06..4aea189a 100644 --- a/src/config.js +++ b/src/config.js @@ -22,8 +22,17 @@ const currencyConfig = { subUnitDivisor: 100, }; +const stripePublishableKey = process.env.REACT_APP_STRIPE_PUBLISHABLE_KEY || + 'pk_test_FWtdKPZvtrj37t45dIomssBI'; + // NOTE: only expose configuration that should be visible in the // client side, don't add any server secrets in this file. -const config = { env, dev, sdk: { clientId: sdkClientId, baseUrl: sdkBaseUrl }, currencyConfig }; +const config = { + env, + dev, + sdk: { clientId: sdkClientId, baseUrl: sdkBaseUrl }, + currencyConfig, + stripe: { publishableKey: stripePublishableKey }, +}; export default config; diff --git a/src/index.js b/src/index.js index 902aa2d4..03d9a25b 100644 --- a/src/index.js +++ b/src/index.js @@ -50,6 +50,14 @@ const renderWhenAuthInfoLoaded = store => { store.dispatch(authInfo()); }; +const setupStripe = () => { + if (typeof window.Stripe === 'undefined') { + throw new Error('Stripe library not loaded'); + } + // https://stripe.com/docs/stripe.js#setting-publishable-key + window.Stripe.setPublishableKey(config.stripe.publishableKey); +}; + // If we're in a browser already, render the client application. if (typeof window !== 'undefined') { // eslint-disable-next-line no-underscore-dangle @@ -60,6 +68,8 @@ if (typeof window !== 'undefined') { store.runSaga(createRootSaga(sdk)); + setupStripe(); + const authInfoLoaded = store.getState().Auth.authInfoLoaded; // If the server already loaded the auth information, render the app