From ed607aff8744415aa7c79e918a74d36f0d2db060 Mon Sep 17 00:00:00 2001 From: FlaviuExtPrimer <149587774+FlaviuExtPrimer@users.noreply.github.com> Date: Thu, 19 Sep 2024 16:31:02 +0300 Subject: [PATCH] chore: allow supporting both mandate text and mandate string resource on Android --- packages/example/src/screens/CheckoutScreen.tsx | 8 ++++---- .../datamodels/PrimerSettingsRN.kt | 3 ++- .../extensions/PrimerPaymentMethodOptionsRN.kt | 2 ++ packages/sdk/src/models/PrimerSettings.ts | 11 +++++++---- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/packages/example/src/screens/CheckoutScreen.tsx b/packages/example/src/screens/CheckoutScreen.tsx index 38a7d486..19c72e7b 100644 --- a/packages/example/src/screens/CheckoutScreen.tsx +++ b/packages/example/src/screens/CheckoutScreen.tsx @@ -258,10 +258,10 @@ const CheckoutScreen = (props: any) => { stripeOptions: { publishableKey: "", mandateData: { - // This will be used for Android if present, otherise - fullMandateResourceKey: "stripe_ach_mandate_text", // TODO TWS: iOS to define localized string with this exact key - // This is used for iOS, and will be used for Android if `fullMandateResourceKey` is not present - fullMandateText: "Full mandate text here ...", + // This will be used for Android if present + fullMandateStringResourceName: "stripe_ach_full_mandate_text", + // This is used for iOS, and will be used for Android if `fullMandateStringResourceName: string;` is not present + // fullMandateText: "Full mandate text here ...", // Comment the above and uncomment below to use Primer's template with your merchant name // merchantName: "Primer Inc.", } diff --git a/packages/sdk/android/src/main/java/com/primerioreactnative/datamodels/PrimerSettingsRN.kt b/packages/sdk/android/src/main/java/com/primerioreactnative/datamodels/PrimerSettingsRN.kt index 5dc91f38..a8656e3b 100644 --- a/packages/sdk/android/src/main/java/com/primerioreactnative/datamodels/PrimerSettingsRN.kt +++ b/packages/sdk/android/src/main/java/com/primerioreactnative/datamodels/PrimerSettingsRN.kt @@ -153,7 +153,8 @@ data class PrimerStripeOptionsRN( ) { @Serializable data class MandateDataRN( - @SerialName("fullMandateResourceKey") val fullMandateStringResName: String? = null, + @SerialName("fullMandateText") val fullMandateText: String? = null, + @SerialName("fullMandateStringResourceName") val fullMandateStringResName: String? = null, val merchantName: String? = null ) } diff --git a/packages/sdk/android/src/main/java/com/primerioreactnative/extensions/PrimerPaymentMethodOptionsRN.kt b/packages/sdk/android/src/main/java/com/primerioreactnative/extensions/PrimerPaymentMethodOptionsRN.kt index fd6c1f9a..b17fc12f 100644 --- a/packages/sdk/android/src/main/java/com/primerioreactnative/extensions/PrimerPaymentMethodOptionsRN.kt +++ b/packages/sdk/android/src/main/java/com/primerioreactnative/extensions/PrimerPaymentMethodOptionsRN.kt @@ -4,6 +4,7 @@ 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 io.primer.android.data.settings.PrimerStripeOptions.MandateData.FullMandateStringData import android.content.Context fun PrimerPaymentMethodOptionsRN.toPrimerPaymentMethodOptions(context: Context) = @@ -35,6 +36,7 @@ fun PrimerStripeOptionsRN.toPrimerStripeOptions(context: Context) = private fun PrimerStripeOptionsRN.MandateDataRN.toMandateData(context: Context) = when { merchantName != null -> TemplateMandateData(merchantName) + fullMandateText != null -> FullMandateStringData(fullMandateText) fullMandateStringResName != null -> FullMandateData( context.getResources().getIdentifier(fullMandateStringResName, "string", context.getPackageName()) ) diff --git a/packages/sdk/src/models/PrimerSettings.ts b/packages/sdk/src/models/PrimerSettings.ts index 0e15928c..04bd6b43 100644 --- a/packages/sdk/src/models/PrimerSettings.ts +++ b/packages/sdk/src/models/PrimerSettings.ts @@ -151,7 +151,7 @@ interface IPrimerThreeDsOptions { interface IPrimerStripeOptions { publishableKey?: string; - mandateData?: IPrimerStripeTemplateMandateData | IPrimerStripeFullMandateData; + mandateData?: IPrimerStripeTemplateMandateData | IPrimerStripeFullMandateStringResourceData | IPrimerStripeFullMandateTextData; } interface IPrimerStripeMandateData {} @@ -160,7 +160,10 @@ interface IPrimerStripeTemplateMandateData extends IPrimerStripeMandateData { merchantName: string; } -interface IPrimerStripeFullMandateData extends IPrimerStripeMandateData { - fullMandateResourceKey?: string; - fullMandateText: string; +interface IPrimerStripeFullMandateStringResourceData extends IPrimerStripeMandateData { + fullMandateStringResourceName: string; } + +interface IPrimerStripeFullMandateTextData extends IPrimerStripeMandateData { + fullMandateText: string; +} \ No newline at end of file