2020-11-24 13:26:15 +01:00
|
|
|
/**
|
|
|
|
* This component initializes the stripe's Elements tag with the API key
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { Elements } from '@stripe/react-stripe-js';
|
|
|
|
import { loadStripe } from "@stripe/stripe-js";
|
2020-11-24 16:26:18 +01:00
|
|
|
import SettingAPI from '../api/setting';
|
|
|
|
import { SettingName } from '../models/setting';
|
2020-11-24 13:26:15 +01:00
|
|
|
|
2020-11-24 16:26:18 +01:00
|
|
|
const stripePublicKey = SettingAPI.get(SettingName.StripePublicKey);
|
2020-11-24 13:26:15 +01:00
|
|
|
|
|
|
|
export const StripeElements: React.FC = ({ children }) => {
|
|
|
|
const publicKey = stripePublicKey.read();
|
|
|
|
const stripePromise = loadStripe(publicKey.value);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Elements stripe={stripePromise}>
|
|
|
|
{children}
|
|
|
|
</Elements>
|
|
|
|
);
|
|
|
|
}
|