2020-11-24 13:26:15 +01:00
|
|
|
/**
|
|
|
|
* This component initializes the stripe's Elements tag with the API key
|
|
|
|
*/
|
|
|
|
|
2020-12-08 12:26:03 +01:00
|
|
|
import React, { memo } from 'react';
|
2020-11-24 13:26:15 +01:00
|
|
|
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
|
|
|
|
2020-12-08 12:26:03 +01:00
|
|
|
export const StripeElements: React.FC = memo(({ children }) => {
|
2020-11-24 13:26:15 +01:00
|
|
|
const publicKey = stripePublicKey.read();
|
|
|
|
const stripePromise = loadStripe(publicKey.value);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Elements stripe={stripePromise}>
|
|
|
|
{children}
|
|
|
|
</Elements>
|
|
|
|
);
|
2020-12-08 12:26:03 +01:00
|
|
|
})
|