In-App Payments SDK Quick Start

Step 4: Take payment with a server backend

cURL commands are useful for testing, but impractical for production. Use our sample server to process a production Charge request.

Java (Android)
Android
iOS
Save

Step 1: Deploy a sample server

The sample server for In-App Payments is an example server that exposes 1 endpoint for charging a card for a cookie. The charge appears as a credit on your Square account.

  1. Click this link to open the Heroku sign up page: Deploy to Heroku
  2. Login or create a Heroku account.
  3. Enter a unique Heroku app name.
  4. Go to the Square Application Dashboard and select your application.
  5. Copy the Personal Access Token from the Credentials tab into the ACCESS_TOKEN field of the Heroku configuration page.
  6. Click Deploy app on the Heroku configuration page.
  7. Copy [Heroku app name].herokuapp.com/chargeForCookie as your URL.

Step 2: Update the sample app to use the sample server

  1. In com/example/supercookie/ConfigHelper.java, set the CHARGE_SERVER_HOST to the Heroku server host deployed in the previous step.
private static final String CHARGE_SERVER_HOST = "REPLACE_ME";
private static final String CHARGE_SERVER_URL = "https://" + CHARGE_SERVER_HOST + "/";
  1. Build and run the app in Android studio.
  2. Tap the Buy button and choose Pay with card and enter your card information.
  3. After submitting your card information, you will get a success message indicating that a nonce has been created. The sample also makes a call to your deployed server to complete the payment with the nonce.
  1. In InAppPaymentsSample/Constants/Constants.swift set the CHARGE_SERVER_HOST to the Heroku server host deployed in the previous step.
struct Square {
    ...
    static let CHARGE_SERVER_HOST: String = "REPLACE_ME"
    static let CHARGE_URL: String = "\(CHARGE_SERVER_HOST)/chargeForCookie"
}
  1. Build and run the app in Xcode.
  2. Tap the Buy button, choose Pay with card, and enter card information.
  3. After submitting your card information, you will get a success message indicating that a nonce has been created. The sample also makes a call to your deployed server to complete the payment with the nonce.

Once you see the success message you can view the transaction details in Square Dashboard.

Congratulations! You just completed a production-style credit card transaction with In-App Payments SDK.

Next Steps

Follow a link below to start building custom solutions with In-App Payments SDK.

Prev
< Take payment with a cURL command

Contact Developer Support, join our Slack channel, or ask for help on Stack Overflow