CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/billing/confirm-payment-method.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Alert, Well } from "@cocalc/frontend/antd-bootstrap";
7
import { Component, Rendered } from "../app-framework";
8
import { Gap } from "../components/gap";
9
import { Icon } from "../components/icon";
10
11
import { Customer, Source } from "./types";
12
import { AddPaymentMethod } from "./add-payment-method";
13
import { PaymentMethod } from "./payment-method";
14
15
interface Props {
16
customer?: Customer;
17
is_recurring: boolean;
18
on_close: Function;
19
}
20
21
export class ConfirmPaymentMethod extends Component<Props> {
22
private render_single_payment_confirmation(): Rendered {
23
if (this.props.is_recurring) return;
24
return (
25
<span>
26
<p>Payment will be processed with the card below.</p>
27
<p>To change payment methods, please change your default card above.</p>
28
</span>
29
);
30
}
31
32
private render_recurring_payment_confirmation(): Rendered {
33
if (!this.props.is_recurring) return;
34
return (
35
<span>
36
<p>
37
The initial payment will be processed with the card below. Future
38
payments will be made with whichever card you have set as your default
39
<Gap />
40
<b>at the time of renewal</b>.
41
</p>
42
</span>
43
);
44
}
45
46
private default_card(): Source | undefined {
47
if (
48
this.props.customer == null ||
49
this.props.customer.sources.data.length == 0
50
) {
51
// no card
52
return;
53
}
54
55
for (const card_data of this.props.customer.sources.data) {
56
if (card_data.id === this.props.customer.default_source) {
57
return card_data;
58
}
59
}
60
// Should not happen (there should always be a default), but
61
// it did: https://github.com/sagemathinc/cocalc/issues/3468
62
// We try again with whatever the first card is.
63
for (const card_data of this.props.customer.sources.data) {
64
return card_data;
65
}
66
// Still no card? This should also never happen since we
67
// checked the length above. Returns undefined which asks for card.
68
}
69
70
public render(): Rendered {
71
const default_card: Source | undefined = this.default_card();
72
if (default_card == null) {
73
return <AddPaymentMethod hide_cancel_button={true} />;
74
}
75
return (
76
<Alert>
77
<h4>
78
<Icon name="check" /> Confirm your payment card
79
</h4>
80
{this.render_single_payment_confirmation()}
81
{this.render_recurring_payment_confirmation()}
82
<Well>
83
<PaymentMethod source={default_card} />
84
</Well>
85
</Alert>
86
);
87
}
88
}
89
90