Skip to content

Commit

Permalink
chore: allow supporting both mandate text and mandate string resource…
Browse files Browse the repository at this point in the history
… on Android
  • Loading branch information
FlaviuExtPrimer committed Sep 19, 2024
1 parent c696350 commit ed607af
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
8 changes: 4 additions & 4 deletions packages/example/src/screens/CheckoutScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,10 @@ const CheckoutScreen = (props: any) => {
stripeOptions: {
publishableKey: "<PUT_YOUR_PUBLISHABLE_KEY_HERE>",
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.",
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand Down Expand Up @@ -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())
)
Expand Down
11 changes: 7 additions & 4 deletions packages/sdk/src/models/PrimerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ interface IPrimerThreeDsOptions {

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

interface IPrimerStripeMandateData {}
Expand All @@ -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;
}

0 comments on commit ed607af

Please sign in to comment.