Skip to content

Commit 06ad677

Browse files
Feat: PayPal Credit OTP and Save Payment Hooks (#774)
* add initial files and credit otp hook * add unit test for credit otp hook * update paypal-payments instance with credit save payment and add corresponding hook * add doc comment above credit save payment property in paypal payments instance interface * fix paypal save payment session hook to support redirect and direct app switch * update package export for credit hooks and add redirect and app-switch logic to credit save payment * remove comment * add tests for credit save payment * chore: add changesets * address PR comments * add doc comments to the credit and paypal save payment hooks * remove comments
1 parent cd1dc60 commit 06ad677

10 files changed

+1779
-4
lines changed

.changeset/icy-webs-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@paypal/react-paypal-js": patch
3+
---
4+
5+
Adds Credit One Time Payment and Credit Save Payment react hooks

.changeset/nine-games-burn.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+
Updates the paypal-payments instance to include the Credit save payment method.

packages/paypal-js/types/v6/components/paypal-payments.d.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ export type SavePaymentSession = Omit<BasePaymentSession, "start"> & {
117117
presentationModeOptions: PayPalPresentationModeOptions,
118118
paymentSessionPromise?: Promise<{ vaultSetupToken: string }>,
119119
) => Promise<void>;
120+
hasReturned?: () => boolean;
121+
resume?: () => Promise<void>;
120122
};
121123

122124
export type PayLaterOneTimePaymentSessionOptions =
@@ -272,4 +274,34 @@ export interface PayPalPaymentsInstance {
272274
createPayPalCreditOneTimePaymentSession: (
273275
paymentSessionOptions: PayPalCreditOneTimePaymentSessionOptions,
274276
) => OneTimePaymentSession;
277+
/**
278+
* Creates a PayPal Credit save payment session for storing PayPal Credit payment methods for future use.
279+
*
280+
* @remarks
281+
* This method allows you to set up vault payment sessions where customers can save
282+
* their PayPal Credit payment method for future transactions without re-entering details.
283+
* Available in supported countries.
284+
*
285+
* @param paymentSessionOptions - Configuration options for the PayPal Credit save payment session
286+
* @returns A session object that can be used to start the PayPal Credit vault setup flow
287+
*
288+
* @example
289+
* ```typescript
290+
* const savePayPalCreditSession = sdkInstance.createPayPalCreditSavePaymentSession({
291+
* vaultSetupToken: 'your-vault-setup-token',
292+
* onApprove: (data) => {
293+
* console.log('PayPal Credit payment method saved:', data);
294+
* },
295+
* onCancel: () => {
296+
* console.log('Save PayPal Credit payment canceled');
297+
* },
298+
* onError: (data) => {
299+
* console.error('Save PayPal Credit payment error:', data);
300+
* }
301+
* });
302+
* ```
303+
*/
304+
createPayPalCreditSavePaymentSession: (
305+
paymentSessionOptions: SavePaymentSessionOptions,
306+
) => SavePaymentSession;
275307
}

packages/react-paypal-js/src/v6/hooks/usePayLaterOneTimePaymentSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function usePayLaterOneTimePaymentSession({
3636
}: PayLaterOneTimePaymentSessionProps): BasePaymentSessionReturn {
3737
const { sdkInstance, loadingStatus } = usePayPal();
3838
const isMountedRef = useIsMountedRef();
39-
const sessionRef = useRef<OneTimePaymentSession | null>(null); // handle cleanup
39+
const sessionRef = useRef<OneTimePaymentSession | null>(null);
4040
const proxyCallbacks = useProxyProps(callbacks);
4141
const [error, setError] = useError();
4242

0 commit comments

Comments
 (0)