Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Express Checkout GPay for Android #240

Merged
merged 5 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/example/src/screens/CheckoutScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@ const CheckoutScreen = (props: any) => {
checkProvidedNetworks: false
},
googlePayOptions: {
isCaptureBillingAddressEnabled: true,
isExistingPaymentMethodRequired: true,
isCaptureBillingAddressEnabled: true,
isExistingPaymentMethodRequired: false,
shippingAddressParameters: {phoneNumberRequired: true},
requireShippingMethod: true,
emailAddressRequired: true
},
threeDsOptions: {
iOS: {
Expand All @@ -259,7 +262,7 @@ const CheckoutScreen = (props: any) => {
publishableKey: "<PUT_YOUR_PUBLISHABLE_KEY_HERE>",
mandateData: {
// This will be used for Android if present
fullMandateStringResourceName: "stripe_ach_full_mandate_text",
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
Expand All @@ -273,7 +276,7 @@ const CheckoutScreen = (props: any) => {
isErrorScreenEnabled: true,
theme: {
// 👇 Uncomment to try theming drop-in checkout

// colors: {
// mainColor: {
// red: 214,
Expand Down
7 changes: 7 additions & 0 deletions packages/example/src/screens/HeadlessCheckoutScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export const HeadlessCheckoutScreen = (props: any) => {
merchantName: "My Merchant Name"
}
},
googlePayOptions: {
isCaptureBillingAddressEnabled: true,
isExistingPaymentMethodRequired: false,
shippingAddressParameters: { phoneNumberRequired: true },
requireShippingMethod: true,
emailAddressRequired: true
},
},
debugOptions: {
is3DSSanityCheckEnabled: false
Expand Down
2 changes: 1 addition & 1 deletion packages/example/src/screens/SettingsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const SettingsScreen = ({ navigation }) => {
<SegmentedControl
testID="Enviroment"
style={{ marginTop: 6 }}
values={['Dev', 'Sandbox', 'Staging', 'Production']}
values={['Sandbox', 'Dev', 'Staging', 'Production']}
selectedIndex={environment}
onChange={(event) => {
const selectedIndex = event.nativeEvent.selectedSegmentIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ data class PrimerCustomerRN(
@Serializable
data class PrimerOrderRN(
val countryCode: CountryCode?,
val shipping: PrimerShippingRN?
)

@Serializable
data class PrimerShippingRN(
val amount: Int?,
val methodId: String?,
val methodName: String?,
val methodDescription: String?
)

@Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ data class PrimerSettingsRN(

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

@Serializable
data class PrimerPaymentMethodOptionsRN(
@SerialName("android")
@SerialName("android")
val androidSettingsRN: AndroidSettingsRN = AndroidSettingsRN(),
var cardPaymentOptions: PrimerCardPaymentOptionsRN = PrimerCardPaymentOptionsRN(),
var googlePayOptions: PrimerGooglePayOptionsRN = PrimerGooglePayOptionsRN(),
Expand Down Expand Up @@ -124,7 +124,7 @@ data class PrimerThreeDsOptionsRN(
val threeDsOptionsAndroid: PrimerThreeDsAndroidOptionsRN? = null
)

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

@Serializable
Expand All @@ -133,10 +133,20 @@ data class PrimerGooglePayOptionsRN(
var allowedCardNetworks: List<String> =
listOf("AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA"),
var buttonStyle: GooglePayButtonStyle = GooglePayButtonStyle.BLACK,
@SerialName("isCaptureBillingAddressEnabled")
@SerialName("isCaptureBillingAddressEnabled")
var captureBillingAddress: Boolean = false,
@SerialName("isExistingPaymentMethodRequired")
var existingPaymentMethodRequired: Boolean = false
var existingPaymentMethodRequired: Boolean = false,
var shippingAddressParameters: PrimerGoogleShippingAddressParametersRN? = null,
@SerialName("requireShippingMethod")
var requireShippingMethod: Boolean = false,
@SerialName("emailAddressRequired")
var emailAddressRequired: Boolean = false
)

@Serializable
data class PrimerGoogleShippingAddressParametersRN(
var phoneNumberRequired: Boolean = false
)

@Serializable
Expand All @@ -153,8 +163,8 @@ data class PrimerStripeOptionsRN(
) {
@Serializable
data class MandateDataRN(
@SerialName("fullMandateText") val fullMandateText: String? = null,
@SerialName("fullMandateStringResourceName") 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
@@ -1,6 +1,10 @@
package com.primerioreactnative.extensions

import com.primerioreactnative.datamodels.PrimerOrderRN
import com.primerioreactnative.datamodels.PrimerShippingRN
import io.primer.android.domain.action.models.PrimerOrder
import io.primer.android.domain.action.models.PrimerShipping

internal fun PrimerOrder.toPrimerOrderRN() = PrimerOrderRN(countryCode)
internal fun PrimerOrder.toPrimerOrderRN() = PrimerOrderRN(countryCode, shipping?.toPrimerShippingRN())

internal fun PrimerShipping.toPrimerShippingRN() = PrimerShippingRN(amount, methodId, methodName, methodDescription)
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ fun PrimerGooglePayOptionsRN.toPrimerGooglePayOptions() =
allowedCardNetworks = allowedCardNetworks,
buttonStyle = buttonStyle,
captureBillingAddress = captureBillingAddress,
existingPaymentMethodRequired = existingPaymentMethodRequired
existingPaymentMethodRequired = existingPaymentMethodRequired,
shippingAddressParameters = shippingAddressParameters?.toPrimerGoogleShippingAddressParameters(),
requireShippingMethod = requireShippingMethod,
emailAddressRequired = emailAddressRequired
)

fun PrimerGoogleShippingAddressParametersRN.toPrimerGoogleShippingAddressParameters() =
PrimerGoogleShippingAddressParameters(phoneNumberRequired)

fun PrimerKlarnaOptionsRN.toPrimerKlarnaOptions() =
PrimerKlarnaOptions(recurringPaymentDescription, webViewTitle)

fun PrimerThreeDsOptionsRN.toPrimerThreeDsOptions() =
PrimerThreeDsOptions(threeDsOptionsAndroid?.threeDsAppRequestorUrl)

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

private fun PrimerStripeOptionsRN.MandateDataRN.toMandateData(context: Context) = when {
Expand All @@ -44,7 +50,7 @@ private fun PrimerStripeOptionsRN.MandateDataRN.toMandateData(context: Context)
if (fullMandateText != null) {
FullMandateStringData(fullMandateText)
} else {
error("Missing mandate data")
error("Missing mandate data")
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion packages/sdk/src/models/PrimerClientSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export type PrimerOrder = IPrimerOrder;

interface IPrimerOrder {
countryCode?: string;
shipping?: IPrimerShipping;
}

interface IPrimerShipping {
amount?: number;
methodId?: string;
methodName?: string;
methodDescription?: string;
}

export type PrimerCustomer = IPrimerCustomer;
Expand All @@ -50,4 +58,4 @@ interface IPrimerAddress {
city?: string;
state?: string;
countryCode?: string;
}
}
9 changes: 8 additions & 1 deletion packages/sdk/src/models/PrimerSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ interface IPrimerGooglePayOptions {
allowedCardNetworks?: string[];
isCaptureBillingAddressEnabled?: boolean;
isExistingPaymentMethodRequired?: boolean;
shippingAddressParameters?: IPrimerGoogleShippingAddressParameters;
requireShippingMethod?: boolean;
emailAddressRequired?: boolean;
}

interface IPrimerGoogleShippingAddressParameters {
isPhoneNumberRequired?: boolean;
}

interface IPrimerKlarnaOptions {
Expand Down Expand Up @@ -163,4 +170,4 @@ interface IPrimerStripeTemplateMandateData extends IPrimerStripeMandateData {
interface IPrimerFullMandateData extends IPrimerStripeMandateData {
fullMandateText: string;
fullMandateStringResourceName?: string;
}
}
Loading