mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 20:53:24 +10:00
Load and setup Stripe library
This commit is contained in:
parent
9a320bd7a6
commit
a346297aa5
3 changed files with 24 additions and 2 deletions
|
|
@ -5,10 +5,13 @@
|
|||
<!--!title-->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
<!--!preloadedStateScript-->
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"><!--!body--></div>
|
||||
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAIhL8ykNE8WcPihRdpkL33TXng-0SYDr0&libraries=places"></script>
|
||||
<!-- Stripe script should be on every page, not just the pages that use the API:
|
||||
https://stripe.com/docs/stripe.js#including-stripejs -->
|
||||
<script src="https://js.stripe.com/v2/"></script>
|
||||
<!--!preloadedStateScript-->
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
10
src/index.js
10
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue