Skip to content

Commit

Permalink
feat: add support for paymentMethodOrder (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliecruzan-stripe authored May 24, 2024
1 parent 36d9d3f commit b2369b3
Show file tree
Hide file tree
Showing 22 changed files with 696 additions and 705 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:
jobs:
test-android:
name: e2e-android-test
runs-on: macos-latest
runs-on: macos-13
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: 14.15.0
node-version: 16

- name: Install React Native CLI
run: npm install react-native-cli
Expand All @@ -41,7 +41,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Gradle cache
uses: actions/cache@v2
Expand Down Expand Up @@ -72,10 +72,10 @@ jobs:
test-ios:
name: e2e-ios-test
runs-on: macos-latest
runs-on: macos-13
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -99,7 +99,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: 14.15.0
node-version: 16

- name: Install React Native CLI
run: npm install react-native-cli
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -27,7 +27,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: 14.15.0
node-version: 16

- name: Install Dependencies
run: |
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ on:
jobs:
test-ios:
name: unit-test-ios
runs-on: macos-12
runs-on: macos-13
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: 14.15.0
node-version: 16

- name: Install React Native CLI
run: npm install react-native-cli
Expand All @@ -49,10 +49,10 @@ jobs:

test-android:
name: unit-test-android
runs-on: macos-latest
runs-on: macos-13
steps:
- name: checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -69,7 +69,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/[email protected]
with:
node-version: 14.15.0
node-version: 16

- name: Install React Native CLI
run: npm install react-native-cli
Expand All @@ -81,7 +81,7 @@ jobs:
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '11'
java-version: '17'

- name: Gradle cache
uses: actions/cache@v2
Expand Down
17 changes: 11 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@

## Unreleased

**Features**

- Adds support for `paymentMethodOrder` in PaymentSheet, which provides client side sorting of payment methods.
- Updated `stripe-android` to 20.44.\*

## 0.37.3 - 2024-04-19

**Fixes**

- Fixed an issue with generating App Privacy reports.
- Updated `stripe-ios` to 23.27.*
- Updated `stripe-android` to 20.41.*
- Updated `stripe-ios` to 23.27.\*
- Updated `stripe-android` to 20.41.\*

## 0.37.2 - 2024-04-02

**Fixes**

- Updated `stripe-ios` to 23.26.*
- Updated `stripe-android` to 20.40.*
- Updated `stripe-ios` to 23.26.\*
- Updated `stripe-android` to 20.40.\*

## 0.37.1 - 2024-03-15

**Fixes**

- Updated `stripe-ios` to 23.25.*
- Updated `stripe-android` to 20.39.*
- Updated `stripe-ios` to 23.25.\*
- Updated `stripe-android` to 20.39.\*

## 0.37.0 - 2024-02-16

Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0'

// play-services-wallet is already included in stripe-android
compileOnly "com.google.android.gms:play-services-wallet:19.2.0"
compileOnly "com.google.android.gms:play-services-wallet:19.3.0"

// Users need to declare this dependency on their own, otherwise all methods are a no-op
compileOnly 'com.stripe:stripe-android-issuing-push-provisioning:1.1.0'
Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
StripeSdk_kotlinVersion=1.8.0
# Keep StripeSdk_stripeVersion in sync with https://github.com/stripe/stripe-identity-react-native/blob/main/android/gradle.properties
StripeSdk_stripeVersion=20.41.+
StripeSdk_stripeVersion=20.44.+
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ class PaymentLauncherFragment(
StripeIntent.NextActionType.DisplayOxxoDetails,
StripeIntent.NextActionType.DisplayBoletoDetails,
StripeIntent.NextActionType.DisplayKonbiniDetails,
StripeIntent.NextActionType.VerifyWithMicrodeposits -> true
StripeIntent.NextActionType.VerifyWithMicrodeposits,
StripeIntent.NextActionType.DisplayMultibancoDetails -> true
StripeIntent.NextActionType.RedirectToUrl,
StripeIntent.NextActionType.UseStripeSdk,
StripeIntent.NextActionType.AlipayRedirect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ import com.reactnativestripesdk.addresssheet.AddressSheetView
import com.reactnativestripesdk.utils.*
import com.reactnativestripesdk.utils.createError
import com.reactnativestripesdk.utils.createResult
import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
import com.stripe.android.paymentsheet.*
import kotlinx.coroutines.CompletableDeferred
import java.io.ByteArrayOutputStream
import kotlin.Exception

@OptIn(ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
class PaymentSheetFragment(
private val context: ReactApplicationContext,
private val initPromise: Promise
Expand Down Expand Up @@ -67,6 +69,8 @@ class PaymentSheetFragment(
val allowsDelayedPaymentMethods = arguments?.getBoolean("allowsDelayedPaymentMethods")
val billingDetailsBundle = arguments?.getBundle("defaultBillingDetails")
val billingConfigParams = arguments?.getBundle("billingDetailsCollectionConfiguration")
val paymentMethodOrder = arguments?.getStringArrayList("paymentMethodOrder")
val allowsRemovalOfLastSavedPaymentMethod = arguments?.getBoolean("allowsRemovalOfLastSavedPaymentMethod")
paymentIntentClientSecret = arguments?.getString("paymentIntentClientSecret").orEmpty()
setupIntentClientSecret = arguments?.getString("setupIntentClientSecret").orEmpty()
intentConfiguration = try {
Expand Down Expand Up @@ -181,22 +185,29 @@ class PaymentSheetFragment(
billingDetailsBundle.getString("name"),
billingDetailsBundle.getString("phone"))
}
val configurationBuilder = PaymentSheet.Configuration.Builder(merchantDisplayName)
.allowsDelayedPaymentMethods(allowsDelayedPaymentMethods ?: false)
.defaultBillingDetails(defaultBillingDetails)
.customer(
if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) PaymentSheet.CustomerConfiguration(
id = customerId,
ephemeralKeySecret = customerEphemeralKeySecret
) else null
)
.googlePay(googlePayConfig)
.appearance(appearance)
.shippingDetails(shippingDetails)
.billingDetailsCollectionConfiguration(billingDetailsConfig)
.preferredNetworks(mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks")))
.allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod ?: true)
primaryButtonLabel?.let {
configurationBuilder.primaryButtonLabel(it)
}
paymentMethodOrder?.let {
configurationBuilder.paymentMethodOrder(it)
}

paymentSheetConfiguration = PaymentSheet.Configuration(
merchantDisplayName = merchantDisplayName,
allowsDelayedPaymentMethods = allowsDelayedPaymentMethods ?: false,
defaultBillingDetails=defaultBillingDetails,
customer = if (customerId.isNotEmpty() && customerEphemeralKeySecret.isNotEmpty()) PaymentSheet.CustomerConfiguration(
id = customerId,
ephemeralKeySecret = customerEphemeralKeySecret
) else null,
googlePay = googlePayConfig,
appearance = appearance,
shippingDetails = shippingDetails,
primaryButtonLabel = primaryButtonLabel,
billingDetailsCollectionConfiguration = billingDetailsConfig,
preferredNetworks = mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks"))
)
paymentSheetConfiguration = configurationBuilder.build()

if (arguments?.getBoolean("customFlow") == true) {
flowController = if (intentConfiguration != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.fragment.app.Fragment
import com.facebook.react.bridge.*
import com.reactnativestripesdk.customersheet.ReactNativeCustomerAdapter
import com.reactnativestripesdk.utils.*
import com.stripe.android.ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi
import com.stripe.android.customersheet.CustomerAdapter
import com.stripe.android.customersheet.CustomerEphemeralKey
import com.stripe.android.customersheet.CustomerSheet
Expand All @@ -28,7 +29,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch


@OptIn(ExperimentalCustomerSheetApi::class)
@OptIn(ExperimentalCustomerSheetApi::class, ExperimentalAllowsRemovalOfLastSavedPaymentMethodApi::class)
class CustomerSheetFragment : Fragment() {
private var customerSheet: CustomerSheet? = null
internal var customerAdapter: ReactNativeCustomerAdapter? = null
Expand Down Expand Up @@ -67,7 +68,8 @@ class CustomerSheetFragment : Fragment() {
val customerId = arguments?.getString("customerId")
val customerEphemeralKeySecret = arguments?.getString("customerEphemeralKeySecret")
val customerAdapterOverrideParams = arguments?.getBundle("customerAdapter")

val allowsRemovalOfLastSavedPaymentMethod = arguments?.getBoolean("allowsRemovalOfLastSavedPaymentMethod")
val paymentMethodOrder = arguments?.getStringArrayList("paymentMethodOrder")
if (customerId == null) {
initPromise.resolve(createError(ErrorType.Failed.toString(), "You must provide a value for `customerId`"))
return
Expand All @@ -89,7 +91,11 @@ class CustomerSheetFragment : Fragment() {
.googlePayEnabled(googlePayEnabled)
.headerTextForSelectionScreen(headerTextForSelectionScreen)
.preferredNetworks(mapToPreferredNetworks(arguments?.getIntegerArrayList("preferredNetworks")))
.allowsRemovalOfLastSavedPaymentMethod(allowsRemovalOfLastSavedPaymentMethod ?: true)

paymentMethodOrder?.let {
configuration.paymentMethodOrder(it)
}
billingDetailsBundle?.let {
configuration.defaultBillingDetails(createDefaultBillingDetails(billingDetailsBundle))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,12 @@ internal fun mapNextAction(type: NextActionType?, data: NextActionData?): Writab
nextActionMap.putString("mobileAuthUrl", it.mobileAuthUrl)
}
}
NextActionType.DisplayMultibancoDetails -> {
(data as? NextActionData.DisplayMultibancoDetails)?.let {
nextActionMap.putString("type", "multibanco")
nextActionMap.putString("voucherURL", it.hostedVoucherUrl)
}
}
}
return nextActionMap
}
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ target 'StripeSdkExample' do
production: production,
hermes_enabled: flags[:hermes_enabled],
fabric_enabled: flags[:fabric_enabled],
flipper_configuration: FlipperConfiguration.enabled,
# flipper_configuration: FlipperConfiguration.enabled,
# An absolute path to your application root.
app_path: "#{Pod::Config.instance.installation_root}/.."
)
Expand Down
Loading

0 comments on commit b2369b3

Please sign in to comment.