Accept in-app payments
Build a customized payments integration in your iOS, Android, or React Native app using the Payment Element.
The Payment Element is a customizable component that renders a list of payment methods that you can add into any screen in your app. When customers interact with payment methods in the list, the component opens individual bottom sheets to collect payment details.
The Payment Element allows you to accept multiple payment methods using a single integration. In this integration, you build a custom payment flow where you render the Payment Element, create the PaymentIntent, and confirm the payment in your app.
Set up StripeServer-sideClient-side
First, you need a Stripe account. Register now.
Server-side 
This integration requires endpoints on your server that talk to the Stripe API. Use the official libraries for access to the Stripe API from your server:
Client-side 
The Stripe Android SDK is open source and fully documented.
To install the SDK, add stripe-android to the dependencies block of your app/build.gradle file:
Note
For details on the latest SDK release and past versions, see the Releases page on GitHub. To receive notifications when a new release is published, watch releases for the repository.
You also need to set your publishable key so that the SDK can make API calls to Stripe. To get started quickly, you can hardcode this on the client while you’re integrating, but fetch the publishable key from your server in production.
// Set your publishable key: remember to change this to your live publishable key in production // See your keys here: https://dashboard.stripe.com/apikeys PaymentConfiguration.init(context, publishableKey =)"pk_test_TYooMQauvdEDq54NiTphI7jx"
Enable payment methods
View your payment methods settings and enable the payment methods you want to support. You need at least one payment method enabled to create a PaymentIntent.
By default, Stripe enables cards and other prevalent payment methods that can help you reach more customers, but we recommend turning on additional payment methods that are relevant for your business and customers. See Payment method support for product and payment method support, and our pricing page for fees.
OptionalClear the selected payment option
If you have payment options external to EmbeddedPaymentElement, you might need to clear the selected payment option. To do so, use the clearPaymentOption API to deselect the selected payment option.
@Composable fun CheckoutScreen() { val embeddedPaymentElementBuilder = .... val embeddedPaymentElement = rememberEmbeddedPaymentElement(embeddedPaymentElementBuilder) .... Button( onClick = embeddedPaymentElement::clearPaymentOption ) { Text("Select external payment option") } }
OptionalDisplay the mandate yourself
To ensure regulatory compliance, the Embedded Mobile Payment Element displays mandates and legal disclaimers by default. This text must be located close to your Buy button. If you disable the default display of this text in the view, you must display it yourself.
Warning
To be compliant, your integration must display the mandate text accurately. If you display it yourself, make sure that any URLs are rendered correctly by including the text in a Text composable.
val configuration = EmbeddedPaymentElement.Configuration.Builder("Merchant, Inc") .embeddedViewDisplaysMandateText(false) .build() .... val selectedPaymentOption by embeddedPaymentElement.paymentOption.collectAsState() selectedPaymentOption?.mandateText?.let { mandateText -> Text(mandateText) }
OptionalLet the customer pay immediately in the sheet
To configure the button in the form sheet to immediately confirm payment, set formSheetAction on your EmbeddedPaymentElement. object.
The completion block executes with the result of the payment after the sheet dismisses. The embedded UI isn’t usable after payment completes, so we recommend that your implementation directs the user to a different screen, such as a receipt screen.
@Composable fun CheckoutScreen() { val embeddedBuilder = .... val embeddedPaymentElement = rememberEmbeddedPaymentElement(embeddedBuilder) LaunchedEffect(embeddedPaymentElement) { embeddedPaymentElement.configure( intentConfiguration = ...., configuration = EmbeddedPaymentElement.Configuration.Builder("Powdur") .formSheetAction(EmbeddedPaymentElement.FormSheetAction.Confirm) .build() ) } }
Handle post-payment eventsServer-side
Stripe sends a payment_intent.succeeded event when the payment completes. Use the Dashboard webhook tool or follow the webhook guide to receive these events and run actions, such as sending an order confirmation email to your customer, logging the sale in a database, or starting a shipping workflow.
Listen for these events rather than waiting on a callback from the client. On the client, the customer could close the browser window or quit the app before the callback executes, and malicious clients could manipulate the response. Setting up your integration to listen for asynchronous events is what enables you to accept different types of payment methods with a single integration.
In addition to handling the payment_ event, we recommend handling these other events when collecting payments with the Payment Element:
| Event | Description | Action |
|---|---|---|
| payment_intent.succeeded | Sent when a customer successfully completes a payment. | Send the customer an order confirmation and fulfill their order. |
| payment_intent.processing | Sent when a customer successfully initiates a payment, but the payment has yet to complete. This event is most commonly sent when the customer initiates a bank debit. It’s followed by either a payment_ or payment_ event in the future. | Send the customer an order confirmation that indicates their payment is pending. For digital goods, you might want to fulfill the order before waiting for payment to complete. |
| payment_intent.payment_failed | Sent when a customer attempts a payment, but the payment fails. | If a payment transitions from processing to payment_, offer the customer another attempt to pay. |
Test the integration
See Testing for additional information to test your integration.
OptionalEnable saved cardsServer-sideClient-side
EmbeddedPaymentElement can allow the customer to save their card and can include the customer’s saved cards in available payment methods. The customer must have an associated Customer object on your server. To enable a checkbox that allows the customer to save their card, create an Ephemeral Key associated with the Customer.
const stripe = require("stripe")(); const express = require('express'); const app = express(); app.set('trust proxy', true); app.use(express.json()); app.post('/payment-sheet', async (req, res) => { // Use an existing Customer ID if this is a returning customer. const customer = await stripe.customers.create(); const ephemeralKey = await stripe.ephemeralKeys.create( {customer: customer.id}, {apiVersion: '2020-08-27'} ); res.json({ ephemeralKey: ephemeralKey.secret, customer: customer.id, }); });"sk_test_BQokikJOvBiI2HlWgH4olfQ2"
Next, configure EmbeddedPaymentElement with the Customer’s ID and the Ephemeral Key’s client secret.
val configuration = EmbeddedPaymentElement.Configuration.Builder("Merchant, Inc.") .customer( PaymentSheet.CustomerConfiguration( id = customerId, ephemeralKeySecret = customerEphemeralKeySecret, ) ) .build() embeddedPaymentElement.configure( intentConfiguration = // ... , configuration = configuration, )
OptionalAllow delayed payment methodsClient-side
Delayed payment methods don’t guarantee that you’ll receive funds from your customer at the end of checkout, either because they take time to settle (for example, US Bank Accounts, SEPA Debit, iDEAL, Bancontact, and Sofort) or because they require customer action to complete (for example, OXXO, Konbini, and Boleto).
By default, EmbeddedPaymentElement doesn’t display delayed payment methods, even if you accept them. To display the delayed payment methods that you’ve enabled, set allowsDelayedPaymentMethods to true in your EmbeddedPaymentElement..
val configuration = EmbeddedPaymentElement.Configuration.Builder(merchantDisplayName = "Powdur") .allowsDelayedPaymentMethods(true) .build()
If the customer successfully uses a delayed payment method in an EmbeddedPaymentElement, the payment result returned is EmbeddedPaymentElement..
OptionalEnable Google Pay
Note
If your checkout screen has a dedicated Google Pay button, follow the Google Pay guide. You can use Embedded Payment Element to handle other payment method types.
Set up your integration
To use Google Pay, first enable the Google Pay API by adding the following to the <application> tag of your AndroidManifest.xml:
<application> ... <meta-data android:name="com.google.android.gms.wallet.api.enabled" android:value="true" /> </application>
For more details, see Google Pay’s Set up Google Pay API for Android.
Add Google Pay
To add Google Pay to your integration, pass a PaymentSheet.GooglePayConfiguration with your Google Pay environment (production or test) and the country code of your business when initializing EmbeddedPaymentElement..
val googlePayConfiguration = PaymentSheet.GooglePayConfiguration( environment = PaymentSheet.GooglePayConfiguration.Environment.Test, countryCode = "US", currencyCode = "USD" // Required for Setup Intents, optional for Payment Intents ) val configuration = EmbeddedPaymentElement.Configuration.Builder("Merchant, Inc.") .googlePay(googlePayConfiguration) .build()
Test Google Pay
Google allows you to make test payments through their Test card suite. The test suite supports using stripe test cards.
You can test Google Pay using a physical Android device. Make sure you have a device in a country where google pay is supported and log in to a Google account on your test device with a real card saved to Google Wallet.
OptionalEnable card scanning
To enable card scanning support, add stripecardscan to the dependencies block of your app/build.gradle file:
OptionalCustomize the sheet
All customization is configured through the EmbeddedPaymentElement. object.
Appearance
Customize colors, fonts, and so on to match the look and feel of your app by using the appearance API.
Collect customer addresses
Collect shipping and billing addresses from your customers using the Address Element.
Customize the displayed business name
Specify a customer-facing business name by setting merchantDisplayName. If you don’t specify a name, the default value is your app’s name.
val configuration = EmbeddedPaymentElement.Configuration.Builder(merchantDisplayName = "Merchant, Inc.") .build()
Specify default billing details
To set default values for billing details collected in EmbeddedPaymentElement, configure the defaultBillingDetails property. The EmbeddedPaymentElement pre-populates its fields with the values that you provide.
val configuration = EmbeddedPaymentElement.Configuration.Builder(merchantDisplayName = "Merchant, Inc.") .defaultBillingDetails( PaymentSheet.BillingDetails( address = PaymentSheet.Address( country = "US", ), email = "foo@bar.com" ) ) .build()
Configure collection of billing details
Use BillingDetailsCollectionConfiguration to specify how you want to collect billing details in the EmbeddedPaymentElement.
You can collect your customer’s name, email, phone number, and address.
If you want to attach default billing details to the PaymentMethod object even when those fields aren’t collected in the UI, set billingDetailsCollectionConfiguration. to true.
import com.stripe.android.paymentsheet.PaymentSheet.BillingDetailsCollectionConfiguration val billingDetails = PaymentSheet.BillingDetails( email = "foo@bar.com" ) val billingDetailsCollectionConfiguration = BillingDetailsCollectionConfiguration( attachDefaultsToPaymentMethod = true, name = BillingDetailsCollectionConfiguration.CollectionMode.Always, email = BillingDetailsCollectionConfiguration.CollectionMode.Never, address = BillingDetailsCollectionConfiguration.AddressCollectionMode.Full, ) val configuration = EmbeddedPaymentElement.Configuration.Builder(merchantDisplayName = "Merchant, Inc.") .defaultBillingDetails(billingDetails) .billingDetailsCollectionConfiguration(billingDetailsCollectionConfiguration) .build()
Note
Consult with your legal counsel regarding laws that apply to collecting information. Only collect phone numbers if you need them for the transaction.
OptionalEnable CVC recollection on confirmation
Update parameters of the intent creation
To re-collect the CVC when confirming payment, include both the customerId and require_ parameters during the creation of the PaymentIntent.
