Pay By Card - One-Time Payment

This guide walks through creating and capturing a one-time payment by card. For this example, we will charge the card an amount of $12.01.

Step 1: Tokenize Card

POSThttps://testapi.payarc.net/v1/tokens

We will use this API to create a token that represents the credit or debit card used to carry out this transaction.

We are assuming the card source is INTERNET, and will capture the card number 4012000098765439, expiration month 12and 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 2: Create a Charge with the token

POSThttps://testapi.payarc.net/v1/charges

Remember from previous steps, the ID of the card we tokenized is P19v20v519L10M5y.

We will charge the customer's card $12.01, which will be represented by the amount 1201.

You will need to set the capture flag to 1 which means authorize and charge the payment at the same time.

var https = require('follow-redirects').https;
var fs = require('fs');

var qs = require('querystring');

var options = {
  'method': 'POST',
  'hostname': 'api.payarc.net',
  'path': '/v1/charges',
  'headers': {
    'Accept': 'application/json',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Authorization': 'Bearer {{Access-Token-From-Payarc-Dashboard}}'
  },
  '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': '1201',
  'currency': 'usd',
  'statement_description': 'statement description',
  'token_id': '8YmNlwYL8LYEwEq0',
  'capture': '1'
});

req.write(postData);

req.end();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://api.payarc.net/v1/charges");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer {{Access-Token-From-Payarc-Dashboard}}");
var collection = new List<KeyValuePair<string, string>>();
collection.Add(new("amount", "1201"));
collection.Add(new("currency", "usd"));
collection.Add(new("statement_description", "statement description"));
collection.Add(new("token_id", "8YmNlwYL8LYEwEq0"));
collection.Add(new("capture", "1"));
collection.Add(new("email", "[email protected]"));
collection.Add(new("phone_number", "5417543010"));
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": "DMnBROWBWyLoOWLb",
    "amount": 1201,
    "amount_refunded": 0,
    "amount_captured": "1201",
    "amount_voided": 0,
    "application_fee_amount": 0,
    "tip_amount": 0,
    "payarc_fees": 0,
    "type": "Sale",
    "net_amount": 1200,
    "captured": 1,
    "is_refunded": 0,
    "status": "submitted_for_settlement",
    "auth_code": "TAS321",
    "failure_code": null,
    "failure_message": null,
    "charge_description": null,
    "statement_description": "statement description",
    "invoice": null,
    "under_review": false,
    "created_at": 1609164769,
    "updated_at": 1609164772,
    "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,
    "refund": {
      "data": []
    },
    "card": {
      "data": {
        "object": "Card",
        "id": "N2m1v0LyP9M90MPy",
        "address1": null,
        "address2": null,
        "card_source": "INTERNET",
        "card_holder_name": null,
        "is_default": 0,
        "exp_month": "05",
        "exp_year": "2022",
        "is_verified": 0,
        "fingerprint": "Lv0NmMPNLv591505",
        "city": null,
        "state": null,
        "zip": null,
        "brand": "V",
        "last4digit": "1111",
        "first6digit": 411111,
        "country": null,
        "avs_status": null,
        "cvc_status": null,
        "address_check_passed": 0,
        "zip_check_passed": 0,
        "customer_id": null,
        "created_at": 1609164756,
        "updated_at": 1609164756
      }
    }
  },
  "meta": {
    "include": [
      "review"
    ],
    "custom": []
  }
}

Congratulations on creating the payment!