Download, Configure, and Run the Client Sample

In this step, you download a Square-provided sample application. You can choose either the Android or iOS sample application. You need to update the sample application code by providing your Square account information (Square application ID and location ID). You then run the application, buy a cookie, and specify a credit card to pay for it. The card you specify is a Square-provided fictitious credit card used for Sandbox testing. This credit card isn't charged. The In-App Payments SDK (embedded in the application code) uses the card information and generates a payment token. The next section explains how to charge the payment token using server-side Square Payments API.

Choose the Android or iOS sample application and follow the steps to download and test the application.

Link to section

Sample Java (Android) application

  1. Clone the application from the In-App Payments SDK Sample Android Application.

  2. In Android Studio, open the application.

  3. In in-app-payments-android-quickstart/app/src/main folder, open AndroidManifest.xml and replace the value for sqip.SQUARE_APPLICATION_ID with your Square Sandbox application ID (see Get your credentials).

    <meta-data android:name="sqip.SQUARE_APPLICATION_ID" android:value="REPLACE_ME"/>
  4. In app/src/main/java/com/example/supercookie, open ConfigHelper.java and replace the value for GOOGLE_PAY_MERCHANT_ID in line 13 with your location ID (see Get your credentials).

    public static final String GOOGLE_PAY_MERCHANT_ID = "REPLACE_ME";
  5. Test the client. The application is preconfigured with the following three UI screens:

    A graphic showing the buyer an Android input fragment in the second screen of the Super Cookie Quickstart application.

    The application allows you to purchase a cookie for $1. You pay for the cookie using a fictitious credit card that Square provides for Sandbox testing. The In-App Payments SDK uses the credit card information to generate a payment token.

    After you enter the credit card information in the card entry form, the In-App Payments SDK generates the payment token. For more information, see the paymentAuthorizationViewController function in the ExampleViewController.swift file.

    Complete the following steps to buy a cookie and pay for it with a credit card:

    1. Run the application, and then choose Buy.
    2. Choose Pay with card, and then enter the following information:
      • Card number: 4111 1111 1111 1111
      • Expiry date: any date in the future
      • CVV: any three-digit number
      • ZIP: any five-digit number

    In response, the In-App Payments SDK generates a payment token (for example, cnon:CBASENLkTNuEF6eUTZ8dZlsDsLo. You can find the generated payment token in the Android Studio Logcat.

Link to section

Sample Swift (iOS) application

  1. Download the In-App Payments SDK Sample iOS Application.

  2. Open InAppPaymentsSample.xcworkspace.

  3. In the InAppPaymentsSample project, open the General tab for your application target and change the Bundle identifier to a unique string. You should append .YOUR_NAME to the existing ID.

  4. Open Constants.swift and update the SQUARE_LOCATION_ID and APPLICATION_ID variables with your Sandbox location ID and application ID values, respectively.

    static let SQUARE_LOCATION_ID: String = "<# REPLACE_ME #>" static let APPLICATION_ID: String = "<# REPLACE_ME #>"
  5. Test the client. The application is preconfigured with the following three UI screens:

    A graphic showing the buyer a Swift input fragment in the second screen of the Super Cookie Quickstart application.

    The application allows you to purchase a cookie for $1. fictitious credit card that Square provides for Sandbox testing. The In-App Payments SDK uses the card information to generate a payment token.

    After you enter the credit card information in the card entry form, the In-App Payments SDK generates the payment token. For more information, see the paymentAuthorizationViewController function in the ExampleViewController.swift.

    Complete the following steps to buy a cookie and pay for it with a credit card:

    1. Run the application, and then choose Buy.
    2. Choose Pay with card, and then enter the following information:
      • Card number: 4111 1111 1111 1111
      • Expiry date: any date in the future
      • CVV: any three-digit number
      • ZIP: any five-digit number

    In response, the In-App Payments SDK generates a payment token (for example, cnon:CBASENLkTNuEF6eUTZ8dZlsDsLo). You can find the generated payment token in the Xcode console.