How It Works

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.

Link to section

Overview

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.

Link to section

Process flow

The SDK process flow on Android has two core flows: payment token generation and payment completion.

Link to section

Payment token generation

  1. The mobile application sets the Square application ID for the In-App Payments SDK based on configuration information in AndroidManifest.xml.
  2. The mobile application sets a card payment token background handler object reference for the In-App Payments SDK in CardEntry.
  3. The mobile application calls CardEntry.startCardEntryActivity to start the card entry activity and begin the Checkout activity.
  4. The In-App Payments SDK collects user payment information, generates a payment token, and invokes the payment token background handler with the result.
  5. The mobile application completes the card entry activity and gets the payment token from the background handler.
Link to section

Payment completion

  1. The mobile application sends the payment token returned by the In-App Payments SDK and the payment amount to a secure backend service.

  2. The backend service creates a Payments API CreatePayment request with the provided payment token.

  3. The CreatePayment endpoint processes the request and returns a Payment object that represents the captured payment.

  4. The backend service returns an operation result with a status (Finish or ShowError). In the event of an error, the result should include actionable error information that can be logged or displayed.

  5. 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 of Activity.onActivityResult to CardEntry.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.
  6. The mobile application handles CardEntryActivityResult and runs the appropriate business logic.

    A diagram showing the mobile client to Square server process flow in the In-App Payments SDK with the payment token returned to an application background process.