Skip to content

Commit

Permalink
Sync with Stripe React Native 0.27.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbark committed Apr 22, 2023
1 parent 5bdbe30 commit 77c98c6
Show file tree
Hide file tree
Showing 19 changed files with 94 additions and 16 deletions.
2 changes: 1 addition & 1 deletion 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.20.0, 20.22.0['
ext.stripe_version = '20.23.+'

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class PaymentSheetFragment(
val googlePayConfig = buildGooglePayConfig(arguments?.getBundle("googlePay"))
val allowsDelayedPaymentMethods = arguments?.getBoolean("allowsDelayedPaymentMethods")
val billingDetailsBundle = arguments?.getBundle("defaultBillingDetails")
val billingConfigParams = arguments?.getBundle("billingDetailsCollectionConfiguration")
paymentIntentClientSecret = arguments?.getString("paymentIntentClientSecret").orEmpty()
setupIntentClientSecret = arguments?.getString("setupIntentClientSecret").orEmpty()
val appearance = try {
Expand Down Expand Up @@ -119,6 +120,15 @@ class PaymentSheetFragment(
}
}

val billingDetailsConfig = PaymentSheet.BillingDetailsCollectionConfiguration(
name = mapToCollectionMode(billingConfigParams?.getString("name")),
phone = mapToCollectionMode(billingConfigParams?.getString("phone")),
email = mapToCollectionMode(billingConfigParams?.getString("email")),
address = mapToAddressCollectionMode(billingConfigParams?.getString("address")),
attachDefaultsToPaymentMethod = billingConfigParams?.getBoolean("attachDefaultsToPaymentMethod")
?: false
)

var defaultBillingDetails: PaymentSheet.BillingDetails? = null
if (billingDetailsBundle != null) {
val addressBundle = billingDetailsBundle.getBundle("address")
Expand Down Expand Up @@ -147,7 +157,8 @@ class PaymentSheetFragment(
googlePay = googlePayConfig,
appearance = appearance,
shippingDetails = shippingDetails,
primaryButtonLabel = primaryButtonLabel
primaryButtonLabel = primaryButtonLabel,
billingDetailsCollectionConfiguration = billingDetailsConfig
)

if (arguments?.getBoolean("customFlow") == true) {
Expand Down Expand Up @@ -300,3 +311,21 @@ fun getBase64FromBitmap(bitmap: Bitmap?): String? {
val imageBytes: ByteArray = stream.toByteArray()
return Base64.encodeToString(imageBytes, Base64.DEFAULT)
}

fun mapToCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode {
return when (str) {
"automatic" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
"never" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Never
"always" -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Always
else -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic
}
}

fun mapToAddressCollectionMode(str: String?): PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode {
return when (str) {
"automatic" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
"never" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Never
"full" -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Full
else -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ internal fun mapFromPaymentMethod(paymentMethod: PaymentMethod): WritableMap {
it.putString("fingerprint", paymentMethod.card?.fingerprint)
it.putString("preferredNetwork", paymentMethod.card?.networks?.preferred)
it.putArray("availableNetworks", paymentMethod.card?.networks?.available?.toList() as? ReadableArray)
it.putMap("threeDSecureUsage", WritableNativeMap().also { threeDSecureUsageMap ->
threeDSecureUsageMap.putBoolean("isSupported", paymentMethod.card?.threeDSecureUsage?.isSupported ?: false)
})
})
pm.putMap("SepaDebit", WritableNativeMap().also {
it.putString("bankCode", paymentMethod.sepaDebit?.bankCode)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#e0ffffff">
<item
android:drawable="@drawable/googlepay_button_background_image" />
</ripple>

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#e0ffffff">
<item
android:drawable="@drawable/googlepay_button_no_shadow_background_image" />
</ripple>

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<size android:width="270dp" android:height="49dp"/>
<solid android:color="#000"/>
<stroke android:color="#747775" android:width="1dp"/>
<corners android:radius="24dp"/>
</shape>
</item>
</layer-list>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/googlepay_button_background_image" />
</selector>
9 changes: 6 additions & 3 deletions packages/stripe_ios/ios/Classes/Stripe Sdk/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class Mappers {
"isPending": shippingMethod.type == .pending,
"label": shippingMethod.label
]

if #available(iOS 15.0, *) {
if let dateComponentsRange = shippingMethod.dateComponentsRange {
method.setObject(
Expand Down Expand Up @@ -612,8 +612,11 @@ class Mappers {
"last4": paymentMethod.card?.last4 ?? NSNull(),
"preferredNetwork": paymentMethod.card?.networks?.preferred ?? NSNull(),
"availableNetworks": paymentMethod.card?.networks?.available ?? NSNull(),
"threeDSecureUsage": [
"isSupported": paymentMethod.card?.threeDSecureUsage?.supported ?? false
],
]

let sepaDebit: NSDictionary = [
"bankCode": paymentMethod.sepaDebit?.bankCode ?? NSNull(),
"country": paymentMethod.sepaDebit?.country ?? NSNull(),
Expand Down Expand Up @@ -950,7 +953,7 @@ class Mappers {
}
return nil
}

class func convertDateToUnixTimestampSeconds(date: Date?) -> String? {
if let date = date {
let value = date.timeIntervalSince1970
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ extension StripeSdk {
if let allowsDelayedPaymentMethods = params["allowsDelayedPaymentMethods"] as? Bool {
configuration.allowsDelayedPaymentMethods = allowsDelayedPaymentMethods
}

if let billingConfigParams = params["billingDetailsCollectionConfiguration"] as? [String: Any?] {
configuration.billingDetailsCollectionConfiguration.name = StripeSdk.mapToCollectionMode(str: billingConfigParams["name"] as? String)
configuration.billingDetailsCollectionConfiguration.phone = StripeSdk.mapToCollectionMode(str: billingConfigParams["phone"] as? String)
configuration.billingDetailsCollectionConfiguration.email = StripeSdk.mapToCollectionMode(str: billingConfigParams["email"] as? String)
configuration.billingDetailsCollectionConfiguration.address = StripeSdk.mapToAddressCollectionMode(str: billingConfigParams["address"] as? String)
configuration.billingDetailsCollectionConfiguration.attachDefaultsToPaymentMethod = billingConfigParams["attachDefaultsToPaymentMethod"] as? Bool == true
}

if let defaultBillingDetails = params["defaultBillingDetails"] as? [String: Any?] {
configuration.defaultBillingDetails.name = defaultBillingDetails["name"] as? String
Expand Down Expand Up @@ -163,4 +171,31 @@ extension StripeSdk {
}
})
}

private static func mapToCollectionMode(str: String?) -> PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode {
switch str {
case "automatic":
return .automatic
case "never":
return .never
case "always":
return .always
default:
return .automatic
}
}

private static func mapToAddressCollectionMode(str: String?) -> PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode {
switch str {
case "automatic":
return .automatic
case "never":
return .never
case "full":
return .full
default:
return .automatic
}
}
}

2 changes: 1 addition & 1 deletion packages/stripe_ios/ios/stripe_ios.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html.
# Run `pod lib lint stripe_ios.podspec' to validate before publishing.
#
stripe_version = '~> 23.5.0'
stripe_version = '23.6.0'
Pod::Spec.new do |s|
s.name = 'stripe_ios'
s.version = '0.0.1'
Expand Down

0 comments on commit 77c98c6

Please sign in to comment.