From b74891e6688bee8bc0853a56e24f9404f0dafe9a Mon Sep 17 00:00:00 2001 From: Charlie Cruzan Date: Tue, 18 Oct 2022 09:44:32 -0700 Subject: [PATCH] partial migration guide --- docs/Native-Pay-Migration.md | 30 ++++++++++++++++++++++++++++++ src/hooks/useNativePay.tsx | 7 ++++--- 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 docs/Native-Pay-Migration.md diff --git a/docs/Native-Pay-Migration.md b/docs/Native-Pay-Migration.md new file mode 100644 index 000000000..a4277098b --- /dev/null +++ b/docs/Native-Pay-Migration.md @@ -0,0 +1,30 @@ +# `isApplePaySupported` and `isGooglePaySupported` + +`isApplePaySupported` and `isGooglePaySupported` have both been replaced by `isNativePaySupported`. + +`isNativePaySupported` requires no parameters, but you _can_ optionally pass in the same parameter you passed in to `isGooglePaySupported`. However, this now belongs under the `googlePay` field. So the change would look like: + +```diff +- isGooglePaySupported(myParams); ++ isNativePaySupported({googlePay: myParams}); +``` + +# `presentApplePay`, `confirmApplePayPayment`, `initGooglePay`, `presentGooglePay`, and `createGooglePayPaymentMethod` + +`presentApplePay`, `confirmApplePayPayment`, `isGooglePaySupported`, `presentGooglePay`, and `createGooglePayPaymentMethod` have been replaced with: + +- `confirmNativePaySetupIntent` if you were using them to confirm a setup intent +- `confirmNativePayPayment` if you were using them to confirm a payment intent +- `createNativePayPaymentMethod` if you were using them to create a payment method (this was impossible previously with Apple Pay, so it was only possible on Android). This method also now creates and returns the Stripe token object. + +# `updateApplePaySummaryItems` + +`updateApplePaySummaryItems` has been replaced with `updateApplePaySheet`. + +`updateApplePaySheet` accepts the same first parameter: your cart items. The second parameter allows you to set new shipping methods, and the third parameter allows you to set specific errors in the Apple Pay sheet so your customer can take action during checkout. + +# `useGooglePay` and `useApplePay` + +`useGooglePay` and `useApplePay` have both been replaced by the `useNativePay` hook. + +`useNativePay` allows you to take action when a customer inputs a coupon code (via the `onApplePayCouponCodeEntered` prop). diff --git a/src/hooks/useNativePay.tsx b/src/hooks/useNativePay.tsx index 48e80b18d..490150b9b 100644 --- a/src/hooks/useNativePay.tsx +++ b/src/hooks/useNativePay.tsx @@ -14,7 +14,7 @@ export type Props = { * Pass this callback function to update the Apple Pay sheet after the customer selects a shipping method. * @example * ```ts - * const { presentApplePay } = useNativePay({ + * const { ... } = useNativePay({ * onApplePayShippingMethodSelected: (shippingMethod, handler) => { * handler(newCartItems, shippingMethods, anyErrors); * } @@ -35,7 +35,7 @@ export type Props = { * Pass this callback function to update the Apple Pay sheet after the customer edits their contact. * @example * ```ts - * const { presentApplePay } = useNativePay({ + * const { ... } = useNativePay({ * onApplePayShippingContactSelected: (contact, handler) => { * handler(newCartItems, shippingMethods, anyErrors); * } @@ -56,7 +56,7 @@ export type Props = { * Pass this callback function to update the Apple Pay sheet (including pricing) after the customer inputs a coupon code. * @example * ```ts - * const { presentApplePay } = useNativePay({ + * const { ... } = useNativePay({ * onApplePayCouponCodeEntered: (couponCode, handler) => { * if (isValid(couponCode)) { * handler(newCartItems, shippingMethods, []); @@ -291,6 +291,7 @@ export function useNativePay({ ); return { + /** Use this boolean to present a spinner or other similar loading screen. `true` if the SDK is currently processing, `false` if it is not. */ loading, /** * Check if the relevant native wallet (Apple Pay on iOS, Google Pay on Android) is supported.