Swift3 / GP-API Collection / TRA_10.1 Interac Authorize
Back to Collection Items
func chilkatTest() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
var success: Bool
// Use this online tool to generate code from sample JSON: Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "account_name": "{{acc_name}}",
// "channel": "CP",
// "amount": "1000",
// "currency": "CAD",
// "reference": "11223344",
// "country": "CA",
// "payment_method": {
// "entry_mode": "CHIP",
// "card": {
// "track": ";4506445006931933=22122200162907400000?",
// "tag": "82021C008407A0000002771010950580000080009A031907319B0268009C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F0607A00000027710109F080200019F090200019F100706010A03A4A8009F1A0201249F21031558109F2608395F21408D87BAB09F2701809F3303E0F8C89F34030100029F3501229F360200609F37048C8C7AC59F3901059F410400000025",
// "funding": "DEBIT"
// },
// "authentication": {
// "mac": "A01B82D800000000"
// }
// },
// "device": {
// "time": "2019-10-14T05:58:40",
// "sequence_number": "000010010500"
// }
// }
let json = CkoJsonObject()!
json.update("account_name", value: "{{acc_name}}")
json.update("channel", value: "CP")
json.update("amount", value: "1000")
json.update("currency", value: "CAD")
json.update("reference", value: "11223344")
json.update("country", value: "CA")
json.update("payment_method.entry_mode", value: "CHIP")
json.update("payment_method.card.track", value: ";4506445006931933=22122200162907400000?")
json.update("payment_method.card.tag", value: "82021C008407A0000002771010950580000080009A031907319B0268009C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F0607A00000027710109F080200019F090200019F100706010A03A4A8009F1A0201249F21031558109F2608395F21408D87BAB09F2701809F3303E0F8C89F34030100029F3501229F360200609F37048C8C7AC59F3901059F410400000025")
json.update("payment_method.card.funding", value: "DEBIT")
json.update("payment_method.authentication.mac", value: "A01B82D800000000")
json.update("device.time", value: "2019-10-14T05:58:40")
json.update("device.sequence_number", value: "000010010500")
// Adds the "Authorization: Bearer {{token}}" header.
http.authToken = "{{token}}"
http.setRequestHeader("X-GP-Version", value: "{{version}}")
var resp: CkoHttpResponse? = http.postJson3("https://{{url}}/ucp/transactions", contentType: "application/json", json: json)
if http.lastMethodSuccess == false {
print("\(http.lastErrorText!)")
return
}
print("\(resp!.statusCode.intValue)")
print("\(resp!.bodyStr!)")
resp = nil
}
Curl Command
curl -X POST
-H "X-GP-Version: {{version}}"
-H "Authorization: Bearer {{token}}"
-d '{
"account_name": "{{acc_name}}",
"channel": "CP",
"amount": "1000",
"currency": "CAD",
"reference": "11223344",
"country": "CA",
"payment_method": {
"entry_mode": "CHIP",
"card": {
"track": ";4506445006931933=22122200162907400000?",
"tag": "82021C008407A0000002771010950580000080009A031907319B0268009C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F0607A00000027710109F080200019F090200019F100706010A03A4A8009F1A0201249F21031558109F2608395F21408D87BAB09F2701809F3303E0F8C89F34030100029F3501229F360200609F37048C8C7AC59F3901059F410400000025",
"funding": "DEBIT"
},
"authentication": {
"mac": "A01B82D800000000"
}
},
"device": {
"time": "2019-10-14T05:58:40",
"sequence_number": "000010010500"
}
}'
https://{{url}}/ucp/transactions
Postman Collection Item JSON
{
"name": "TRA_10.1 Interac Authorize",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = JSON.parse(responseBody);\r",
"postman.setEnvironmentVariable(\"trn_id\", jsonData.id);\r",
"postman.setEnvironmentVariable(\"sale_trn_id\",jsonData.id);\r",
"postman.setEnvironmentVariable(\"reference\", jsonData.reference);\r",
"postman.setEnvironmentVariable(\"batch_id\", jsonData.batch_id);\r",
"postman.setEnvironmentVariable(\"act_id\", jsonData.action.id);"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "noauth"
},
"method": "POST",
"header": [
{
"key": "X-GP-Version",
"value": "{{version}}",
"type": "text"
},
{
"key": "Authorization",
"value": "Bearer {{token}}",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"account_name\": \"{{acc_name}}\",\r\n \"channel\": \"CP\",\r\n \"amount\": \"1000\",\r\n \"currency\": \"CAD\",\r\n \"reference\": \"11223344\",\r\n \"country\": \"CA\",\r\n \"payment_method\": {\r\n \"entry_mode\": \"CHIP\",\r\n \"card\": {\r\n \"track\": \";4506445006931933=22122200162907400000?\",\r\n \"tag\": \"82021C008407A0000002771010950580000080009A031907319B0268009C01005F280201245F2A0201245F3401019F02060000000010009F03060000000000009F0607A00000027710109F080200019F090200019F100706010A03A4A8009F1A0201249F21031558109F2608395F21408D87BAB09F2701809F3303E0F8C89F34030100029F3501229F360200609F37048C8C7AC59F3901059F410400000025\",\r\n \"funding\": \"DEBIT\"\r\n },\r\n \"authentication\": {\r\n \"mac\": \"A01B82D800000000\"\r\n }\r\n },\r\n \"device\": {\r\n \"time\": \"2019-10-14T05:58:40\",\r\n \"sequence_number\": \"000010010500\"\r\n }\r\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://{{url}}/ucp/transactions",
"protocol": "https",
"host": [
"{{url}}"
],
"path": [
"ucp",
"transactions"
]
}
},
"response": [
]
}