Skip to content

Commit

Permalink
Sync with Stripe React Native 0.38.0 (#1799)
Browse files Browse the repository at this point in the history
* Sync with Stripe React Native 0.38.0

* fix #1795

* feat: sync dart layer with 0.38 sdk

* fix: #1796 incorrect refurrel for recurring apple pay payments

* fix #1802 incorrect type for preferredNetwork

* fix #1753 make sure that it is clear that enablepostal code only works for android

---------

Co-authored-by: Remon <[email protected]>
  • Loading branch information
jonasbark and Remon authored Jun 21, 2024
1 parent 528dac4 commit 2a0928b
Show file tree
Hide file tree
Showing 47 changed files with 855 additions and 420 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,15 @@ class _PaymentSheetScreenState extends State<ApplePayPaymentSheetScreen> {
request: PaymentRequestType.recurring(
description: 'subscription',
managementUrl: 'https://flutter.dev',
billing: ImmediateCartSummaryItem(
billing: RecurringCartSummaryItem(
label: 'Subscription',
amount: '10.0',
isPending: false,
intervalCount: 12,
intervalUnit: ApplePayIntervalUnit.month,
startDate: DateTime.now().millisecondsSinceEpoch,
endDate: DateTime.now()
.add(Duration(days: 365))
.millisecondsSinceEpoch,
),
),
),
Expand Down
4 changes: 3 additions & 1 deletion packages/stripe/lib/src/widgets/card_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class CardFormField extends StatefulWidget {
/// Defaults is `true`. If your configuration in Stripe requires a postalcode
/// check as defined in https://stripe.com/docs/radar/rules#traditional-bank-checks
/// make sure this one is set to `true`.
///
/// This is only supported on android
final bool enablePostalCode;

/// Android only: Controls the postal code entry shown (when `enablePostalCode` is set to true).
Expand Down Expand Up @@ -217,7 +219,7 @@ class _MethodChannelCardFormField extends StatefulWidget {
Key? key,
this.onFocus,
this.style,
this.enablePostalCode = false,
this.enablePostalCode = true,
double? width,
double? height,
BoxConstraints? constraints,
Expand Down
4 changes: 2 additions & 2 deletions packages/stripe_android/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.8.0'
ext.stripe_version = '20.41.+'
ext.stripe_version = '20.44.+'

repositories {
google()
Expand Down Expand Up @@ -60,7 +60,7 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'

// 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
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

Check warning on line 288 in packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/PaymentLauncherFragment.kt

View workflow job for this annotation

GitHub Actions / Typo CI

DisplayMultibancoDetails

"DisplayMultibancoDetails" is a typo. Did you mean "DisplayMultifunctionDetails"?
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 -> {

Check warning on line 516 in packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/utils/Mappers.kt

View workflow job for this annotation

GitHub Actions / Typo CI

DisplayMultibancoDetails

"DisplayMultibancoDetails" is a typo. Did you mean "DisplayMultifunctionDetails"?
(data as? NextActionData.DisplayMultibancoDetails)?.let {

Check warning on line 517 in packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/utils/Mappers.kt

View workflow job for this annotation

GitHub Actions / Typo CI

DisplayMultibancoDetails

"DisplayMultibancoDetails" is a typo. Did you mean "DisplayMultifunctionDetails"?
nextActionMap.putString("type", "multibanco")

Check warning on line 518 in packages/stripe_android/android/src/main/kotlin/com/reactnativestripesdk/utils/Mappers.kt

View workflow job for this annotation

GitHub Actions / Typo CI

multibanco

"multibanco" is a typo. Did you mean "multifunction"?
nextActionMap.putString("voucherURL", it.hostedVoucherUrl)
}
}
}
return nextActionMap
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
@_spi(PrivateBetaCustomerSheet) import StripePaymentSheet
@_spi(PrivateBetaCustomerSheet) @_spi(STP) import StripePaymentSheet

class CustomerSheetUtils {
internal class func buildCustomerSheetConfiguration(
Expand All @@ -19,7 +19,8 @@ class CustomerSheetUtils {
merchantDisplayName: String?,
billingDetailsCollectionConfiguration: NSDictionary?,
defaultBillingDetails: NSDictionary?,
preferredNetworks: Array<Int>?
preferredNetworks: Array<Int>?,
allowsRemovalOfLastSavedPaymentMethod: Bool?
) -> CustomerSheet.Configuration {
var config = CustomerSheet.Configuration()
config.appearance = appearance
Expand Down Expand Up @@ -54,6 +55,9 @@ class CustomerSheetUtils {
state: address["state"])
}
}
if let allowsRemovalOfLastSavedPaymentMethod = allowsRemovalOfLastSavedPaymentMethod {
config.allowsRemovalOfLastSavedPaymentMethod = allowsRemovalOfLastSavedPaymentMethod
}
return config
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ extension StripeSdk {
merchantDisplayName: params["merchantDisplayName"] as? String,
billingDetailsCollectionConfiguration: params["billingDetailsCollectionConfiguration"] as? NSDictionary,
defaultBillingDetails: params["defaultBillingDetails"] as? NSDictionary,
preferredNetworks: params["preferredNetworks"] as? Array<Int>
preferredNetworks: params["preferredNetworks"] as? Array<Int>,
allowsRemovalOfLastSavedPaymentMethod: params["allowsRemovalOfLastSavedPaymentMethod"] as? Bool
)
} catch {
resolve(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
import StripePaymentSheet
@_spi(ExperimentalAllowsRemovalOfLastSavedPaymentMethodAPI) @_spi(STP) import StripePaymentSheet

extension StripeSdk {
internal func buildPaymentSheetConfiguration(
Expand Down Expand Up @@ -103,6 +103,14 @@ extension StripeSdk {
configuration.preferredNetworks = preferredNetworksAsInts.map(Mappers.intToCardBrand).compactMap { $0 }
}

if let allowsRemovalOfLastSavedPaymentMethod = params["allowsRemovalOfLastSavedPaymentMethod"] as? Bool {
configuration.allowsRemovalOfLastSavedPaymentMethod = allowsRemovalOfLastSavedPaymentMethod
}

if let paymentMethodOrder = params["paymentMethodOrder"] as? Array<String> {
configuration.paymentMethodOrder = paymentMethodOrder
}

return (nil, configuration)
}

Expand Down
2 changes: 2 additions & 0 deletions packages/stripe_ios/ios/Classes/StripePlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ class StripePlugin: StripeSdk, FlutterPlugin, ViewManagerDelegate {
resolver: resolver(for: result),
rejecter: rejecter(for: result)
)
case "handleNextActionForSetupIntent":
return handleNextActionForSetupIntent(call, result: result)
default:
result(FlutterMethodNotImplemented)
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ class ApplePayCartSummaryItem with _$ApplePayCartSummaryItem {

/// The unix timestamp of the start date. Measured in seconds.
int? startDate,

////The unix timestamp of the end date. Measured in seconds. */
int? number,
int? endDate,
}) = RecurringCartSummaryItem;

factory ApplePayCartSummaryItem.fromJson(Map<String, dynamic> json) =>
Expand Down
Loading

0 comments on commit 2a0928b

Please sign in to comment.