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

Add amount and label to GooglePayLauncher and GooglePayConfiguration #7191

Merged
merged 9 commits into from
Sep 14, 2023
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

### PaymentSheet
* [ADDED][7302](https://github.com/stripe/stripe-android/pull/7302) PaymentSheet now supports Alma for PaymentIntents in private beta.
* [ADDED][7191](https://github.com/stripe/stripe-android/pull/7191) `PaymentSheet.GooglePayConfiguration` now takes an optional `amount` and `label`. The `amount` will be displayed in Google Pay for SetupIntents, while `label` will be displayed for both PaymentIntents and SetupIntents.

### Payments
* [ADDED][7191](https://github.com/stripe/stripe-android/pull/7191) `GooglePayLauncher` now takes an optional `label` when presenting Google Pay for PaymentIntents, and an optional `amount` and `label` when presenting for SetupIntents.
* [ADDED][7191](https://github.com/stripe/stripe-android/pull/7191) `GooglePayPaymentMethodLauncher` now takes an optional `label` when presenting Google Pay.

## 20.30.2 - 2023-09-13

Expand Down
21 changes: 16 additions & 5 deletions payments-core/api/payments-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,12 @@ public final class com/stripe/android/googlepaylauncher/GooglePayLauncher {
public fun <init> (Landroidx/activity/ComponentActivity;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$ReadyCallback;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$ResultCallback;)V
public fun <init> (Landroidx/fragment/app/Fragment;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$ReadyCallback;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$ResultCallback;)V
public final fun presentForPaymentIntent (Ljava/lang/String;)V
public final fun presentForPaymentIntent (Ljava/lang/String;Ljava/lang/String;)V
public static synthetic fun presentForPaymentIntent$default (Lcom/stripe/android/googlepaylauncher/GooglePayLauncher;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)V
public final fun presentForSetupIntent (Ljava/lang/String;Ljava/lang/String;)V
public final fun presentForSetupIntent (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;)V
public final fun presentForSetupIntent (Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;)V
public static synthetic fun presentForSetupIntent$default (Lcom/stripe/android/googlepaylauncher/GooglePayLauncher;Ljava/lang/String;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;ILjava/lang/Object;)V
}

public final class com/stripe/android/googlepaylauncher/GooglePayLauncher$BillingAddressConfig : android/os/Parcelable {
Expand Down Expand Up @@ -1263,8 +1268,10 @@ public final class com/stripe/android/googlepaylauncher/GooglePayLauncherContrac
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
public fun <init> (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;)V
public final fun copy (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;)Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$PaymentIntentArgs;
public static synthetic fun copy$default (Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$PaymentIntentArgs;Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;ILjava/lang/Object;)Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$PaymentIntentArgs;
public fun <init> (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun copy (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;)Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$PaymentIntentArgs;
public static synthetic fun copy$default (Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$PaymentIntentArgs;Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$PaymentIntentArgs;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
Expand All @@ -1284,8 +1291,11 @@ public final class com/stripe/android/googlepaylauncher/GooglePayLauncherContrac
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
public fun <init> (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;)V
jaynewstrom-stripe marked this conversation as resolved.
Show resolved Hide resolved
public final fun copy (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;)Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$SetupIntentArgs;
public static synthetic fun copy$default (Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$SetupIntentArgs;Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$SetupIntentArgs;
public fun <init> (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;Ljava/lang/Long;)V
public fun <init> (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;)V
public synthetic fun <init> (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun copy (Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;)Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$SetupIntentArgs;
public static synthetic fun copy$default (Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$SetupIntentArgs;Ljava/lang/String;Lcom/stripe/android/googlepaylauncher/GooglePayLauncher$Config;Ljava/lang/String;Ljava/lang/Long;Ljava/lang/String;ILjava/lang/Object;)Lcom/stripe/android/googlepaylauncher/GooglePayLauncherContract$SetupIntentArgs;
public fun describeContents ()I
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
Expand Down Expand Up @@ -1350,8 +1360,9 @@ public final class com/stripe/android/googlepaylauncher/GooglePayPaymentMethodLa
public final fun present (Ljava/lang/String;ILjava/lang/String;)V
public final fun present (Ljava/lang/String;J)V
public final fun present (Ljava/lang/String;JLjava/lang/String;)V
public final fun present (Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;)V
public static synthetic fun present$default (Lcom/stripe/android/googlepaylauncher/GooglePayPaymentMethodLauncher;Ljava/lang/String;ILjava/lang/String;ILjava/lang/Object;)V
public static synthetic fun present$default (Lcom/stripe/android/googlepaylauncher/GooglePayPaymentMethodLauncher;Ljava/lang/String;JLjava/lang/String;ILjava/lang/Object;)V
public static synthetic fun present$default (Lcom/stripe/android/googlepaylauncher/GooglePayPaymentMethodLauncher;Ljava/lang/String;JLjava/lang/String;Ljava/lang/String;ILjava/lang/Object;)V
}

public final class com/stripe/android/googlepaylauncher/GooglePayPaymentMethodLauncher$BillingAddressConfig : android/os/Parcelable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,24 @@ class GooglePayLauncher internal constructor(
* object.
*
* @param clientSecret the PaymentIntent's [client secret](https://stripe.com/docs/api/payment_intents/object#payment_intent_object-client_secret)
* @param label An optional label to display with the amount. Google Pay may or may not display
* this label depending on its own internal logic. Defaults to a generic label if none is
* provided.
*/
fun presentForPaymentIntent(clientSecret: String) {
@JvmOverloads
fun presentForPaymentIntent(
clientSecret: String,
label: String? = null,
) {
check(isReady) {
"presentForPaymentIntent() may only be called when Google Pay is available on this device."
}

activityResultLauncher.launch(
GooglePayLauncherContract.PaymentIntentArgs(
clientSecret = clientSecret,
config = config
config = config,
label = label,
)
)
}
Expand All @@ -175,10 +183,18 @@ class GooglePayLauncher internal constructor(
*
* @param clientSecret the SetupIntent's [client secret](https://stripe.com/docs/api/setup_intents/object#setup_intent_object-client_secret)
* @param currencyCode The ISO 4217 alphabetic currency code.
* @param amount An optional amount to display. Google Pay may or may not display this amount
* depending on its own internal logic. Defaults to 0 if none is provided.
* @param label An optional label to display with the amount. Google Pay may or may not display
* this label depending on its own internal logic. Defaults to a generic label if none is
* provided.
*/
@JvmOverloads
fun presentForSetupIntent(
clientSecret: String,
currencyCode: String
currencyCode: String,
amount: Long? = null,
label: String? = null,
) {
check(isReady) {
"presentForSetupIntent() may only be called when Google Pay is available on this device."
Expand All @@ -188,7 +204,9 @@ class GooglePayLauncher internal constructor(
GooglePayLauncherContract.SetupIntentArgs(
clientSecret = clientSecret,
config = config,
currencyCode = currencyCode
currencyCode = currencyCode,
amount = amount,
label = label,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ class GooglePayLauncherContract :
* Args for launching [GooglePayLauncherContract] to confirm a [PaymentIntent].
*/
@Parcelize
data class PaymentIntentArgs(
data class PaymentIntentArgs @JvmOverloads constructor(
override val clientSecret: String,
override val config: GooglePayLauncher.Config
override val config: GooglePayLauncher.Config,
internal val label: String? = null,
) : Args()

/**
* Args for launching [GooglePayLauncherContract] to confirm a [SetupIntent].
*/
@Parcelize
data class SetupIntentArgs(
data class SetupIntentArgs @JvmOverloads constructor(
override val clientSecret: String,
override val config: GooglePayLauncher.Config,
internal val currencyCode: String
internal val currencyCode: String,
internal val amount: Long? = null,
internal val label: String? = null,
) : Args()

sealed class Args : Parcelable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ internal class GooglePayLauncherViewModel(
createTransactionInfo(
stripeIntent = intent,
currencyCode = intent.currency.orEmpty(),
label = args.label,
)
}
}
Expand All @@ -95,6 +96,8 @@ internal class GooglePayLauncherViewModel(
createTransactionInfo(
stripeIntent = intent,
currencyCode = args.currencyCode,
amount = args.amount,
label = args.label,
)
}
}
Expand Down Expand Up @@ -123,7 +126,9 @@ internal class GooglePayLauncherViewModel(
@VisibleForTesting
internal fun createTransactionInfo(
stripeIntent: StripeIntent,
currencyCode: String
currencyCode: String,
amount: Long? = null,
label: String? = null,
): GooglePayJsonFactory.TransactionInfo {
return when (stripeIntent) {
is PaymentIntent -> {
Expand All @@ -134,7 +139,7 @@ internal class GooglePayLauncherViewModel(
transactionId = stripeIntent.id,
totalPrice = stripeIntent.amount,
totalPriceLabel = null,
checkoutOption = GooglePayJsonFactory.TransactionInfo.CheckoutOption.CompleteImmediatePurchase
checkoutOption = GooglePayJsonFactory.TransactionInfo.CheckoutOption.CompleteImmediatePurchase,
)
}
is SetupIntent -> {
Expand All @@ -143,9 +148,9 @@ internal class GooglePayLauncherViewModel(
totalPriceStatus = GooglePayJsonFactory.TransactionInfo.TotalPriceStatus.Estimated,
countryCode = args.config.merchantCountryCode,
transactionId = stripeIntent.id,
totalPrice = 0L,
totalPriceLabel = null,
checkoutOption = GooglePayJsonFactory.TransactionInfo.CheckoutOption.Default
totalPrice = amount ?: 0L,
totalPriceLabel = label,
checkoutOption = GooglePayJsonFactory.TransactionInfo.CheckoutOption.Default,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,16 @@ class GooglePayPaymentMethodLauncher @AssistedInject internal constructor(
* @param transactionId A unique ID that identifies a transaction attempt. Merchants may use an
* existing ID or generate a specific one for Google Pay transaction attempts.
* This field is required when you send callbacks to the Google Transaction Events API.
* @param label An optional label to display with the amount. Google Pay may or may not display
* this label depending on its own internal logic. Defaults to a generic label if none is
* provided.
*/
@JvmOverloads
fun present(
currencyCode: String,
amount: Long = 0L,
transactionId: String? = null
transactionId: String? = null,
label: String? = null,
) {
check(skipReadyCheck || isReady) {
"present() may only be called when Google Pay is available on this device."
Expand All @@ -263,6 +267,7 @@ class GooglePayPaymentMethodLauncher @AssistedInject internal constructor(
config = config,
currencyCode = currencyCode,
amount = amount,
label = label,
transactionId = transactionId,
injectionParams = GooglePayPaymentMethodLauncherContractV2.Args.InjectionParams(
injectorKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,26 @@ class GooglePayPaymentMethodLauncherContractV2 :
internal val config: GooglePayPaymentMethodLauncher.Config,
internal val currencyCode: String,
internal val amount: Long,
internal val label: String? = null,
internal val transactionId: String? = null,
internal val injectionParams: InjectionParams? = null
internal val injectionParams: InjectionParams? = null,
jaynewstrom-stripe marked this conversation as resolved.
Show resolved Hide resolved
) : Parcelable {

@JvmOverloads
constructor(
config: GooglePayPaymentMethodLauncher.Config,
currencyCode: String,
amount: Long,
transactionId: String? = null
) : this(config, currencyCode, amount, transactionId, null)
transactionId: String? = null,
label: String? = null,
) : this(
config = config,
currencyCode = currencyCode,
amount = amount,
label = label,
transactionId = transactionId,
injectionParams = null,
)

internal fun toBundle() = bundleOf(EXTRA_ARGS to this)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal class GooglePayPaymentMethodLauncherViewModel @Inject constructor(
countryCode = args.config.merchantCountryCode,
transactionId = args.transactionId,
totalPrice = args.amount,
totalPriceLabel = null,
totalPriceLabel = args.label,
checkoutOption = GooglePayJsonFactory.TransactionInfo.CheckoutOption.Default
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ class GooglePayPaymentMethodLauncherViewModelTest {

val factory = GooglePayPaymentMethodLauncherViewModel.Factory(
GooglePayPaymentMethodLauncherContractV2.Args(
mock(),
"usd",
1099,
null,
GooglePayPaymentMethodLauncherContractV2.Args.InjectionParams(
config = mock(),
currencyCode = "usd",
amount = 1099,
label = null,
transactionId = null,
injectionParams = GooglePayPaymentMethodLauncherContractV2.Args.InjectionParams(
injectorKey,
emptySet(),
false,
Expand Down Expand Up @@ -201,15 +202,16 @@ class GooglePayPaymentMethodLauncherViewModelTest {

val factory = GooglePayPaymentMethodLauncherViewModel.Factory(
GooglePayPaymentMethodLauncherContractV2.Args(
GooglePayPaymentMethodLauncher.Config(
config = GooglePayPaymentMethodLauncher.Config(
GooglePayEnvironment.Test,
"US",
"merchant"
),
"usd",
1099,
null,
GooglePayPaymentMethodLauncherContractV2.Args.InjectionParams(
currencyCode = "usd",
amount = 1099,
label = null,
transactionId = null,
injectionParams = GooglePayPaymentMethodLauncherContractV2.Args.InjectionParams(
DUMMY_INJECTOR_KEY,
productUsage,
false,
Expand Down
Loading
Loading