Configure a test server for the Square In-App Payments SDK Quickstart.
In-App Payments SDK: Quickstart

Step 2: Deploy the Server

To charge the payment token generated by the In-App Payments SDK, client applications need to call the server Payments API (CreatePayment endpoint). For quick testing, you can use cURL to send a CreatePayment request. You can also use API Explorer to test the call.

Create Payment
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
curl https://connect.squareupsandbox.com/v2/payments \
  -X POST \
  -H 'Square-Version: 2022-11-16' \
  -H 'Authorization: Bearer {ACCESS_TOKEN}' \
  -H 'Content-Type: application/json' \
  -d '{
    "idempotency_key": "{UNIQUE_KEY}",
    "amount_money": {
      "amount": 100,
      "currency": "USD"
    },
    "source_id": "{PAYMENT_TOKEN_REPRESENTING_A_CARD}"
  }'

On receiving the request, Square charges the credit card represented by the payment token, specified as source_id in the request. In the response, the Payments API returns the Payment object created from this transaction.

In a production environment, however, the seller uses their server to make a Payments API call. This Quickstart provides instructions to deploy a Heroku server. You can optionally follow steps to set up the server and test the end-to-end application experience.

  1. Make sure you have your Sandbox access token (see Get your credentials). You add this access token to the server code so that the server can send authenticated requests to Square.

  2. Open the In-App Payments Server Quickstart project and follow the instructions in the README.md file.

    These instructions describe how to set up a Heroku application and deploy the provided server code. This server makes the CreatePayment call. See the index.js file in the server code.

Depending on the platform you are using, follow one of these steps to connect the sample application to the Heroku server.

  • Java (Android) client. In the Android project, open the app\java\com.example.supercookie.ConfigHelper.java file and update the CHARGE_SERVER_HOST value from:

    to the URL of the Heroku application location (for example, <app-name>.herokuapp.com). Do not include "https://". You can find this location on the Heroku application Settings tab.

  • Swift (iOS) client. In the Xcode project, open the InAppPaymentsSample/Constants/Constants.swift file and update the CHARGE_SERVER_HOST value from:

    to the URL of the Heroku application location (for example, https://<app-name>.herokuapp.com). You can find this location on the Heroku application Settings tab.

  1. Run the application. In this end-to-end testing, after you buy a cookie and provide credit card information, the In-App Payments SDK generates a payment token. This token is then passed to the backend server. The server sends a CreatePayment request to the Square Payments API by providing the payment token generated by the SDK. Square then charges the credit card represented by the payment token and creates a Payment object.

  2. In the Heroku application, view logs to see the created Payment object. You can use the payment ID to retrieve the payment in the next section.

    If the Heroku log shows only a partial payment object (the payment ID is not visible), you might see the ID of the order that was created. You can use this ID to first retrieve the order that was created. The Order.tender gives the ID of the created payment. You can then use this ID to retrieve the Payment object.

You can call the Payments API (RetrievePayment endpoint) to retrieve the payment or view the payment in the Seller Dashboard.

  1. Confirm the payment by calling the RetrievePayment endpoint (Payments API). Update the code by providing your Sandbox access token and payment ID.

    Get Payment
    • 1
    • 2
    • 3
    • 4
    curl https://connect.squareupsandbox.com/v2/payments/{payment_id} \
      -H 'Square-Version: 2022-11-16' \
      -H 'Authorization: Bearer {ACCESS_TOKEN}' \
      -H 'Content-Type: application/json'
  2. Confirm the payment in the Seller Dashboard. You can also see the payment in the Sandbox Seller Dashboard for the default test account.

    1. Sign in to the Developer Dashboard.

    2. Under Sandbox Test Accounts, choose the Open button for the default test account to open the Sandbox Seller Dashboard.

    3. In the Sandbox Seller Dashboard, choose Transactions to show the list of payments on this test account.

You have now completed a production-style credit card transaction with the In-App Payments SDK.

If you need more assistance, contact Developer Support or ask for help in the Developer Forums.