Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with Stripe React Native 0.38.0 #1799

Merged
merged 7 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Loading