diff --git a/core/server/lib/members/static/auth/pages/StripeSubscribePage.js b/core/server/lib/members/static/auth/pages/StripeSubscribePage.js index 7099a2fa96..4bc186dd79 100644 --- a/core/server/lib/members/static/auth/pages/StripeSubscribePage.js +++ b/core/server/lib/members/static/auth/pages/StripeSubscribePage.js @@ -5,10 +5,16 @@ import FormSubmit from '../components/FormSubmit'; import FormHeaderCTA from '../components/FormHeaderCTA'; import NameInput from '../components/NameInput'; import EmailInput from '../components/EmailInput'; +import CouponInput from '../components/CouponInput'; import PasswordInput from '../components/PasswordInput'; import CheckoutForm from '../components/CheckoutForm'; import Form from '../components/Form'; +const getCouponData = frameLocation => { + const params = new URLSearchParams(frameLocation.query); + const coupon = params.get('coupon') || ''; + return { coupon }; +}; class PaymentForm extends Component { @@ -16,7 +22,7 @@ class PaymentForm extends Component { super(props); } - handleSubmit = ({ name, email, password, plan }) => { + handleSubmit = ({ name, email, password, plan, coupon }) => { // 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 : ""; @@ -25,7 +31,7 @@ class PaymentForm extends Component { adapter: 'stripe', plan: plan, stripeToken: token.id, - name, email, password + name, email, password, coupon }); }); }; @@ -34,17 +40,19 @@ class PaymentForm extends Component { this.props.stripe.createToken({ name: name }); } - render() { + render({frameLocation}) { let label = this.props.showSpinner ? ( ( Signing up... - ) + ) ) : "Confirm payment"; + const { coupon } = getCouponData(frameLocation); return ( -
@@ -109,7 +117,7 @@ export default class StripePaymentPage extends Component { ) } - render({ error, handleSubmit, stripeConfig, siteConfig, showSpinner }) { + render({ error, handleSubmit, stripeConfig, siteConfig, showSpinner, frameLocation }) { const publicKey = stripeConfig.config.publicKey || ''; let iconUrl = siteConfig && siteConfig.icon; let title = (siteConfig && siteConfig.title) || "Ghost Publication"; @@ -124,7 +132,7 @@ export default class StripePaymentPage extends Component {