tonder-web-sdk 1.12.0-beta.1 → 1.12.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,118 @@
1
+ import {ICustomer} from "./customer";
2
+
3
+ export interface IStartCheckoutRequestBase {
4
+ name: any;
5
+ last_name: string;
6
+ email_client: any;
7
+ phone_number: any;
8
+ return_url?: string;
9
+ id_product: string;
10
+ quantity_product: number;
11
+ id_ship: string;
12
+ instance_id_ship: string;
13
+ amount: any;
14
+ title_ship: string;
15
+ description: string;
16
+ device_session_id: any;
17
+ token_id: string;
18
+ order_id: any;
19
+ business_id: any;
20
+ payment_id: any;
21
+ source: string;
22
+ browser_info?: any;
23
+ metadata: any;
24
+ currency: string;
25
+ }
26
+
27
+ export type IStartCheckoutRequestWithCard = IStartCheckoutRequestBase & {
28
+ card: any;
29
+ payment_method?: never;
30
+ };
31
+
32
+ export type IStartCheckoutRequestWithPaymentMethod =
33
+ IStartCheckoutRequestBase & {
34
+ card?: never;
35
+ payment_method: string;
36
+ };
37
+
38
+ export type IStartCheckoutRequest =
39
+ | IStartCheckoutRequestWithCard
40
+ | IStartCheckoutRequestWithPaymentMethod;
41
+
42
+ export interface IStartCheckoutIdRequest {
43
+ checkout_id: string;
44
+ }
45
+
46
+ export interface IStartCheckoutErrorResponse {
47
+ status: string;
48
+ message: string;
49
+ psp_response: [
50
+ {
51
+ status: number;
52
+ response: Object;
53
+ },
54
+ ];
55
+ checkout_id: string;
56
+ is_route_finished: boolean;
57
+ }
58
+
59
+ export interface IStartCheckoutResponse {
60
+ status: string;
61
+ message: string;
62
+ psp_response: Record<string, any>;
63
+ checkout_id: string;
64
+ is_route_finished: Boolean;
65
+ transaction_status: string;
66
+ transaction_id: number;
67
+ payment_id: number;
68
+ provider: string;
69
+ next_action: {
70
+ redirect_to_url: {
71
+ url: string;
72
+ return_url: string;
73
+ verify_transaction_status_url: string;
74
+ };
75
+ iframe_resources?: {
76
+ iframe: string;
77
+ };
78
+ };
79
+ actions: IStartCheckoutActionResponse[];
80
+ }
81
+
82
+ export interface IStartCheckoutActionResponse {
83
+ name: string;
84
+ url: string;
85
+ method: string;
86
+ }
87
+
88
+
89
+ export interface IItem {
90
+ description: string;
91
+ quantity: number;
92
+ price_unit: number;
93
+ discount: number;
94
+ taxes: number;
95
+ product_reference: number;
96
+ name: string;
97
+ amount_total: number;
98
+ }
99
+
100
+ export interface IProcessPaymentRequest {
101
+ customer: ICustomer;
102
+ cart: {
103
+ total: string | number;
104
+ items: IItem[];
105
+ };
106
+ metadata?: Record<string, any>;
107
+ currency?: string;
108
+ payment_method?: string;
109
+ card?: ICardFields | string;
110
+ }
111
+
112
+ export interface ICardFields {
113
+ card_number: string;
114
+ cvv: string;
115
+ expiration_month: string;
116
+ expiration_year: string;
117
+ cardholder_name: string;
118
+ }
@@ -0,0 +1,26 @@
1
+ import { ICustomer } from "./customer";
2
+
3
+ export interface IInlineCheckoutBaseOptions {
4
+ mode?: "production" | "sandbox" | "stage" | "development";
5
+ apiKey: string;
6
+ returnUrl: string;
7
+ callBack?: (response: any) => void;
8
+ }
9
+
10
+ export interface IConfigureCheckout {
11
+ customer: ICustomer;
12
+ }
13
+
14
+ export interface IApiError {
15
+ code: string;
16
+ body: Record<string, string> | string;
17
+ name: string;
18
+ message: string;
19
+ }
20
+
21
+ export interface IPublicError {
22
+ status: string;
23
+ code: number;
24
+ message: string;
25
+ detail: Record<string, any> | string;
26
+ }
@@ -0,0 +1,11 @@
1
+ export type ICustomer = {
2
+ firstName: string;
3
+ lastName: string;
4
+ country?: string;
5
+ street?: string;
6
+ city?: string;
7
+ state?: string;
8
+ postCode?: string;
9
+ email: string;
10
+ phone?: string;
11
+ };
package/types/index.d.ts CHANGED
@@ -1,79 +1,11 @@
1
- export class InlineCheckout {
2
- constructor(options: InlineCheckoutOptions);
3
- configureCheckout(data: { customer?: Customer }): Promise<void>;
4
- injectCheckout(): Promise<void>;
5
- payment(): Promise<void>;
6
- verify3dsTransaction(): Promise<void>;
7
- }
1
+ export * from './card';
2
+ export * from './checkout';
3
+ export * from './common';
4
+ export * from './customer';
5
+ export * from './transaction';
6
+ export * from './paymentMethod';
7
+ export * from './inlineCheckout';
8
+ export * from './liteInlineCheckout';
8
9
 
