Pay By Card - Existing Customer
This guide walks through the basic setup of a customer, tokenizing their card details and then creating and capturing a charge.
Step 1: Create a Customer
POST
https://testapi.payarc.net/v1/customers
For this guide, we will create a basic customer profile containing only an email
, [email protected], but if you would like to capture more of the customer's data, please review the Customer entity for details on what we support.
import http.client
conn = http.client.HTTPSConnection("https")
payload = 'email=customer%40xyz.com'
headers = {
'Authorization': '{{bearer_token}}',
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}
conn.request("POST", "//testapi.payarc.net/v1/customers", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
var https = require('follow-redirects').https;
var fs = require('fs');
var qs = require('querystring');
var options = {
'method': 'POST',
'hostname': 'https',
'path': '//testapi.payarc.net/v1/customers',
'headers': {
'Authorization': '{{bearer_token}}',
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = qs.stringify({
'email': '[email protected]'
});
req.write(postData);
req.end();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://testapi.payarc.net/v1/customers");
request.Headers.Add("Authorization", "{{bearer_token}}");
request.Headers.Add("Accept", "application/json");
var collection = new List<KeyValuePair<string, string>>();
collection.Add(new("email", "[email protected]"));
var content = new FormUrlEncodedContent(collection);
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
let parameters = "email=customer%40xyz.com"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https//api.payarc.net/v1/customers")!,timeoutInterval: Double.infinity)
request.addValue("{{bearer_token}}", forHTTPHeaderField: "Authorization")
request.addValue("application/json", forHTTPHeaderField: "Accept")
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
The response will return a new Customer object. For the next steps, you will need the newly generated customer ID KPxMADVnxMV4nNjp
:
{
"data": {
"object": "customer",
"id": "KPxMADVnxMV4nNjp",
"name": null,
"real_id": 110,
"email": "[email protected]",
"description": null,
"payment_overdue": null,
"send_email_address": null,
"cc_email_address": null,
"source_id": null,
"address_1": null,
"address_2": null,
"city": null,
"state": null,
"zip": null,
"phone": null,
"country": null,
"created_at": "2018-11-27 07:36:58",
"updated_at": "2018-11-27 07:36:58",
"readable_created_at": "1 second ago",
"readable_updated_at": "1 second ago",
"invoice_prefix": "52KZ",
"card": {
"data": []
},
"charge": {
"data": []
}
},
"meta": {
"include": [
"card",
"charge",
"subscription",
"invoice"
],
"custom": []
}
}
Step 2: Tokenize Card
POST
https://testapi.payarc.net/v1/tokens
We will use this API to create a token that represents a credit or debit card used to carry out a transaction.
We are assuming the card source is INTERNET
, and will capture the card number 4012000098765439
, expiration month 12
and year 2025
and CVV 999
.
import http.client
conn = http.client.HTTPSConnection("testapi.payarc.net")
payload = 'card_source=INTERNET&card_number=4012000098765439&exp_month=12&exp_year=2025&cvv=999'
headers = {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI0NTIyIiwianRpIjoiYmQ5NjhjZDVlMDI5ZDg3MGMzNjljZmExOGZkN2IxMTk3MjJlYWQ4YzcxODMzNTM0ZjE0OTU3Zjc1Y2E4ZWI2NmM5MTIwMDk0NTI0NWFmNzMiLCJpYXQiOjE3MDE5MzU4NjEsIm5iZiI6MTcwMTkzNTg2MSwiZXhwIjoxODU5NjE1ODYxLCJzdWIiOiI4NTI2MTg4Iiwic2NvcGVzIjoiKiJ9.KOJALGZ-u8CuRJcapzV22anTy7VGYyEUm3qzAaXVpQfX5rX_8bmuD9Kl2vF4FfvCreJ-cOem0-c3BZLLd6cEOiV4v0kwA2O70g3HCg80g8YCPsw9F3ggOtVFWgLPofBZp56WI0q-slykAQhXQOeM7MbqnHvLUdVQClCTrxb4-_332wyZUbX_zMj2Q_o-Wunzo0DPQhGrBTV7Va-jTXwOfcHcFMtuGTVoCGoz0qqmpO5E5QuAP9DQW2296SWd-zNF90XJ9RiqKN5BUQjx9-0m7TV0ryYpm4H-bhdOwuDpWBrJyIhNsQ9hpOjF8MXEXPho5weJwMKTsDk3iii6x7AAWv_8WvppC0ZGBLxT-TcV09vVumbsm2JVjG8wKLZRYE16Y2VFXrQc8s7TkZ-h-vHbHEGantICV5XdAZ9eTVnSY9NhgNlvsC4DYdw9hL7mW3F5qpT8mqFVzVGDIUMdXkuGuFpX7BZHw-pKU82ID7P3Jxpv8t1QzES7ITyCCGZswtOiNTh8PaPRIcLHtOWxaNUQTk0BCWuvNDesqkRDKBm8bQKfXu3vjBFq-_MHV4HiylGaec_KBSJv0fLyzTcwfHrXFbFFoevJANzw5BMezMwEPWY7XL-tH2LZ3HfiwiQcjFkNYyYVzrzOa-dIzHx0U35BzQdCxKEqxLpgFUY1T-PIr08'
}
conn.request("POST", "/v1/tokens", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
var https = require('follow-redirects').https;
var fs = require('fs');
var qs = require('querystring');
var options = {
'method': 'POST',
'hostname': 'testapi.payarc.net',
'path': '/v1/tokens',
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI0NTIyIiwianRpIjoiYmQ5NjhjZDVlMDI5ZDg3MGMzNjljZmExOGZkN2IxMTk3MjJlYWQ4YzcxODMzNTM0ZjE0OTU3Zjc1Y2E4ZWI2NmM5MTIwMDk0NTI0NWFmNzMiLCJpYXQiOjE3MDE5MzU4NjEsIm5iZiI6MTcwMTkzNTg2MSwiZXhwIjoxODU5NjE1ODYxLCJzdWIiOiI4NTI2MTg4Iiwic2NvcGVzIjoiKiJ9.KOJALGZ-u8CuRJcapzV22anTy7VGYyEUm3qzAaXVpQfX5rX_8bmuD9Kl2vF4FfvCreJ-cOem0-c3BZLLd6cEOiV4v0kwA2O70g3HCg80g8YCPsw9F3ggOtVFWgLPofBZp56WI0q-slykAQhXQOeM7MbqnHvLUdVQClCTrxb4-_332wyZUbX_zMj2Q_o-Wunzo0DPQhGrBTV7Va-jTXwOfcHcFMtuGTVoCGoz0qqmpO5E5QuAP9DQW2296SWd-zNF90XJ9RiqKN5BUQjx9-0m7TV0ryYpm4H-bhdOwuDpWBrJyIhNsQ9hpOjF8MXEXPho5weJwMKTsDk3iii6x7AAWv_8WvppC0ZGBLxT-TcV09vVumbsm2JVjG8wKLZRYE16Y2VFXrQc8s7TkZ-h-vHbHEGantICV5XdAZ9eTVnSY9NhgNlvsC4DYdw9hL7mW3F5qpT8mqFVzVGDIUMdXkuGuFpX7BZHw-pKU82ID7P3Jxpv8t1QzES7ITyCCGZswtOiNTh8PaPRIcLHtOWxaNUQTk0BCWuvNDesqkRDKBm8bQKfXu3vjBFq-_MHV4HiylGaec_KBSJv0fLyzTcwfHrXFbFFoevJANzw5BMezMwEPWY7XL-tH2LZ3HfiwiQcjFkNYyYVzrzOa-dIzHx0U35BzQdCxKEqxLpgFUY1T-PIr08'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = qs.stringify({
'card_source': 'INTERNET',
'card_number': '4012000098765439',
'exp_month': '12',
'exp_year': '2025',
'cvv': '999'
});
req.write(postData);
req.end();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://testapi.payarc.net/v1/tokens");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI0NTIyIiwianRpIjoiYmQ5NjhjZDVlMDI5ZDg3MGMzNjljZmExOGZkN2IxMTk3MjJlYWQ4YzcxODMzNTM0ZjE0OTU3Zjc1Y2E4ZWI2NmM5MTIwMDk0NTI0NWFmNzMiLCJpYXQiOjE3MDE5MzU4NjEsIm5iZiI6MTcwMTkzNTg2MSwiZXhwIjoxODU5NjE1ODYxLCJzdWIiOiI4NTI2MTg4Iiwic2NvcGVzIjoiKiJ9.KOJALGZ-u8CuRJcapzV22anTy7VGYyEUm3qzAaXVpQfX5rX_8bmuD9Kl2vF4FfvCreJ-cOem0-c3BZLLd6cEOiV4v0kwA2O70g3HCg80g8YCPsw9F3ggOtVFWgLPofBZp56WI0q-slykAQhXQOeM7MbqnHvLUdVQClCTrxb4-_332wyZUbX_zMj2Q_o-Wunzo0DPQhGrBTV7Va-jTXwOfcHcFMtuGTVoCGoz0qqmpO5E5QuAP9DQW2296SWd-zNF90XJ9RiqKN5BUQjx9-0m7TV0ryYpm4H-bhdOwuDpWBrJyIhNsQ9hpOjF8MXEXPho5weJwMKTsDk3iii6x7AAWv_8WvppC0ZGBLxT-TcV09vVumbsm2JVjG8wKLZRYE16Y2VFXrQc8s7TkZ-h-vHbHEGantICV5XdAZ9eTVnSY9NhgNlvsC4DYdw9hL7mW3F5qpT8mqFVzVGDIUMdXkuGuFpX7BZHw-pKU82ID7P3Jxpv8t1QzES7ITyCCGZswtOiNTh8PaPRIcLHtOWxaNUQTk0BCWuvNDesqkRDKBm8bQKfXu3vjBFq-_MHV4HiylGaec_KBSJv0fLyzTcwfHrXFbFFoevJANzw5BMezMwEPWY7XL-tH2LZ3HfiwiQcjFkNYyYVzrzOa-dIzHx0U35BzQdCxKEqxLpgFUY1T-PIr08");
var collection = new List<KeyValuePair<string, string>>();
collection.Add(new("card_source", "INTERNET"));
collection.Add(new("card_number", "4012000098765439"));
collection.Add(new("exp_month", "12"));
collection.Add(new("exp_year", "2025"));
collection.Add(new("cvv", "999"));
var content = new FormUrlEncodedContent(collection);
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
The token we receive can be used only once, to either create a new transaction or attach a new card to an existing customer.
We'll use the token ID we receive, 8YmNlwY0qY0mwEq0
, for the next step.
{
"data": {
"object": "Token",
"id": "8YmNlwY0qY0mwEq0",
"used": false,
"ip": null,
"tokenization_method": null,
"created_at": 1620129383,
"updated_at": 1620129383,
"card": {
"data": {
"object": "Card",
"id": "P19v20v519L10M5y",
"address1": null,
"address2": null,
"card_source": "INTERNET",
"card_holder_name": null,
"is_default": 0,
"exp_month": "12",
"exp_year": "2025",
"is_verified": 0,
"fingerprint": "my905PmvmPNmNP0M",
"city": null,
"state": null,
"zip": null,
"brand": "V",
"last4digit": "5439",
"first6digit": 401200,
"country": null,
"avs_status": null,
"cvc_status": null,
"address_check_passed": 0,
"zip_check_passed": 0,
"customer_id": null,
"created_at": 1620129383,
"updated_at": 1620129383
}
}
},
"meta": {
"include": [],
"custom": []
}
}
Step 3: Assign Card to Customer
PATCH
https://testapi.payarc.net/v1/customers/DPpKjVKDnDMDVnMN
We will attach the card token 8YmNlwY0qY0mwEq0
that we created at step 2 to the customer ID KPxMADVnxMV4nNjp
we created at step 1.
import http.client
conn = http.client.HTTPSConnection("https")
payload = 'token_id=8YmNlwY0qY0mwEq0'
headers = {
'Authorization': '{{bearer_token}}',
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}
conn.request("PATCH", "//testapi.payarc.net/v1/customers/KPxMADVnxMV4nNjp", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
var https = require('follow-redirects').https;
var fs = require('fs');
var qs = require('querystring');
var options = {
'method': 'PATCH',
'hostname': 'https',
'path': '//testapi.payarc.net/v1/customers/KPxMADVnxMV4nNjp',
'headers': {
'Authorization': '{{bearer_token}}',
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = qs.stringify({
'token_id': '8YmNlwY0qY0mwEq0'
});
req.write(postData);
req.end();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Patch, "https://testapi.payarc.net/v1/customers/KPxMADVnxMV4nNjp");
request.Headers.Add("Authorization", "{{bearer_token}}");
request.Headers.Add("Accept", "application/json");
var collection = new List<KeyValuePair<string, string>>();
collection.Add(new("token_id", "8YmNlwY0qY0mwEq0"));
var content = new FormUrlEncodedContent(collection);
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
We will receive the updated customer entity
{
"data": {
"object": "customer",
"id": "MKNDnpVNAnVA4jxP",
"name": "1",
"real_id": 95,
"email": "[email protected]",
"description": "test",
"payment_overdue": 0,
"send_email_address": "[email protected]",
"cc_email_address": "[email protected]",
"source_id": "2NLy9v0922L0m1MP",
"address_1": "1",
"address_2": "1",
"city": "1",
"state": "Georgia",
"zip": "79002",
"phone": "1234567812",
"country": "US",
"created_at": "2018-10-29 07:04:57",
"updated_at": "2018-11-29 09:40:43",
"readable_created_at": "1 month ago",
"readable_updated_at": "33 minutes ago",
"invoice_prefix": "ADML",
"card": {
"data": [
{
"object": "Card",
"id": "5LN2P10M9910m9yM",
"address1": "",
"address2": "",
"real_id": 1058,
"card_holder_name": "",
"is_default": 0,
"exp_month": "11",
"exp_year": "2022",
"fingerprint": "y905NML155vPvP0M",
"city": null,
"state": "",
"zip": "",
"brand": "V",
"last4digit": "1111",
"first6digit": 411111,
"country": "",
"avs_status": "0",
"cvc_status": "N",
"address_check_passed": 0,
"zip_check_passed": 0,
"customer_id": "MKNDnpVNAnVA4jxP",
"created_at": {
"date": "2018-11-29 09:48:48.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2018-11-29 09:48:49.000000",
"timezone_type": 3,
"timezone": "UTC"
}
},
{
"object": "Card",
"id": "LN2m1v0LPPM0MPy5",
"address1": "920 Sunnyslope Ave",
"address2": "Bronx",
"real_id": 1057,
"card_holder_name": "Rex Joseph",
"is_default": 0,
"exp_month": "11",
"exp_year": "2022",
"fingerprint": "Pm20y1vM9y1vm50M",
"city": "New York",
"state": "New York",
"zip": "10469",
"brand": "V",
"last4digit": "1111",
"first6digit": 411111,
"country": "USA",
"avs_status": "N",
"cvc_status": "N",
"address_check_passed": 0,
"zip_check_passed": 0,
"customer_id": "MKNDnpVNAnVA4jxP",
"created_at": {
"date": "2018-11-29 09:43:08.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2018-11-29 09:51:51.000000",
"timezone_type": 3,
"timezone": "UTC"
}
},
{
"object": "Card",
"id": "mP19v20vLv50M5yN",
"address1": "",
"address2": "",
"real_id": 1054,
"card_holder_name": "",
"is_default": 0,
"exp_month": "11",
"exp_year": "2022",
"fingerprint": "y905NML155vPvP0M",
"city": null,
"state": "",
"zip": "",
"brand": "V",
"last4digit": "1111",
"first6digit": 411111,
"country": "",
"avs_status": "0",
"cvc_status": "N",
"address_check_passed": 0,
"zip_check_passed": 0,
"customer_id": "MKNDnpVNAnVA4jxP",
"created_at": {
"date": "2018-11-29 09:26:43.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2018-11-29 09:26:44.000000",
"timezone_type": 3,
"timezone": "UTC"
}
},
{
"object": "Card",
"id": "P15y29012P20MLvm",
"address1": "",
"address2": "",
"real_id": 1053,
"card_holder_name": "",
"is_default": 0,
"exp_month": "11",
"exp_year": "2022",
"fingerprint": "y905NML155vPvP0M",
"city": null,
"state": "",
"zip": "",
"brand": "V",
"last4digit": "1111",
"first6digit": 411111,
"country": "",
"avs_status": "0",
"cvc_status": "N",
"address_check_passed": 0,
"zip_check_passed": 0,
"customer_id": "MKNDnpVNAnVA4jxP",
"created_at": {
"date": "2018-11-29 09:24:54.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2018-11-29 09:24:54.000000",
"timezone_type": 3,
"timezone": "UTC"
}
},
{
"object": "Card",
"id": "2NLy9v099Ly0m1MP",
"address1": "",
"address2": "",
"real_id": 856,
"card_holder_name": "",
"is_default": 1,
"exp_month": "02",
"exp_year": "2025",
"fingerprint": "m20yP99mmyLvLN0M",
"city": null,
"state": "",
"zip": "",
"brand": "V",
"last4digit": "1111",
"first6digit": 411111,
"country": "",
"avs_status": "0",
"cvc_status": "N",
"address_check_passed": 0,
"zip_check_passed": 0,
"customer_id": "MKNDnpVNAnVA4jxP",
"created_at": {
"date": "2018-11-08 08:51:35.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2018-11-29 09:47:45.000000",
"timezone_type": 3,
"timezone": "UTC"
}
}
]
},
"charge": {
"data": [
{
"object": "Charge",
"id": "WonDXOXWnBXObLyR",
"real_id": 1786,
"amount": 1200,
"amount_refunded": 0,
"amount_captured": 1200,
"amount_voided": 0,
"payarc_fees": 38,
"type": "Sale",
"net_amount": 1162,
"captured": 1,
"is_refunded": 0,
"status": "submitted_for_settlement",
"auth_code": "TAS535",
"failure_code": null,
"failure_message": null,
"charge_description": "sample statement description",
"invoice": null,
"under_review": 0,
"created_at": "2018-11-27 08:53:35",
"updated_at": "2018-11-27 08:53:37",
"refund": {
"data": []
},
"card": {
"data": []
}
},
{
"object": "Charge",
"id": "RbWLnOyXyMyODBXo",
"real_id": 1785,
"amount": 1200,
"amount_refunded": 0,
"amount_captured": 1200,
"amount_voided": 0,
"payarc_fees": 38,
"type": "Sale",
"net_amount": 1162,
"captured": 1,
"is_refunded": 0,
"status": "submitted_for_settlement",
"auth_code": "TAS462",
"failure_code": null,
"failure_message": null,
"charge_description": "sample statement description",
"invoice": null,
"under_review": 0,
"created_at": "2018-11-27 08:52:52",
"updated_at": "2018-11-27 08:52:54",
"refund": {
"data": []
},
"card": {
"data": []
}
},
{
"object": "Charge",
"id": "DMnBROWMLbyOWLbX",
"real_id": 1784,
"amount": 122,
"amount_refunded": 0,
"amount_captured": 122,
"amount_voided": 0,
"payarc_fees": 0,
"type": "Sale",
"net_amount": 122,
"captured": 1,
"is_refunded": 0,
"status": "failed_by_gateway",
"auth_code": null,
"failure_code": "D2999",
"failure_message": "General Card Auth Decline",
"charge_description": "sample statement description",
"invoice": null,
"under_review": 0,
"created_at": "2018-11-27 08:52:38",
"updated_at": "2018-11-27 08:52:40",
"refund": {
"data": []
},
"card": {
"data": []
}
},
{
"object": "Charge",
"id": "nBoLWODRWMLOXybM",
"real_id": 1690,
"amount": 1500,
"amount_refunded": 0,
"amount_captured": 1500,
"amount_voided": 0,
"payarc_fees": 48,
"type": "Sale",
"net_amount": 1452,
"captured": 1,
"is_refunded": 0,
"status": "submitted_for_settlement",
"auth_code": "TAS469",
"failure_code": null,
"failure_message": null,
"charge_description": "asdasdasd",
"invoice": null,
"under_review": 0,
"created_at": "2018-11-09 13:36:47",
"updated_at": "2018-11-09 13:36:49",
"refund": {
"data": []
},
"card": {
"data": []
}
},
{
"object": "Charge",
"id": "LDoBnOnyBLDOyWXb",
"real_id": 1689,
"amount": 1000,
"amount_refunded": 0,
"amount_captured": 1000,
"amount_voided": 0,
"payarc_fees": 32,
"type": "Sale",
"net_amount": 968,
"captured": 1,
"is_refunded": 0,
"status": "submitted_for_settlement",
"auth_code": "TAS464",
"failure_code": null,
"failure_message": null,
"charge_description": "asdasd",
"invoice": null,
"under_review": 0,
"created_at": "2018-11-09 13:36:19",
"updated_at": "2018-11-09 13:36:21",
"refund": {
"data": []
},
"card": {
"data": []
}
}
]
}
},
"meta": {
"include": [
"card",
"charge",
"subscription",
"invoice"
],
"custom": []
}
}
Step 4: Create a Charge - Keyed
POST
https://testapi.payarc.net/v1/charges
Remember from previous steps, our customer ID is KPxMADVnxMV4nNjp
, and the ID of the card we tokenized is P19v20v519L10M5y
.
We will charge the customer's card $12, which will be represented by the amount 1200
and fill in some additional customer data such as email [email protected]
, phone number 5417543010
, and the customer's name, John Smith
.
import http.client
conn = http.client.HTTPSConnection("testapi.payarc.net")
payload = 'amount=1200&customer_id=KPxMADVnxMV4nNjp¤cy=usd&statement_description=statement%20description&email=john.doe%40example.com&phone_number=5417543010&card_id=P19v20v519L10M5y&metadata=%7B%22FullCustomerName%22%20%3A%20%22%20John%20Smith%22%2C%20%22CustomerID%22%20%3A%20%221234567890%22%7D'
headers = {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI0NTIyIiwianRpIjoiYmQ5NjhjZDVlMDI5ZDg3MGMzNjljZmExOGZkN2IxMTk3MjJlYWQ4YzcxODMzNTM0ZjE0OTU3Zjc1Y2E4ZWI2NmM5MTIwMDk0NTI0NWFmNzMiLCJpYXQiOjE3MDE5MzU4NjEsIm5iZiI6MTcwMTkzNTg2MSwiZXhwIjoxODU5NjE1ODYxLCJzdWIiOiI4NTI2MTg4Iiwic2NvcGVzIjoiKiJ9.KOJALGZ-u8CuRJcapzV22anTy7VGYyEUm3qzAaXVpQfX5rX_8bmuD9Kl2vF4FfvCreJ-cOem0-c3BZLLd6cEOiV4v0kwA2O70g3HCg80g8YCPsw9F3ggOtVFWgLPofBZp56WI0q-slykAQhXQOeM7MbqnHvLUdVQClCTrxb4-_332wyZUbX_zMj2Q_o-Wunzo0DPQhGrBTV7Va-jTXwOfcHcFMtuGTVoCGoz0qqmpO5E5QuAP9DQW2296SWd-zNF90XJ9RiqKN5BUQjx9-0m7TV0ryYpm4H-bhdOwuDpWBrJyIhNsQ9hpOjF8MXEXPho5weJwMKTsDk3iii6x7AAWv_8WvppC0ZGBLxT-TcV09vVumbsm2JVjG8wKLZRYE16Y2VFXrQc8s7TkZ-h-vHbHEGantICV5XdAZ9eTVnSY9NhgNlvsC4DYdw9hL7mW3F5qpT8mqFVzVGDIUMdXkuGuFpX7BZHw-pKU82ID7P3Jxpv8t1QzES7ITyCCGZswtOiNTh8PaPRIcLHtOWxaNUQTk0BCWuvNDesqkRDKBm8bQKfXu3vjBFq-_MHV4HiylGaec_KBSJv0fLyzTcwfHrXFbFFoevJANzw5BMezMwEPWY7XL-tH2LZ3HfiwiQcjFkNYyYVzrzOa-dIzHx0U35BzQdCxKEqxLpgFUY1T-PIr08'
}
conn.request("POST", "/v1/charges", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
var https = require('follow-redirects').https;
var fs = require('fs');
var qs = require('querystring');
var options = {
'method': 'POST',
'hostname': 'testapi.payarc.net',
'path': '/v1/charges',
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI0NTIyIiwianRpIjoiYmQ5NjhjZDVlMDI5ZDg3MGMzNjljZmExOGZkN2IxMTk3MjJlYWQ4YzcxODMzNTM0ZjE0OTU3Zjc1Y2E4ZWI2NmM5MTIwMDk0NTI0NWFmNzMiLCJpYXQiOjE3MDE5MzU4NjEsIm5iZiI6MTcwMTkzNTg2MSwiZXhwIjoxODU5NjE1ODYxLCJzdWIiOiI4NTI2MTg4Iiwic2NvcGVzIjoiKiJ9.KOJALGZ-u8CuRJcapzV22anTy7VGYyEUm3qzAaXVpQfX5rX_8bmuD9Kl2vF4FfvCreJ-cOem0-c3BZLLd6cEOiV4v0kwA2O70g3HCg80g8YCPsw9F3ggOtVFWgLPofBZp56WI0q-slykAQhXQOeM7MbqnHvLUdVQClCTrxb4-_332wyZUbX_zMj2Q_o-Wunzo0DPQhGrBTV7Va-jTXwOfcHcFMtuGTVoCGoz0qqmpO5E5QuAP9DQW2296SWd-zNF90XJ9RiqKN5BUQjx9-0m7TV0ryYpm4H-bhdOwuDpWBrJyIhNsQ9hpOjF8MXEXPho5weJwMKTsDk3iii6x7AAWv_8WvppC0ZGBLxT-TcV09vVumbsm2JVjG8wKLZRYE16Y2VFXrQc8s7TkZ-h-vHbHEGantICV5XdAZ9eTVnSY9NhgNlvsC4DYdw9hL7mW3F5qpT8mqFVzVGDIUMdXkuGuFpX7BZHw-pKU82ID7P3Jxpv8t1QzES7ITyCCGZswtOiNTh8PaPRIcLHtOWxaNUQTk0BCWuvNDesqkRDKBm8bQKfXu3vjBFq-_MHV4HiylGaec_KBSJv0fLyzTcwfHrXFbFFoevJANzw5BMezMwEPWY7XL-tH2LZ3HfiwiQcjFkNYyYVzrzOa-dIzHx0U35BzQdCxKEqxLpgFUY1T-PIr08'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = qs.stringify({
'amount': '1200',
'customer_id': 'KPxMADVnxMV4nNjp',
'currency': 'usd',
'statement_description': 'statement description',
'email': '[email protected]',
'phone_number': '5417543010',
'card_id': 'P19v20v519L10M5y',
'metadata': '{"FullCustomerName" : " John Smith", "CustomerID" : "1234567890"}'
});
req.write(postData);
req.end();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://testapi.payarc.net/v1/charges");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI0NTIyIiwianRpIjoiYmQ5NjhjZDVlMDI5ZDg3MGMzNjljZmExOGZkN2IxMTk3MjJlYWQ4YzcxODMzNTM0ZjE0OTU3Zjc1Y2E4ZWI2NmM5MTIwMDk0NTI0NWFmNzMiLCJpYXQiOjE3MDE5MzU4NjEsIm5iZiI6MTcwMTkzNTg2MSwiZXhwIjoxODU5NjE1ODYxLCJzdWIiOiI4NTI2MTg4Iiwic2NvcGVzIjoiKiJ9.KOJALGZ-u8CuRJcapzV22anTy7VGYyEUm3qzAaXVpQfX5rX_8bmuD9Kl2vF4FfvCreJ-cOem0-c3BZLLd6cEOiV4v0kwA2O70g3HCg80g8YCPsw9F3ggOtVFWgLPofBZp56WI0q-slykAQhXQOeM7MbqnHvLUdVQClCTrxb4-_332wyZUbX_zMj2Q_o-Wunzo0DPQhGrBTV7Va-jTXwOfcHcFMtuGTVoCGoz0qqmpO5E5QuAP9DQW2296SWd-zNF90XJ9RiqKN5BUQjx9-0m7TV0ryYpm4H-bhdOwuDpWBrJyIhNsQ9hpOjF8MXEXPho5weJwMKTsDk3iii6x7AAWv_8WvppC0ZGBLxT-TcV09vVumbsm2JVjG8wKLZRYE16Y2VFXrQc8s7TkZ-h-vHbHEGantICV5XdAZ9eTVnSY9NhgNlvsC4DYdw9hL7mW3F5qpT8mqFVzVGDIUMdXkuGuFpX7BZHw-pKU82ID7P3Jxpv8t1QzES7ITyCCGZswtOiNTh8PaPRIcLHtOWxaNUQTk0BCWuvNDesqkRDKBm8bQKfXu3vjBFq-_MHV4HiylGaec_KBSJv0fLyzTcwfHrXFbFFoevJANzw5BMezMwEPWY7XL-tH2LZ3HfiwiQcjFkNYyYVzrzOa-dIzHx0U35BzQdCxKEqxLpgFUY1T-PIr08");
var collection = new List<KeyValuePair<string, string>>();
collection.Add(new("amount", "1200"));
collection.Add(new("customer_id", "KPxMADVnxMV4nNjp"));
collection.Add(new("currency", "usd"));
collection.Add(new("statement_description", "statement description"));
collection.Add(new("email", "[email protected]"));
collection.Add(new("phone_number", "5417543010"));
collection.Add(new("card_id", "P19v20v519L10M5y"));
collection.Add(new("metadata", "{\"FullCustomerName\" : \" John Smith\", \"CustomerID\" : \"1234567890\"}"));
var content = new FormUrlEncodedContent(collection);
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
We will receive a Charge, in our case the charge ID is nBoLWODLMLLoOXyb
{
"data": {
"object": "Charge",
"id": ",
"amount": 1200,
"amount_refunded": 0,
"amount_captured": "1200",
"amount_voided": 0,
"application_fee_amount": 0,
"tip_amount": 0,
"payarc_fees": 35,
"type": "Sale",
"net_amount": 1165,
"captured": 1,
"is_refunded": 0,
"status": "submitted_for_settlement",
"auth_code": "TAS712",
"failure_code": null,
"failure_message": null,
"charge_description": null,
"statement_description": "statement description",
"invoice": null,
"under_review": false,
"created_at": 1611924403,
"updated_at": 1611924405,
"email": "[email protected]",
"phone_number": "5417543010",
"card_level": "LEVEL1",
"sales_tax": null,
"purchase_order": null,
"supplier_reference_number": null,
"customer_ref_id": null,
"ship_to_zip": null,
"amex_descriptor": null,
"customer_vat_number": null,
"summary_commodity_code": null,
"shipping_charges": null,
"duty_charges": null,
"ship_from_zip": null,
"destination_country_code": null,
"vat_invoice": null,
"order_date": null,
"tax_category": null,
"tax_type": null,
"tax_rate": null,
"tax_amount": null,
"created_by": "[email protected]",
"terminal_register": null,
"tip_amount_refunded": null,
"sales_tax_refunded": null,
"shipping_charges_refunded": null,
"duty_charges_refunded": null,
"pax_reference_number": null,
"refund_reason": null,
"refund_description": null,
"surcharge": 0,
"toll_amount": null,
"refund": {
"data": []
},
"card": {
"data": {
"object": "Card",
"id": "2mMPL029yyP50vyN",
"address1": "",
"address2": "",
"card_source": "PHONE",
"card_holder_name": "Test One",
"is_default": 1,
"exp_month": "12",
"exp_year": "2022",
"is_verified": 0,
"fingerprint": "9v09mPMLP5NMNM0m",
"city": null,
"state": null,
"zip": "",
"brand": "V",
"last4digit": "1111",
"first6digit": 411111,
"country": null,
"avs_status": null,
"cvc_status": null,
"address_check_passed": 0,
"zip_check_passed": 0,
"customer_id": "4jAPDKVp44MVNxnM",
"created_at": 1611924035,
"updated_at": 1611924038
}
}
},
"meta": {
"include": [
"review"
],
"custom": []
}
}
Step 5: Capture the Charge
POST
https://testapi.payarc.net/v1/charges/{charge_id}/capture
In order to finalize our payment flow, we will need to capture the charge we created at the previous step, say, after we shipped the product. We will send again the same amount of 1200
, representing the $12.
import http.client
conn = http.client.HTTPSConnection("testapi.payarc.net")
payload = 'amount=1200'
headers = {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI0NTIyIiwianRpIjoiYmQ5NjhjZDVlMDI5ZDg3MGMzNjljZmExOGZkN2IxMTk3MjJlYWQ4YzcxODMzNTM0ZjE0OTU3Zjc1Y2E4ZWI2NmM5MTIwMDk0NTI0NWFmNzMiLCJpYXQiOjE3MDE5MzU4NjEsIm5iZiI6MTcwMTkzNTg2MSwiZXhwIjoxODU5NjE1ODYxLCJzdWIiOiI4NTI2MTg4Iiwic2NvcGVzIjoiKiJ9.KOJALGZ-u8CuRJcapzV22anTy7VGYyEUm3qzAaXVpQfX5rX_8bmuD9Kl2vF4FfvCreJ-cOem0-c3BZLLd6cEOiV4v0kwA2O70g3HCg80g8YCPsw9F3ggOtVFWgLPofBZp56WI0q-slykAQhXQOeM7MbqnHvLUdVQClCTrxb4-_332wyZUbX_zMj2Q_o-Wunzo0DPQhGrBTV7Va-jTXwOfcHcFMtuGTVoCGoz0qqmpO5E5QuAP9DQW2296SWd-zNF90XJ9RiqKN5BUQjx9-0m7TV0ryYpm4H-bhdOwuDpWBrJyIhNsQ9hpOjF8MXEXPho5weJwMKTsDk3iii6x7AAWv_8WvppC0ZGBLxT-TcV09vVumbsm2JVjG8wKLZRYE16Y2VFXrQc8s7TkZ-h-vHbHEGantICV5XdAZ9eTVnSY9NhgNlvsC4DYdw9hL7mW3F5qpT8mqFVzVGDIUMdXkuGuFpX7BZHw-pKU82ID7P3Jxpv8t1QzES7ITyCCGZswtOiNTh8PaPRIcLHtOWxaNUQTk0BCWuvNDesqkRDKBm8bQKfXu3vjBFq-_MHV4HiylGaec_KBSJv0fLyzTcwfHrXFbFFoevJANzw5BMezMwEPWY7XL-tH2LZ3HfiwiQcjFkNYyYVzrzOa-dIzHx0U35BzQdCxKEqxLpgFUY1T-PIr08'
}
conn.request("POST", "/v1/charges/{charge_id}/capture", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
var https = require('follow-redirects').https;
var fs = require('fs');
var qs = require('querystring');
var options = {
'method': 'POST',
'hostname': 'testapi.payarc.net',
'path': '/v1/charges/{charge_id}/capture',
'headers': {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI0NTIyIiwianRpIjoiYmQ5NjhjZDVlMDI5ZDg3MGMzNjljZmExOGZkN2IxMTk3MjJlYWQ4YzcxODMzNTM0ZjE0OTU3Zjc1Y2E4ZWI2NmM5MTIwMDk0NTI0NWFmNzMiLCJpYXQiOjE3MDE5MzU4NjEsIm5iZiI6MTcwMTkzNTg2MSwiZXhwIjoxODU5NjE1ODYxLCJzdWIiOiI4NTI2MTg4Iiwic2NvcGVzIjoiKiJ9.KOJALGZ-u8CuRJcapzV22anTy7VGYyEUm3qzAaXVpQfX5rX_8bmuD9Kl2vF4FfvCreJ-cOem0-c3BZLLd6cEOiV4v0kwA2O70g3HCg80g8YCPsw9F3ggOtVFWgLPofBZp56WI0q-slykAQhXQOeM7MbqnHvLUdVQClCTrxb4-_332wyZUbX_zMj2Q_o-Wunzo0DPQhGrBTV7Va-jTXwOfcHcFMtuGTVoCGoz0qqmpO5E5QuAP9DQW2296SWd-zNF90XJ9RiqKN5BUQjx9-0m7TV0ryYpm4H-bhdOwuDpWBrJyIhNsQ9hpOjF8MXEXPho5weJwMKTsDk3iii6x7AAWv_8WvppC0ZGBLxT-TcV09vVumbsm2JVjG8wKLZRYE16Y2VFXrQc8s7TkZ-h-vHbHEGantICV5XdAZ9eTVnSY9NhgNlvsC4DYdw9hL7mW3F5qpT8mqFVzVGDIUMdXkuGuFpX7BZHw-pKU82ID7P3Jxpv8t1QzES7ITyCCGZswtOiNTh8PaPRIcLHtOWxaNUQTk0BCWuvNDesqkRDKBm8bQKfXu3vjBFq-_MHV4HiylGaec_KBSJv0fLyzTcwfHrXFbFFoevJANzw5BMezMwEPWY7XL-tH2LZ3HfiwiQcjFkNYyYVzrzOa-dIzHx0U35BzQdCxKEqxLpgFUY1T-PIr08'
},
'maxRedirects': 20
};
var req = https.request(options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function (chunk) {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
res.on("error", function (error) {
console.error(error);
});
});
var postData = qs.stringify({
'amount': '1200'
});
req.write(postData);
req.end();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://testapi.payarc.net/v1/charges/{charge_id}/capture");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiI0NTIyIiwianRpIjoiYmQ5NjhjZDVlMDI5ZDg3MGMzNjljZmExOGZkN2IxMTk3MjJlYWQ4YzcxODMzNTM0ZjE0OTU3Zjc1Y2E4ZWI2NmM5MTIwMDk0NTI0NWFmNzMiLCJpYXQiOjE3MDE5MzU4NjEsIm5iZiI6MTcwMTkzNTg2MSwiZXhwIjoxODU5NjE1ODYxLCJzdWIiOiI4NTI2MTg4Iiwic2NvcGVzIjoiKiJ9.KOJALGZ-u8CuRJcapzV22anTy7VGYyEUm3qzAaXVpQfX5rX_8bmuD9Kl2vF4FfvCreJ-cOem0-c3BZLLd6cEOiV4v0kwA2O70g3HCg80g8YCPsw9F3ggOtVFWgLPofBZp56WI0q-slykAQhXQOeM7MbqnHvLUdVQClCTrxb4-_332wyZUbX_zMj2Q_o-Wunzo0DPQhGrBTV7Va-jTXwOfcHcFMtuGTVoCGoz0qqmpO5E5QuAP9DQW2296SWd-zNF90XJ9RiqKN5BUQjx9-0m7TV0ryYpm4H-bhdOwuDpWBrJyIhNsQ9hpOjF8MXEXPho5weJwMKTsDk3iii6x7AAWv_8WvppC0ZGBLxT-TcV09vVumbsm2JVjG8wKLZRYE16Y2VFXrQc8s7TkZ-h-vHbHEGantICV5XdAZ9eTVnSY9NhgNlvsC4DYdw9hL7mW3F5qpT8mqFVzVGDIUMdXkuGuFpX7BZHw-pKU82ID7P3Jxpv8t1QzES7ITyCCGZswtOiNTh8PaPRIcLHtOWxaNUQTk0BCWuvNDesqkRDKBm8bQKfXu3vjBFq-_MHV4HiylGaec_KBSJv0fLyzTcwfHrXFbFFoevJANzw5BMezMwEPWY7XL-tH2LZ3HfiwiQcjFkNYyYVzrzOa-dIzHx0U35BzQdCxKEqxLpgFUY1T-PIr08");
var collection = new List<KeyValuePair<string, string>>();
collection.Add(new("amount", "1200"));
var content = new FormUrlEncodedContent(collection);
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
The response is
\\\ this is missing from the API documentation
Congratulations on creating your first payment!
Updated about 1 month ago