@stripe/stripe-react-native 0.23.1 → 0.23.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.23.2 - 2023-02-06
6
+
7
+ ## Fixes
8
+
9
+ - Fixed a bug on Android where `canAddCardToWallet` wouldn't correctly return the `details.token` object. [#1282](https://github.com/stripe/stripe-react-native/pull/1282)
10
+
5
11
  ## 0.23.1 - 2023-01-25
6
12
 
7
13
  ## Fixes
@@ -5,8 +5,8 @@ import android.view.LayoutInflater
5
5
  import android.view.View
6
6
  import android.view.ViewGroup
7
7
  import android.widget.FrameLayout
8
- import androidx.appcompat.app.AppCompatActivity
9
8
  import androidx.fragment.app.Fragment
9
+ import androidx.fragment.app.FragmentActivity
10
10
  import com.facebook.react.bridge.*
11
11
  import com.reactnativestripesdk.utils.*
12
12
  import com.reactnativestripesdk.utils.createError
@@ -69,7 +69,7 @@ class FinancialConnectionsSheetFragment : Fragment() {
69
69
  }
70
70
  is FinancialConnectionsSheetForTokenResult.Completed -> {
71
71
  promise.resolve(createTokenResult(result))
72
- (context.currentActivity as? AppCompatActivity)?.supportFragmentManager?.beginTransaction()?.remove(this)?.commitAllowingStateLoss()
72
+ (context.currentActivity as? FragmentActivity)?.supportFragmentManager?.beginTransaction()?.remove(this)?.commitAllowingStateLoss()
73
73
  }
74
74
  }
75
75
  }
@@ -92,7 +92,7 @@ class FinancialConnectionsSheetFragment : Fragment() {
92
92
  it.putMap("session", mapFromSession(result.financialConnectionsSession))
93
93
  }
94
94
  )
95
- (context.currentActivity as? AppCompatActivity)?.supportFragmentManager?.beginTransaction()?.remove(this)?.commitAllowingStateLoss()
95
+ (context.currentActivity as? FragmentActivity)?.supportFragmentManager?.beginTransaction()?.remove(this)?.commitAllowingStateLoss()
96
96
  }
97
97
  }
98
98
  }
@@ -107,7 +107,7 @@ class FinancialConnectionsSheetFragment : Fragment() {
107
107
  stripeAccountId = stripeAccountId,
108
108
  )
109
109
 
