Skip to content

Commit

Permalink
Merge pull request #219 from primer-io/feat/ACC-3333-ACH-drop-in
Browse files Browse the repository at this point in the history
feat: ACH drop-in support
  • Loading branch information
jnewc authored Sep 17, 2024
2 parents 9e74135 + 5cb4935 commit e1da9b8
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 53 deletions.
2 changes: 2 additions & 0 deletions packages/example/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<resources>
<string name="app_name">example</string>

<string name="stripe_ach_full_mandate_text">Would you like to accept this mandate?</string>
</resources>
9 changes: 8 additions & 1 deletion packages/example/src/screens/CheckoutScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,14 @@ const CheckoutScreen = (props: any) => {
android: {
threeDsAppRequestorUrl: "https://primer.io"
}
}
},
stripeOptions: {
publishableKey: "pk_test_51O8zfQKUK6bXIdC2xPvSS6UvriE9kwpvttwB7H9PAzhNAZoGzLgiDOyd4WooozeWHxoRrKo6b2VjZYxNCMX3W7bk00rMDivjau",
mandateData: {
fullMandateResourceKey: "stripe_ach_full_mandate_text", // TODO TWS: iOS to define localized string with this exact key
// merchantName: "Primer Inc.",
}
},
},
uiOptions: {
isInitScreenEnabled: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
arguments=
auto.sync=false
arguments=--init-script /var/folders/wt/mqwpc4jx2kjgqf88mzm5qvx40000gn/T/d146c9752a26f79b52047fb6dc6ed385d064e120494f96f08ca63a317c41f94c.gradle --init-script /var/folders/wt/mqwpc4jx2kjgqf88mzm5qvx40000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle
auto.sync=true
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(7.4.2))
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=../../example/android
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.14.jdk/Contents/Home
java.home=/Applications/Android Studio.app/Contents/jbr/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.json.JSONObject

