Skip to content

Commit 53b1f63

Browse files
authored
fix(types): export v6 types for callback arguments (#691)
1 parent 77487d6 commit 53b1f63

File tree

6 files changed

+61
-15
lines changed

6 files changed

+61
-15
lines changed

.changeset/witty-hornets-smoke.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+
Export v6 types for all callbacks

packages/paypal-js/types/v6/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,10 @@ export * from "./components/paypal-payments";
101101
export * from "./components/paypal-legacy-billing-agreements";
102102
export * from "./components/venmo-payments";
103103
export * from "./components/find-eligible-methods";
104+
105+
// export a subset of types from base-component
106+
export {
107+
OnApproveDataOneTimePayments,
108+
OnCompleteData,
109+
OnErrorData,
110+
} from "./components/base-component";

packages/paypal-js/types/v6/tests/paypal-legacy-billing-agreements.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { loadCoreSdkScript } from "../../../src/v6";
2-
import type { PayPalV6Namespace } from "../index";
2+
import type {
3+
OnApproveDataBillingAgreements,
4+
PayPalV6Namespace,
5+
} from "../index";
36

47
// eslint-disable-next-line @typescript-eslint/no-unused-vars
58
async function main() {
@@ -31,9 +34,20 @@ async function main() {
3134
return;
3235
}
3336

37+
function onApproveCallback({
38+
billingToken,
39+
payerId,
40+
}: OnApproveDataBillingAgreements) {
41+
console.log({
42+
billingToken,
43+
payerId,
44+
});
45+
return Promise.resolve();
46+
}
47+
3448
const paypalPaymentSession =
3549
sdkInstance.createPayPalBillingAgreementWithoutPurchase({
36-
onApprove: () => Promise.resolve(),
50+
onApprove: onApproveCallback,
3751
});
3852

3953
const createBillingToken = () =>

packages/paypal-js/types/v6/tests/paypal-payments.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { loadCoreSdkScript } from "../../../src/v6";
2-
import type { PayPalV6Namespace } from "../index";
2+
import type { OnApproveDataOneTimePayments, PayPalV6Namespace } from "../index";
33

44
// eslint-disable-next-line @typescript-eslint/no-unused-vars
55
async function main() {
@@ -31,8 +31,19 @@ async function main() {
3131
return;
3232
}
3333

34+
function onApproveCallback({
35+
orderId,
36+
payerId,
37+
}: OnApproveDataOneTimePayments) {
38+
console.log({
39+
orderId,
40+
payerId,
41+
});
42+
return Promise.resolve();
43+
}
44+
3445
const paypalPaymentSession = sdkInstance.createPayPalOneTimePaymentSession({
35-
onApprove: () => Promise.resolve(),
46+
onApprove: onApproveCallback,
3647
});
3748

3849
const createOrder = () => Promise.resolve({ orderId: "ABC123" });

packages/paypal-js/types/v6/tests/venmo-payments.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { loadCoreSdkScript } from "../../../src/v6";
2-
import type { PayPalV6Namespace } from "../index";
2+
import type { OnApproveDataOneTimePayments, PayPalV6Namespace } from "../index";
33

44
// eslint-disable-next-line @typescript-eslint/no-unused-vars
55
async function main() {
@@ -31,8 +31,19 @@ async function main() {
3131
return;
3232
}
3333

34+
function onApproveCallback({
35+
orderId,
36+
payerId,
37+
}: OnApproveDataOneTimePayments) {
38+
console.log({
39+
orderId,
40+
payerId,
41+
});
42+
return Promise.resolve();
43+
}
44+
3445
const venmoPaymentSession = sdkInstance.createVenmoOneTimePaymentSession({
35-
onApprove: () => Promise.resolve(),
46+
onApprove: onApproveCallback,
3647
});
3748

3849
const createOrder = () => Promise.resolve({ orderId: "ABC123" });

packages/react-paypal-js/src/components/braintree/BraintreePayPalButtons.test.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -372,20 +372,18 @@ describe("render Braintree PayPal button component", () => {
372372
dataClientToken: CLIENT_TOKEN,
373373
};
374374
render(
375-
<PayPalScriptProvider options={ options }>
376-
<BraintreePayPalButtons
377-
message={{ amount: "100" }}
378-
/>
379-
</PayPalScriptProvider>
375+
<PayPalScriptProvider options={options}>
376+
<BraintreePayPalButtons message={{ amount: "100" }} />
377+
</PayPalScriptProvider>,
380378
);
381379

382380
await waitFor(() => {
383-
const mockButtons = (window.paypal &&
384-
window.paypal.Buttons) as jest.Mock;
385-
expect(mockButtons).toBeCalledWith({
381+
const mockButtons = (window.paypal &&
382+
window.paypal.Buttons) as jest.Mock;
383+
expect(mockButtons).toBeCalledWith({
386384
message: { amount: "100" },
387385
onInit: expect.any(Function),
388-
})
386+
});
389387
});
390388
});
391389
});

0 commit comments

Comments
 (0)