import { Elements, StripeProvider, injectStripe } from 'react-stripe-elements'; import { Component } from 'react'; import FormHeader from '../components/FormHeader'; import FormSubmit from '../components/FormSubmit'; import FormHeaderCTA from '../components/FormHeaderCTA'; import { IconClose } from '../components/icons'; import NameInput from '../components/NameInput'; import EmailInput from '../components/EmailInput'; import PasswordInput from '../components/PasswordInput'; import CheckoutForm from '../components/CheckoutForm'; import Form from '../components/Form'; class PaymentForm extends Component { constructor(props) { super(props); } handleSubmit = ({ name, email, password, plan }) => { // Within the context of `Elements`, this call to createToken knows which Element to // tokenize, since there's only one in this group. plan = this.props.selectedPlan ? this.props.selectedPlan.name : ""; this.props.stripe.createToken({ name: name }).then(({ token }) => { this.props.handleSubmit({ adapter: 'stripe', plan: plan, stripeToken: token.id, name, email, password }); }); }; render({frameLocation}) { return (
); } } const PaymentFormWrapped = injectStripe(PaymentForm); export default class StripeSubscriptionPage extends Component { constructor(props) { super(props); this.plans = props.stripeConfig.config.plans || []; this.state = { selectedPlan: this.plans[0] ? this.plans[0] : "" } } renderPlan({ currency, amount, id, interval, name }) { const selectedPlanId = this.state.selectedPlan ? this.state.selectedPlan.id : ""; const dollarAmount = (amount / 100); return ( ) } changePlan(e) { const plan = this.plans.find(plan => plan.id === e.target.value); this.setState({ selectedPlan: plan }) } renderPlans(plans) { return (