Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/billing/confirm-payment-method.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Alert, Well } from "@cocalc/frontend/antd-bootstrap";6import { Component, Rendered } from "../app-framework";7import { Gap } from "../components/gap";8import { Icon } from "../components/icon";910import { Customer, Source } from "./types";11import { AddPaymentMethod } from "./add-payment-method";12import { PaymentMethod } from "./payment-method";1314interface Props {15customer?: Customer;16is_recurring: boolean;17on_close: Function;18}1920export class ConfirmPaymentMethod extends Component<Props> {21private render_single_payment_confirmation(): Rendered {22if (this.props.is_recurring) return;23return (24<span>25<p>Payment will be processed with the card below.</p>26<p>To change payment methods, please change your default card above.</p>27</span>28);29}3031private render_recurring_payment_confirmation(): Rendered {32if (!this.props.is_recurring) return;33return (34<span>35<p>36The initial payment will be processed with the card below. Future37payments will be made with whichever card you have set as your default38<Gap />39<b>at the time of renewal</b>.40</p>41</span>42);43}4445private default_card(): Source | undefined {46if (47this.props.customer == null ||48this.props.customer.sources.data.length == 049) {50// no card51return;52}5354for (const card_data of this.props.customer.sources.data) {55if (card_data.id === this.props.customer.default_source) {56return card_data;57}58}59// Should not happen (there should always be a default), but60// it did: https://github.com/sagemathinc/cocalc/issues/346861// We try again with whatever the first card is.62for (const card_data of this.props.customer.sources.data) {63return card_data;64}65// Still no card? This should also never happen since we66// checked the length above. Returns undefined which asks for card.67}6869public render(): Rendered {70const default_card: Source | undefined = this.default_card();71if (default_card == null) {72return <AddPaymentMethod hide_cancel_button={true} />;73}74return (75<Alert>76<h4>77<Icon name="check" /> Confirm your payment card78</h4>79{this.render_single_payment_confirmation()}80{this.render_recurring_payment_confirmation()}81<Well>82<PaymentMethod source={default_card} />83</Well>84</Alert>85);86}87}888990