Back to Collection Items
Use ChilkatAx-win32.pkg
Procedure Test
Handle hoHttp
Boolean iSuccess
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Boolean bTemp1
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComBasicAuth Of hoHttp To True
Set ComLogin Of hoHttp To "100100248"
Set ComPassword Of hoHttp To "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",
// "amount": {
// "amount": "37.00",
// "currency": "USD"
// },
// "merchantReference": "merchant-order-number"
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "requestId" "merchant-generated-request-guid" To iSuccess
Get ComUpdateString Of hoJson "amount.amount" "37.00" To iSuccess
Get ComUpdateString Of hoJson "amount.currency" "USD" To iSuccess
Get ComUpdateString Of hoJson "merchantReference" "merchant-order-number" To iSuccess
Send ComSetRequestHeader To hoHttp "Content-Type" "application/json"
Get pvComObject of hoJson to vJson
Get ComPostJson3 Of hoHttp "https://api.us-sandbox.afterpay.com/v2/payments/{{id}}/refund" "application/json" vJson To vResp
If (IsComObject(vResp)) Begin
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
Set pvComObject Of hoResp To vResp
End
Get ComLastMethodSuccess Of hoHttp To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln iTemp1
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Send Destroy of hoResp
End_Procedure
Curl Command
curl -X POST
-u '100100248:117f3fe5a01a0e400f3e4782baf8ffa43a9d21e9217a15f50d545bc72480d081ecaecc1d6a42ac7a785b7437232bd4cf62dbee679b78a75a3892547059018f9b'
-H "Content-Type: application/json"
-d '{
"requestId": "merchant-generated-request-guid",
"amount" : {
"amount" : "37.00",
"currency" : "USD"
},
"merchantReference" : "merchant-order-number"
}'
https://api.us-sandbox.afterpay.com/v2/payments/{{id}}/refund
Postman Collection Item JSON
{
"name": "Create Refund",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"requestId\": \"merchant-generated-request-guid\",\n\t\"amount\" : {\n\t\t\"amount\" : \"37.00\",\n\t\t\"currency\" : \"USD\"\n\t\t},\n\t\"merchantReference\" : \"merchant-order-number\"\n}"
},
"url": {
"raw": "https://api.us-sandbox.afterpay.com/v2/payments/{{id}}/refund",
"protocol": "https",
"host": [
"api",
"us-sandbox",
"afterpay",
"com"
],
"path": [
"v2",
"payments",
"{{id}}",
"refund"
]
},
"description": "This resource performs a full or partial refund.\n\nThe resource is idempotent if a unique requestId is provided."
},
"response": [
]
}