Deploy the Server

Applies to: In-App Payments SDK - Android | In-App Payments SDK - iOS | Payments API

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

Link to section

Overview

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

After 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.

Link to section

1. Deploy a Heroku server

  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.

Link to section

2. Connect the application client to the server

Depending on the platform you're 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 the following to the URL of the Heroku application location (for example, <app-name>.herokuapp.com). Don't include "https://". You can find this location on the Heroku application Settings tab.

    private static final String CHARGE_SERVER_HOST = "REPLACE_ME";
  • Swift (iOS) client - In the Xcode project, open the InAppPaymentsSample/Constants/Constants.swift file and update the CHARGE_SERVER_HOST value from the following 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.

    static let CHARGE_SERVER_HOST: String = "REPLACE_ME"
Link to section

3. Test the application end to end

  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 isn't 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.

Link to section

4. Verify the payment

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

  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.

Success

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