File tree Expand file tree Collapse file tree 7 files changed +44
-5
lines changed
packages/paypal-js/types/v6 Expand file tree Collapse file tree 7 files changed +44
-5
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @paypal/paypal-js " : minor
3+ ---
4+
5+ Add v6 types for onCancel() callback
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ export type OnApproveDataOneTimePayments = {
1111 billingToken ?: string ;
1212} ;
1313
14+ export type OnCancelDataOneTimePayments = {
15+ orderId ?: string ;
16+ } ;
17+
1418export type OnCompleteData = {
1519 paymentSessionState : "approved" | "canceled" | "error" ;
1620} ;
@@ -34,7 +38,7 @@ export type OnErrorData = PayPalError;
3438 */
3539export type BasePaymentSessionOptions = {
3640 onApprove : ( data : OnApproveDataOneTimePayments ) => Promise < void > ;
37- onCancel ?: ( ) => void ;
41+ onCancel ?: ( data : OnCancelDataOneTimePayments ) => void ;
3842 onComplete ?: ( data : OnCompleteData ) => void ;
3943 onError ?: ( data : OnErrorData ) => void ;
4044 testBuyerCountry ?: string ;
Original file line number Diff line number Diff line change @@ -15,12 +15,17 @@ export type OnApproveDataBillingAgreements = {
1515 payerId ?: string ;
1616} ;
1717
18+ export type OnCancelDataBillingAgreements = {
19+ billingToken ?: string ;
20+ } ;
21+
1822export type PayPalLegacyBillingAgreementsSessionOptions = Omit <
1923 BasePaymentSessionOptions ,
20- "onApprove"
24+ "onApprove" | "onCancel"
2125> & {
2226 billingToken ?: string ;
2327 onApprove : ( data : OnApproveDataBillingAgreements ) => Promise < void > ;
28+ onCancel ?: ( data : OnCancelDataBillingAgreements ) => void ;
2429} ;
2530
2631export type PayPalLegacyBillingPresentationModeOptions =
Original file line number Diff line number Diff line change @@ -74,6 +74,10 @@ export type OnApproveDataSavePayments = {
7474 payerId ?: string ;
7575} ;
7676
77+ export type OnCancelDataSavePayments = {
78+ vaultSetupToken ?: string ;
79+ } ;
80+
7781export type PayPalOneTimePaymentSessionOptions = BasePaymentSessionOptions & {
7882 orderId ?: string ;
7983 onApprove ?: ( data : OnApproveDataOneTimePayments ) => Promise < void > ;
@@ -87,12 +91,13 @@ export type PayPalOneTimePaymentSessionOptions = BasePaymentSessionOptions & {
8791
8892export type SavePaymentSessionOptions = Omit <
8993 BasePaymentSessionOptions ,
90- "onApprove"
94+ "onApprove" | "onCancel"
9195> & {
9296 clientMetadataId ?: string ;
9397 orderId ?: never ;
9498 vaultSetupToken ?: string ;
95- onApprove ?: ( data ?: OnApproveDataSavePayments ) => void ;
99+ onApprove ?: ( data : OnApproveDataSavePayments ) => Promise < void > ;
100+ onCancel ?: ( data : OnCancelDataSavePayments ) => void ;
96101} ;
97102
98103export type PayPalPresentationModeOptions =
Original file line number Diff line number Diff line change @@ -214,6 +214,7 @@ export {
214214 CreateOrderCallback ,
215215 CreateOrderPromise ,
216216 OnApproveDataOneTimePayments ,
217+ OnCancelDataOneTimePayments ,
217218 OnCompleteData ,
218219 OnErrorData ,
219220} from "./components/base-component" ;
Original file line number Diff line number Diff line change 11import { loadCoreSdkScript } from "../../../src/v6" ;
22import type {
33 OnApproveDataBillingAgreements ,
4+ OnCancelDataBillingAgreements ,
45 PayPalV6Namespace ,
56} from "../index" ;
67
@@ -49,9 +50,16 @@ async function main() {
4950 return Promise . resolve ( ) ;
5051 }
5152
53+ function onCancelCallback ( { billingToken } : OnCancelDataBillingAgreements ) {
54+ console . log ( {
55+ billingToken,
56+ } ) ;
57+ }
58+
5259 const paypalPaymentSession =
5360 sdkInstance . createPayPalBillingAgreementWithoutPurchase ( {
5461 onApprove : onApproveCallback ,
62+ onCancel : onCancelCallback ,
5563 } ) ;
5664
5765 const createBillingToken = ( ) =>
Original file line number Diff line number Diff line change 11import { loadCoreSdkScript } from "../../../src/v6" ;
2- import type { OnApproveDataOneTimePayments , PayPalV6Namespace } from "../index" ;
2+ import type {
3+ OnApproveDataOneTimePayments ,
4+ OnCancelDataOneTimePayments ,
5+ PayPalV6Namespace ,
6+ } from "../index" ;
37
48// eslint-disable-next-line @typescript-eslint/no-unused-vars
59async function main ( ) {
@@ -46,8 +50,15 @@ async function main() {
4650 return Promise . resolve ( ) ;
4751 }
4852
53+ function onCancelCallback ( { orderId } : OnCancelDataOneTimePayments ) {
54+ console . log ( {
55+ orderId,
56+ } ) ;
57+ }
58+
4959 const paypalPaymentSession = sdkInstance . createPayPalOneTimePaymentSession ( {
5060 onApprove : onApproveCallback ,
61+ onCancel : onCancelCallback ,
5162 } ) ;
5263
5364 const createOrder = ( ) => Promise . resolve ( { orderId : "ABC123" } ) ;
You can’t perform that action at this time.
0 commit comments