The core of this integration is the
PaymentSession class. It uses
CustomerSession to launch full-screen activities to collect and store payment information, and can also be used to collect shipping info. Think of it as the data source for your checkout activity—it handles asynchronously retrieving the data you need, and notifies its
PaymentSessionListener when your UI should change.
To work with
PaymentSession, you’ll need to:
- Create a
- Implement a
PaymentSessionConfig object is created using a Builder. All of the
Builder’s fields are optional. See the API reference for details on each method.
After creating the
PaymentSessionConfig, you’ll need to implement
This method should also check for whether or not the payment data is complete, according to the
PaymentSessionConfig specified. If you receive an update for which
PaymentSessionData#isPaymentReadyToCharge() returns true, you can immediately send a message to your server to complete the charge.
void onCommunicatingStateChanged(boolean isCommunicating)
This method is called whenever the network communication state has changed. We recommend showing a spinner or infinite progress bar when it is set to
void onError(int errorCode, @Nullable String errorMessage)
This method is called whenever an error occurs when connecting to the Stripe API. Make sure users can see the error messages, so display them in an alert dialog.
Initialize a PaymentSession
Having created your
PaymentSessionListener, you can now initialize the
PaymentSession. In the below example, we use anonymous classes to create our listener and config for simplicity.