Chilkat Online Tools

Java / Afterpay Online US API v2 / Capture Payment

Back to Collection Items

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http = new CkHttp();
    boolean success;

    http.put_BasicAuth(true);
    http.put_Login("100100248");
    http.put_Password("117f3fe5a01a0e400f3e4782baf8ffa43a9d21e9217a15f50d545bc72480d081ecaecc1d6a42ac7a785b7437232bd4cf62dbee679b78a75a3892547059018f9b");

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "requestId": "merchant-generated-request-guid",
    //   "merchantReference": "merchant-order-number",
    //   "amount": {
    //     "amount": "37.00",
    //     "currency": "USD"
    //   }
    // }

    CkJsonObject json = new CkJsonObject();
    json.UpdateString("requestId","merchant-generated-request-guid");
    json.UpdateString("merchantReference","merchant-order-number");
    json.UpdateString("amount.amount","37.00");
    json.UpdateString("amount.currency","USD");

    http.SetRequestHeader("Content-Type","application/json");
    http.SetRequestHeader("Accept","application/json");

    CkHttpResponse resp = http.PostJson3("https://api.us-sandbox.afterpay.com/v2/payments/{{id}}/capture","application/json",json);
    if (http.get_LastMethodSuccess() == false) {
        System.out.println(http.lastErrorText());
        return;
        }

    System.out.println(resp.get_StatusCode());
    System.out.println(resp.bodyStr());
  }
}

Curl Command

curl -X POST
	-u '100100248:117f3fe5a01a0e400f3e4782baf8ffa43a9d21e9217a15f50d545bc72480d081ecaecc1d6a42ac7a785b7437232bd4cf62dbee679b78a75a3892547059018f9b'
	-H "Accept: application/json"
	-H "Content-Type: application/json"
	-d '{
         "requestId": "merchant-generated-request-guid",
         "merchantReference": "merchant-order-number",
         "amount" : {
             "amount" : "37.00",
             "currency" : "USD"
         }
     }'
https://api.us-sandbox.afterpay.com/v2/payments/{{id}}/capture

Postman Collection Item JSON

{
  "name": "Capture Payment",
  "event": [
    {
      "listen": "test",
      "script": {
        "id": "ce54d0ec-48f7-43ed-af8e-165c898c6d39",
        "exec": [
          ""
        ],
        "type": "text/javascript"
      }
    }
  ],
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      },
      {
        "key": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n         \"requestId\": \"merchant-generated-request-guid\",\n         \"merchantReference\": \"merchant-order-number\",\n         \"amount\" : {\n             \"amount\" : \"37.00\",\n             \"currency\" : \"USD\"\n         }\n     }"
    },
    "url": {
      "raw": "https://api.us-sandbox.afterpay.com/v2/payments/{{id}}/capture",
      "protocol": "https",
      "host": [
        "api",
        "us-sandbox",
        "afterpay",
        "com"
      ],
      "path": [
        "v2",
        "payments",
        "{{id}}",
        "capture"
      ]
    },
    "description": "This resource performs a capture against an authorisation. Multiple captures can be performed against an authorisation, provided that the sum of captures does not exceed the authorised amount. Once the total amount authorised is captured, the payment state will be updated to “CAPTURED” and no further capture requests will succeed.\n\nThe resource is idempotent if a unique requestId is provided."
  },
  "response": [
  ]
}