class PrimerRN(reactContext: ReactApplicationContext, private val json: Json) :
class PrimerRN(private val reactContext: ReactApplicationContext, private val json: Json) :
ReactContextBaseJavaModule(reactContext) {
private val mListener = PrimerRNEventListener()

Expand All @@ -36,7 +36,7 @@ class PrimerRN(reactContext: ReactApplicationContext, private val json: Json) :
if (settingsStr.isBlank()) PrimerSettingsRN() else json.decodeFromString(
settingsStr
)
startSdk(settings.toPrimerSettings())
startSdk(settings.toPrimerSettings(reactContext))
promise.resolve(null)
} catch (e: Exception) {
Log.e("PrimerRN", "configure settings error: $e")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PrimerRNHeadlessUniversalCheckout(
PrimerHeadlessUniversalCheckout.current.start(
reactContext,
clientToken,
settings.toPrimerSettings(),
settings.toPrimerSettings(reactContext),
listener,
listener
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.primerioreactnative.datamodels

import android.content.Context
import com.primerioreactnative.extensions.toLocale
import com.primerioreactnative.extensions.toPrimerDebugOptions
import com.primerioreactnative.extensions.toPrimerPaymentMethodOptions
Expand All @@ -24,20 +25,20 @@ data class PrimerSettingsRN(

@Serializable
data class LocaleSettingsRN(
val languageCode: String? = null,
val localeCode: String? = null
val languageCode: String? = null,
val localeCode: String? = null
)

@Serializable
data class PrimerPaymentMethodOptionsRN(
@SerialName("android")
val androidSettingsRN: AndroidSettingsRN = AndroidSettingsRN(),
var cardPaymentOptions: PrimerCardPaymentOptionsRN = PrimerCardPaymentOptionsRN(),
var googlePayOptions: PrimerGooglePayOptionsRN = PrimerGooglePayOptionsRN(),
var klarnaOptions: PrimerKlarnaOptionsRN = PrimerKlarnaOptionsRN(),
var apayaOptions: PrimerApayaOptionsRN = PrimerApayaOptionsRN(),
var threeDsOptions: PrimerThreeDsOptionsRN = PrimerThreeDsOptionsRN(),
var stripeOptions: PrimerStripeOptionsRN = PrimerStripeOptionsRN(),
@SerialName("android")
val androidSettingsRN: AndroidSettingsRN = AndroidSettingsRN(),
var cardPaymentOptions: PrimerCardPaymentOptionsRN = PrimerCardPaymentOptionsRN(),
var googlePayOptions: PrimerGooglePayOptionsRN = PrimerGooglePayOptionsRN(),
var klarnaOptions: PrimerKlarnaOptionsRN = PrimerKlarnaOptionsRN(),
var apayaOptions: PrimerApayaOptionsRN = PrimerApayaOptionsRN(),
var threeDsOptions: PrimerThreeDsOptionsRN = PrimerThreeDsOptionsRN(),
var stripeOptions: PrimerStripeOptionsRN = PrimerStripeOptionsRN(),
)

@Serializable
Expand Down Expand Up @@ -115,62 +116,59 @@ data class ColorRN(
data class PrimerDebugOptionsRN(val is3DSSanityCheckEnabled: Boolean = true)

@Serializable
data class PrimerCardPaymentOptionsRN(
var is3DSOnVaultingEnabled: Boolean = true
)
data class PrimerCardPaymentOptionsRN(var is3DSOnVaultingEnabled: Boolean = true)

@Serializable
data class PrimerThreeDsOptionsRN(
@SerialName("android")
val threeDsOptionsAndroid: PrimerThreeDsAndroidOptionsRN? = null
@SerialName("android")
val threeDsOptionsAndroid: PrimerThreeDsAndroidOptionsRN? = null
)

@Serializable
data class PrimerThreeDsAndroidOptionsRN(
val threeDsAppRequestorUrl: String? = null
)
@Serializable
data class PrimerThreeDsAndroidOptionsRN(val threeDsAppRequestorUrl: String? = null)

@Serializable
data class PrimerGooglePayOptionsRN(
var merchantName: String? = null,
var allowedCardNetworks: List<String> = listOf(
"AMEX",
"DISCOVER",
"JCB",
"MASTERCARD",
"VISA"
),
var buttonStyle: GooglePayButtonStyle = GooglePayButtonStyle.BLACK,
@SerialName("isCaptureBillingAddressEnabled") var captureBillingAddress: Boolean = false,
@SerialName("isExistingPaymentMethodRequired") var existingPaymentMethodRequired: Boolean = false
var merchantName: String? = null,
var allowedCardNetworks: List<String> =
listOf("AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA"),
var buttonStyle: GooglePayButtonStyle = GooglePayButtonStyle.BLACK,
@SerialName("isCaptureBillingAddressEnabled")
var captureBillingAddress: Boolean = false,
@SerialName("isExistingPaymentMethodRequired")
var existingPaymentMethodRequired: Boolean = false
)

@Serializable
data class PrimerKlarnaOptionsRN(
var recurringPaymentDescription: String? = null,
@Deprecated("This property is deprecated and will be removed in future release.")
var webViewTitle: String? = null,
var recurringPaymentDescription: String? = null,
@Deprecated("This property is deprecated and will be removed in future release.")
var webViewTitle: String? = null,
)

@Serializable
data class PrimerStripeOptionsRN(
var mandateData: PrimerStripeOptions.MandateData? = null,
var publishableKey: String? = null,
)
val mandateData: MandateDataRN? = null,
val publishableKey: String? = null,
) {
@Serializable
data class MandateDataRN(
@SerialName("fullMandateResourceKey") val fullMandateStringResName: String? = null,
val merchantName: String? = null
)
}

@Serializable
@Deprecated("This class is deprecated and will be removed in future release.")
data class PrimerApayaOptionsRN(
var webViewTitle: String? = null,
var webViewTitle: String? = null,
)

fun PrimerSettingsRN.toPrimerSettings() = PrimerSettings(
fun PrimerSettingsRN.toPrimerSettings(context: Context) = PrimerSettings(
paymentHandling = paymentHandling,
locale = localeData.toLocale(),
paymentMethodOptions = paymentMethodOptions.toPrimerPaymentMethodOptions(),
paymentMethodOptions = paymentMethodOptions.toPrimerPaymentMethodOptions(context),
uiOptions = uiOptions.toPrimerUIOptions(),
debugOptions = debugOptions.toPrimerDebugOptions(),
clientSessionCachingEnabled = clientSessionCachingEnabled
)


Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package com.primerioreactnative.extensions

import com.primerioreactnative.datamodels.*
import io.primer.android.data.settings.*
import io.primer.android.data.settings.PrimerStripeOptions.MandateData.TemplateMandateData
import io.primer.android.data.settings.PrimerStripeOptions.MandateData.FullMandateData
import android.content.Context

fun PrimerPaymentMethodOptionsRN.toPrimerPaymentMethodOptions() =
fun PrimerPaymentMethodOptionsRN.toPrimerPaymentMethodOptions(context: Context) =
PrimerPaymentMethodOptions(
androidSettingsRN.redirectScheme,
googlePayOptions.toPrimerGooglePayOptions(),
klarnaOptions.toPrimerKlarnaOptions(),
threeDsOptions.toPrimerThreeDsOptions(),
stripeOptions.toPrimerStripeOptions(),
stripeOptions.toPrimerStripeOptions(context),
)

fun PrimerGooglePayOptionsRN.toPrimerGooglePayOptions() =
Expand All @@ -27,4 +30,13 @@ fun PrimerKlarnaOptionsRN.toPrimerKlarnaOptions() =
fun PrimerThreeDsOptionsRN.toPrimerThreeDsOptions() =
PrimerThreeDsOptions(threeDsOptionsAndroid?.threeDsAppRequestorUrl)

fun PrimerStripeOptionsRN.toPrimerStripeOptions() = PrimerStripeOptions(mandateData, publishableKey)
fun PrimerStripeOptionsRN.toPrimerStripeOptions(context: Context) =
PrimerStripeOptions(mandateData = mandateData?.toMandateData(context), publishableKey = publishableKey)

private fun PrimerStripeOptionsRN.MandateDataRN.toMandateData(context: Context) = when {
merchantName != null -> TemplateMandateData(merchantName)
fullMandateStringResName != null -> FullMandateData(
context.getResources().getIdentifier(fullMandateStringResName, "string", context.getPackageName())
)
else -> error("Missing mandate data")
}
13 changes: 12 additions & 1 deletion packages/sdk/src/models/PrimerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,15 @@ interface IPrimerThreeDsOptions {

interface IPrimerStripeOptions {
publishableKey?: string;
}
mandateData?: IPrimerStripeTemplateMandateData | IPrimerStripeFullMandateData;
}

interface IPrimerStripeMandateData {}

interface IPrimerStripeTemplateMandateData extends IPrimerStripeMandateData {
merchantName: string;
}

interface IPrimerStripeFullMandateData extends IPrimerStripeMandateData {
fullMandateResourceKey: string;
}

0 comments on commit e1da9b8

Please sign in to comment.