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 crypto payment method #9753

Merged
merged 1 commit into from
Dec 6, 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
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 - 20XX-XX-XX

### Payments
* [ADDED][9753](https://github.com/stripe/stripe-android/pull/9753) Added support for Crypto to API bindings and payment sheet.

## 21.2.1 - 2024-12-02
### PaymentSheet
- [FIXED][9695](https://github.com/stripe/stripe-android/pull/9695) US Bank Account now supports the `instant_or_skip` verification method.
Expand Down
1 change: 1 addition & 0 deletions example/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<activity android:name=".activity.SunbitActivity"/>
<activity android:name=".activity.BillieActivity"/>
<activity android:name=".activity.SatispayActivity"/>
<activity android:name=".activity.CryptoActivity"/>
<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 @@ -39,6 +39,7 @@
<string name="sunbit_example">Sunbit</string>
<string name="billie_example">Billie</string>
<string name="satispay_example">Satispay</string>
<string name="crypto_example">Crypto</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
@@ -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 CryptoActivity : 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 = "")

CryptoPayScreen(
isProcessing = isProcessing,
status = status,
onButtonPressed = { payWithCrypto() }
)
}
}

private fun payWithCrypto() {
val params = PaymentMethodCreateParams.createCrypto()
createAndConfirmPaymentIntent(
country = "US",
paymentMethodCreateParams = params,
supportedPaymentMethods = PaymentMethod.Type.Crypto.code,
currency = "USD",
)
}
}

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

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),
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ class LauncherActivity : AppCompatActivity() {
activity.getString(R.string.satispay_example),
SatispayActivity::class.java
),
Item(
activity.getString(R.string.crypto_example),
CryptoActivity::class.java
),
// This is for internal use so as not to confuse the user.
Item(
"StripeImage Example",
Expand Down
10 changes: 10 additions & 0 deletions payments-core/api/payments-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -3526,6 +3526,7 @@ public final class com/stripe/android/model/PaymentMethod$Type : java/lang/Enum,
public static final field CardPresent Lcom/stripe/android/model/PaymentMethod$Type;
public static final field CashAppPay Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Companion Lcom/stripe/android/model/PaymentMethod$Type$Companion;
public static final field Crypto Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Eps Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Fpx Lcom/stripe/android/model/PaymentMethod$Type;
public static final field Giropay Lcom/stripe/android/model/PaymentMethod$Type;
Expand Down Expand Up @@ -3797,6 +3798,10 @@ public final class com/stripe/android/model/PaymentMethodCreateParams : android/
public static final fun createCashAppPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createCashAppPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createCashAppPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createCrypto ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createCrypto (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createCrypto (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createCrypto (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createEps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createEps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createEps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down Expand Up @@ -4091,6 +4096,11 @@ public final class com/stripe/android/model/PaymentMethodCreateParams$Companion
public final fun createCashAppPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createCashAppPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createCashAppPay$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createCrypto ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createCrypto (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createCrypto (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createCrypto (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createCrypto$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createEps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createEps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createEps (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;Lcom/stripe/android/model/PaymentMethod$AllowRedisplay;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,13 @@ constructor(
requiresMandate = false,
hasDelayedSettlement = false,
),
Crypto(
"crypto",
isReusable = false,
isVoucher = false,
requiresMandate = false,
hasDelayedSettlement = false,
),
AmazonPay(
"amazon_pay",
isReusable = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,25 @@ constructor(
)
}

/**
* Helper method to create [PaymentMethodCreateParams] with [PaymentMethod.Type.Crypto] as the payment
* method type
*/
@JvmStatic
@JvmOverloads
fun createCrypto(
billingDetails: PaymentMethod.BillingDetails? = null,
metadata: Map<String, String>? = null,
allowRedisplay: PaymentMethod.AllowRedisplay? = null,
): PaymentMethodCreateParams {
return PaymentMethodCreateParams(
type = PaymentMethod.Type.Crypto,
billingDetails = billingDetails,
metadata = metadata,
allowRedisplay = allowRedisplay,
)
}

/**
* 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 @@ -45,4 +45,6 @@ internal object ApiKeyFixtures {
"pk_test_51PSnNaAlz2yHYCNZgjajit4L8Hl1rDDPPCj9XhHNZWRSi4vwHhrHIbTgstLJptPSzwQVl1HlyqhwWRs1rBJHag8W00sM0SOXIL"
const val SATISPAY_PUBLISHABLE_KEY =
"pk_test_51PSnETIFbdis1OxTALF4Z8ugUQpVS06UQDVahMSmwrbEYphjNYitXtOSqMPVKfzl3jukg6gLLrtZNnPlDrRbDpMd00U0tId6iv"
const val CRYPTO_PUBLISHABLE_KEY =
"pk_test_51HvTI7Lu5o3P18Zp6t5AgBSkMvWoTtA0nyA7pVYDqpfLkRtWun7qZTYCOHCReprfLM464yaBeF72UFfB7cY9WG4a00ZnDtiC2C"
}
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,15 @@ internal class PaymentMethodEndToEndTest {
assertThat(paymentMethod.type).isEqualTo(PaymentMethod.Type.Satispay)
}

@Test
fun createPaymentMethod_withCrypto_shouldCreateObject() {
val params = PaymentMethodCreateParamsFixtures.CRYPTO
val stripe = Stripe(context, ApiKeyFixtures.CRYPTO_PUBLISHABLE_KEY)

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

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

internal val CRYPTO = PaymentMethodCreateParams.createCrypto(
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,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M8,16C12.418,16 16,12.418 16,8C16,3.582 12.418,0 8,0C3.582,0 0,3.582 0,8C0,12.418 3.582,16 8,16ZM6.625,3C6.28,3 6,3.28 6,3.625V4.536C5.572,4.783 5.19,5.109 4.877,5.501C4.312,6.206 4.003,7.082 4,7.986C3.997,8.89 4.3,9.768 4.86,10.478C5.176,10.879 5.564,11.212 6,11.464V12.375C6,12.72 6.28,13 6.625,13C6.97,13 7.25,12.72 7.25,12.375V11.929C7.748,12.024 8.257,12.023 8.75,11.929V12.375C8.75,12.72 9.03,13 9.375,13C9.72,13 10,12.72 10,12.375V11.464C10.451,11.204 10.845,10.859 11.162,10.45C11.433,10.101 11.265,9.615 10.869,9.419C10.474,9.223 10.001,9.399 9.687,9.709C9.495,9.899 9.271,10.056 9.023,10.173C8.532,10.404 7.978,10.462 7.45,10.337C6.921,10.213 6.451,9.913 6.115,9.487C5.779,9.061 5.597,8.534 5.599,7.992C5.601,7.449 5.786,6.923 6.125,6.5C6.464,6.076 6.937,5.78 7.466,5.659C7.995,5.538 8.549,5.6 9.038,5.835C9.285,5.953 9.508,6.111 9.698,6.302C10.011,6.614 10.482,6.794 10.879,6.601C11.276,6.408 11.447,5.923 11.179,5.572C10.859,5.153 10.459,4.801 10,4.536V3.625C10,3.28 9.72,3 9.375,3C9.03,3 8.75,3.28 8.75,3.625V4.071C8.257,3.977 7.748,3.976 7.25,4.071V3.625C7.25,3.28 6.97,3 6.625,3Z"
android:fillColor="#000000"
android:fillType="evenOdd"/>
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="16dp"
android:height="16dp"
android:viewportWidth="16"
android:viewportHeight="16">
<path
android:pathData="M8,16C12.418,16 16,12.418 16,8C16,3.582 12.418,0 8,0C3.582,0 0,3.582 0,8C0,12.418 3.582,16 8,16ZM6.625,3C6.28,3 6,3.28 6,3.625V4.536C5.572,4.783 5.191,5.109 4.878,5.501C4.313,6.206 4.004,7.082 4.001,7.986C3.998,8.89 4.301,9.768 4.86,10.478C5.177,10.878 5.564,11.212 6,11.464V12.375C6,12.72 6.28,13 6.625,13C6.97,13 7.25,12.72 7.25,12.375V11.929C7.748,12.024 8.257,12.023 8.75,11.929V12.375C8.75,12.72 9.03,13 9.375,13C9.72,13 10,12.72 10,12.375V11.465C10.451,11.204 10.846,10.859 11.163,10.45C11.433,10.101 11.265,9.615 10.87,9.419C10.474,9.223 10.002,9.399 9.687,9.709C9.495,9.899 9.271,10.056 9.024,10.173C8.533,10.404 7.978,10.462 7.45,10.337C6.922,10.213 6.452,9.913 6.116,9.487C5.779,9.061 5.598,8.534 5.599,7.992C5.601,7.449 5.787,6.923 6.126,6.5C6.465,6.076 6.937,5.78 7.466,5.659C7.995,5.538 8.549,5.6 9.039,5.835C9.285,5.953 9.508,6.111 9.699,6.302C10.011,6.614 10.482,6.794 10.879,6.601C11.276,6.408 11.448,5.923 11.18,5.572C10.86,5.153 10.459,4.8 10,4.535V3.625C10,3.28 9.72,3 9.375,3C9.03,3 8.75,3.28 8.75,3.625V4.071C8.257,3.977 7.748,3.976 7.25,4.071V3.625C7.25,3.28 6.97,3 6.625,3Z"
android:fillColor="#EBEBEB"
android:fillType="evenOdd"/>
</vector>
1 change: 1 addition & 0 deletions payments-ui-core/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<string name="stripe_paymentsheet_payment_method_sunbit">Sunbit</string>
<string name="stripe_paymentsheet_payment_method_billie">Billie</string>
<string name="stripe_paymentsheet_payment_method_satispay">Satispay</string>
<string name="stripe_paymentsheet_payment_method_crypto">Crypto</string>
<string name="stripe_paymentsheet_payment_method_alma">Alma</string>
<string name="stripe_paymentsheet_payment_method_mobile_pay">MobilePay</string>
<string name="stripe_paymentsheet_payment_method_zip">Zip</string>
Expand Down
27 changes: 27 additions & 0 deletions payments-ui-core/src/main/resources/lpms.json
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,33 @@
}
}
},
{
"type": "crypto",
"async": false,
"selector_icon": {
"light_theme_png": "https://js.stripe.com/v3/fingerprinted/img/payment-methods/icon-pm-crypto@3x-94c06c199e78e6d9ff9290210912bd5e.png",
"light_theme_svg": "https://js.stripe.com/v3/fingerprinted/img/payment-methods/icon-pm-crypto-15fd4ffeafd1b13e40688c8a06d79ba4.svg",
"dark_theme_png": "https://js.stripe.com/v3/fingerprinted/img/payment-methods/icon-pm-crypto_dark@3x-8f7b0e91b45cb56de550af37d41aac1d.png",
"dark_theme_svg": "https://js.stripe.com/v3/fingerprinted/img/payment-methods/icon-pm-crypto_dark-f19bb5c5400c6cde94dd53b7f1ce7217.svg"
},
"fields": [
],
"next_action_spec": {
"confirm_response_status_specs": {
"requires_action": {
"type": "redirect_to_url"
}
},
"post_confirm_handling_pi_status_specs": {
"succeeded": {
"type": "finished"
},
"requires_action": {
"type": "canceled"
}
}
}
},
{
"type": "mobilepay",
"async": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.stripe.android.lpm

import androidx.test.ext.junit.runners.AndroidJUnit4
import com.stripe.android.BasePlaygroundTest
import com.stripe.android.model.PaymentMethod
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 TestCrypto : BasePlaygroundTest() {
private val testParameters = TestParameters.create(
paymentMethodCode = "crypto",
) { settings ->
settings[CountrySettingsDefinition] = Country.US
settings[CurrencySettingsDefinition] = Currency.USD
settings[SupportedPaymentMethodsSettingsDefinition] = listOf(
PaymentMethod.Type.Crypto
).joinToString(",")
}

@Test
fun testCrypto() {
testDriver.confirmCustom(
testParameters = testParameters,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.stripe.android.lpmfoundations.paymentmethod.definitions.BlikDefinitio
import com.stripe.android.lpmfoundations.paymentmethod.definitions.BoletoDefinition
import com.stripe.android.lpmfoundations.paymentmethod.definitions.CardDefinition
import com.stripe.android.lpmfoundations.paymentmethod.definitions.CashAppPayDefinition
import com.stripe.android.lpmfoundations.paymentmethod.definitions.CryptoDefinition
import com.stripe.android.lpmfoundations.paymentmethod.definitions.EpsDefinition
import com.stripe.android.lpmfoundations.paymentmethod.definitions.FpxDefinition
import com.stripe.android.lpmfoundations.paymentmethod.definitions.GiroPayDefinition
Expand Down Expand Up @@ -54,6 +55,7 @@ internal object PaymentMethodRegistry {
BoletoDefinition,
CardDefinition,
CashAppPayDefinition,
CryptoDefinition,
EpsDefinition,
FpxDefinition,
GiroPayDefinition,
Expand Down
Loading
Loading