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

Integrate Sunbit on PaymentSheet #8595

Merged
merged 9 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

## XX.XX.XX - 20XX-XX-XX

### PaymentSheet
* [ADDED][8595](https://github.com/stripe/stripe-android/pull/8595) Added support for Sunbit to PaymentSheet.

### Payments
* [FIXED][8590](https://github.com/stripe/stripe-android/pull/8590) Fix an issue where cancelling payment for Amazon Pay and Cash App Pay would show an error
* [ADDED][8595](https://github.com/stripe/stripe-android/pull/8595) Added support for Sunbit to API bindings.

## 20.44.2 - 2024-06-03

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

Expand Down
1 change: 1 addition & 0 deletions example/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<string name="amazon_pay_example">Amazon Pay</string>
<string name="revolut_pay_example">Revolut Pay</string>
<string name="alma_example">Alma</string>
<string name="sunbit_example">Sunbit</string>
<string name="swish_example">Swish</string>
<string name="mobilepay_example">MobilePay</string>
<string name="card_brands">Card Brands</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class LauncherActivity : AppCompatActivity() {
activity.getString(R.string.alma_example),
AlmaActivity::class.java
),
Item(
activity.getString(R.string.sunbit_example),
SunbitActivity::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.PaymentMethod
import com.stripe.android.model.PaymentMethodCreateParams

class SunbitActivity : 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 = "")

SunbitPayScreen(
isProcessing = isProcessing,
status = status,
onButtonPressed = { payWithSunbit() }
)
}
}

private fun payWithSunbit() {
val params = PaymentMethodCreateParams.createSunbit()
createAndConfirmPaymentIntent(
country = "US",
paymentMethodCreateParams = params,
supportedPaymentMethods = PaymentMethod.Type.Sunbit.code,
currency = "USD",
)
}
}

