-
Notifications
You must be signed in to change notification settings - Fork 71
/
buttons.d.ts
133 lines (123 loc) · 5.04 KB
/
buttons.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import type { CreateOrderRequestBody, OrderResponseBody } from "../apis/orders";
import type { CreateSubscriptionRequestBody } from "../apis/subscriptions";
type UnknownObject = Record<string, unknown>;
export type CreateOrderActions = {
order: {
/** Used to create an order for client-side integrations. Accepts the same options as the request body of the [/v2/checkout/orders api](https://developer.paypal.com/docs/api/orders/v2/#orders-create-request-body). */
create: (options: CreateOrderRequestBody) => Promise<string>;
};
};
export type CreateSubscriptionActions = {
subscription: {
/** Used to create a subscription for client-side integrations. Accepts the same options as the request body of the [/v1/billing/subscription api](https://developer.paypal.com/docs/api/subscriptions/v1#subscriptions-create-request-body). */
create: (options: CreateSubscriptionRequestBody) => Promise<string>;
};
};
export type OnInitActions = {
enable: () => Promise<void>;
disable: () => Promise<void>;
};
export type OnClickActions = {
reject: () => Promise<void>;
resolve: () => Promise<void>;
};
export type OnApproveData = {
billingToken?: string | null;
facilitatorAccessToken: string;
orderID: string;
payerID?: string | null;
paymentID?: string | null;
subscriptionID?: string | null;
authCode?: string | null;
};
export type OnApproveActions = {
order: {
capture: () => Promise<OrderResponseBody>;
authorize: () => Promise<OrderResponseBody>;
};
redirect: (redirectURL: string) => void;
restart: () => void;
};
export type OnCancelledActions = {
redirect: () => void;
};
export interface PayPalButtonsComponentOptions {
/**
* Called on button click. Often used for [Braintree vault integrations](https://developers.braintreepayments.com/guides/paypal/vault/javascript/v3).
*/
createBillingAgreement?: () => Promise<string>;
/**
* Called on button click to set up a one-time payment. [createOrder docs](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-reference/#createorder).
*/
createOrder?: (
data: UnknownObject,
actions: CreateOrderActions
) => Promise<string>;
/**
* Called on button click to set up a recurring payment. [createSubscription docs](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-reference/#createsubscription).
*/
createSubscription?: (
data: UnknownObject,
actions: CreateSubscriptionActions
) => Promise<string>;
/**
* Used for defining a standalone button.
* Learn more about [configuring the funding source for standalone buttons](https://developer.paypal.com/docs/business/checkout/configure-payments/standalone-buttons/#4-funding-sources).
*/
fundingSource?: string;
/**
* Called when finalizing the transaction. Often used to inform the buyer that the transaction is complete. [onApprove docs](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-reference/#onapprove).
*/
onApprove?: (
data: OnApproveData,
actions: OnApproveActions
) => Promise<void>;
/**
* Called when the buyer cancels the transaction.
* Often used to show the buyer a [cancellation page](https://developer.paypal.com/docs/business/checkout/add-capabilities/buyer-experience/#3-show-cancellation-page).
*/
onCancel?: (data: UnknownObject, actions: OnCancelledActions) => void;
/**
* Called when the button is clicked. Often used for [validation](https://developer.paypal.com/docs/checkout/integration-features/validation/).
*/
onClick?: (
data: UnknownObject,
actions: OnClickActions
) => Promise<void> | void;
/**
* Catch all for errors preventing buyer checkout.
* Often used to show the buyer an [error page](https://developer.paypal.com/docs/checkout/integration-features/handle-errors/).
*/
onError?: (err: UnknownObject) => void;
/**
* Called when the buttons are initialized. The component is initialized after the iframe has successfully loaded.
*/
onInit?: (data: UnknownObject, actions: OnInitActions) => void;
/**
* Called when the buyer changes their shipping address on PayPal.
*/
onShippingChange?: () => void;
/**
* [Styling options](https://developer.paypal.com/docs/business/checkout/reference/style-guide/#customize-the-payment-buttons) for customizing the button appearance.
*/
style?: {
color?: "gold" | "blue" | "silver" | "white" | "black";
height?: number;
label?:
| "paypal"
| "checkout"
| "buynow"
| "pay"
| "installment"
| "subscribe"
| "donate";
layout?: "vertical" | "horizontal";
shape?: "rect" | "pill";
tagline?: boolean;
};
}
export interface PayPalButtonsComponent {
close: () => Promise<void>;
isEligible: () => boolean;
render: (container: HTMLElement | string) => Promise<void>;
}