Skip to content

Commit 22f23ab

Browse files
hnguyen510Hai-Yen Nguyen
and
Hai-Yen Nguyen
authored
Export type for buttons components props (#553)
* split up each props * redo the spliting * fix formating * changeset --------- Co-authored-by: Hai-Yen Nguyen <[email protected]>
1 parent 638e8e6 commit 22f23ab

File tree

3 files changed

+102
-64
lines changed

3 files changed

+102
-64
lines changed

.changeset/thirty-impalas-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@paypal/paypal-js": patch
3+
---
4+
5+
Split up each props into its own type to export

packages/paypal-js/types/components/buttons.d.ts

Lines changed: 95 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -201,122 +201,155 @@ type OnShippingAddressChangeActions = {
201201

202202
export type DisplayOnlyOptions = "vaultable";
203203

204+
export type PayPalButtonCreateOrder = (
205+
data: CreateOrderData,
206+
actions: CreateOrderActions,
207+
) => Promise<string>;
208+
209+
export type PayPalButtonCreateBillingAgreement = () => Promise<string>;
210+
211+
export type PayPalButtonCreateSubscription = (
212+
data: Record<string, unknown>,
213+
actions: CreateSubscriptionActions,
214+
) => Promise<string>;
215+
216+
export type PayPalButtonCreateVaultSetupToken = () => Promise<string>;
217+
218+
export type PayPalButtonFundingSource = FUNDING_SOURCE;
219+
220+
export type PayPalButtonOnApprove = (
221+
data: OnApproveData,
222+
actions: OnApproveActions,
223+
) => Promise<void>;
224+
225+
export type PayPalButtonOnCancel = (
226+
data: Record<string, unknown>,
227+
actions: OnCancelledActions,
228+
) => void;
229+
230+
export type PayPalButtonOnClick = (
231+
data: Record<string, unknown>,
232+
actions: OnClickActions,
233+
) => Promise<void> | void;
234+
235+
export type PayPalButtonOnError = (err: Record<string, unknown>) => void;
236+
237+
export type PayPalButtonOnInit = (
238+
data: Record<string, unknown>,
239+
actions: OnInitActions,
240+
) => void;
241+
242+
export type PayPalButtonOnShippingChange = (
243+
data: OnShippingChangeData,
244+
actions: OnShippingChangeActions,
245+
) => Promise<void>;
246+
247+
export type PayPalButtonOnShippingOptionsChange = (
248+
data: OnShippingOptionsChangeData,
249+
actions: OnShippingOptionsChangeActions,
250+
) => Promise<void>;
251+
252+
export type PayPalButtonOnShippingAddressChange = (
253+
data: OnShippingAddressChangeData,
254+
actions: OnShippingAddressChangeActions,
255+
) => Promise<void>;
256+
257+
export type PayPalButtonStyle = {
258+
borderRadius?: number;
259+
color?: "gold" | "blue" | "silver" | "white" | "black";
260+
disableMaxWidth?: boolean;
261+
height?: number;
262+
label?:
263+
| "paypal"
264+
| "checkout"
265+
| "buynow"
266+
| "pay"
267+
| "installment"
268+
| "subscribe"
269+
| "donate";
270+
layout?: "vertical" | "horizontal";
271+
shape?: "rect" | "pill" | "sharp";
272+
tagline?: boolean;
273+
};
274+
export type PayPalButtonDisplayOnly = DisplayOnlyOptions[];
275+
export type PayPalButtonMessage = {
276+
amount?: number;
277+
align?: "center" | "left" | "right";
278+
color?: "black" | "white";
279+
position?: "top" | "bottom";
280+
offer?: "pay_later_short_term" | "pay_later_long_term";
281+
};
282+
204283
export interface PayPalButtonsComponentOptions {
205284
/**
206285
* Called on button click. Often used for [Braintree vault integrations](https://developers.braintreepayments.com/guides/paypal/vault/javascript/v3).
207286
*/
208-
createBillingAgreement?: () => Promise<string>;
287+
createBillingAgreement?: PayPalButtonCreateBillingAgreement;
209288
/**
210289
* 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).
211290
*/
212-
createOrder?: (
213-
data: CreateOrderData,
214-
actions: CreateOrderActions,
215-
) => Promise<string>;
291+
createOrder?: PayPalButtonCreateOrder;
216292
/**
217293
* Called on button click to set up a recurring payment. [createSubscription docs](https://developer.paypal.com/docs/business/javascript-sdk/javascript-sdk-reference/#createsubscription).
218294
*/
219-
createSubscription?: (
220-
data: Record<string, unknown>,
221-
actions: CreateSubscriptionActions,
222-
) => Promise<string>;
295+
createSubscription?: PayPalButtonCreateSubscription;
223296
/**
224297
* Save payment methods to charge payers after a set amount of time. For example, you can offer a free trial and charge payers after the trial expires. Payers don't need to be present when charged. No checkout required.
225298
* https://developer.paypal.com/docs/checkout/save-payment-methods/purchase-later/js-sdk/paypal/#link-clientsidecodesample
226299
*/
227-
createVaultSetupToken?: () => Promise<string>;
300+
createVaultSetupToken?: PayPalButtonCreateVaultSetupToken;
228301
/**
229302
* Used for defining a standalone button.
230303
* Learn more about [configuring the funding source for standalone buttons](https://developer.paypal.com/docs/business/checkout/configure-payments/standalone-buttons/#4-funding-sources).
231304
*/
232-
fundingSource?: FUNDING_SOURCE;
305+
fundingSource?: PayPalButtonFundingSource;
233306
/**
234307
* 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).
235308
*/
236-
onApprove?: (
237-
data: OnApproveData,
238-
actions: OnApproveActions,
239-
) => Promise<void>;
309+
onApprove?: PayPalButtonOnApprove;
240310
/**
241311
* Called when the buyer cancels the transaction.
242312
* Often used to show the buyer a [cancellation page](https://developer.paypal.com/docs/business/checkout/add-capabilities/buyer-experience/#3-show-cancellation-page).
243313
*/
244-
onCancel?: (
245-
data: Record<string, unknown>,
246-
actions: OnCancelledActions,
247-
) => void;
314+
onCancel?: PayPalButtonOnCancel;
248315
/**
249316
* Called when the button is clicked. Often used for [validation](https://developer.paypal.com/docs/checkout/integration-features/validation/).
250317
*/
251-
onClick?: (
252-
data: Record<string, unknown>,
253-
actions: OnClickActions,
254-
) => Promise<void> | void;
318+
onClick?: PayPalButtonOnClick;
255319
/**
256320
* Catch all for errors preventing buyer checkout.
257321
* Often used to show the buyer an [error page](https://developer.paypal.com/docs/checkout/integration-features/handle-errors/).
258322
*/
259-
onError?: (err: Record<string, unknown>) => void;
323+
onError?: PayPalButtonOnError;
260324
/**
261325
* Called when the buttons are initialized. The component is initialized after the iframe has successfully loaded.
262326
*/
263-
onInit?: (data: Record<string, unknown>, actions: OnInitActions) => void;
327+
onInit?: PayPalButtonOnInit;
264328
/**
265329
* Called when the buyer changes their shipping address on PayPal.
266330
* @deprecated Use `onShippingAddressChange` or `onShippingOptionsChange` instead.
267331
*/
268-
onShippingChange?: (
269-
data: OnShippingChangeData,
270-
actions: OnShippingChangeActions,
271-
) => Promise<void>;
332+
onShippingChange?: PayPalButtonOnShippingChange;
272333
/**
273334
* Called when the buyer selects a new shipping option on PayPal.
274335
*/
275-
onShippingOptionsChange?: (
276-
data: OnShippingOptionsChangeData,
277-
actions: OnShippingOptionsChangeActions,
278-
) => Promise<void>;
336+
onShippingOptionsChange?: PayPalButtonOnShippingOptionsChange;
279337
/**
280338
* Called when the buyer updates their shipping address on PayPal.
281339
*/
282-
onShippingAddressChange?: (
283-
data: OnShippingAddressChangeData,
284-
actions: OnShippingAddressChangeActions,
285-
) => Promise<void>;
340+
onShippingAddressChange?: PayPalButtonOnShippingAddressChange;
286341
/**
287342
* [Styling options](https://developer.paypal.com/docs/business/checkout/reference/style-guide/#customize-the-payment-buttons) for customizing the button appearance.
288343
*/
289-
style?: {
290-
borderRadius?: number;
291-
color?: "gold" | "blue" | "silver" | "white" | "black";
292-
disableMaxWidth?: boolean;
293-
height?: number;
294-
label?:
295-
| "paypal"
296-
| "checkout"
297-
| "buynow"
298-
| "pay"
299-
| "installment"
300-
| "subscribe"
301-
| "donate";
302-
layout?: "vertical" | "horizontal";
303-
shape?: "rect" | "pill" | "sharp";
304-
tagline?: boolean;
305-
};
344+
style?: PayPalButtonStyle;
306345
/**
307346
* Used for displaying only vaultable buttons.
308347
*/
309-
displayOnly?: DisplayOnlyOptions[];
348+
displayOnly?: PayPalButtonDisplayOnly;
310349
/**
311350
* [Message options](https://developer.paypal.com/sdk/js/reference/#message) for customizing the message appearance and limited content control.
312351
*/
313-
message?: {
314-
amount?: number;
315-
align?: "center" | "left" | "right";
316-
color?: "black" | "white";
317-
position?: "top" | "bottom";
318-
offer?: "pay_later_short_term" | "pay_later_long_term";
319-
};
352+
message?: PayPalButtonMessage;
320353
}
321354

322355
export interface PayPalButtonsComponent {

packages/react-paypal-js/src/stories/components/CopyButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { useSandpack } from "@codesandbox/sandpack-react";
33

44
import type { ReactElement } from "react";
55

6-
import type { Properties as CSSProperties} from "csstype";
6+
import type { Properties as CSSProperties } from "csstype";
77

8-
const COPY_BUTTON: CSSProperties = {
8+
const COPY_BUTTON: CSSProperties = {
99
padding: "4px 10px",
1010
cursor: "pointer",
1111
display: "flex",

0 commit comments

Comments
 (0)