Chilkat Online Tools

Objective-C / Afterpay Online US API v2 / Capture (without Auth)

Back to Collection Items

#import <CkoHttp.h>
#import <CkoJsonObject.h>
#import <CkoHttpResponse.h>

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoHttp *http = [[CkoHttp alloc] init];
BOOL success;

http.BasicAuth = YES;
http.Login = @"100100248";
http.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.

// {
//   "token": "{{token}}",
//   "merchantReference": "merchant-order-number"
// }

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"token" value: @"{{token}}"];
[json UpdateString: @"merchantReference" value: @"merchant-order-number"];

[http SetRequestHeader: @"Content-Type" value: @"application/json"];
[http SetRequestHeader: @"Accept" value: @"application/json"];

CkoHttpResponse *resp = [http PostJson3: @"https://api.us-sandbox.afterpay.com/v2/payments/capture" contentType: @"application/json" json: json];
if (http.LastMethodSuccess == NO) {
    NSLog(@"%@",http.LastErrorText);
    return;
}

NSLog(@"%d",[resp.StatusCode intValue]);
NSLog(@"%@",resp.BodyStr);

Curl Command

curl -X POST
	-u '100100248:117f3fe5a01a0e400f3e4782baf8ffa43a9d21e9217a15f50d545bc72480d081ecaecc1d6a42ac7a785b7437232bd4cf62dbee679b78a75a3892547059018f9b'
	-H "Accept: application/json"
	-H "Content-Type: application/json"
	-d '{
	"token": "{{token}}",
	"merchantReference": "merchant-order-number"
}'
https://api.us-sandbox.afterpay.com/v2/payments/capture

Postman Collection Item JSON

{
  "name": "Capture (without Auth)",
  "event": [
    {
      "listen": "test",
      "script": {
        "id": "ce54d0ec-48f7-43ed-af8e-165c898c6d39",
        "exec": [
          "var jsonData = JSON.parse(responseBody);",
          "postman.setEnvironmentVariable(\"id\", jsonData.id);"
        ],
        "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\t\"token\": \"{{token}}\",\n\t\"merchantReference\": \"merchant-order-number\"\n}"
    },
    "url": {
      "raw": "https://api.us-sandbox.afterpay.com/v2/payments/capture",
      "protocol": "https",
      "host": [
        "api",
        "us-sandbox",
        "afterpay",
        "com"
      ],
      "path": [
        "v2",
        "payments",
        "capture"
      ]
    },
    "description": "This resource performs a direct payment capture and is the equivalent of capturing a credit card.\n\nThe payment resource is idempotent based on the token. The idempotent nature of the payment resources allows for the safe retry of requests, guaranteeing the operation is only performed once."
  },
  "response": [
  ]
}