@stripe/stripe-react-native 0.70.0 → 0.72.0
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/android/gradle.properties +1 -1
- package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementView.kt +7 -103
- package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorElementViewManager.kt +1 -5
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementView.kt +0 -26
- package/android/src/main/java/com/reactnativestripesdk/EmbeddedPaymentElementViewManager.kt +6 -21
- package/android/src/main/java/com/reactnativestripesdk/LinkControllerManager.kt +59 -18
- package/android/src/main/java/com/reactnativestripesdk/PaymentMethodCreateParamsFactory.kt +22 -0
- package/android/src/main/java/com/reactnativestripesdk/PaymentSheetManager.kt +6 -50
- package/android/src/main/java/com/reactnativestripesdk/StripeSdkModule.kt +38 -187
- package/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt +4 -0
- package/android/src/oldarch/java/com/reactnativestripesdk/NativeStripeSdkModuleSpec.java +4 -0
- package/android/src/onramp/java/com/reactnativestripesdk/OnrampMappers.kt +1 -0
- package/android/src/test/java/com/reactnativestripesdk/mappers/MappersTest.kt +10 -60
- package/ios/CurrencySelectorElementView.swift +18 -129
- package/ios/Mappers.swift +4 -0
- package/ios/PaymentMethodFactory.swift +22 -0
- package/ios/StripeSdk.mm +7 -0
- package/ios/StripeSdkImpl+Checkout.swift +35 -259
- package/ios/StripeSdkImpl+Embedded.swift +5 -28
- package/ios/StripeSdkImpl+LinkController.swift +40 -2
- package/ios/StripeSdkImpl+PaymentSheet.swift +2 -15
- package/ios/StripeSdkImpl.swift +2 -4
- package/lib/commonjs/components/AddToWalletButton.js +1 -1
- package/lib/commonjs/components/AddToWalletButton.js.map +1 -1
- package/lib/commonjs/components/AddressSheet.js +1 -1
- package/lib/commonjs/components/AddressSheet.js.map +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js +1 -1
- package/lib/commonjs/components/AuBECSDebitForm.js.map +1 -1
- package/lib/commonjs/components/CardField.js +1 -1
- package/lib/commonjs/components/CardField.js.map +1 -1
- package/lib/commonjs/components/CardForm.js +1 -1
- package/lib/commonjs/components/CardForm.js.map +1 -1
- package/lib/commonjs/components/CurrencySelectorElement.js +1 -1
- package/lib/commonjs/components/CurrencySelectorElement.js.map +1 -1
- package/lib/commonjs/components/PaymentMethodMessagingElement.js +1 -1
- package/lib/commonjs/components/PaymentMethodMessagingElement.js.map +1 -1
- package/lib/commonjs/components/PlatformPayButton.js +1 -1
- package/lib/commonjs/components/PlatformPayButton.js.map +1 -1
- package/lib/commonjs/components/StripeContainer.js +1 -1
- package/lib/commonjs/components/StripeContainer.js.map +1 -1
- package/lib/commonjs/connect/Components.js +1 -1
- package/lib/commonjs/connect/Components.js.map +1 -1
- package/lib/commonjs/connect/ConnectComponentsProvider.js +1 -1
- package/lib/commonjs/connect/ConnectComponentsProvider.js.map +1 -1
- package/lib/commonjs/connect/EmbeddedComponent.js +2 -2
- package/lib/commonjs/connect/EmbeddedComponent.js.map +1 -1
- package/lib/commonjs/connect/ModalCloseButton.js +1 -1
- package/lib/commonjs/connect/ModalCloseButton.js.map +1 -1
- package/lib/commonjs/connect/NavigationBar.js +1 -1
- package/lib/commonjs/connect/NavigationBar.js.map +1 -1
- package/lib/commonjs/functions.js +1 -1
- package/lib/commonjs/functions.js.map +1 -1
- package/lib/commonjs/helpers.js +1 -1
- package/lib/commonjs/hooks/useLinkController.js +1 -1
- package/lib/commonjs/hooks/useLinkController.js.map +1 -1
- package/lib/commonjs/specs/NativeAddToWalletButton.js +1 -1
- package/lib/commonjs/specs/NativeAddressSheet.js +1 -1
- package/lib/commonjs/specs/NativeApplePayButton.js +1 -1
- package/lib/commonjs/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/commonjs/specs/NativeCardField.js +1 -1
- package/lib/commonjs/specs/NativeCardField.js.map +1 -1
- package/lib/commonjs/specs/NativeCardForm.js +1 -1
- package/lib/commonjs/specs/NativeCardForm.js.map +1 -1
- package/lib/commonjs/specs/NativeConnectAccountOnboardingView.js +1 -1
- package/lib/commonjs/specs/NativeCurrencySelectorElement.js +1 -1
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/specs/NativeGooglePayButton.js +1 -1
- package/lib/commonjs/specs/NativeNavigationBar.js +1 -1
- package/lib/commonjs/specs/NativePaymentMethodMessagingElement.js +1 -1
- package/lib/commonjs/specs/NativeStripeContainer.js +1 -1
- package/lib/commonjs/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.js +1 -1
- package/lib/commonjs/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/commonjs/types/PaymentIntent.js.map +1 -1
- package/lib/module/components/AddToWalletButton.js +1 -1
- package/lib/module/components/AddToWalletButton.js.map +1 -1
- package/lib/module/components/AddressSheet.js +1 -1
- package/lib/module/components/AddressSheet.js.map +1 -1
- package/lib/module/components/AuBECSDebitForm.js +1 -1
- package/lib/module/components/AuBECSDebitForm.js.map +1 -1
- package/lib/module/components/CardField.js +1 -1
- package/lib/module/components/CardField.js.map +1 -1
- package/lib/module/components/CardForm.js +1 -1
- package/lib/module/components/CardForm.js.map +1 -1
- package/lib/module/components/CurrencySelectorElement.js +1 -1
- package/lib/module/components/CurrencySelectorElement.js.map +1 -1
- package/lib/module/components/PaymentMethodMessagingElement.js +1 -1
- package/lib/module/components/PaymentMethodMessagingElement.js.map +1 -1
- package/lib/module/components/PlatformPayButton.js +1 -1
- package/lib/module/components/PlatformPayButton.js.map +1 -1
- package/lib/module/components/StripeContainer.js +1 -1
- package/lib/module/components/StripeContainer.js.map +1 -1
- package/lib/module/connect/Components.js +1 -1
- package/lib/module/connect/Components.js.map +1 -1
- package/lib/module/connect/ConnectComponentsProvider.js +1 -1
- package/lib/module/connect/ConnectComponentsProvider.js.map +1 -1
- package/lib/module/connect/EmbeddedComponent.js +2 -2
- package/lib/module/connect/EmbeddedComponent.js.map +1 -1
- package/lib/module/connect/ModalCloseButton.js +1 -1
- package/lib/module/connect/ModalCloseButton.js.map +1 -1
- package/lib/module/connect/NavigationBar.js +1 -1
- package/lib/module/connect/NavigationBar.js.map +1 -1
- package/lib/module/functions.js +1 -1
- package/lib/module/functions.js.map +1 -1
- package/lib/module/helpers.js +1 -1
- package/lib/module/hooks/useLinkController.js +1 -1
- package/lib/module/hooks/useLinkController.js.map +1 -1
- package/lib/module/specs/NativeAddToWalletButton.js +1 -1
- package/lib/module/specs/NativeAddressSheet.js +1 -1
- package/lib/module/specs/NativeApplePayButton.js +1 -1
- package/lib/module/specs/NativeAuBECSDebitForm.js +1 -1
- package/lib/module/specs/NativeCardField.js +1 -1
- package/lib/module/specs/NativeCardField.js.map +1 -1
- package/lib/module/specs/NativeCardForm.js +1 -1
- package/lib/module/specs/NativeCardForm.js.map +1 -1
- package/lib/module/specs/NativeConnectAccountOnboardingView.js +1 -1
- package/lib/module/specs/NativeCurrencySelectorElement.js +1 -1
- package/lib/module/specs/NativeEmbeddedPaymentElement.js +1 -1
- package/lib/module/specs/NativeEmbeddedPaymentElement.js.map +1 -1
- package/lib/module/specs/NativeGooglePayButton.js +1 -1
- package/lib/module/specs/NativeNavigationBar.js +1 -1
- package/lib/module/specs/NativePaymentMethodMessagingElement.js +1 -1
- package/lib/module/specs/NativeStripeContainer.js +1 -1
- package/lib/module/specs/NativeStripeSdkModule.js.map +1 -1
- package/lib/module/types/EmbeddedPaymentElement.js +1 -1
- package/lib/module/types/EmbeddedPaymentElement.js.map +1 -1
- package/lib/module/types/PaymentIntent.js.map +1 -1
- package/lib/typescript/src/connect/EmbeddedComponent.d.ts +1 -0
- package/lib/typescript/src/connect/EmbeddedComponent.d.ts.map +1 -1
- package/lib/typescript/src/functions.d.ts +11 -0
- package/lib/typescript/src/functions.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useLinkController.d.ts +7 -0
- package/lib/typescript/src/hooks/useLinkController.d.ts.map +1 -1
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts +4 -0
- package/lib/typescript/src/specs/NativeStripeSdkModule.d.ts.map +1 -1
- package/lib/typescript/src/types/LinkController.d.ts +10 -5
- package/lib/typescript/src/types/LinkController.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentIntent.d.ts +17 -1
- package/lib/typescript/src/types/PaymentIntent.d.ts.map +1 -1
- package/lib/typescript/src/types/PaymentMethod.d.ts +1 -1
- package/lib/typescript/src/types/PaymentMethod.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/connect/EmbeddedComponent.tsx +14 -2
- package/src/functions.ts +26 -0
- package/src/hooks/useLinkController.tsx +24 -1
- package/src/specs/NativeStripeSdkModule.ts +5 -0
- package/src/types/LinkController.ts +9 -5
- package/src/types/PaymentIntent.ts +21 -1
- package/src/types/PaymentMethod.ts +1 -0
- package/stripe-react-native.podspec +1 -1
- package/android/.idea/AndroidProjectSystem.xml +0 -6
- package/android/.idea/caches/deviceStreaming.xml +0 -835
- package/android/.idea/compiler.xml +0 -6
- package/android/.idea/gradle.xml +0 -17
- package/android/.idea/migrations.xml +0 -10
- package/android/.idea/misc.xml +0 -10
- package/android/.idea/runConfigurations.xml +0 -17
- package/android/.idea/vcs.xml +0 -6
- package/android/local.properties +0 -8
- package/android/src/main/java/com/reactnativestripesdk/CurrencySelectorAppearance.kt +0 -229
- package/android/src/main/java/com/reactnativestripesdk/utils/CheckoutAddressUpdate.kt +0 -45
- package/android/src/main/java/com/reactnativestripesdk/utils/CheckoutMappers.kt +0 -127
- package/android/src/test/java/com/reactnativestripesdk/CurrencySelectorAppearanceTest.kt +0 -137
- package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutMappersTest.kt +0 -98
- package/android/src/test/java/com/reactnativestripesdk/utils/CheckoutTestFixtures.java +0 -57
- package/ios/CurrencySelectorAppearance.swift +0 -120
- package/ios/Mappers+Checkout.swift +0 -337
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
package com.reactnativestripesdk.utils
|
|
2
|
-
|
|
3
|
-
import com.stripe.android.paymentelement.CheckoutSessionPreview
|
|
4
|
-
import org.junit.Assert.assertEquals
|
|
5
|
-
import org.junit.Assert.assertFalse
|
|
6
|
-
import org.junit.Assert.assertNotNull
|
|
7
|
-
import org.junit.Assert.assertNull
|
|
8
|
-
import org.junit.Test
|
|
9
|
-
import org.junit.runner.RunWith
|
|
10
|
-
import org.robolectric.RobolectricTestRunner
|
|
11
|
-
|
|
12
|
-
@RunWith(RobolectricTestRunner::class)
|
|
13
|
-
@OptIn(CheckoutSessionPreview::class)
|
|
14
|
-
class CheckoutMappersTest {
|
|
15
|
-
@Test
|
|
16
|
-
fun mapFromCheckoutState_mapsLoadedSession() {
|
|
17
|
-
val mapped =
|
|
18
|
-
mapFromCheckoutState(
|
|
19
|
-
isLoading = false,
|
|
20
|
-
session = CheckoutTestFixtures.fullSession(),
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
assertEquals("loaded", mapped.getString("status"))
|
|
24
|
-
|
|
25
|
-
val session = mapped.getMap("session")
|
|
26
|
-
assertNotNull(session)
|
|
27
|
-
assertEquals("cs_test_123", session!!.getString("id"))
|
|
28
|
-
assertFalse(session.getBoolean("livemode"))
|
|
29
|
-
assertEquals("usd", session.getString("currency"))
|
|
30
|
-
|
|
31
|
-
val status = session.getMap("status")
|
|
32
|
-
assertNotNull(status)
|
|
33
|
-
assertEquals("open", status!!.getString("type"))
|
|
34
|
-
|
|
35
|
-
val tax = session.getMap("tax")
|
|
36
|
-
assertNotNull(tax)
|
|
37
|
-
assertEquals("ready", tax!!.getString("status"))
|
|
38
|
-
|
|
39
|
-
val total = session.getMap("total")
|
|
40
|
-
assertNotNull(total)
|
|
41
|
-
val subtotal = total!!.getMap("subtotal")
|
|
42
|
-
assertNotNull(subtotal)
|
|
43
|
-
assertEquals(5000.0, subtotal!!.getDouble("minorUnitsAmount"), 0.0)
|
|
44
|
-
assertEquals("", subtotal.getString("amount"))
|
|
45
|
-
|
|
46
|
-
val grandTotal = total.getMap("total")
|
|
47
|
-
assertNotNull(grandTotal)
|
|
48
|
-
assertEquals(4044.0, grandTotal!!.getDouble("minorUnitsAmount"), 0.0)
|
|
49
|
-
|
|
50
|
-
val lineItems = session.getArray("lineItems")
|
|
51
|
-
assertNotNull(lineItems)
|
|
52
|
-
assertEquals(2, lineItems!!.size())
|
|
53
|
-
assertEquals("li_item1", lineItems.getMap(0)?.getString("id"))
|
|
54
|
-
assertEquals("Llama Figure", lineItems.getMap(0)?.getString("name"))
|
|
55
|
-
assertEquals(2, lineItems.getMap(0)?.getInt("quantity"))
|
|
56
|
-
assertFalse(lineItems.getMap(0)!!.hasKey("unitAmount"))
|
|
57
|
-
|
|
58
|
-
val item2UnitAmount = lineItems.getMap(1)?.getMap("unitAmount")
|
|
59
|
-
assertNotNull(item2UnitAmount)
|
|
60
|
-
assertEquals(2499.0, item2UnitAmount!!.getDouble("minorUnitsAmount"), 0.0)
|
|
61
|
-
|
|
62
|
-
val shippingOptions = session.getArray("shippingOptions")
|
|
63
|
-
assertNotNull(shippingOptions)
|
|
64
|
-
assertEquals(2, shippingOptions!!.size())
|
|
65
|
-
assertEquals("shr_standard", shippingOptions.getMap(0)?.getString("id"))
|
|
66
|
-
val shippingAmount = shippingOptions.getMap(0)?.getMap("amount")
|
|
67
|
-
assertNotNull(shippingAmount)
|
|
68
|
-
assertEquals(500.0, shippingAmount!!.getDouble("minorUnitsAmount"), 0.0)
|
|
69
|
-
|
|
70
|
-
val discountAmounts = session.getArray("discountAmounts")
|
|
71
|
-
assertNotNull(discountAmounts)
|
|
72
|
-
assertEquals(0, discountAmounts!!.size())
|
|
73
|
-
|
|
74
|
-
val currencyOptions = session.getArray("currencyOptions")
|
|
75
|
-
assertNotNull(currencyOptions)
|
|
76
|
-
assertEquals(0, currencyOptions!!.size())
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
@Test
|
|
80
|
-
fun mapFromCheckoutState_mapsLoadingStateAndOmitsBlankCurrency() {
|
|
81
|
-
val mapped =
|
|
82
|
-
mapFromCheckoutState(
|
|
83
|
-
isLoading = true,
|
|
84
|
-
session = CheckoutTestFixtures.blankCurrencySession(),
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
assertEquals("loading", mapped.getString("status"))
|
|
88
|
-
|
|
89
|
-
val session = mapped.getMap("session")
|
|
90
|
-
assertNotNull(session)
|
|
91
|
-
assertEquals("cs_test_blank_currency", session!!.getString("id"))
|
|
92
|
-
assertFalse(session.hasKey("currency"))
|
|
93
|
-
assertNull(session.getMap("total"))
|
|
94
|
-
assertEquals(0, session.getArray("lineItems")!!.size())
|
|
95
|
-
assertEquals(0, session.getArray("shippingOptions")!!.size())
|
|
96
|
-
assertEquals(0, session.getArray("discountAmounts")!!.size())
|
|
97
|
-
}
|
|
98
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
package com.reactnativestripesdk.utils;
|
|
2
|
-
|
|
3
|
-
import com.stripe.android.checkout.CheckoutSession;
|
|
4
|
-
import com.stripe.android.paymentsheet.verticalmode.CurrencySelectorOptions;
|
|
5
|
-
import java.util.Arrays;
|
|
6
|
-
import java.util.Collections;
|
|
7
|
-
|
|
8
|
-
public final class CheckoutTestFixtures {
|
|
9
|
-
private CheckoutTestFixtures() {}
|
|
10
|
-
|
|
11
|
-
public static CheckoutSession fullSession() {
|
|
12
|
-
CheckoutSession.TotalSummary totals =
|
|
13
|
-
new CheckoutSession.TotalSummary(
|
|
14
|
-
5000L,
|
|
15
|
-
4044L,
|
|
16
|
-
4044L,
|
|
17
|
-
Arrays.asList(
|
|
18
|
-
new CheckoutSession.DiscountAmount(500L, "SUMMER10"),
|
|
19
|
-
new CheckoutSession.DiscountAmount(250L, "LOYALTY5")),
|
|
20
|
-
Collections.singletonList(
|
|
21
|
-
new CheckoutSession.TaxAmount(294L, false, "Sales Tax", 6.875d)),
|
|
22
|
-
new CheckoutSession.ShippingRate(
|
|
23
|
-
"shr_standard", 500L, "Standard Shipping", "5-7 business days"),
|
|
24
|
-
null);
|
|
25
|
-
|
|
26
|
-
return new CheckoutSession(
|
|
27
|
-
"cs_test_123",
|
|
28
|
-
CheckoutSession.Status.Open,
|
|
29
|
-
false,
|
|
30
|
-
"usd",
|
|
31
|
-
null,
|
|
32
|
-
new CheckoutSession.Tax(CheckoutSession.Tax.Status.Ready),
|
|
33
|
-
totals,
|
|
34
|
-
Arrays.asList(
|
|
35
|
-
new CheckoutSession.LineItem("li_item1", "Llama Figure", 2, null, 1998L, 1998L),
|
|
36
|
-
new CheckoutSession.LineItem("li_item2", "Alpaca Plushie", 1, 2499L, 2499L, 2499L)),
|
|
37
|
-
Arrays.asList(
|
|
38
|
-
new CheckoutSession.ShippingRate("shr_standard", 500L, "Standard Shipping", null),
|
|
39
|
-
new CheckoutSession.ShippingRate(
|
|
40
|
-
"shr_express", 1500L, "Express Shipping", "1-2 business days")),
|
|
41
|
-
(CurrencySelectorOptions) null);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
public static CheckoutSession blankCurrencySession() {
|
|
45
|
-
return new CheckoutSession(
|
|
46
|
-
"cs_test_blank_currency",
|
|
47
|
-
CheckoutSession.Status.Open,
|
|
48
|
-
false,
|
|
49
|
-
"",
|
|
50
|
-
null,
|
|
51
|
-
new CheckoutSession.Tax(CheckoutSession.Tax.Status.Ready),
|
|
52
|
-
null,
|
|
53
|
-
Collections.<CheckoutSession.LineItem>emptyList(),
|
|
54
|
-
Collections.<CheckoutSession.ShippingRate>emptyList(),
|
|
55
|
-
(CurrencySelectorOptions) null);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// CurrencySelectorAppearance.swift
|
|
3
|
-
// stripe-react-native
|
|
4
|
-
//
|
|
5
|
-
// Created by Nick Porter on 6/24/26.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
@_spi(ReactNativeSDK) import StripePaymentSheet
|
|
9
|
-
import UIKit
|
|
10
|
-
|
|
11
|
-
internal class CurrencySelectorAppearance {
|
|
12
|
-
class func buildAppearanceFromParams(params: NSDictionary?) -> Checkout.CurrencySelectorView.Appearance {
|
|
13
|
-
var appearance = Checkout.CurrencySelectorView.Appearance()
|
|
14
|
-
|
|
15
|
-
guard let params = params else { return appearance }
|
|
16
|
-
|
|
17
|
-
if let background = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.BACKGROUND) {
|
|
18
|
-
appearance.background = background
|
|
19
|
-
}
|
|
20
|
-
if let selectedBackground = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.SELECTED_BACKGROUND) {
|
|
21
|
-
appearance.selectedBackground = selectedBackground
|
|
22
|
-
}
|
|
23
|
-
if let borderColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.BORDER_COLOR) {
|
|
24
|
-
appearance.border = borderColor
|
|
25
|
-
}
|
|
26
|
-
if let textColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.TEXT_COLOR) {
|
|
27
|
-
appearance.text = textColor
|
|
28
|
-
}
|
|
29
|
-
if let selectedTextColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.SELECTED_TEXT_COLOR) {
|
|
30
|
-
appearance.selectedText = selectedTextColor
|
|
31
|
-
}
|
|
32
|
-
if let textSecondaryColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.TEXT_SECONDARY_COLOR) {
|
|
33
|
-
appearance.textSecondary = textSecondaryColor
|
|
34
|
-
}
|
|
35
|
-
if let dangerColor = parseThemedColor(params: params, key: CurrencySelectorAppearanceKeys.DANGER_COLOR) {
|
|
36
|
-
appearance.danger = dangerColor
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if let cornerRadius = params[CurrencySelectorAppearanceKeys.CORNER_RADIUS] as? CGFloat {
|
|
40
|
-
appearance.cornerRadius = cornerRadius
|
|
41
|
-
}
|
|
42
|
-
if let borderWidth = params[CurrencySelectorAppearanceKeys.BORDER_WIDTH] as? CGFloat {
|
|
43
|
-
appearance.borderWidth = borderWidth
|
|
44
|
-
}
|
|
45
|
-
if let contentVerticalPadding = params[CurrencySelectorAppearanceKeys.CONTENT_VERTICAL_PADDING] as? CGFloat {
|
|
46
|
-
appearance.contentVerticalPadding = contentVerticalPadding
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if let fontParams = params[CurrencySelectorAppearanceKeys.FONT] as? NSDictionary {
|
|
50
|
-
if let family = fontParams[CurrencySelectorAppearanceKeys.FAMILY] as? String,
|
|
51
|
-
let customFont = UIFont(name: family, size: appearance.font.pointSize) {
|
|
52
|
-
appearance.font = customFont
|
|
53
|
-
}
|
|
54
|
-
if let scale = fontParams[CurrencySelectorAppearanceKeys.SCALE] as? CGFloat {
|
|
55
|
-
appearance.sizeScaleFactor = scale
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if let labelContent = params[CurrencySelectorAppearanceKeys.LABEL_CONTENT] as? String {
|
|
60
|
-
switch labelContent {
|
|
61
|
-
case CurrencySelectorAppearanceKeys.CURRENCY_CODE:
|
|
62
|
-
appearance.labelContent = .currencyCode
|
|
63
|
-
case CurrencySelectorAppearanceKeys.AMOUNT:
|
|
64
|
-
appearance.labelContent = .amount
|
|
65
|
-
case CurrencySelectorAppearanceKeys.AUTOMATIC:
|
|
66
|
-
appearance.labelContent = .automatic
|
|
67
|
-
default:
|
|
68
|
-
break
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return appearance
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
private class func parseThemedColor(params: NSDictionary, key: String) -> UIColor? {
|
|
76
|
-
if let colorDict = params[key] as? [String: String] {
|
|
77
|
-
let light = colorDict[CurrencySelectorAppearanceKeys.LIGHT]
|
|
78
|
-
let dark = colorDict[CurrencySelectorAppearanceKeys.DARK]
|
|
79
|
-
guard light != nil || dark != nil else { return nil }
|
|
80
|
-
return UIColor { traitCollection in
|
|
81
|
-
let hex = traitCollection.userInterfaceStyle == .dark
|
|
82
|
-
? (dark ?? light!)
|
|
83
|
-
: (light ?? dark!)
|
|
84
|
-
return UIColor(hexString: hex)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if let colorString = params[key] as? String {
|
|
89
|
-
return UIColor(hexString: colorString)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return nil
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
private enum CurrencySelectorAppearanceKeys {
|
|
97
|
-
static let LIGHT = "light"
|
|
98
|
-
static let DARK = "dark"
|
|
99
|
-
|
|
100
|
-
static let BACKGROUND = "background"
|
|
101
|
-
static let SELECTED_BACKGROUND = "selectedBackground"
|
|
102
|
-
static let BORDER_COLOR = "borderColor"
|
|
103
|
-
static let TEXT_COLOR = "textColor"
|
|
104
|
-
static let SELECTED_TEXT_COLOR = "selectedTextColor"
|
|
105
|
-
static let TEXT_SECONDARY_COLOR = "textSecondaryColor"
|
|
106
|
-
static let DANGER_COLOR = "dangerColor"
|
|
107
|
-
|
|
108
|
-
static let CORNER_RADIUS = "cornerRadius"
|
|
109
|
-
static let BORDER_WIDTH = "borderWidth"
|
|
110
|
-
static let CONTENT_VERTICAL_PADDING = "contentVerticalPadding"
|
|
111
|
-
|
|
112
|
-
static let FONT = "font"
|
|
113
|
-
static let FAMILY = "family"
|
|
114
|
-
static let SCALE = "scale"
|
|
115
|
-
|
|
116
|
-
static let LABEL_CONTENT = "labelContent"
|
|
117
|
-
static let AUTOMATIC = "automatic"
|
|
118
|
-
static let CURRENCY_CODE = "currencyCode"
|
|
119
|
-
static let AMOUNT = "amount"
|
|
120
|
-
}
|
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Mappers+Checkout.swift
|
|
3
|
-
// stripe-react-native
|
|
4
|
-
//
|
|
5
|
-
// Created by Nick Porter on 4/29/26.
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
@_spi(ReactNativeSDK) import StripePaymentSheet
|
|
10
|
-
|
|
11
|
-
extension Mappers {
|
|
12
|
-
|
|
13
|
-
// MARK: - State & Session
|
|
14
|
-
|
|
15
|
-
class func mapFromCheckoutState(isLoading: Bool, session: Checkout.Session) -> NSDictionary {
|
|
16
|
-
[
|
|
17
|
-
"status": isLoading ? "loading" : "loaded",
|
|
18
|
-
"session": mapFromCheckoutSession(session),
|
|
19
|
-
]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
class func mapFromCheckoutSession(_ session: Checkout.Session) -> NSDictionary {
|
|
23
|
-
let result = NSMutableDictionary()
|
|
24
|
-
result["id"] = session.id
|
|
25
|
-
result["livemode"] = session.livemode
|
|
26
|
-
result["lineItems"] = session.lineItems.map(mapFromLineItem)
|
|
27
|
-
result["shippingOptions"] = session.shippingOptions.map(mapFromShippingOption)
|
|
28
|
-
result["discountAmounts"] = session.discountAmounts.map(mapFromDiscountAmount)
|
|
29
|
-
result["currencyOptions"] = session.currencyOptions.map(mapFromCurrencyOption)
|
|
30
|
-
result["tax"] = mapFromTax(session.tax)
|
|
31
|
-
|
|
32
|
-
if let businessName = session.businessName {
|
|
33
|
-
result["businessName"] = businessName
|
|
34
|
-
}
|
|
35
|
-
if let currency = session.currency {
|
|
36
|
-
result["currency"] = currency
|
|
37
|
-
}
|
|
38
|
-
if let email = session.email {
|
|
39
|
-
result["email"] = email
|
|
40
|
-
}
|
|
41
|
-
if let minorUnitsAmountDivisor = session.minorUnitsAmountDivisor {
|
|
42
|
-
result["minorUnitsAmountDivisor"] = minorUnitsAmountDivisor
|
|
43
|
-
}
|
|
44
|
-
if let status = session.status {
|
|
45
|
-
result["status"] = mapFromStatus(status)
|
|
46
|
-
}
|
|
47
|
-
if let total = session.total {
|
|
48
|
-
result["total"] = mapFromTotal(total)
|
|
49
|
-
}
|
|
50
|
-
if let shipping = session.shipping {
|
|
51
|
-
result["shipping"] = mapFromSelectedShipping(shipping)
|
|
52
|
-
}
|
|
53
|
-
if let billingAddress = session.billingAddress {
|
|
54
|
-
result["billingAddress"] = mapFromContactAddress(billingAddress)
|
|
55
|
-
}
|
|
56
|
-
if let shippingAddress = session.shippingAddress {
|
|
57
|
-
result["shippingAddress"] = mapFromContactAddress(shippingAddress)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return result
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// MARK: - Amount
|
|
64
|
-
|
|
65
|
-
class func mapFromAmount(_ amount: Checkout.Amount) -> NSDictionary {
|
|
66
|
-
[
|
|
67
|
-
"amount": amount.amount,
|
|
68
|
-
"minorUnitsAmount": amount.minorUnitsAmount,
|
|
69
|
-
]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
class func mapFromDecimalAmount(_ decimalAmount: Checkout.DecimalAmount) -> NSDictionary {
|
|
73
|
-
[
|
|
74
|
-
"amount": decimalAmount.amount,
|
|
75
|
-
"minorUnitsAmount": NSDecimalNumber(decimal: decimalAmount.minorUnitsAmount).doubleValue,
|
|
76
|
-
]
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// MARK: - Status
|
|
80
|
-
|
|
81
|
-
class func mapFromStatus(_ status: Checkout.Status) -> NSDictionary {
|
|
82
|
-
let result = NSMutableDictionary()
|
|
83
|
-
result["type"] = mapFromStatusType(status.type)
|
|
84
|
-
|
|
85
|
-
if let paymentStatus = status.paymentStatus {
|
|
86
|
-
result["paymentStatus"] = mapFromPaymentStatus(paymentStatus)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return result
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private class func mapFromStatusType(_ type: Checkout.StatusType) -> String {
|
|
93
|
-
switch type {
|
|
94
|
-
case .open: return "open"
|
|
95
|
-
case .complete: return "complete"
|
|
96
|
-
case .expired: return "expired"
|
|
97
|
-
case .unknown: return "unknown"
|
|
98
|
-
@unknown default: return "unknown"
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
private class func mapFromPaymentStatus(_ paymentStatus: Checkout.PaymentStatus) -> String {
|
|
103
|
-
switch paymentStatus {
|
|
104
|
-
case .paid: return "paid"
|
|
105
|
-
case .unpaid: return "unpaid"
|
|
106
|
-
case .noPaymentRequired: return "noPaymentRequired"
|
|
107
|
-
case .unknown: return "unknown"
|
|
108
|
-
@unknown default: return "unknown"
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// MARK: - Total
|
|
113
|
-
|
|
114
|
-
class func mapFromTotal(_ total: Checkout.Total) -> NSDictionary {
|
|
115
|
-
[
|
|
116
|
-
"subtotal": mapFromAmount(total.subtotal),
|
|
117
|
-
"taxExclusive": mapFromAmount(total.taxExclusive),
|
|
118
|
-
"taxInclusive": mapFromAmount(total.taxInclusive),
|
|
119
|
-
"shippingRate": mapFromAmount(total.shippingRate),
|
|
120
|
-
"discount": mapFromAmount(total.discount),
|
|
121
|
-
"total": mapFromAmount(total.total),
|
|
122
|
-
"appliedBalance": mapFromAmount(total.appliedBalance),
|
|
123
|
-
"balanceAppliedToNextInvoice": total.balanceAppliedToNextInvoice,
|
|
124
|
-
]
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// MARK: - Tax
|
|
128
|
-
|
|
129
|
-
class func mapFromTax(_ tax: Checkout.Tax) -> NSDictionary {
|
|
130
|
-
let result = NSMutableDictionary()
|
|
131
|
-
result["status"] = mapFromTaxStatus(tax.status)
|
|
132
|
-
|
|
133
|
-
if let taxAmounts = tax.taxAmounts {
|
|
134
|
-
result["taxAmounts"] = taxAmounts.map(mapFromTaxAmount)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return result
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private class func mapFromTaxStatus(_ status: Checkout.TaxStatus) -> String {
|
|
141
|
-
switch status {
|
|
142
|
-
case .ready: return "ready"
|
|
143
|
-
case .requiresShippingAddress: return "requiresShippingAddress"
|
|
144
|
-
case .requiresBillingAddress: return "requiresBillingAddress"
|
|
145
|
-
case .unknown: return "unknown"
|
|
146
|
-
@unknown default: return "unknown"
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private class func mapFromTaxAmount(_ taxAmount: Checkout.TaxAmount) -> NSDictionary {
|
|
151
|
-
[
|
|
152
|
-
"amount": mapFromAmount(taxAmount.amount),
|
|
153
|
-
"inclusive": taxAmount.inclusive,
|
|
154
|
-
"displayName": taxAmount.displayName,
|
|
155
|
-
]
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// MARK: - Line Items
|
|
159
|
-
|
|
160
|
-
class func mapFromLineItem(_ lineItem: Checkout.LineItem) -> NSDictionary {
|
|
161
|
-
let result = NSMutableDictionary()
|
|
162
|
-
result["id"] = lineItem.id
|
|
163
|
-
result["name"] = lineItem.name
|
|
164
|
-
result["images"] = lineItem.images
|
|
165
|
-
result["quantity"] = lineItem.quantity
|
|
166
|
-
result["discountAmounts"] = lineItem.discountAmounts.map(mapFromDiscountAmount)
|
|
167
|
-
result["taxAmounts"] = lineItem.taxAmounts.map(mapFromTaxAmount)
|
|
168
|
-
|
|
169
|
-
if let description = lineItem.description {
|
|
170
|
-
result["description"] = description
|
|
171
|
-
}
|
|
172
|
-
if let unitAmount = lineItem.unitAmount {
|
|
173
|
-
result["unitAmount"] = mapFromAmount(unitAmount)
|
|
174
|
-
}
|
|
175
|
-
if let unitAmountDecimal = lineItem.unitAmountDecimal {
|
|
176
|
-
result["unitAmountDecimal"] = mapFromDecimalAmount(unitAmountDecimal)
|
|
177
|
-
}
|
|
178
|
-
if let subtotal = lineItem.subtotal {
|
|
179
|
-
result["subtotal"] = mapFromAmount(subtotal)
|
|
180
|
-
}
|
|
181
|
-
if let discount = lineItem.discount {
|
|
182
|
-
result["discount"] = mapFromAmount(discount)
|
|
183
|
-
}
|
|
184
|
-
if let taxExclusive = lineItem.taxExclusive {
|
|
185
|
-
result["taxExclusive"] = mapFromAmount(taxExclusive)
|
|
186
|
-
}
|
|
187
|
-
if let taxInclusive = lineItem.taxInclusive {
|
|
188
|
-
result["taxInclusive"] = mapFromAmount(taxInclusive)
|
|
189
|
-
}
|
|
190
|
-
if let total = lineItem.total {
|
|
191
|
-
result["total"] = mapFromAmount(total)
|
|
192
|
-
}
|
|
193
|
-
if let adjustableQuantity = lineItem.adjustableQuantity {
|
|
194
|
-
result["adjustableQuantity"] = mapFromAdjustableQuantity(adjustableQuantity)
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return result
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
private class func mapFromAdjustableQuantity(_ adjustableQuantity: Checkout.AdjustableQuantity) -> NSDictionary {
|
|
201
|
-
[
|
|
202
|
-
"minimum": adjustableQuantity.minimum,
|
|
203
|
-
"maximum": adjustableQuantity.maximum,
|
|
204
|
-
]
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// MARK: - Shipping
|
|
208
|
-
|
|
209
|
-
class func mapFromShippingOption(_ shippingOption: Checkout.ShippingOption) -> NSDictionary {
|
|
210
|
-
let result = NSMutableDictionary()
|
|
211
|
-
result["id"] = shippingOption.id
|
|
212
|
-
result["amount"] = mapFromAmount(shippingOption.amount)
|
|
213
|
-
result["currency"] = shippingOption.currency
|
|
214
|
-
|
|
215
|
-
if let displayName = shippingOption.displayName {
|
|
216
|
-
result["displayName"] = displayName
|
|
217
|
-
}
|
|
218
|
-
if let deliveryEstimate = shippingOption.deliveryEstimate {
|
|
219
|
-
result["deliveryEstimate"] = mapFromDeliveryEstimate(deliveryEstimate)
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return result
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
private class func mapFromDeliveryEstimate(_ estimate: Checkout.DeliveryEstimate) -> NSDictionary {
|
|
226
|
-
let result = NSMutableDictionary()
|
|
227
|
-
|
|
228
|
-
if let minimum = estimate.minimum {
|
|
229
|
-
result["minimum"] = mapFromDeliveryEstimateBound(minimum)
|
|
230
|
-
}
|
|
231
|
-
if let maximum = estimate.maximum {
|
|
232
|
-
result["maximum"] = mapFromDeliveryEstimateBound(maximum)
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
return result
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private class func mapFromDeliveryEstimateBound(_ bound: Checkout.DeliveryEstimate.Bound) -> NSDictionary {
|
|
239
|
-
[
|
|
240
|
-
"unit": mapFromDeliveryEstimateUnit(bound.unit),
|
|
241
|
-
"value": bound.value,
|
|
242
|
-
]
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
private class func mapFromDeliveryEstimateUnit(_ unit: Checkout.DeliveryEstimate.Bound.Unit) -> String {
|
|
246
|
-
switch unit {
|
|
247
|
-
case .hour: return "hour"
|
|
248
|
-
case .day: return "day"
|
|
249
|
-
case .businessDay: return "businessDay"
|
|
250
|
-
case .week: return "week"
|
|
251
|
-
case .month: return "month"
|
|
252
|
-
case .unknown: return "unknown"
|
|
253
|
-
@unknown default: return "unknown"
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
class func mapFromSelectedShipping(_ selectedShipping: Checkout.SelectedShipping) -> NSDictionary {
|
|
258
|
-
[
|
|
259
|
-
"shippingOption": mapFromShippingOption(selectedShipping.shippingOption),
|
|
260
|
-
"taxAmounts": selectedShipping.taxAmounts.map(mapFromTaxAmount),
|
|
261
|
-
]
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// MARK: - Discounts
|
|
265
|
-
|
|
266
|
-
class func mapFromDiscountAmount(_ discountAmount: Checkout.DiscountAmount) -> NSDictionary {
|
|
267
|
-
let result = NSMutableDictionary()
|
|
268
|
-
result["amount"] = mapFromAmount(discountAmount.amount)
|
|
269
|
-
result["displayName"] = discountAmount.displayName
|
|
270
|
-
|
|
271
|
-
if let promotionCode = discountAmount.promotionCode {
|
|
272
|
-
result["promotionCode"] = promotionCode
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return result
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// MARK: - Currency Options
|
|
279
|
-
|
|
280
|
-
class func mapFromCurrencyOption(_ currencyOption: Checkout.CurrencyOption) -> NSDictionary {
|
|
281
|
-
let result = NSMutableDictionary()
|
|
282
|
-
result["amount"] = mapFromAmount(currencyOption.amount)
|
|
283
|
-
result["currency"] = currencyOption.currency
|
|
284
|
-
|
|
285
|
-
if let currencyConversion = currencyOption.currencyConversion {
|
|
286
|
-
result["currencyConversion"] = mapFromCurrencyConversion(currencyConversion)
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return result
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
private class func mapFromCurrencyConversion(_ conversion: Checkout.CurrencyConversion) -> NSDictionary {
|
|
293
|
-
[
|
|
294
|
-
"fxRate": conversion.fxRate,
|
|
295
|
-
"sourceCurrency": conversion.sourceCurrency,
|
|
296
|
-
]
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// MARK: - Address
|
|
300
|
-
|
|
301
|
-
class func mapFromContactAddress(_ contactAddress: Checkout.ContactAddress) -> NSDictionary {
|
|
302
|
-
let result = NSMutableDictionary()
|
|
303
|
-
result["address"] = mapFromCheckoutAddress(contactAddress.address)
|
|
304
|
-
|
|
305
|
-
if let name = contactAddress.name {
|
|
306
|
-
result["name"] = name
|
|
307
|
-
}
|
|
308
|
-
if let phone = contactAddress.phone {
|
|
309
|
-
result["phone"] = phone
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
return result
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
private class func mapFromCheckoutAddress(_ address: Checkout.Address) -> NSDictionary {
|
|
316
|
-
let result = NSMutableDictionary()
|
|
317
|
-
result["country"] = address.country
|
|
318
|
-
|
|
319
|
-
if let line1 = address.line1 {
|
|
320
|
-
result["line1"] = line1
|
|
321
|
-
}
|
|
322
|
-
if let line2 = address.line2 {
|
|
323
|
-
result["line2"] = line2
|
|
324
|
-
}
|
|
325
|
-
if let city = address.city {
|
|
326
|
-
result["city"] = city
|
|
327
|
-
}
|
|
328
|
-
if let state = address.state {
|
|
329
|
-
result["state"] = state
|
|
330
|
-
}
|
|
331
|
-
if let postalCode = address.postalCode {
|
|
332
|
-
result["postalCode"] = postalCode
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
return result
|
|
336
|
-
}
|
|
337
|
-
}
|