@Composable
private fun SunbitPayScreen(
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 Sunbit")
}

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),
)
}
}
}
}
32 changes: 29 additions & 3 deletions payments-core/api/payments-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -3760,6 +3760,7 @@ public final class com/stripe/android/model/PaymentMethod$Type : java/lang/Enum,
public static final field RevolutPay Lcom/stripe/android/model/PaymentMethod$Type;
public static final field SepaDebit Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Sofort Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Sunbit Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Swish Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Twint Lcom/stripe/android/model/PaymentMethod$Type;
public static final field USBankAccount Lcom/stripe/android/model/PaymentMethod$Type;
Expand Down Expand Up @@ -3935,13 +3936,14 @@ public final class com/stripe/android/model/PaymentMethodCreateParams : android/
public synthetic fun <init> (Lcom/stripe/android/model/PaymentMethodCreateParams$Netbanking;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lcom/stripe/android/model/PaymentMethodCreateParams$SepaDebit;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lcom/stripe/android/model/PaymentMethodCreateParams$Sofort;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lcom/stripe/android/model/PaymentMethodCreateParams$Sunbit;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lcom/stripe/android/model/PaymentMethodCreateParams$Swish;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lcom/stripe/android/model/PaymentMethodCreateParams$USBankAccount;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (Lcom/stripe/android/model/PaymentMethodCreateParams$Upi;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component16 ()Lcom/stripe/android/model/PaymentMethod$BillingDetails;
public final fun component17 ()Lcom/stripe/android/model/PaymentMethod$BillingDetails;
public final fun component3 ()Lcom/stripe/android/model/PaymentMethodCreateParams$Card;
public final fun copy (Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethodCreateParams$Card;Lcom/stripe/android/model/PaymentMethodCreateParams$Ideal;Lcom/stripe/android/model/PaymentMethodCreateParams$Fpx;Lcom/stripe/android/model/PaymentMethodCreateParams$SepaDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$AuBecsDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$BacsDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$Sofort;Lcom/stripe/android/model/PaymentMethodCreateParams$Upi;Lcom/stripe/android/model/PaymentMethodCreateParams$Netbanking;Lcom/stripe/android/model/PaymentMethodCreateParams$USBankAccount;Lcom/stripe/android/model/PaymentMethodCreateParams$Link;Lcom/stripe/android/model/PaymentMethodCreateParams$CashAppPay;Lcom/stripe/android/model/PaymentMethodCreateParams$Swish;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Ljava/util/Set;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun copy$default (Lcom/stripe/android/model/PaymentMethodCreateParams;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethodCreateParams$Card;Lcom/stripe/android/model/PaymentMethodCreateParams$Ideal;Lcom/stripe/android/model/PaymentMethodCreateParams$Fpx;Lcom/stripe/android/model/PaymentMethodCreateParams$SepaDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$AuBecsDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$BacsDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$Sofort;Lcom/stripe/android/model/PaymentMethodCreateParams$Upi;Lcom/stripe/android/model/PaymentMethodCreateParams$Netbanking;Lcom/stripe/android/model/PaymentMethodCreateParams$USBankAccount;Lcom/stripe/android/model/PaymentMethodCreateParams$Link;Lcom/stripe/android/model/PaymentMethodCreateParams$CashAppPay;Lcom/stripe/android/model/PaymentMethodCreateParams$Swish;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Ljava/util/Set;Ljava/util/Map;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun copy (Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethodCreateParams$Card;Lcom/stripe/android/model/PaymentMethodCreateParams$Ideal;Lcom/stripe/android/model/PaymentMethodCreateParams$Fpx;Lcom/stripe/android/model/PaymentMethodCreateParams$SepaDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$AuBecsDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$BacsDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$Sofort;Lcom/stripe/android/model/PaymentMethodCreateParams$Upi;Lcom/stripe/android/model/PaymentMethodCreateParams$Netbanking;Lcom/stripe/android/model/PaymentMethodCreateParams$USBankAccount;Lcom/stripe/android/model/PaymentMethodCreateParams$Link;Lcom/stripe/android/model/PaymentMethodCreateParams$CashAppPay;Lcom/stripe/android/model/PaymentMethodCreateParams$Sunbit;Lcom/stripe/android/model/PaymentMethodCreateParams$Swish;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Ljava/util/Set;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun copy$default (Lcom/stripe/android/model/PaymentMethodCreateParams;Ljava/lang/String;ZLcom/stripe/android/model/PaymentMethodCreateParams$Card;Lcom/stripe/android/model/PaymentMethodCreateParams$Ideal;Lcom/stripe/android/model/PaymentMethodCreateParams$Fpx;Lcom/stripe/android/model/PaymentMethodCreateParams$SepaDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$AuBecsDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$BacsDebit;Lcom/stripe/android/model/PaymentMethodCreateParams$Sofort;Lcom/stripe/android/model/PaymentMethodCreateParams$Upi;Lcom/stripe/android/model/PaymentMethodCreateParams$Netbanking;Lcom/stripe/android/model/PaymentMethodCreateParams$USBankAccount;Lcom/stripe/android/model/PaymentMethodCreateParams$Link;Lcom/stripe/android/model/PaymentMethodCreateParams$CashAppPay;Lcom/stripe/android/model/PaymentMethodCreateParams$Sunbit;Lcom/stripe/android/model/PaymentMethodCreateParams$Swish;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Ljava/util/Set;Ljava/util/Map;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun create (Lcom/stripe/android/model/PaymentMethodCreateParams$AuBecsDebit;Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun create (Lcom/stripe/android/model/PaymentMethodCreateParams$AuBecsDebit;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun create (Lcom/stripe/android/model/PaymentMethodCreateParams$BacsDebit;Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down Expand Up @@ -4018,6 +4020,9 @@ public final class com/stripe/android/model/PaymentMethodCreateParams : android/
public static final fun createRevolutPay ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createRevolutPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createRevolutPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createSunbit ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createSunbit (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createSunbit (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createSwish ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createSwish (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createSwish (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down Expand Up @@ -4278,6 +4283,10 @@ public final class com/stripe/android/model/PaymentMethodCreateParams$Companion
public final fun createRevolutPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createRevolutPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createRevolutPay$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 createSunbit ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createSunbit (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createSunbit (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createSunbit$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 createSwish ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createSwish (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createSwish (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down Expand Up @@ -4442,6 +4451,23 @@ public final class com/stripe/android/model/PaymentMethodCreateParams$Sofort$Cre
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/model/PaymentMethodCreateParams$Sunbit : android/os/Parcelable, com/stripe/android/model/StripeParamsModel {
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
public fun <init> ()V
public fun describeContents ()I
public fun toParamMap ()Ljava/util/Map;
public fun writeToParcel (Landroid/os/Parcel;I)V
}

public final class com/stripe/android/model/PaymentMethodCreateParams$Sunbit$Creator : android/os/Parcelable$Creator {
public fun <init> ()V
public final fun createFromParcel (Landroid/os/Parcel;)Lcom/stripe/android/model/PaymentMethodCreateParams$Sunbit;
public synthetic fun createFromParcel (Landroid/os/Parcel;)Ljava/lang/Object;
public final fun newArray (I)[Lcom/stripe/android/model/PaymentMethodCreateParams$Sunbit;
public synthetic fun newArray (I)[Ljava/lang/Object;
}

public final class com/stripe/android/model/PaymentMethodCreateParams$Swish : android/os/Parcelable, com/stripe/android/model/StripeParamsModel {
public static final field $stable I
public static final field CREATOR Landroid/os/Parcelable$Creator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ constructor(
hasDelayedSettlement = false,
shouldRefreshIfIntentRequiresAction = false,
),
Sunbit(
"sunbit",
isReusable = false,
isVoucher = false,
requiresMandate = false,
hasDelayedSettlement = false,
shouldRefreshIfIntentRequiresAction = false,
),
AmazonPay(
"amazon_pay",
isReusable = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,23 @@ data class PaymentMethodCreateParams internal constructor(
)
}

/**
* Helper method to create [PaymentMethodCreateParams] with [PaymentMethod.Type.Sunbit] as the payment
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know why this is showing the fully qualified type name here (PaymentMethod.Type.Sunbit)? Can it show Sunbit instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the time of this comment, we didn't have a Sunbit method. I added it in here (and piped it through in a few places), but I'm not sure if we get much value out of it.

Here's the commit, let me know if you think we should take this approach for the other payment methods.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm agreed that it doesn't seem like we get much value out of it and it looks like we didn't do this for Multibanco or Amazon Pay, so I don't think we need it here either or for the other payment methods. Sorry for the churn!

* method type
*/
@JvmStatic
@JvmOverloads
fun createSunbit(
billingDetails: PaymentMethod.BillingDetails? = null,
metadata: Map<String, String>? = null
): PaymentMethodCreateParams {
return PaymentMethodCreateParams(
type = PaymentMethod.Type.Sunbit,
billingDetails = billingDetails,
metadata = metadata
)
}

/**
* Helper method to create [PaymentMethodCreateParams] with [Swish] as the payment
* method type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ internal object ApiKeyFixtures {
"pk_test_51HvTI7Lu5o3P18Zp6t5AgBSkMvWoTtA0nyA7pVYDqpfLkRtWun7qZTYCOHCReprfLM464yaBeF72UFfB7cY9WG4a00ZnDtiC2C"
const val ALMA_PUBLISHABLE_KEY =
"pk_test_51JtgfQKG6vc7r7YCU0qQNOkDaaHrEgeHgGKrJMNfuWwaKgXMLzPUA1f8ZlCNPonIROLOnzpUnJK1C1xFH3M3Mz8X00Q6O4GfUt"
const val SUNBIT_PUBLISHABLE_KEY =
"pk_test_51PHAxOEXPZHliQOymEG4f3mVg18FAseUQkcugmWoQ2S7gmAa418zKZTgoBsnaiPRcBrxRpIeTlclfTwm1PwF6ndu00zvHhDWCe"
}
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,15 @@ internal class PaymentMethodEndToEndTest {
assertThat(paymentMethod.type).isEqualTo(PaymentMethod.Type.Alma)
}

@Test
fun createPaymentMethod_withSunbit_shouldCreateObject() {
val params = PaymentMethodCreateParamsFixtures.SUNBIT
val stripe = Stripe(context, ApiKeyFixtures.SUNBIT_PUBLISHABLE_KEY)

val paymentMethod = stripe.createPaymentMethodSynchronous(params)
assertThat(paymentMethod.type).isEqualTo(PaymentMethod.Type.Sunbit)
}

@Test
fun createPaymentMethod_withMultibanco_shouldCreateObject() {
val params = PaymentMethodCreateParamsFixtures.MULTIBANCO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ internal object PaymentMethodCreateParamsFixtures {
billingDetails = BILLING_DETAILS
)

internal val SUNBIT = PaymentMethodCreateParams.createSunbit(
billingDetails = BILLING_DETAILS
)

@JvmStatic
fun createWith(metadata: Map<String, String>): PaymentMethodCreateParams {
return PaymentMethodCreateParams.create(
Expand Down
Loading
Loading