110
- (context.currentActivity as? AppCompatActivity)?.let {
110
+ (context.currentActivity as? FragmentActivity)?.let {
111
111
  attemptToCleanupPreviousFragment(it)
112
112
  commitFragmentAndStartFlow(it)
113
113
  } ?: run {
@@ -116,13 +116,13 @@ class FinancialConnectionsSheetFragment : Fragment() {
116
116
  }
117
117
  }
118
118
 
119
- private fun attemptToCleanupPreviousFragment(currentActivity: AppCompatActivity) {
119
+ private fun attemptToCleanupPreviousFragment(currentActivity: FragmentActivity) {
120
120
  currentActivity.supportFragmentManager.beginTransaction()
121
121
  .remove(this)
122
122
  .commitAllowingStateLoss()
123
123
  }
124
124
 
125
- private fun commitFragmentAndStartFlow(currentActivity: AppCompatActivity) {
125
+ private fun commitFragmentAndStartFlow(currentActivity: FragmentActivity) {
126
126
  try {
127
127
  currentActivity.supportFragmentManager.beginTransaction()
128
128
  .add(this, TAG)
@@ -5,8 +5,8 @@ import android.view.LayoutInflater
5
5
  import android.view.View
6
6
  import android.view.ViewGroup
7
7
  import android.widget.FrameLayout
8
- import androidx.appcompat.app.AppCompatActivity
9
8
  import androidx.fragment.app.Fragment
9
+ import androidx.fragment.app.FragmentActivity
10
10
  import com.facebook.react.bridge.*
11
11
  import com.reactnativestripesdk.utils.*
12
12
  import com.reactnativestripesdk.utils.createError
@@ -57,7 +57,7 @@ class GooglePayLauncherFragment : Fragment() {
57
57
  allowCreditCards = googlePayParams.getBooleanOr("allowCreditCards", true),
58
58
  )
59
59
 
60
- (context.currentActivity as? AppCompatActivity)?.let {
60
+ (context.currentActivity as? FragmentActivity)?.let {
61
61
  attemptToCleanupPreviousFragment(it)
62
62
  commitFragmentAndStartFlow(it)
63
63
  } ?: run {
@@ -66,13 +66,13 @@ class GooglePayLauncherFragment : Fragment() {
66
66
  }
67
67
  }
68
68
 
69
- private fun attemptToCleanupPreviousFragment(currentActivity: AppCompatActivity) {
69
+ private fun attemptToCleanupPreviousFragment(currentActivity: FragmentActivity) {
70
70
  currentActivity.supportFragmentManager.beginTransaction()
71
71
  .remove(this)
72
72
  .commitAllowingStateLoss()
73
73
  }
74
74
 
75
- private fun commitFragmentAndStartFlow(currentActivity: AppCompatActivity) {
75
+ private fun commitFragmentAndStartFlow(currentActivity: FragmentActivity) {
76
76
  try {
77
77
  currentActivity.supportFragmentManager.beginTransaction()
78
78
  .add(this, TAG)
@@ -2,7 +2,7 @@ package com.reactnativestripesdk
2
2
 
3
3
  import android.app.Activity
4
4
  import android.content.Intent
5
- import androidx.appcompat.app.AppCompatActivity
5
+ import androidx.fragment.app.FragmentActivity
6
6
  import com.facebook.react.bridge.Promise
7
7
  import com.facebook.react.bridge.ReadableMap
8
8
  import com.facebook.react.bridge.WritableNativeMap
@@ -25,7 +25,7 @@ class GooglePayRequestHelper {
25
25
  companion object {
26
26
  internal const val LOAD_PAYMENT_DATA_REQUEST_CODE = 414243
27
27
 
28
- internal fun createPaymentRequest(activity: AppCompatActivity, factory: GooglePayJsonFactory, googlePayParams: ReadableMap): Task<PaymentData> {
28
+ internal fun createPaymentRequest(activity: FragmentActivity, factory: GooglePayJsonFactory, googlePayParams: ReadableMap): Task<PaymentData> {
29
29
  val transactionInfo = buildTransactionInfo(googlePayParams)
30
30
  val merchantInfo = GooglePayJsonFactory.MerchantInfo(googlePayParams.getString("merchantName").orEmpty())
31
31
  val billingAddressParameters = buildBillingAddressParameters(googlePayParams.getMap("billingAddressConfig"))
@@ -90,7 +90,7 @@ class GooglePayRequestHelper {
90
90
  )
91
91
  }
92
92
 
93
- internal fun createPaymentMethod(request: Task<PaymentData>, activity: AppCompatActivity) {
93
+ internal fun createPaymentMethod(request: Task<PaymentData>, activity: FragmentActivity) {
94
94
  AutoResolveHelper.resolveTask(
95
95
  request,
96
96
  activity,
@@ -5,8 +5,8 @@ import android.view.LayoutInflater
5
5
  import android.view.View
6
6
  import android.view.ViewGroup
7
7
  import android.widget.FrameLayout
8
- import androidx.appcompat.app.AppCompatActivity
9
8
  import androidx.fragment.app.Fragment
9
+ import androidx.fragment.app.FragmentActivity
10
10
  import com.facebook.react.bridge.Promise
11
11
  import com.facebook.react.bridge.ReactApplicationContext
12
12
  import com.reactnativestripesdk.utils.*
@@ -107,7 +107,7 @@ class PaymentLauncherFragment(
107
107
  }
108
108
 
109
109
  private fun addFragment(fragment: PaymentLauncherFragment, context: ReactApplicationContext, promise: Promise) {
110
- (context.currentActivity as? AppCompatActivity)?.let {
110
+ (context.currentActivity as? FragmentActivity)?.let {
111
111
  try {
112
112
  it.supportFragmentManager.beginTransaction()
113
113
  .add(fragment, TAG)
@@ -1,12 +1,13 @@
1
1
  package com.reactnativestripesdk
2
2
 
3
+ import android.content.Context
3
4
  import android.graphics.Color
4
5
  import android.os.Bundle
5
6
  import com.facebook.react.bridge.ReactContext
6
7
  import com.reactnativestripesdk.utils.PaymentSheetAppearanceException
7
8
  import com.stripe.android.paymentsheet.PaymentSheet
8
9
 
9
- fun buildPaymentSheetAppearance(userParams: Bundle?, context: ReactContext): PaymentSheet.Appearance {
10
+ fun buildPaymentSheetAppearance(userParams: Bundle?, context: Context): PaymentSheet.Appearance {
10
11
  val colorParams = userParams?.getBundle(PaymentSheetAppearanceKeys.COLORS)
11
12
  val lightColorParams = colorParams?.getBundle(PaymentSheetAppearanceKeys.LIGHT) ?: colorParams
12
13
  val darkColorParams = colorParams?.getBundle(PaymentSheetAppearanceKeys.DARK) ?: colorParams
@@ -20,7 +21,7 @@ fun buildPaymentSheetAppearance(userParams: Bundle?, context: ReactContext): Pay
20
21
  )
21
22
  }
22
23
 
23
- private fun buildTypography(fontParams: Bundle?, context: ReactContext): PaymentSheet.Typography {
24
+ private fun buildTypography(fontParams: Bundle?, context: Context): PaymentSheet.Typography {
24
25
  return PaymentSheet.Typography.default.copy(
25
26
  sizeScaleFactor = getFloatOr(fontParams, PaymentSheetAppearanceKeys.SCALE, PaymentSheet.Typography.default.sizeScaleFactor),
26
27
  fontResId = getFontResId(fontParams, PaymentSheetAppearanceKeys.FAMILY, PaymentSheet.Typography.default.fontResId, context)
@@ -65,7 +66,7 @@ private fun buildShapes(shapeParams: Bundle?): PaymentSheet.Shapes {
65
66
  )
66
67
  }
67
68
 
68
- private fun buildPrimaryButton(params: Bundle?, context: ReactContext): PaymentSheet.PrimaryButton {
69
+ private fun buildPrimaryButton(params: Bundle?, context: Context): PaymentSheet.PrimaryButton {
69
70
  if (params == null) {
70
71
  return PaymentSheet.PrimaryButton()
71
72
  }
@@ -121,7 +122,7 @@ private fun getFloatOrNull(bundle: Bundle?, key: String): Float? {
121
122
  }
122
123
 
123
124
  @Throws(PaymentSheetAppearanceException::class)
124
- private fun getFontResId(bundle: Bundle?, key: String, defaultValue: Int?, context: ReactContext): Int? {
125
+ private fun getFontResId(bundle: Bundle?, key: String, defaultValue: Int?, context: Context): Int? {
125
126
  val fontErrorPrefix = "Encountered an error when setting a custom font:"
126
127
  if (bundle?.containsKey(key) != true) {
127
128
  return defaultValue
@@ -4,7 +4,7 @@ import android.app.Activity
4
4
  import android.content.Intent
5
5
  import android.os.Parcelable
6
6
  import android.util.Log
7
- import androidx.appcompat.app.AppCompatActivity
7
+ import androidx.fragment.app.FragmentActivity
8
8
  import com.facebook.react.bridge.*
9
9
  import com.facebook.react.module.annotations.ReactModule
10
10
  import com.reactnativestripesdk.addresssheet.AddressLauncherFragment
@@ -861,8 +861,8 @@ class StripeSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
861
861
  * Safely get and cast the current activity as an AppCompatActivity. If that fails, the promise
862
862
  * provided will be resolved with an error message instructing the user to retry the method.
863
863
  */
864
- private fun getCurrentActivityOrResolveWithError(promise: Promise?): AppCompatActivity? {
865
- (currentActivity as? AppCompatActivity)?.let {
864
+ private fun getCurrentActivityOrResolveWithError(promise: Promise?): FragmentActivity? {
865
+ (currentActivity as? FragmentActivity)?.let {
866
866
  return it
867
867
  }
868
868
  promise?.resolve(createMissingActivityError())
@@ -5,8 +5,8 @@ import android.view.LayoutInflater
5
5
  import android.view.View
6
6
  import android.view.ViewGroup
7
7
  import android.widget.FrameLayout
8
- import androidx.appcompat.app.AppCompatActivity
9
8
  import androidx.fragment.app.Fragment
9
+ import androidx.fragment.app.FragmentActivity
10
10
  import com.facebook.react.bridge.ReactContext
11
11
  import com.facebook.react.bridge.WritableMap
12
12
  import com.reactnativestripesdk.utils.ErrorType
@@ -89,19 +89,19 @@ class AddressLauncherFragment : Fragment() {
89
89
  autocompleteCountries = autocompleteCountries,
90
90
  )
91
91
  this.callback = callback
92
- (context.currentActivity as? AppCompatActivity)?.let {
92
+ (context.currentActivity as? FragmentActivity)?.let {
93
93
  attemptToCleanupPreviousFragment(it)
94
94
  commitFragmentAndStartFlow(it)
95
95
  }
96
96
  }
97
97
 
98
- private fun attemptToCleanupPreviousFragment(currentActivity: AppCompatActivity) {
98
+ private fun attemptToCleanupPreviousFragment(currentActivity: FragmentActivity) {
99
99
  currentActivity.supportFragmentManager.beginTransaction()
100
100
  .remove(this)
101
101
  .commitAllowingStateLoss()
102
102
  }
103
103
 
104
- private fun commitFragmentAndStartFlow(currentActivity: AppCompatActivity) {
104
+ private fun commitFragmentAndStartFlow(currentActivity: FragmentActivity) {
105
105
  try {
106
106
  currentActivity.supportFragmentManager.beginTransaction()
107
107
  .add(this, TAG)
@@ -1,15 +1,15 @@
1
1
  package com.reactnativestripesdk.pushprovisioning
2
2
 
3
+ import android.content.Context
3
4
  import com.bumptech.glide.Glide
4
5
  import com.facebook.react.bridge.ReadableMap
5
6
  import com.facebook.react.common.MapBuilder
6
7
  import com.facebook.react.uimanager.SimpleViewManager
7
8
  import com.facebook.react.uimanager.ThemedReactContext
8
9
  import com.facebook.react.uimanager.annotations.ReactProp
9
- import com.facebook.react.bridge.ReactApplicationContext
10
10
 
11
11
 
12
- class AddToWalletButtonManager(applicationContext: ReactApplicationContext) : SimpleViewManager<AddToWalletButtonView?>() {
12
+ class AddToWalletButtonManager(applicationContext: Context) : SimpleViewManager<AddToWalletButtonView?>() {
13
13
  private val requestManager = Glide.with(applicationContext)
14
14
  override fun getName() = "AddToWalletButton"
15
15
 
@@ -83,34 +83,33 @@ object TapAndPayProxy {
83
83
  }
84
84
  }
85
85
 
86
- private fun mapFromTokenInfo(token: Any?): WritableMap? {
87
- if (token == null) {
88
- return null
89
- }
86
+ private fun mapFromTokenInfo(token: Any?): WritableMap {
90
87
  val result = WritableNativeMap()
91
- try {
92
- val tokenInfoClass = Class.forName("com.google.android.gms.tapandpay.issuer.TokenInfo")
93
- result.putString(
94
- "id",
95
- tokenInfoClass.getMethod("getIssuerTokenId").invoke(token) as String)
96
- result.putString(
97
- "cardLastFour",
98
- tokenInfoClass.getMethod("getFpanLastFour").invoke(token) as String)
99
- result.putString(
100
- "issuer",
101
- tokenInfoClass.getMethod("getIssuerName").invoke(token) as String)
102
- result.putString(
103
- "status",
104
- mapFromTokenState(tokenInfoClass.getMethod("getTokenState").invoke(token) as Int))
105
- result.putInt(
106
- "network",
107
- tokenInfoClass.getMethod("getNetwork").invoke(token) as Int)
108
- result.putInt(
109
- "serviceProvider",
110
- tokenInfoClass.getMethod("getTokenServiceProvider").invoke(token) as Int)
111
- } catch (e: Exception) {
112
- Log.e(TAG,
113
- "There was a problem finding the class com.google.android.gms.tapandpay.issuer.TokenInfo. Make sure you've included Google's TapAndPay dependency.")
88
+ token?.let {
89
+ try {
90
+ val tokenInfoClass = Class.forName("com.google.android.gms.tapandpay.issuer.TokenInfo")
91
+ result.putString(
92
+ "id",
93
+ tokenInfoClass.getMethod("getIssuerTokenId").invoke(it) as String)
94
+ result.putString(
95
+ "cardLastFour",
96
+ tokenInfoClass.getMethod("getFpanLastFour").invoke(it) as String)
97
+ result.putString(
98
+ "issuer",
99
+ tokenInfoClass.getMethod("getIssuerName").invoke(it) as String)
100
+ result.putString(
101
+ "status",
102
+ mapFromTokenState(tokenInfoClass.getMethod("getTokenState").invoke(it) as Int))
103
+ result.putInt(
104
+ "network",
105
+ tokenInfoClass.getMethod("getNetwork").invoke(it) as Int)
106
+ result.putInt(
107
+ "serviceProvider",
108
+ tokenInfoClass.getMethod("getTokenServiceProvider").invoke(it) as Int)
109
+ } catch (e: Exception) {
110
+ Log.e(TAG,
111
+ "There was a problem finding the class com.google.android.gms.tapandpay.issuer.TokenInfo. Make sure you've included Google's TapAndPay dependency.")
112
+ }
114
113
  }
115
114
  return result
116
115
  }
@@ -3,8 +3,8 @@ package com.reactnativestripesdk.utils
3
3
  import android.content.Context
4
4
  import android.view.View
5
5
  import android.view.inputmethod.InputMethodManager
6
- import androidx.appcompat.app.AppCompatActivity
7
6
  import androidx.fragment.app.Fragment
7
+ import androidx.fragment.app.FragmentActivity
8
8
  import com.facebook.react.bridge.ReactApplicationContext
9
9
  import com.facebook.react.bridge.ReadableMap
10
10
 
@@ -25,7 +25,7 @@ fun View.hideSoftKeyboard() {
25
25
  }
26
26
 
27
27
  fun Fragment.removeFragment(context: ReactApplicationContext) {
28
- (context.currentActivity as? AppCompatActivity)?.supportFragmentManager?.let {
28
+ (context.currentActivity as? FragmentActivity)?.supportFragmentManager?.let {
29
29
  if (it.findFragmentByTag(this.tag) != null) {
30
30
  it.beginTransaction().remove(this).commitAllowingStateLoss()
31
31
  }
@@ -17,14 +17,12 @@ internal fun createResult(key: String, value: WritableMap): WritableMap {
17
17
  internal fun createCanAddCardResult(canAddCard: Boolean, status: String? = null, token: WritableMap? = null): WritableNativeMap {
18
18
  val result = WritableNativeMap()
19
19
  val details = WritableNativeMap()
20
+ result.putBoolean("canAddCard", canAddCard)
20
21
  if (status != null) {
21
- result.putBoolean("canAddCard", false)
22
22
  details.putString("status", status)
23
- } else {
24
- result.putBoolean("canAddCard", canAddCard)
25
- if (token != null) {
26
- details.putMap("token", token)
27
- }
23
+ }
24
+ if (token != null) {
25
+ details.putMap("token", token)
28
26
  }
29
27
  result.putMap("details", details)
30
28
  return result
@@ -1 +1 @@
1
- {"version":3,"names":["AddToWalletButtonNative","requireNativeComponent","AddToWalletButton","onComplete","props","value","nativeEvent"],"sources":["AddToWalletButton.tsx"],"sourcesContent":["import React from 'react';\nimport {\n AccessibilityProps,\n StyleProp,\n ViewStyle,\n requireNativeComponent,\n NativeSyntheticEvent,\n ImageSourcePropType,\n} from 'react-native';\nimport type {\n Token,\n CardActionError,\n StripeError,\n GooglePayCardToken,\n} from '../types';\n\nconst AddToWalletButtonNative =\n requireNativeComponent<any>('AddToWalletButton');\n\n/**\n * Add to wallet button component props\n */\nexport interface Props extends AccessibilityProps {\n style?: StyleProp<ViewStyle>;\n /** Sets the Apple Wallet/Google Pay button style. If the button is placed over a dark background, set this to 'onDarkBackground', otherwise set to 'onLightBackground'. */\n iOSButtonStyle?: 'onDarkBackground' | 'onLightBackground';\n /** The image asset to use as the Google Pay button. Downloadable from https://developers.google.com/pay/issuers/apis/push-provisioning/android/downloads/flutter/googlepay_flutter_buttons.zip */\n androidAssetSource: ImageSourcePropType;\n testID?: string;\n /** iOS only. Set this to `true` until shipping through TestFlight || App Store. If false, you must be using live cards, and have the proper iOS entitlement set up. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#requesting-access-for-ios */\n testEnv?: boolean;\n /** Details of the Issued Card you'd like added to the device's wallet */\n cardDetails: {\n /** The `primary_account_identifier` value from the issued card. */\n primaryAccountIdentifier: string | null;\n /** The card holder name (used only on iOS) */\n name: string;\n /** A user-facing description of the card. Required on Android.*/\n description: string;\n /** Last 4 digits of the card, only used on iOS */\n lastFour?: string;\n /** Optional, only used on iOS */\n brand?: Token.CardBrand;\n };\n // Optional, only for Android and only for cards that are in the \"yellow path\" (as defined by Google- https://developers.google.com/pay/issuers/apis/push-provisioning/android/wallet-operations#resolving_yellow_path). Obtain this value via the `isCardInWallet` method.\n token?: GooglePayCardToken | null;\n /** Used by stripe to securely obtain card info of the card being provisioned. */\n ephemeralKey: object;\n /** Called when the flow completes. If the `error` field is `null`, then the card was successfully added to the user's native wallet. */\n onComplete(result: { error: StripeError<CardActionError> | null }): void;\n}\n\n/**\n * Add to wallet button\n *\n * @example\n * ```ts\n * <AddToWalletButton\n * testEnv={true}\n * style={styles.myButtonStyle}\n * iOSButtonStyle=\"onLightBackground\"\n * cardDetails={{\n * primaryAccountIdentifier: \"V-123\",\n * name: \"David Wallace\",\n * lastFour: \"4242\",\n * }}\n * ephemeralKey={myEphemeralKey} // This object is retrieved from your server. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#update-your-backend\n * onComplete={(error) => {\n * Alert.alert(\n * error ? error.code : 'Success',\n * error\n * ? error.message\n * : 'Card was successfully added to the wallet.'\n * );\n * }}\n * />\n * ```\n * @param __namedParameters Props\n * @returns JSX.Element\n * @category ReactComponents\n */\nexport function AddToWalletButton({ onComplete, ...props }: Props) {\n return (\n <AddToWalletButtonNative\n {...props}\n onCompleteAction={(\n value: NativeSyntheticEvent<{\n error: StripeError<CardActionError> | null;\n }>\n ) => onComplete(value.nativeEvent)}\n />\n );\n}\n"],"mappings":"wXAAA,oDACA,yCAOsB,qIAQtB,GAAMA,wBAAuB,CAC3B,GAAAC,mCAAsB,EAAM,mBAAmB,CAAC,CAgE3C,QAASC,kBAAiB,MAAkC,IAA/BC,WAAU,MAAVA,UAAU,CAAKC,KAAK,uDACtD,MACE,8BAAC,uBAAuB,0BAClBA,KAAK,EACT,gBAAgB,CAAE,0BAChBC,KAEE,QACCF,WAAU,CAACE,KAAK,CAACC,WAAW,CAAC,EAAC,6EACnC,CAEN"}
1
+ {"version":3,"names":["AddToWalletButtonNative","requireNativeComponent","AddToWalletButton","onComplete","props","value","nativeEvent"],"sources":["AddToWalletButton.tsx"],"sourcesContent":["import React from 'react';\nimport {\n AccessibilityProps,\n StyleProp,\n ViewStyle,\n requireNativeComponent,\n NativeSyntheticEvent,\n ImageSourcePropType,\n} from 'react-native';\nimport type {\n Token,\n CardActionError,\n StripeError,\n GooglePayCardToken,\n} from '../types';\n\nconst AddToWalletButtonNative =\n requireNativeComponent<any>('AddToWalletButton');\n\n/**\n * Add to wallet button component props\n */\nexport interface Props extends AccessibilityProps {\n style?: StyleProp<ViewStyle>;\n /** Sets the Apple Wallet/Google Pay button style. If the button is placed over a dark background, set this to 'onDarkBackground', otherwise set to 'onLightBackground'. */\n iOSButtonStyle?: 'onDarkBackground' | 'onLightBackground';\n /** The image asset to use as the Google Pay button. Downloadable from https://developers.google.com/static/pay/issuers/apis/push-provisioning/android/downloads/flutter/2022_googlepay_flutter_buttons.zip */\n androidAssetSource: ImageSourcePropType;\n testID?: string;\n /** iOS only. Set this to `true` until shipping through TestFlight || App Store. If false, you must be using live cards, and have the proper iOS entitlement set up. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#requesting-access-for-ios */\n testEnv?: boolean;\n /** Details of the Issued Card you'd like added to the device's wallet */\n cardDetails: {\n /** The `primary_account_identifier` value from the issued card. */\n primaryAccountIdentifier: string | null;\n /** The card holder name (used only on iOS) */\n name: string;\n /** A user-facing description of the card. Required on Android.*/\n description: string;\n /** Last 4 digits of the card, only used on iOS */\n lastFour?: string;\n /** Optional, only used on iOS */\n brand?: Token.CardBrand;\n };\n // Optional, only for Android and only for cards that are in the \"yellow path\" (as defined by Google- https://developers.google.com/pay/issuers/apis/push-provisioning/android/wallet-operations#resolving_yellow_path). Obtain this value via the `isCardInWallet` method.\n token?: GooglePayCardToken | null;\n /** Used by stripe to securely obtain card info of the card being provisioned. */\n ephemeralKey: object;\n /** Called when the flow completes. If the `error` field is `null`, then the card was successfully added to the user's native wallet. */\n onComplete(result: { error: StripeError<CardActionError> | null }): void;\n}\n\n/**\n * Add to wallet button\n *\n * @example\n * ```ts\n * <AddToWalletButton\n * testEnv={true}\n * style={styles.myButtonStyle}\n * iOSButtonStyle=\"onLightBackground\"\n * cardDetails={{\n * primaryAccountIdentifier: \"V-123\",\n * name: \"David Wallace\",\n * lastFour: \"4242\",\n * }}\n * ephemeralKey={myEphemeralKey} // This object is retrieved from your server. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#update-your-backend\n * onComplete={(error) => {\n * Alert.alert(\n * error ? error.code : 'Success',\n * error\n * ? error.message\n * : 'Card was successfully added to the wallet.'\n * );\n * }}\n * />\n * ```\n * @param __namedParameters Props\n * @returns JSX.Element\n * @category ReactComponents\n */\nexport function AddToWalletButton({ onComplete, ...props }: Props) {\n return (\n <AddToWalletButtonNative\n {...props}\n onCompleteAction={(\n value: NativeSyntheticEvent<{\n error: StripeError<CardActionError> | null;\n }>\n ) => onComplete(value.nativeEvent)}\n />\n );\n}\n"],"mappings":"wXAAA,oDACA,yCAOsB,qIAQtB,GAAMA,wBAAuB,CAC3B,GAAAC,mCAAsB,EAAM,mBAAmB,CAAC,CAgE3C,QAASC,kBAAiB,MAAkC,IAA/BC,WAAU,MAAVA,UAAU,CAAKC,KAAK,uDACtD,MACE,8BAAC,uBAAuB,0BAClBA,KAAK,EACT,gBAAgB,CAAE,0BAChBC,KAEE,QACCF,WAAU,CAACE,KAAK,CAACC,WAAW,CAAC,EAAC,6EACnC,CAEN"}
@@ -1 +1 @@
1
- {"version":3,"names":["AddToWalletButtonNative","requireNativeComponent","AddToWalletButton","onComplete","props","value","nativeEvent"],"sources":["AddToWalletButton.tsx"],"sourcesContent":["import React from 'react';\nimport {\n AccessibilityProps,\n StyleProp,\n ViewStyle,\n requireNativeComponent,\n NativeSyntheticEvent,\n ImageSourcePropType,\n} from 'react-native';\nimport type {\n Token,\n CardActionError,\n StripeError,\n GooglePayCardToken,\n} from '../types';\n\nconst AddToWalletButtonNative =\n requireNativeComponent<any>('AddToWalletButton');\n\n/**\n * Add to wallet button component props\n */\nexport interface Props extends AccessibilityProps {\n style?: StyleProp<ViewStyle>;\n /** Sets the Apple Wallet/Google Pay button style. If the button is placed over a dark background, set this to 'onDarkBackground', otherwise set to 'onLightBackground'. */\n iOSButtonStyle?: 'onDarkBackground' | 'onLightBackground';\n /** The image asset to use as the Google Pay button. Downloadable from https://developers.google.com/pay/issuers/apis/push-provisioning/android/downloads/flutter/googlepay_flutter_buttons.zip */\n androidAssetSource: ImageSourcePropType;\n testID?: string;\n /** iOS only. Set this to `true` until shipping through TestFlight || App Store. If false, you must be using live cards, and have the proper iOS entitlement set up. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#requesting-access-for-ios */\n testEnv?: boolean;\n /** Details of the Issued Card you'd like added to the device's wallet */\n cardDetails: {\n /** The `primary_account_identifier` value from the issued card. */\n primaryAccountIdentifier: string | null;\n /** The card holder name (used only on iOS) */\n name: string;\n /** A user-facing description of the card. Required on Android.*/\n description: string;\n /** Last 4 digits of the card, only used on iOS */\n lastFour?: string;\n /** Optional, only used on iOS */\n brand?: Token.CardBrand;\n };\n // Optional, only for Android and only for cards that are in the \"yellow path\" (as defined by Google- https://developers.google.com/pay/issuers/apis/push-provisioning/android/wallet-operations#resolving_yellow_path). Obtain this value via the `isCardInWallet` method.\n token?: GooglePayCardToken | null;\n /** Used by stripe to securely obtain card info of the card being provisioned. */\n ephemeralKey: object;\n /** Called when the flow completes. If the `error` field is `null`, then the card was successfully added to the user's native wallet. */\n onComplete(result: { error: StripeError<CardActionError> | null }): void;\n}\n\n/**\n * Add to wallet button\n *\n * @example\n * ```ts\n * <AddToWalletButton\n * testEnv={true}\n * style={styles.myButtonStyle}\n * iOSButtonStyle=\"onLightBackground\"\n * cardDetails={{\n * primaryAccountIdentifier: \"V-123\",\n * name: \"David Wallace\",\n * lastFour: \"4242\",\n * }}\n * ephemeralKey={myEphemeralKey} // This object is retrieved from your server. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#update-your-backend\n * onComplete={(error) => {\n * Alert.alert(\n * error ? error.code : 'Success',\n * error\n * ? error.message\n * : 'Card was successfully added to the wallet.'\n * );\n * }}\n * />\n * ```\n * @param __namedParameters Props\n * @returns JSX.Element\n * @category ReactComponents\n */\nexport function AddToWalletButton({ onComplete, ...props }: Props) {\n return (\n <AddToWalletButtonNative\n {...props}\n onCompleteAction={(\n value: NativeSyntheticEvent<{\n error: StripeError<CardActionError> | null;\n }>\n ) => onComplete(value.nativeEvent)}\n />\n );\n}\n"],"mappings":"wXAAA,oDACA,yCAOsB,qIAQtB,GAAMA,wBAAuB,CAC3B,GAAAC,mCAAsB,EAAM,mBAAmB,CAAC,CAgE3C,QAASC,kBAAiB,MAAkC,IAA/BC,WAAU,MAAVA,UAAU,CAAKC,KAAK,uDACtD,MACE,8BAAC,uBAAuB,0BAClBA,KAAK,EACT,gBAAgB,CAAE,0BAChBC,KAEE,QACCF,WAAU,CAACE,KAAK,CAACC,WAAW,CAAC,EAAC,6EACnC,CAEN"}
1
+ {"version":3,"names":["AddToWalletButtonNative","requireNativeComponent","AddToWalletButton","onComplete","props","value","nativeEvent"],"sources":["AddToWalletButton.tsx"],"sourcesContent":["import React from 'react';\nimport {\n AccessibilityProps,\n StyleProp,\n ViewStyle,\n requireNativeComponent,\n NativeSyntheticEvent,\n ImageSourcePropType,\n} from 'react-native';\nimport type {\n Token,\n CardActionError,\n StripeError,\n GooglePayCardToken,\n} from '../types';\n\nconst AddToWalletButtonNative =\n requireNativeComponent<any>('AddToWalletButton');\n\n/**\n * Add to wallet button component props\n */\nexport interface Props extends AccessibilityProps {\n style?: StyleProp<ViewStyle>;\n /** Sets the Apple Wallet/Google Pay button style. If the button is placed over a dark background, set this to 'onDarkBackground', otherwise set to 'onLightBackground'. */\n iOSButtonStyle?: 'onDarkBackground' | 'onLightBackground';\n /** The image asset to use as the Google Pay button. Downloadable from https://developers.google.com/static/pay/issuers/apis/push-provisioning/android/downloads/flutter/2022_googlepay_flutter_buttons.zip */\n androidAssetSource: ImageSourcePropType;\n testID?: string;\n /** iOS only. Set this to `true` until shipping through TestFlight || App Store. If false, you must be using live cards, and have the proper iOS entitlement set up. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#requesting-access-for-ios */\n testEnv?: boolean;\n /** Details of the Issued Card you'd like added to the device's wallet */\n cardDetails: {\n /** The `primary_account_identifier` value from the issued card. */\n primaryAccountIdentifier: string | null;\n /** The card holder name (used only on iOS) */\n name: string;\n /** A user-facing description of the card. Required on Android.*/\n description: string;\n /** Last 4 digits of the card, only used on iOS */\n lastFour?: string;\n /** Optional, only used on iOS */\n brand?: Token.CardBrand;\n };\n // Optional, only for Android and only for cards that are in the \"yellow path\" (as defined by Google- https://developers.google.com/pay/issuers/apis/push-provisioning/android/wallet-operations#resolving_yellow_path). Obtain this value via the `isCardInWallet` method.\n token?: GooglePayCardToken | null;\n /** Used by stripe to securely obtain card info of the card being provisioned. */\n ephemeralKey: object;\n /** Called when the flow completes. If the `error` field is `null`, then the card was successfully added to the user's native wallet. */\n onComplete(result: { error: StripeError<CardActionError> | null }): void;\n}\n\n/**\n * Add to wallet button\n *\n * @example\n * ```ts\n * <AddToWalletButton\n * testEnv={true}\n * style={styles.myButtonStyle}\n * iOSButtonStyle=\"onLightBackground\"\n * cardDetails={{\n * primaryAccountIdentifier: \"V-123\",\n * name: \"David Wallace\",\n * lastFour: \"4242\",\n * }}\n * ephemeralKey={myEphemeralKey} // This object is retrieved from your server. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#update-your-backend\n * onComplete={(error) => {\n * Alert.alert(\n * error ? error.code : 'Success',\n * error\n * ? error.message\n * : 'Card was successfully added to the wallet.'\n * );\n * }}\n * />\n * ```\n * @param __namedParameters Props\n * @returns JSX.Element\n * @category ReactComponents\n */\nexport function AddToWalletButton({ onComplete, ...props }: Props) {\n return (\n <AddToWalletButtonNative\n {...props}\n onCompleteAction={(\n value: NativeSyntheticEvent<{\n error: StripeError<CardActionError> | null;\n }>\n ) => onComplete(value.nativeEvent)}\n />\n );\n}\n"],"mappings":"wXAAA,oDACA,yCAOsB,qIAQtB,GAAMA,wBAAuB,CAC3B,GAAAC,mCAAsB,EAAM,mBAAmB,CAAC,CAgE3C,QAASC,kBAAiB,MAAkC,IAA/BC,WAAU,MAAVA,UAAU,CAAKC,KAAK,uDACtD,MACE,8BAAC,uBAAuB,0BAClBA,KAAK,EACT,gBAAgB,CAAE,0BAChBC,KAEE,QACCF,WAAU,CAACE,KAAK,CAACC,WAAW,CAAC,EAAC,6EACnC,CAEN"}
@@ -7,7 +7,7 @@ export interface Props extends AccessibilityProps {
7
7
  style?: StyleProp<ViewStyle>;
8
8
  /** Sets the Apple Wallet/Google Pay button style. If the button is placed over a dark background, set this to 'onDarkBackground', otherwise set to 'onLightBackground'. */
9
9
  iOSButtonStyle?: 'onDarkBackground' | 'onLightBackground';
10
- /** The image asset to use as the Google Pay button. Downloadable from https://developers.google.com/pay/issuers/apis/push-provisioning/android/downloads/flutter/googlepay_flutter_buttons.zip */
10
+ /** The image asset to use as the Google Pay button. Downloadable from https://developers.google.com/static/pay/issuers/apis/push-provisioning/android/downloads/flutter/2022_googlepay_flutter_buttons.zip */
11
11
  androidAssetSource: ImageSourcePropType;
12
12
  testID?: string;
13
13
  /** iOS only. Set this to `true` until shipping through TestFlight || App Store. If false, you must be using live cards, and have the proper iOS entitlement set up. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#requesting-access-for-ios */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stripe/stripe-react-native",
3
- "version": "0.23.1",
3
+ "version": "0.23.2",
4
4
  "author": "Stripe",
5
5
  "description": "Stripe SDK for React Native",
6
6
  "main": "lib/commonjs/index",
@@ -21,10 +21,12 @@
21
21
  "docs": "yarn typedoc ./src/index.tsx --out ./docs/api-reference --tsconfig ./tsconfig.json --readme none --sort source-order",
22
22
  "run-example-ios": "cd example;ENVFILE=.env.ci react-native run-ios --configuration Release --simulator \"iPhone 13 (15.2)\"",
23
23
  "run-example-android": "cd example;ENVFILE=.env.ci react-native run-android --variant=release",
24
- "test:e2e:ios": "mkdir -p .tmp/screenshots && node ./run-appium-tests.js ios",
25
- "test:e2e:android": "mkdir -p .tmp/screenshots && node ./run-appium-tests.js android",
24
+ "test:e2e:ios": "bash ./scripts/run-maestro-tests ios",
25
+ "test:e2e:android": "bash ./scripts/run-maestro-tests android",
26
26
  "test:unit:ios": "xcodebuild test -workspace example/ios/StripeSdkExample.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 13' -scheme UnitTests",
27
- "test:unit:android": "cd example/android && ./gradlew connectedAndroidTest"
27
+ "test:unit:android": "cd example/android && ./gradlew connectedAndroidTest",
28
+ "test-ios": "maestro test -e APP_ID=com.stripe.react.native",
29
+ "test-android": "maestro test -e APP_ID=com.example.reactnativestripesdk"
28
30
  },
29
31
  "keywords": [
30
32
  "react-native",
@@ -46,31 +48,19 @@
46
48
  "@types/jest": "^26.0.23",
47
49
  "@types/react": "^16.9.19",
48
50
  "@types/react-native": "0.62.13",
49
- "@wdio/appium-service": "^7.5.7",
50
- "@wdio/cli": "^7.16.15",
51
- "@wdio/local-runner": "^7.16.15",
52
- "@wdio/mocha-framework": "^7.16.15",
53
- "@wdio/spec-reporter": "^7.16.14",
54
- "@wdio/sync": "^7.16.15",
55
- "appium": "^1.22.3",
56
- "appium-chromedriver": "4.26.2",
57
51
  "eslint": "^7.32.0",
58
52
  "eslint-config-prettier": "^6.11.0",
59
53
  "eslint-plugin-prettier": "^3.1.3",
60
- "expect-webdriverio": "^2.0.1",
61
54
  "expo": "^47.0.8",
62
55
  "husky": "^8.0.0",
63
56
  "jest": "^26.6.3",
64
57
  "metro-react-native-babel-preset": "^0.70.3",
65
- "mocha": "^8.3.2",
66
58
  "prettier": "^2.0.5",
67
59
  "react": "18.0.0",
68
60
  "react-native": "0.69.2",
69
61
  "ts-node": "^9.1.1",
70
62
  "typedoc": "^0.22.12",
71
- "typescript": "~4.4.4",
72
- "wdio-chromedriver-service": "^7.0.0",
73
- "webdriverio": "^7.16.15"
63
+ "typescript": "~4.4.4"
74
64
  },
75
65
  "peerDependencies": {
76
66
  "expo": ">=46.0.9",
@@ -24,7 +24,7 @@ export interface Props extends AccessibilityProps {
24
24
  style?: StyleProp<ViewStyle>;
25
25
  /** Sets the Apple Wallet/Google Pay button style. If the button is placed over a dark background, set this to 'onDarkBackground', otherwise set to 'onLightBackground'. */
26
26
  iOSButtonStyle?: 'onDarkBackground' | 'onLightBackground';
27
- /** The image asset to use as the Google Pay button. Downloadable from https://developers.google.com/pay/issuers/apis/push-provisioning/android/downloads/flutter/googlepay_flutter_buttons.zip */
27
+ /** The image asset to use as the Google Pay button. Downloadable from https://developers.google.com/static/pay/issuers/apis/push-provisioning/android/downloads/flutter/2022_googlepay_flutter_buttons.zip */
28
28
  androidAssetSource: ImageSourcePropType;
29
29
  testID?: string;
30
30
  /** iOS only. Set this to `true` until shipping through TestFlight || App Store. If false, you must be using live cards, and have the proper iOS entitlement set up. See https://stripe.com/docs/issuing/cards/digital-wallets?platform=react-native#requesting-access-for-ios */
@@ -1,273 +0,0 @@
1
- //
2
- // AddressSheetUtilsTests.swift
3
- // stripe-react-native-Unit-Tests
4
- //
5
- // Created by Charles Cruzan on 10/13/22.
6
- //
7
-
8
- import XCTest
9
- @testable import stripe_react_native
10
- import StripePaymentSheet
11
-
12
- class AddressSheetUtilsTests: XCTestCase {
13
- let testCity = "testCity"
14
- let testCountry = "testCountry"
15
- let testLine1 = "testLine1"
16
- let testLine2 = "testLine2"
17
- let testPostalCode = "testPostalCode"
18
- let testState = "testState"
19
- let testName = "testName"
20
- let testPhone = "testPhone"
21
-
22
- func test_buildDefaultValues_whenPassedNil() throws {
23
- let result = AddressSheetUtils.buildDefaultValues(params: nil)
24
- XCTAssertEqual(
25
- result.address, PaymentSheet.Address()
26
- )
27
- XCTAssertEqual(
28
- result.name, nil
29
- )
30
- XCTAssertEqual(
31
- result.phone, nil
32
- )
33
- XCTAssertEqual(
34
- result.isCheckboxSelected, nil
35
- )
36
- }
37
-
38
- func test_buildDefaultValues_whenPassedValues() throws {
39
- let result = AddressSheetUtils.buildDefaultValues(
40
- params: ["name": testName,
41
- "phone": testPhone,
42
- "address": ["city": testCity],
43
- "isCheckboxSelected": true]
44
- )
45
- XCTAssertEqual(
46
- result.address.city, testCity
47
- )
48
- XCTAssertEqual(
49
- result.name, testName
50
- )
51
- XCTAssertEqual(
52
- result.phone, testPhone
53
- )
54
- XCTAssertEqual(
55
- result.isCheckboxSelected, true
56
- )
57
- }
58
-
59
- func test_buildAddressDetails_whenPassedNil() throws {
60
- let result = AddressSheetUtils.buildAddressDetails(params: nil)
61
- XCTAssertEqual(
62
- result.address.country, ""
63
- )
64
- XCTAssertEqual(
65
- result.address.line1, ""
66
- )
67
- XCTAssertEqual(
68
- result.name, nil
69
- )
70
- XCTAssertEqual(
71
- result.phone, nil
72
- )
73
- XCTAssertEqual(
74
- result.isCheckboxSelected, nil
75
- )
76
- }
77
-
78
- func test_buildAddressDetails_whenPassedValues() throws {
79
- let result = AddressSheetUtils.buildAddressDetails(
80
- params: ["name": testName,
81
- "phone": testPhone,
82
- "address": ["city": testCity],
83
- "isCheckboxSelected": true]
84
- )
85
-
86
- XCTAssertEqual(
87
- result.address.city, testCity
88
- )
89
- XCTAssertEqual(
90
- result.address.line1, ""
91
- )
92
- XCTAssertEqual(
93
- result.name, testName
94
- )
95
- XCTAssertEqual(
96
- result.phone, testPhone
97
- )
98
- XCTAssertEqual(
99
- result.isCheckboxSelected, true
100
- )
101
- }
102
-
103
- func test_buildAddress_forPaymentSheet_whenPassedNil() throws {
104
- let result: PaymentSheet.Address = AddressSheetUtils.buildAddress(params: nil)
105
-
106
- XCTAssertEqual(
107
- result.city, nil
108
- )
109
- XCTAssertEqual(
110
- result.line1, nil
111
- )
112
- XCTAssertEqual(
113
- result.line2, nil
114
- )
115
- XCTAssertEqual(
116
- result.country, nil
117
- )
118
- XCTAssertEqual(
119
- result.postalCode, nil
120
- )
121
- XCTAssertEqual(
122
- result.state, nil
123
- )
124
- }
125
-
126
- func test_buildAddress_forPaymentSheet_whenPassedValues() throws {
127
- let result: PaymentSheet.Address = AddressSheetUtils.buildAddress(
128
- params: ["city": testCity, "country": testCountry, "line1": testLine1, "line2": testLine2, "postalCode": testPostalCode, "state": testState]
129
- )
130
-
131
- XCTAssertEqual(
132
- result.city, testCity
133
- )
134
- XCTAssertEqual(
135
- result.line1, testLine1
136
- )
137
- XCTAssertEqual(
138
- result.line2, testLine2
139
- )
140
- XCTAssertEqual(
141
- result.country, testCountry
142
- )
143
- XCTAssertEqual(
144
- result.postalCode, testPostalCode
145
- )
146
- XCTAssertEqual(
147
- result.state, testState
148
- )
149
- }
150
-
151
- func test_buildAddress_forAddressViewController_whenPassedNil() throws {
152
- let result: AddressViewController.AddressDetails.Address = AddressSheetUtils.buildAddress(params: nil)
153
-
154
- XCTAssertEqual(
155
- result.city, nil
156
- )
157
- XCTAssertEqual(
158
- result.line1, ""
159
- )
160
- XCTAssertEqual(
161
- result.line2, nil
162
- )
163
- XCTAssertEqual(
164
- result.country, ""
165
- )
166
- XCTAssertEqual(
167
- result.postalCode, nil
168
- )
169
- XCTAssertEqual(
170
- result.state, nil
171
- )
172
- }
173
-
174
- func test_buildAddress_forAddressViewController_whenPassedValues() throws {
175
- let result: AddressViewController.AddressDetails.Address = AddressSheetUtils.buildAddress(
176
- params: ["city": testCity, "country": testCountry, "line1": testLine1, "line2": testLine2, "postalCode": testPostalCode, "state": testState]
177
- )
178
-
179
- XCTAssertEqual(
180
- result.city, testCity
181
- )
182
- XCTAssertEqual(
183
- result.line1, testLine1
184
- )
185
- XCTAssertEqual(
186
- result.line2, testLine2
187
- )
188
- XCTAssertEqual(
189
- result.country, testCountry
190
- )
191
- XCTAssertEqual(
192
- result.postalCode, testPostalCode
193
- )
194
- XCTAssertEqual(
195
- result.state, testState
196
- )
197
- }
198
-
199
- func test_buildAdditionalFieldsConfiguration_whenPassedNil() throws {
200
- let result = AddressSheetUtils.buildAdditionalFieldsConfiguration(params: nil)
201
-
202
- XCTAssertEqual(
203
- result.phone, .hidden
204
- )
205
- XCTAssertEqual(
206
- result.checkboxLabel, nil
207
- )
208
- }
209
-
210
- func test_buildAdditionalFieldsConfiguration_whenPassedValues() throws {
211
- let testCheckboxLabel = "testCheckboxLabel"
212
- let result = AddressSheetUtils.buildAdditionalFieldsConfiguration(
213
- params: ["name": "hidden", "phoneNumber": "optional", "checkboxLabel": testCheckboxLabel]
214
- )
215
-
216
- XCTAssertEqual(
217
- result.phone, .optional
218
- )
219
- XCTAssertEqual(
220
- result.checkboxLabel, testCheckboxLabel
221
- )
222
- }
223
-
224
- func test_getFieldConfiguration() throws {
225
- XCTAssertEqual(
226
- AddressSheetUtils.getFieldConfiguration(input: nil, default: .hidden), .hidden
227
- )
228
-
229
- XCTAssertEqual(
230
- AddressSheetUtils.getFieldConfiguration(input: "optional", default: .hidden), .optional
231
- )
232
-
233
- XCTAssertEqual(
234
- AddressSheetUtils.getFieldConfiguration(input: "required", default: .hidden), .required
235
- )
236
-
237
- XCTAssertEqual(
238
- AddressSheetUtils.getFieldConfiguration(input: "hidden", default: .hidden), .hidden
239
- )
240
-
241
- XCTAssertEqual(
242
- AddressSheetUtils.getFieldConfiguration(input: "hidden", default: .optional), .hidden
243
- )
244
- }
245
-
246
- func test_buildResult() throws {
247
- let input = AddressViewController.AddressDetails(
248
- address: AddressViewController.AddressDetails.Address(
249
- city: testCity, country: testCountry, line1: testLine1, line2: testLine2, postalCode: testPostalCode, state: testState
250
- ),
251
- name: testName,
252
- phone: testPhone,
253
- isCheckboxSelected: true
254
- )
255
-
256
- XCTAssertEqual(
257
- AddressSheetUtils.buildResult(address: input) as NSDictionary,
258
- [
259
- "name": testName,
260
- "phone": testPhone,
261
- "isCheckboxSelected": true,
262
- "address": [
263
- "city": testCity,
264
- "country": testCountry,
265
- "line1": testLine1,
266
- "line2": testLine2,
267
- "postalCode": testPostalCode,
268
- "state": testState
269
- ]
270
- ] as NSDictionary
271
- )
272
- }
273
- }
@@ -1,213 +0,0 @@
1
- //
2
- // Tests.swift
3
- // Tests
4
- //
5
- // Created by Charles Cruzan on 6/21/22.
6
- // Copyright © 2022 Facebook. All rights reserved.
7
- //
8
-
9
- import XCTest
10
- @testable import stripe_react_native
11
- import PassKit
12
-
13
- @available(iOS 15.0, *)
14
- class ApplePayUtilsTests: XCTestCase {
15
-
16
- func test_buildPaymentSheetApplePayConfig_FailsWithoutMerchantIdentifier() throws {
17
- XCTAssertThrowsError(
18
- try ApplePayUtils.buildPaymentSheetApplePayConfig(merchantIdentifier: nil, merchantCountryCode: "", paymentSummaryItems: nil)
19
- ) { error in
20
- XCTAssertEqual(
21
- error as! ApplePayUtilsError, ApplePayUtilsError.missingMerchantId
22
- )
23
- }
24
- }
25
-
26
- func test_buildPaymentSheetApplePayConfig_FailsWithoutCountryCode() throws {
27
- XCTAssertThrowsError(
28
- try ApplePayUtils.buildPaymentSheetApplePayConfig(merchantIdentifier: TestFixtures.MERCHANT_ID, merchantCountryCode: nil, paymentSummaryItems: nil)
29
- ) { error in
30
- XCTAssertEqual(
31
- error as! ApplePayUtilsError, ApplePayUtilsError.missingCountryCode
32
- )
33
- }
34
- }
35
-
36
- func test_buildPaymentSheetApplePayConfig_withNilAndEmptyArray_shouldBeEqual() throws {
37
- let resultWithItemsAsNil = try ApplePayUtils.buildPaymentSheetApplePayConfig(merchantIdentifier: TestFixtures.MERCHANT_ID, merchantCountryCode: TestFixtures.COUNTRY_CODE, paymentSummaryItems: nil)
38
- let resultWithItemsAsEmptyArray = try ApplePayUtils.buildPaymentSheetApplePayConfig(merchantIdentifier: TestFixtures.MERCHANT_ID, merchantCountryCode: TestFixtures.COUNTRY_CODE, paymentSummaryItems: [])
39
- XCTAssertEqual(resultWithItemsAsNil.paymentSummaryItems, resultWithItemsAsEmptyArray.paymentSummaryItems)
40
- }
41
-
42
- func test_buildPaymentSheetApplePayConfig_withItems_shouldMatchExpected() throws {
43
- let result = try ApplePayUtils.buildPaymentSheetApplePayConfig(merchantIdentifier: TestFixtures.MERCHANT_ID, merchantCountryCode: TestFixtures.COUNTRY_CODE, paymentSummaryItems: TestFixtures.CART_ITEM_DICTIONARY)
44
-
45
- let deferredItemResult = PKDeferredPaymentSummaryItem(label: "deferred label", amount: 1.00)
46
- deferredItemResult.deferredDate = Date(timeIntervalSince1970: 123456789)
47
- let immediateItemResult = PKPaymentSummaryItem(label: "immediate label", amount: 2.00, type: .pending)
48
- let recurringResult = PKRecurringPaymentSummaryItem(label: "recurring label", amount: 1.00)
49
- recurringResult.intervalUnit = .minute
50
- recurringResult.intervalCount = 2
51
- recurringResult.startDate = Date(timeIntervalSince1970: 123456789)
52
- recurringResult.endDate = Date(timeIntervalSince1970: 234567890)
53
-
54
- XCTAssertEqual(
55
- result.paymentSummaryItems,
56
- [deferredItemResult, immediateItemResult, recurringResult]
57
- )
58
- XCTAssertEqual(
59
- result.merchantId,
60
- TestFixtures.MERCHANT_ID
61
- )
62
- XCTAssertEqual(
63
- result.merchantCountryCode,
64
- TestFixtures.COUNTRY_CODE
65
- )
66
- }
67
-
68
- func test_createDeferredPaymentSummaryItem() throws {
69
- let result = try ApplePayUtils.createDeferredPaymentSummaryItem(item: TestFixtures.DEFERRED_CART_ITEM_DICTIONARY)
70
-
71
- let expectedResult = PKDeferredPaymentSummaryItem(label: "deferred label", amount: 1.00)
72
- expectedResult.deferredDate = Date(timeIntervalSince1970: 123456789)
73
-
74
- XCTAssertEqual(
75
- result,
76
- expectedResult
77
- )
78
- }
79
-
80
- func test_createRecurringPaymentSummaryItem() throws {
81
- let result = try ApplePayUtils.createRecurringPaymentSummaryItem(item: TestFixtures.RECURRING_CART_ITEM_DICTIONARY)
82
-
83
- let expectedResult = PKRecurringPaymentSummaryItem(label: "recurring label", amount: 1.00)
84
- expectedResult.intervalUnit = .minute
85
- expectedResult.intervalCount = 2
86
- expectedResult.startDate = Date(timeIntervalSince1970: 123456789)
87
- expectedResult.endDate = Date(timeIntervalSince1970: 234567890)
88
-
89
- XCTAssertEqual(
90
- result,
91
- expectedResult
92
- )
93
- }
94
-
95
- func test_createRecurringPaymentSummaryItem_withUnexpectedIntervalUnit_fails() throws {
96
- XCTAssertThrowsError(
97
- try ApplePayUtils.createRecurringPaymentSummaryItem(item: [
98
- "paymentType":"Recurring",
99
- "intervalUnit": "decade",
100
- "intervalCount": 1,
101
- ] as [String : Any])
102
- ) { error in
103
- XCTAssertEqual(
104
- error as! ApplePayUtilsError, ApplePayUtilsError.invalidTimeInterval("decade")
105
- )
106
- }
107
-
108
- XCTAssertThrowsError(
109
- try ApplePayUtils.createRecurringPaymentSummaryItem(item: [
110
- "paymentType":"Recurring",
111
- "intervalCount": 1,
112
- ] as [String : Any])
113
- ) { error in
114
- XCTAssertEqual(
115
- error as! ApplePayUtilsError, ApplePayUtilsError.invalidTimeInterval("null")
116
- )
117
- }
118
- }
119
-
120
- func test_createImmediatePaymentSummaryItem() throws {
121
- let result = ApplePayUtils.createImmediatePaymentSummaryItem(item: TestFixtures.IMMEDIATE_CART_ITEM_DICTIONARY_NOT_PENDING)
122
-
123
- let expectedResult = PKPaymentSummaryItem(label: "immediate label", amount: 2.00, type: .final)
124
-
125
- XCTAssertEqual(
126
- result,
127
- expectedResult
128
- )
129
- }
130
-
131
- func test_buildPaymentSummaryItems() throws {
132
- let result = try ApplePayUtils.buildPaymentSummaryItems(items: TestFixtures.CART_ITEM_DICTIONARY)
133
- let deferredItemResult = PKDeferredPaymentSummaryItem(label: "deferred label", amount: 1.00)
134
- deferredItemResult.deferredDate = Date(timeIntervalSince1970: 123456789)
135
- let immediateItemResult = PKPaymentSummaryItem(label: "immediate label", amount: 2.00, type: .pending)
136
- let recurringResult = PKRecurringPaymentSummaryItem(label: "recurring label", amount: 1.00)
137
- recurringResult.intervalUnit = .minute
138
- recurringResult.intervalCount = 2
139
- recurringResult.startDate = Date(timeIntervalSince1970: 123456789)
140
- recurringResult.endDate = Date(timeIntervalSince1970: 234567890)
141
-
142
- XCTAssertEqual(
143
- result,
144
- [deferredItemResult, immediateItemResult, recurringResult]
145
- )
146
- }
147
-
148
- func test_buildPaymentSummaryItems_unexpectedType_fails() throws {
149
- XCTAssertThrowsError(
150
- try ApplePayUtils.buildPaymentSummaryItems(items: [[
151
- "paymentType":"wrong type",
152
- ]] as [[String : Any]])
153
- ) { error in
154
- XCTAssertEqual(
155
- error as! ApplePayUtilsError, ApplePayUtilsError.invalidCartSummaryItemType("wrong type")
156
- )
157
- }
158
-
159
- XCTAssertThrowsError(
160
- try ApplePayUtils.buildPaymentSummaryItems(items: [[
161
- "paymentType":"",
162
- ]] as [[String : Any]])
163
- ) { error in
164
- XCTAssertEqual(
165
- error as! ApplePayUtilsError, ApplePayUtilsError.invalidCartSummaryItemType("")
166
- )
167
- }
168
-
169
- XCTAssertThrowsError(
170
- try ApplePayUtils.buildPaymentSummaryItems(items: [[
171
- "label":"my labal",
172
- ]] as [[String : Any]])
173
- ) { error in
174
- XCTAssertEqual(
175
- error as! ApplePayUtilsError, ApplePayUtilsError.invalidCartSummaryItemType("null")
176
- )
177
- }
178
- }
179
-
180
- private struct TestFixtures {
181
- static let MERCHANT_ID = "merchant.com.id"
182
- static let COUNTRY_CODE = "US"
183
- static let DEFERRED_CART_ITEM_DICTIONARY = [
184
- "paymentType":"Deferred",
185
- "deferredDate": 123456789 as NSNumber,
186
- "label": "deferred label",
187
- "amount": "1.00"
188
- ] as [String : Any]
189
- static let RECURRING_CART_ITEM_DICTIONARY = [
190
- "paymentType":"Recurring",
191
- "intervalUnit": "minute",
192
- "intervalCount": 2,
193
- "startDate": 123456789 as NSNumber,
194
- "endDate": 234567890 as NSNumber,
195
- "label": "recurring label",
196
- "amount": "1.00"
197
- ] as [String : Any]
198
- static let IMMEDIATE_CART_ITEM_DICTIONARY = [
199
- "paymentType":"Immediate",
200
- "isPending": true,
201
- "label": "immediate label",
202
- "amount": "2.00"
203
- ] as [String : Any]
204
- static let CART_ITEM_DICTIONARY = [
205
- DEFERRED_CART_ITEM_DICTIONARY, IMMEDIATE_CART_ITEM_DICTIONARY, RECURRING_CART_ITEM_DICTIONARY
206
- ]
207
- static let IMMEDIATE_CART_ITEM_DICTIONARY_NOT_PENDING = [
208
- "paymentType":"Immediate",
209
- "label": "immediate label",
210
- "amount": "2.00"
211
- ] as [String : Any]
212
- }
213
- }
@@ -1,52 +0,0 @@
1
- //
2
- // Tests.swift
3
- // Tests
4
- //
5
- // Created by Charles Cruzan on 6/21/22.
6
- // Copyright © 2022 Facebook. All rights reserved.
7
- //
8
-
9
- import XCTest
10
- @testable import stripe_react_native
11
-
12
- class PushProvisioningTests: XCTestCase {
13
- func testCanAddCardToWalletInTestMode() throws {
14
- PushProvisioningUtils.canAddCardToWallet(last4: "4242",
15
- primaryAccountIdentifier: "",
16
- testEnv: true, hasPairedAppleWatch: false) { canAddCard, status in
17
- XCTAssertEqual(canAddCard, true)
18
- XCTAssertEqual(status, nil)
19
- }
20
- }
21
-
22
- func testCanAddCardToWalletInLiveMode() throws {
23
- PushProvisioningUtils.canAddCardToWallet(last4: "4242",
24
- primaryAccountIdentifier: "",
25
- testEnv: false,
26
- hasPairedAppleWatch: false) { canAddCard, status in
27
- XCTAssertEqual(canAddCard, false)
28
- XCTAssertEqual(status, PushProvisioningUtils.AddCardToWalletStatus.MISSING_CONFIGURATION)
29
- }
30
- }
31
-
32
- func testCanAddPaymentPassInTestMode() throws {
33
- XCTAssertEqual(
34
- PushProvisioningUtils.canAddPaymentPass(primaryAccountIdentifier: "", isTestMode: true),
35
- true
36
- )
37
- }
38
-
39
- func testCanAddPaymentPassInLiveMode() throws {
40
- XCTAssertEqual(
41
- PushProvisioningUtils.canAddPaymentPass(primaryAccountIdentifier: "", isTestMode: false),
42
- false
43
- )
44
- }
45
-
46
- func testCheckIfPassExists() throws {
47
- XCTAssertEqual(
48
- PushProvisioningUtils.getPassLocation(last4: "4242"),
49
- nil
50
- )
51
- }
52
- }