Applies to: In-App Payments SDK - Android | In-App Payments SDK - iOS | Payments API | Cards API
Learn about processing mobile payments with the Square In-App Payments SDK.
The In-App Payments SDK generates a one-time-use, encrypted payment token from a customizable payment card entry view or digital wallet API. The payment token can be processed with Square APIs to take payments (Payments API) and store a card on file for future payments (Cards API). For more information about creating a backend process that saves a card on file for future purchases, see Create a Card on File from a Payment ID, Create a Card on File and a Payment, and Create a Shared Card on File and Make a Payment.
The In-App Payments SDK supports payments on personal mobile devices by embedding a card entry form in a mobile application that produces payment tokens from customer-provided card information or digital wallet applications installed on the device. The In-App Payments SDK can be used with mobile applications that are configured with a Square-assigned application ID from the Developer Console.
The In-App Payments SDK must be initialized with a Square application ID before it can be used to process payments. The general process for generating a payment token and completing a payment on Android is outlined in the following sections.
The SDK process flow on Android has two core flows: payment token generation and payment completion.
- The mobile application sets the Square application ID for the In-App Payments SDK based on configuration information in AndroidManifest.xml.
- The mobile application sets a card payment token background handler object reference for the In-App Payments SDK in
CardEntry. - The mobile application calls
CardEntry.startCardEntryActivityto start the card entry activity and begin theCheckoutactivity. - The In-App Payments SDK collects user payment information, generates a payment token, and invokes the payment token background handler with the result.
- The mobile application completes the card entry activity and gets the payment token from the background handler.
The mobile application sends the payment token returned by the In-App Payments SDK and the payment amount to a secure backend service.
The backend service creates a Payments API CreatePayment request with the provided payment token.
The
CreatePaymentendpoint processes the request and returns a Payment object that represents the captured payment.The backend service returns an operation result with a status (
FinishorShowError). In the event of an error, the result should include actionable error information that can be logged or displayed.The payment token background handler in the mobile application receives the operation result:
- In the case of
Finish, the activity finishes itself and the calling activity forwards the call ofActivity.onActivityResulttoCardEntry.onActivityResult. - In the case of
ShowError, the application should display a localized description of the error and prompt buyers to edit their payment information and resubmit the payment.
- In the case of
The mobile application handles
CardEntryActivityResultand runs the appropriate business logic.