File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 7
7
getClientID ,
8
8
getMerchantID as getSDKMerchantID ,
9
9
} from "@paypal/sdk-client/src" ;
10
+ import { FUNDING } from "@paypal/sdk-constants/src" ;
10
11
11
12
import type {
12
13
ButtonVariables ,
@@ -208,6 +209,14 @@ export const buildHostedButtonOnApprove = ({
208
209
merchant_id : merchantId ,
209
210
context_id : data . orderID ,
210
211
} ) ,
212
+ } ) . then ( ( response ) => {
213
+ // The "Debit or Credit Card" button does not open a popup
214
+ // so we need to redirect to the thank you page for buyers who complete
215
+ // a checkout via "Debit or Credit Card".
216
+ if ( data . paymentSource === FUNDING . CARD ) {
217
+ window . location = `${ baseUrl } /ncp/payment/${ hostedButtonId } /${ data . orderID } ` ;
218
+ }
219
+ return response ;
211
220
} ) ;
212
221
} ;
213
222
} ;
Original file line number Diff line number Diff line change @@ -264,6 +264,28 @@ describe("buildHostedButtonOnApprove", () => {
264
264
) ;
265
265
expect . assertions ( 1 ) ;
266
266
} ) ;
267
+
268
+ describe ( "inline guest" , ( ) => {
269
+ const onApprove = buildHostedButtonOnApprove ( {
270
+ hostedButtonId,
271
+ merchantId,
272
+ } ) ;
273
+ // $FlowIssue
274
+ request . mockImplementation ( ( ) =>
275
+ // eslint-disable-next-line compat/compat
276
+ Promise . resolve ( {
277
+ body : { } ,
278
+ } )
279
+ ) ;
280
+
281
+ test ( "redirects from the merchant's site to a thank you page" , async ( ) => {
282
+ expect ( window . location . href ) . toBe ( "http://localhost:3000/" ) ;
283
+ await onApprove ( { orderID, paymentSource : "card" } ) ;
284
+ expect ( window . location ) . toBe (
285
+ "https://example.com/ncp/payment/B1234567890/EC-1234567890"
286
+ ) ;
287
+ } ) ;
288
+ } ) ;
267
289
} ) ;
268
290
269
291
/* eslint-enable no-restricted-globals, promise/no-native */
You can’t perform that action at this time.
0 commit comments