1 import { type Currency } from '@proton/payments';
3 export interface CountryEntry {
9 export interface CountryListSeparator {
16 export type Country = CountryEntry | CountryListSeparator;
18 export interface ChargebeeInstanceConfiguration {
19 publishableKey: string;
24 export type CardFormRenderMode = 'one-line' | 'two-line';
26 export type CssVariables = {
27 '--signal-danger': string;
28 '--border-radius-md': string;
29 '--border-norm': string;
30 '--focus-outline': string;
31 '--focus-ring': string;
32 '--field-norm': string;
33 '--field-background-color': string;
34 '--field-focus-background-color': string;
35 '--field-focus-text-color': string;
36 '--field-placeholder-color': string;
37 '--field-text-color': string;
38 '--selection-text-color': string;
39 '--selection-background-color': string;
42 export type Translations = {
43 cardNumberPlaceholder: string;
44 cardExpiryPlaceholder: string;
45 cardCvcPlaceholder: string;
46 invalidCardNumberMessage: string;
47 invalidCardExpiryMessage: string;
48 invalidCardCvcMessage: string;
51 export type CbCardConfig = {
52 paymentMethodType: 'card';
53 renderMode: CardFormRenderMode;
54 cssVariables: CssVariables;
55 translations: Translations;
56 } & ChargebeeInstanceConfiguration;
58 export type ChargebeeCssVariable = keyof CssVariables;
59 export const chargebeeCssVariables: ChargebeeCssVariable[] = [
66 '--field-background-color',
67 '--field-focus-background-color',
68 '--field-focus-text-color',
69 '--field-placeholder-color',
71 '--selection-text-color',
72 '--selection-background-color',
75 export type CbPaypalConfig = {
76 paymentMethodType: 'paypal';
77 } & ChargebeeInstanceConfiguration;
79 export type CbSavedCardConfig = {
80 paymentMethodType: 'saved-card';
81 } & ChargebeeInstanceConfiguration;
83 export type CbDirectDebitConfig = {
84 paymentMethodType: 'direct-debit';
85 } & ChargebeeInstanceConfiguration;
87 export type CbIframeConfig = CbCardConfig | CbPaypalConfig | CbSavedCardConfig | CbDirectDebitConfig;
89 export type PaymentIntent = {
91 status: 'inited' | 'authorized';
93 currency_code: Currency;
94 gateway_account_id: string;
99 resource_version: number;
100 object: 'payment_intent';
103 payment_method_type: 'card' | 'paypal';
104 // Present only for saved payment methods
105 reference_id?: string;
108 export interface AuthorizedPaymentIntent extends PaymentIntent {
109 status: 'authorized';
110 active_payment_attempt: {
112 status: 'authorized';
113 payment_method_type: 'card' | 'paypal';
114 id_at_gateway: string;
117 object: 'payment_attempt';
121 export interface ChargebeeSubmitEventPayload {
122 paymentIntent: PaymentIntent;
127 export interface BinData {
132 export function isBinData(obj: any): obj is BinData {
135 typeof obj.bin === 'string' &&
136 obj.bin.length === 6 &&
137 typeof obj.last4 === 'string' &&
138 obj.last4.length === 4
142 export type ChargebeeSubmitEventResponse = {
144 authorizedPaymentIntent: AuthorizedPaymentIntent;
147 export interface SetPaypalPaymentIntentPayload {
148 paymentIntent: PaymentIntent;
151 export const paypalAuthorizedMessageType = 'paypal-authorized';
152 export type PaypalAuthorizedPayload = {
153 paymentIntent: AuthorizedPaymentIntent;
155 export type PaypalAuthorizedMessage = {
156 type: typeof paypalAuthorizedMessageType;
157 } & MessageBusResponseSuccess<PaypalAuthorizedPayload>;
159 export function isPaypalAuthorizedMessage(obj: any): obj is PaypalAuthorizedMessage {
160 return obj && obj.type === paypalAuthorizedMessageType;
163 export type MessageBusResponseSuccess<T> = {
168 export type MessageBusResponseFailure = {
173 export function isMessageBusResponseFailure(obj: any): obj is MessageBusResponseFailure {
174 return !!obj && obj.status === 'failure' && !!obj.error;
177 export type MessageBusResponse<T> = MessageBusResponseSuccess<T> | MessageBusResponseFailure;
179 export type CbIframeResponseStatus = 'success' | 'failure';
181 export type GetHeightResponsePayload = {
185 export type GetHeightResponse = MessageBusResponse<GetHeightResponsePayload>;
187 export const threeDsChallengeMessageType = '3ds-challenge';
188 export type ThreeDsChallengePayload = {
192 export type ThreeDsChallengeMessage = MessageBusResponseSuccess<ThreeDsChallengePayload> & {
193 type: typeof threeDsChallengeMessageType;
196 export function isThreeDsChallengeMessage(obj: any): obj is ThreeDsChallengeMessage {
197 return obj && obj.type === threeDsChallengeMessageType;
200 export type FormValidationError = {
205 export type FormValidationErrors = FormValidationError[] | null;
207 export interface ChargebeeVerifySavedCardEventPayload {
208 paymentIntent: PaymentIntent;
211 export const threeDsMessageType = 'chargebee-submit-response';
213 export type ThreeDsFailedMessage = MessageBusResponseFailure & {
214 type: typeof threeDsMessageType;
217 export function isThreeDsFailedMessage(obj: any): obj is ThreeDsFailedMessage {
218 return obj && obj.type === threeDsMessageType && obj.status === 'failure';
221 export type ThreeDsSuccessMessage = MessageBusResponseSuccess<PaymentIntent> & {
222 type: typeof threeDsMessageType;
225 export function isThreeDsSuccessMessage(obj: any): obj is ThreeDsSuccessMessage {
226 return obj && obj.type === threeDsMessageType && obj.status === 'success';
229 export type ChargebeeSavedCardAuthorizationSuccess = {
231 authorizedPaymentIntent: AuthorizedPaymentIntent;
234 export type ChargebeeSavedCardAuthorizationFailure = {
239 export type ThreeDsRequiredForSavedCardMessage = MessageBusResponseSuccess<ThreeDsChallengePayload> & {
240 type: typeof threeDsChallengeMessageType;
243 export type SavedCardVerificationSuccessMessage = MessageBusResponseSuccess<ChargebeeSavedCardAuthorizationSuccess> & {
244 type: 'chargebee-verify-saved-card-response';
247 export type SavedCardVerificationFailureMessage = MessageBusResponseFailure & {
248 type: 'chargebee-verify-saved-card-response';
251 export function isSavedCardVerificationSuccessMessage(obj: any): obj is SavedCardVerificationSuccessMessage {
252 return obj && obj.type === 'chargebee-verify-saved-card-response' && obj.status === 'success';
255 export function isSavedCardVerificationFailureMessage(obj: any): obj is SavedCardVerificationFailureMessage {
256 return obj && obj.type === 'chargebee-verify-saved-card-response' && obj.status === 'failure';
259 export const paypalFailedMessageType = 'paypal-failed';
260 export type PaypalFailedMessage = MessageBusResponseFailure & {
261 type: typeof paypalFailedMessageType;
263 export function isPaypalFailedMessage(obj: any): obj is PaypalFailedMessage {
264 return obj && obj.type === paypalFailedMessageType;
267 export const paypalClickedMessageType = 'paypal-clicked';
268 export type PaypalClickedMessage = MessageBusResponseSuccess<{}> & {
269 type: typeof paypalClickedMessageType;
271 export function isPaypalClickedMessage(obj: any): obj is PaypalClickedMessage {
272 return obj && obj.type === paypalClickedMessageType;
275 export const paypalCancelledMessageType = 'paypal-cancelled';
276 export type PaypalCancelledMessage = MessageBusResponseSuccess<{}> & {
277 type: typeof paypalCancelledMessageType;
279 export function isPaypalCancelledMessage(obj: any): obj is PaypalCancelledMessage {
280 return obj && obj.type === paypalCancelledMessageType;
283 export const unhandledError = 'chargebee-unhandled-error';
284 export type UnhandledErrorMessage = MessageBusResponseFailure & {
285 type: typeof unhandledError;
287 export function isUnhandledErrorMessage(obj: any): obj is UnhandledErrorMessage {
288 return obj && obj.type === unhandledError;
291 // see https://apidocs.chargebee.com/docs/api/error-handling
292 export const chargebeeValidationErrorName = 'param_wrong_value';
294 export const paymentAttemptRefusedChargebeeErrorName = 'PAYMENT_ATTEMPT_REFUSED';
296 export type UpdateFieldsPayload = {
297 cssVariables: CssVariables;
300 export type DirectDebitCustomerNameType = 'company' | 'individual';
301 export interface DirectDebitCustomer {
306 customerNameType: DirectDebitCustomerNameType;
308 addressLine1: string;
311 export interface DirectDebitBankAccount {
315 export interface ChargebeeSubmitDirectDebitEventPayload {
316 paymentIntent: PaymentIntent;
317 customer: DirectDebitCustomer;
318 bankAccount: DirectDebitBankAccount;