// @flow /* eslint-disable no-console, react/no-multi-comp */ import React from 'react'; import type {InjectedProps} from '../../src/components/inject'; import { CardElement, StripeProvider, Elements, injectStripe, } from '../../src/index'; const handleBlur = () => { console.log('[blur]'); }; const handleChange = (change) => { console.log('[change]', change); }; const handleFocus = () => { console.log('[focus]'); }; const handleReady = () => { console.log('[ready]'); }; const CARD_ELEMENT_OPTIONS = { style: { base: { fontSize: '18px', color: '#424770', letterSpacing: '0.025em', '::placeholder': { color: '#aab7c4', }, }, invalid: { color: '#9e2146', }, }, }; class _CardForm extends React.Component { handleSubmit = (ev) => { ev.preventDefault(); if (this.props.stripe) { this.props.stripe .createToken() .then((payload) => console.log('[token]', payload)); } else { console.log('Form submitted before Stripe.js loaded.'); } }; render() { return (
{this.props.stripe ? ( ) : (
)} ); } } const CardForm = injectStripe(_CardForm); const Checkout = () => { return (
); }; export class App extends React.Component<{}, {stripe: null | StripeShape}> { constructor() { super(); this.state = { stripe: null, }; } componentDidMount() { // componentDidMount only runs in a browser environment. // In addition to loading asynchronously, this code is safe to server-side render. // You can inject a script tag manually like this, // or you can use the 'async' attribute on the Stripe.js v3