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 Alma API bindings #8257

Merged
merged 3 commits into from
Apr 15, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Payments
* [FIXED][8243](https://github.com/stripe/stripe-android/pull/8243) Fixed an issue with R8 when depending directly on `payments-core`.
* [ADDED][8257](https://github.com/stripe/stripe-android/pull/8257) Added support for Alma to API bindings.

## 20.40.4 - 2024-04-04

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.RevolutPayActivity"/>
<activity android:name=".activity.SwishExampleActivity"/>
<activity android:name=".activity.MobilePayExampleActivity"/>
<activity android:name=".activity.AlmaActivity"/>
</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="amazon_pay_example">Amazon Pay</string>
<string name="revolut_pay_example">Revolut Pay</string>
<string name="alma_example">Alma</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 AlmaActivity : 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 = "")

AlmaPayScreen(
isProcessing = isProcessing,
status = status,
onButtonPressed = { payWithAlma() }
)
}
}

private fun payWithAlma() {
val params = PaymentMethodCreateParams.createAlma()
createAndConfirmPaymentIntent(
country = "FR",
paymentMethodCreateParams = params,
supportedPaymentMethods = PaymentMethod.Type.Alma.code,
currency = "EUR",
)
}
}

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

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.mobilepay_example),
MobilePayExampleActivity::class.java
),
Item(
activity.getString(R.string.alma_example),
AlmaActivity::class.java
),
// This is for internal use so as not to confuse the user.
Item(
"StripeImage Example",
Expand Down
7 changes: 7 additions & 0 deletions payments-core/api/payments-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -3961,6 +3961,9 @@ public final class com/stripe/android/model/PaymentMethodCreateParams : android/
public static final fun createAfterpayClearpay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createAlipay ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createAlipay (Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createAlma ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createAlma (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createAlma (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createAmazonPay ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createAmazonPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static final fun createAmazonPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down Expand Up @@ -4200,6 +4203,10 @@ public final class com/stripe/android/model/PaymentMethodCreateParams$Companion
public final fun createAlipay ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createAlipay (Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createAlipay$default (Lcom/stripe/android/model/PaymentMethodCreateParams$Companion;Ljava/util/Map;ILjava/lang/Object;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createAlma ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createAlma (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createAlma (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public static synthetic fun createAlma$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 createAmazonPay ()Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createAmazonPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;)Lcom/stripe/android/model/PaymentMethodCreateParams;
public final fun createAmazonPay (Lcom/stripe/android/model/PaymentMethod$BillingDetails;Ljava/util/Map;)Lcom/stripe/android/model/PaymentMethodCreateParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,23 @@ data class PaymentMethodCreateParams internal constructor(
)
}

/**
* Helper method to create [PaymentMethodCreateParams] with [PaymentMethod.Type.Alma] as the payment
* method type
*/
@JvmStatic
@JvmOverloads
fun createAlma(
billingDetails: PaymentMethod.BillingDetails? = null,
metadata: Map<String, String>? = null
): PaymentMethodCreateParams {
return PaymentMethodCreateParams(
type = PaymentMethod.Type.Alma,
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 @@ -35,4 +35,6 @@ internal object ApiKeyFixtures {
"pk_test_51JtgfQKG6vc7r7YCU0qQNOkDaaHrEgeHgGKrJMNfuWwaKgXMLzPUA1f8ZlCNPonIROLOnzpUnJK1C1xFH3M3Mz8X00Q6O4GfUt"
const val AMAZON_PAY_PUBLISHABLE_KEY =
"pk_test_51HvTI7Lu5o3P18Zp6t5AgBSkMvWoTtA0nyA7pVYDqpfLkRtWun7qZTYCOHCReprfLM464yaBeF72UFfB7cY9WG4a00ZnDtiC2C"
const val ALMA_PUBLISHABLE_KEY =
"pk_test_51JtgfQKG6vc7r7YCU0qQNOkDaaHrEgeHgGKrJMNfuWwaKgXMLzPUA1f8ZlCNPonIROLOnzpUnJK1C1xFH3M3Mz8X00Q6O4GfUt"
}
Original file line number Diff line number Diff line change
Expand Up @@ -473,4 +473,13 @@ internal class PaymentMethodEndToEndTest {
val paymentMethod = stripe.createPaymentMethodSynchronous(params)
assertThat(paymentMethod.type).isEqualTo(PaymentMethod.Type.AmazonPay)
}

@Test
fun createPaymentMethod_withAlma_shouldCreateObject() {
val params = PaymentMethodCreateParamsFixtures.ALMA
val stripe = Stripe(context, ApiKeyFixtures.ALMA_PUBLISHABLE_KEY)

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

internal val ALMA = PaymentMethodCreateParams.createAlma(
billingDetails = BILLING_DETAILS
)

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