9
10
 
10
- export class LiteInlineCheckout {
11
- constructor(options: InlineLiteCheckoutOptions);
12
- configureCheckout(data: { customer?: Customer }): void;
13
- injectCheckout(): Promise<void>;
14
- payment(): Promise<void>;
15
- verify3dsTransaction(): Promise<void>;
16
- getCustomerCards(authToken: string, businessId: string | number): Promise<CustomerCards>;
17
-
18
- /**
19
- * Saves a card to a customer's account. This method can be used to add a new card
20
- * or update an existing one.
21
- * @param {string} authToken - The customer's authentication token.
22
- * @param {string} businessId - The business primary key.
23
- * @param {Object} card - The card information to be saved.
24
- * @returns {Promise<Object>} A promise that resolves with the saved card data.
25
- * @public
26
- */
27
- saveCustomerCard(authToken: string, businessId: string, card: { card_number: string; cvv: string; expiration_month: string; expiration_year: string; cardholder_name: string; }): Promise<void>;
28
- removeCustomerCard(authToken: string, skyflowId: string, businessId: string): Promise<void>;
29
- getCustomerAPMs(): Promise<void>;
30
- }
31
11
 
32
-
33
- export interface InlineCheckoutOptions {
34
- mode?: string;
35
- apiKey: string;
36
- returnUrl: string;
37
- renderPaymentButton?: boolean;
38
- callBack?: (response: any) => void;
39
- styles?: Record<string, string>;
40
- }
41
-
42
- export interface InlineLiteCheckoutOptions {
43
- mode?: string;
44
- apiKey: string;
45
- returnUrl: string;
46
- renderPaymentButton?: boolean;
47
- callBack?: (response: any) => void;
48
- }
49
-
50
-
51
- export type Customer = {
52
- firstName: string;
53
- lastName: string;
54
- country: string;
55
- street: string;
56
- city: string;
57
- state: string;
58
- postCode: string;
59
- email: string;
60
- phone: string;
61
- };
62
-
63
-
64
- interface CardFields {
65
- card_number: string;
66
- expiration_month: string;
67
- expiration_year: string;
68
- skyflow_id: string;
69
- card_scheme: string;
70
- }
71
-
72
- interface Card {
73
- fields: CardFields;
74
- }
75
-
76
- interface CustomerCards {
77
- user_id: number;
78
- cards: Card[];
79
- }
@@ -0,0 +1,65 @@
1
+ import {IConfigureCheckout, IInlineCheckoutBaseOptions} from "./common";
2
+ import {IProcessPaymentRequest, IStartCheckoutResponse} from "./checkout";
3
+ import {ITransaction} from "./transaction";
4
+
5
+ export class InlineCheckout {
6
+ constructor(options: IInlineCheckoutOptions);
7
+
8
+ /**
9
+ * The configureCheckout function allows you to set initial information, such as the customer's email, which is used to retrieve a list of saved cards.
10
+ * @param {import("../../types").IConfigureCheckout} data - Configuration data including customer information and potentially other settings.
11
+ * @returns {Promise<void>}.
12
+ * @public
13
+ */
14
+ configureCheckout(data: IConfigureCheckout): Promise<void>;
15
+
16
+ /**
17
+ * Injects the checkout into the DOM and initializes it.
18
+ * Checks for an existing container and sets up an observer if needed.
19
+ * @returns {void}
20
+ * @public
21
+ */
22
+ injectCheckout(): Promise<void>;
23
+
24
+ /**
25
+ * Processes a payment.
26
+ * @param {import("../../types").IProcessPaymentRequest} data - Payment data including customer, cart, and other relevant information.
27
+ * @returns {Promise<import("../../types").IStartCheckoutResponse>} A promise that resolves with the payment response or 3DS redirect or is rejected with an error.
28
+ *
29
+ * @throws {Error} Throws an error if the checkout process fails. The error object contains
30
+ * additional `details` property with the response from the server if available.
31
+ * @property {import("../../types").IStartCheckoutErrorResponse} error.details - The response body from the server when an error occurs.
32
+ *
33
+ * @public
34
+ */
35
+ payment(data: IProcessPaymentRequest): Promise<IStartCheckoutResponse>;
36
+
37
+ /**
38
+ * Verifies the 3DS transaction status.
39
+ * @returns {Promise<import("../../types").ITransaction | void>} The result of the 3DS verification and checkout resumption.
40
+ * @public
41
+ */
42
+ verify3dsTransaction(): Promise<ITransaction | void>;
43
+
44
+ /**
45
+ * Removes the checkout from the DOM and cleans up associated resources.
46
+ *
47
+ * This method performs the following actions:
48
+ * 1. Resets the injection status flags for the checkout, cards, and APMs.
49
+ * 2. Aborts any ongoing requests using the AbortController.
50
+ * 3. Creates a new AbortController for future use.
51
+ * 4. Clears any existing injection intervals.
52
+ *
53
+ * Note: This method should be called when you want to completely remove
54
+ * the checkout from the page and reset its state.
55
+ *
56
+ * @returns {void}
57
+ * @public
58
+ */
59
+ removeCheckout(): void;
60
+ }
61
+
62
+ export interface IInlineCheckoutOptions extends IInlineCheckoutBaseOptions{
63
+ styles?: Record<string, string>;
64
+ renderPaymentButton?: boolean;
65
+ }
@@ -0,0 +1,96 @@
1
+ import {IConfigureCheckout, IInlineCheckoutBaseOptions} from "./common";
2
+ import {ICustomerCardsResponse, ISaveCardRequest, ISaveCardResponse} from "./card";
3
+ import {IPaymentMethod} from "./paymentMethod";
4
+ import {IProcessPaymentRequest, IStartCheckoutResponse} from "./checkout";
5
+ import {ITransaction} from "./transaction";
6
+
7
+ export class LiteInlineCheckout {
8
+ constructor(options: IInlineLiteCheckoutOptions);
9
+
10
+ /**
11
+ * The configureCheckout function allows you to set initial information, such as the customer's email, which is used to retrieve a list of saved cards.
12
+ * @param {import("../../types").IConfigureCheckout} data - Configuration data including customer information and potentially other settings.
13
+ * @returns {Promise<void>}.
14
+ * @public
15
+ */
16
+ configureCheckout(data: IConfigureCheckout): void;
17
+
18
+ /**
19
+ * Initializes and prepares the checkout for use.
20
+ * This method set up the initial environment.
21
+ * @returns {Promise<void>} A promise that resolves when the checkout has been initialized.
22
+ * @throws {Error} If there's any problem during the checkout initialization.
23
+ * @public
24
+ */
25
+ injectCheckout(): Promise<void>;
26
+
27
+ /**
28
+ * Processes a payment.
29
+ * @param {import("../../types").IProcessPaymentRequest} data - Payment data including customer, cart, and other relevant information.
30
+ * @returns {Promise<import("../../types").IStartCheckoutResponse>} A promise that resolves with the payment response or 3DS redirect or is rejected with an error.
31
+ *
32
+ * @throws {Error} Throws an error if the checkout process fails. The error object contains
33
+ * additional `details` property with the response from the server if available.
34
+ * @property {import("../../types").IStartCheckoutErrorResponse} error.details - The response body from the server when an error occurs.
35
+ *
36
+ * @public
37
+ */
38
+ payment(data: IProcessPaymentRequest): Promise<IStartCheckoutResponse>;
39
+
40
+ /**
41
+ * Verifies the 3DS transaction status.
42
+ * @returns {Promise<import("../../types").ITransaction | void>} The result of the 3DS verification and checkout resumption.
43
+ * @public
44
+ */
45
+ verify3dsTransaction(): Promise<ITransaction | void>;
46
+
47
+ /**
48
+ * Retrieves the list of cards associated with a customer.
49
+ * @returns {Promise<import("../../types").ICustomerCardsResponse>} A promise that resolves with the customer's card data.
50
+ *
51
+ * @throws {import("../../types").IPublicError} Throws an error object if the operation fails.
52
+ *
53
+ * @public
54
+ */
55
+ getCustomerCards(): Promise<ICustomerCardsResponse>;
56
+
57
+ /**
58
+ * Saves a card to a customer's account. This method can be used to add a new card
59
+ * or update an existing one.
60
+ * @param {import("../../types").ISaveCardRequest} card - The card information to be saved.
61
+ * @returns {Promise<import("../../types").ISaveCardResponse>} A promise that resolves with the saved card data.
62
+ *
63
+ * @throws {import("../../types").IPublicError} Throws an error object if the operation fails.
64
+ *
65
+ * @public
66
+ */
67
+ saveCustomerCard(
68
+ card: ISaveCardRequest,
69
+ ): Promise<ISaveCardResponse>;
70
+
71
+ /**
72
+ * Removes a card from a customer's account.
73
+ * @param {string} skyflowId - The unique identifier of the card to be deleted.
74
+ * @returns {Promise<string>} A promise that resolves when the card is successfully deleted.
75
+ *
76
+ * @throws {import("../../types").IPublicError} Throws an error object if the operation fails.
77
+ *
78
+ * @public
79
+ */
80
+ removeCustomerCard(
81
+ skyflowId: string,
82
+ ): Promise<void>;
83
+
84
+ /**
85
+ * Retrieves the list of available Alternative Payment Methods (APMs).
86
+ * @returns {Promise<import("../../types").IPaymentMethod[]>} A promise that resolves with the list of APMs.
87
+ *
88
+ * @throws {import("../../types").IPublicError} Throws an error object if the operation fails.
89
+ *
90
+ * @public
91
+ */
92
+ getCustomerPaymentMethods(): Promise<IPaymentMethod[]>;
93
+ }
94
+
95
+
96
+ export interface IInlineLiteCheckoutOptions extends IInlineCheckoutBaseOptions {}
@@ -0,0 +1,24 @@
1
+ export interface IPaymentMethodResponse {
2
+ count: number;
3
+ next: string | null;
4
+ previous: string | null;
5
+ results: ITonderPaymentMethod[];
6
+ }
7
+
8
+ export interface ITonderPaymentMethod {
9
+ pk: string;
10
+ payment_method: string;
11
+ priority: number;
12
+ category: string;
13
+ unavailable_countries: string[];
14
+ status: string;
15
+ }
16
+
17
+ export interface IPaymentMethod {
18
+ id: string;
19
+ payment_method: string;
20
+ priority: number;
21
+ category: string;
22
+ icon: string;
23
+ label: string;
24
+ }
@@ -0,0 +1,101 @@
1
+ export interface ITransaction {
2
+ id: number;
3
+ provider: string;
4
+ country: string;
5
+ currency_code: string;
6
+ transaction_status: string;
7
+ created: string;
8
+ modified: string;
9
+ operation_date: string;
10
+ transaction_reference: string;
11
+ transaction_type: string;
12
+ status: string;
13
+ amount: string;
14
+ related_transaction_reference?: null | string;
15
+ reason?: null | string;
16
+ is_refunded?: null | boolean;
17
+ is_disputed?: null | boolean;
18
+ number_of_payment_attempts: number;
19
+ card_brand?: null | string;
20
+ number_of_installments: number;
21
+ payment?: {
22
+ id: number;
23
+ created: string;
24
+ modified: string;
25
+ amount: string;
26
+ status: string;
27
+ date: string;
28
+ paid_date: null | string;
29
+ source: null | string;
30
+ customer_order_reference: null | string;
31
+ client: number;
32
+ business: number;
33
+ shipping_address?: null | string;
34
+ billing_address?: null | string;
35
+ order: number;
36
+ };
37
+ checkout: {
38
+ id: string;
39
+ created: string;
40
+ modified: string;
41
+ checkout_data: {
42
+ name: string;
43
+ amount: number;
44
+ source: string;
45
+ id_ship: string;
46
+ currency: string;
47
+ order_id: number;
48
+ token_id: string;
49
+ last_name: string;
50
+ id_product: string;
51
+ ip_address: string;
52
+ payment_id: number;
53
+ return_url: string;
54
+ title_ship: string;
55
+ business_id: number;
56
+ checkout_id: string;
57
+ description: string;
58
+ browser_info: {
59
+ language: string;
60
+ time_zone: number;
61
+ user_agent: string;
62
+ color_depth: number;
63
+ screen_width: number;
64
+ screen_height: number;
65
+ javascript_enabled: boolean;
66
+ };
67
+ email_client: string;
68
+ phone_number: string;
69
+ instance_id_ship: string;
70
+ quantity_product: number;
71
+ device_session_id: null | string;
72
+ number_of_payment_attempts: number;
73
+ };
74
+ number_of_payment_attempts: number;
75
+ tried_psps: string[];
76
+ rejected_transactions: string[];
77
+ routing_step: number;
78
+ route_length: number;
79
+ last_status: string;
80
+ ip_address: string;
81
+ is_dynamic_routing: boolean;
82
+ is_route_finished: boolean;
83
+ business: number;
84
+ payment: number;
85
+ };
86
+ currency: {
87
+ id: number;
88
+ name: string;
89
+ code: string;
90
+ symbol: string;
91
+ country: null | string;
92
+ };
93
+ payment_method?: null | {
94
+ id: number;
95
+ name: string;
96
+ display_name: string;
97
+ category: string;
98
+ is_apm: boolean;
99
+ };
100
+ issuing_country?: null | string;
101
+ }