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 bindings support for mobile pay. #7431

Merged
merged 2 commits into from
Oct 12, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## XX.XX.XX - 2023-XX-XX

### Payments
* [ADDED][7431](https://github.com/stripe/stripe-android/pull/7431) Added bindings support for MobilePay. See [private beta information](https://stripe.com/docs/payments/mobilepay).

## 20.32.1 - 2023-10-09

### PaymentSheet
Expand Down
1 change: 1 addition & 0 deletions example/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<activity android:name=".activity.BlikPaymentMethodActivity"/>
<activity android:name=".activity.RevolutPayActivity"/>
<activity android:name=".activity.SwishExampleActivity"/>
<activity android:name=".activity.MobilePayExampleActivity"/>
</application>

</manifest>
1 change: 1 addition & 0 deletions example/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<string name="cash_app_pay_example">Cash App Pay</string>
<string name="revolut_pay_example">Revolut Pay</string>
<string name="swish_example">Swish</string>
<string name="mobilepay_example">MobilePay</string>
<string name="card_brands">Card Brands</string>
<string name="card_brands_hint">Card number</string>
<string name="possible_card_brands">Possible Card Brands</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ class LauncherActivity : AppCompatActivity() {
activity.getString(R.string.swish_example),
SwishExampleActivity::class.java
),
Item(
activity.getString(R.string.mobilepay_example),
MobilePayExampleActivity::class.java
),
// This is for internal use so as not to confuse the user.
Item(
"StripeImage Example",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.stripe.example.activity

import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Button
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.google.accompanist.themeadapter.material.MdcTheme
import com.stripe.android.model.PaymentMethodCreateParams

class MobilePayExampleActivity : StripeIntentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
val isProcessing by viewModel.inProgress.observeAsState(initial = false)
val status by viewModel.status.observeAsState(initial = "")

MobilePayScreen(
isProcessing = isProcessing,
status = status,
onButtonPressed = { payWithMobilePay() },
)
}
}

private fun payWithMobilePay() {
val params = PaymentMethodCreateParams.createMobilePay()

createAndConfirmPaymentIntent(
country = "FR",
currency = "EUR",
paymentMethodCreateParams = params,
supportedPaymentMethods = "mobilepay",
)
}
}

@Composable
private fun MobilePayScreen(
isProcessing: Boolean,
status: String,
onButtonPressed: () -> Unit,
) {
MdcTheme {
Column(modifier = Modifier.fillMaxSize()) {
Row(verticalAlignment = Alignment.CenterVertically) {
Button(
onClick = onButtonPressed,
enabled = !isProcessing,
modifier = Modifier.padding(16.dp),
) {
Text("Pay with MobilePay")
}

if (isProcessing) {
CircularProgressIndicator(modifier = Modifier.size(24.dp))
}
}

if (status.isNotBlank()) {
Divider(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp),
)

Text(
text = status,
modifier = Modifier
.fillMaxWidth()
.padding(16.dp),
)
}
}
}
}
7 changes: 7 additions & 0 deletions payments-core/api/payments-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -3971,6 +3971,9 @@ public final class com/stripe/android/model/PaymentMethodCreateParams : android/
public static final fun createKlarna ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createKlarna (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createKlarna (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createMobilePay ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createMobilePay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createMobilePay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createOxxo (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createOxxo (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createP24 (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down Expand Up @@ -4194,6 +4197,10 @@ public final class com/stripe/android/model/PaymentMethodCreateParams$Companion
public final fun createKlarna (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createKlarna (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createKlarna$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createMobilePay ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createMobilePay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createMobilePay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createMobilePay$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createOxxo (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createOxxo (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createOxxo$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,6 +1048,19 @@ data class PaymentMethodCreateParams internal constructor(
)
}

@JvmStatic
@JvmOverloads
fun createMobilePay(
billingDetails: PaymentMethod.BillingDetails? = null,
metadata: Map<String, String>? = null
): PaymentMethodCreateParams {
return PaymentMethodCreateParams(
type = PaymentMethod.Type.MobilePay,
billingDetails = billingDetails,
metadata = metadata
)
}

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
fun createLink(
paymentDetailsId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ internal object ApiKeyFixtures {
"pk_test_51KmkHbGoesj9fw9QAZJlz1qY4dns8nFmLKc7rXiWKAIj8QU7NPFPwSY1h8mqRaFRKQ9njs9pVJoo2jhN6ZKSDA4h00mjcbGF7b"
const val SWISH_PUBLISHABLE_KEY =
"pk_test_51JtgfQKG6vc7r7YCU0qQNOkDaaHrEgeHgGKrJMNfuWwaKgXMLzPUA1f8ZlCNPonIROLOnzpUnJK1C1xFH3M3Mz8X00Q6O4GfUt"
const val MOBILE_PAY_PUBLISHABLE_KEY =
"pk_test_51JtgfQKG6vc7r7YCU0qQNOkDaaHrEgeHgGKrJMNfuWwaKgXMLzPUA1f8ZlCNPonIROLOnzpUnJK1C1xFH3M3Mz8X00Q6O4GfUt"
}
Original file line number Diff line number Diff line change
Expand Up @@ -465,4 +465,13 @@ internal class PaymentMethodEndToEndTest {
val paymentMethod = stripe.createPaymentMethodSynchronous(params)
assertThat(paymentMethod.type).isEqualTo(PaymentMethod.Type.Swish)
}

@Test
fun createPaymentMethod_withMobilePay_shouldCreateObject() {
val params = PaymentMethodCreateParamsFixtures.MOBILE_PAY
val stripe = Stripe(context, ApiKeyFixtures.MOBILE_PAY_PUBLISHABLE_KEY)

val paymentMethod = stripe.createPaymentMethodSynchronous(params)
assertThat(paymentMethod.type).isEqualTo(PaymentMethod.Type.MobilePay)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ internal object PaymentMethodCreateParamsFixtures {
billingDetails = BILLING_DETAILS,
)

internal val MOBILE_PAY = PaymentMethodCreateParams.createMobilePay(
billingDetails = BILLING_DETAILS,
)

@JvmStatic
fun createWith(metadata: Map<String, String>): PaymentMethodCreateParams {
return PaymentMethodCreateParams.create(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.stripe.android.lpm

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.paymentsheet.example.playground.settings.Country
import com.stripe.android.paymentsheet.example.playground.settings.CountrySettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.Currency
import com.stripe.android.paymentsheet.example.playground.settings.CurrencySettingsDefinition
import com.stripe.android.paymentsheet.example.playground.settings.SupportedPaymentMethodsSettingsDefinition
import com.stripe.android.test.core.TestParameters
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
internal class TestMobilePay : BasePlaygroundTest() {
private val testParameters = TestParameters.create(
paymentMethodCode = "mobilepay",
) { settings ->
settings[CountrySettingsDefinition] = Country.FR
settings[CurrencySettingsDefinition] = Currency.EUR
settings[SupportedPaymentMethodsSettingsDefinition] = listOf("card", "mobilepay")
}

@Test
fun testMobilePay() {
testDriver.confirmNewOrGuestComplete(
testParameters = testParameters,
)
}

@Test
fun testMobilePayInCustomFlow() {
testDriver.confirmCustom(
testParameters = testParameters,
)
}
}