Direct Payment Method
In addition to our integrated methods, emergepay now supports sending payments directly for synchronous, server-to-server integrations.
Additional PCI Requirements
Due to your application directly handling card data, Gravity requires additional documentation around your integration and your merchants for PCI compliance. Please contact our Integration Specialists to learn more.
Don't want to worry about PCI?
Take a look at our other iframe solutions that handle all card information for you!
Getting Started
Emergepay provides a sandbox for testing your integration prior to release. These URLs can be used in the environment_url
 referenced in the following code samples.
Environment URLs
Environment | Endpoint |
---|---|
Sandbox | https://api.emergepay-sandbox.chargeitpro.com/virtualterminal/v1 |
Production | https://api.emergepay.chargeitpro.com/virtualterminal/v1 |
Emergepay uses a JWT (authToken
) and a unique identifier for your account (oid
) to authenticate requests. Please contact your integration specialist for these values.
// install the module below with the following command:
// npm install emergepay-sdk@^1.9
const sdk = require('emergepay-sdk').emergepaySdk;
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new sdk({ oid, authToken, environmentUrl });
emergepay.authorizationTransaction({
amount: "1.00",
cardNumber: "4111111111111111",
cardExpirationDate: "01-24",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
billingAddress: "123 Main St",
billingName: "John Smith",
billingPostalCode: "90210",
cardSecurityCode: "111",
cashierId: "My Cashier",
tipAmount: "0.00",
transactionReference: "My Invoice ID",
// Only applicable to level 2 transactions
taxAmount: "",
level2: {
isTaxExempt: false,
purchaseId: "your internal purchase identifier", // required
purchaseOrderNumber: "customer's order number", // required
customerTaxId: "customer's tax identifier",
destinationPostalCode: "destination postal code for the transaction",
productDescription: "description for the order"
}
})
.then(response => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
// install the module below with the following command:
// npm install emergepay-sdk@^1.9
import {
emergepaySdk,
SaleTransactionData,
TransactionResponse,
} from "emergepay-sdk";
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new emergepaySdk({ oid, authToken, environmentUrl });
const request: SaleTransactionData = {
amount: "1.00",
cardNumber: "4111111111111111",
cardExpirationDate: "01-24",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
billingAddress: "123 Main St",
billingName: "John Smith",
billingPostalCode: "90210",
cardSecurityCode: "111",
cashierId: "My Cashier",
tipAmount: "0.00",
transactionReference: "My Invoice ID",
// Only applicable to level 2 transactions
taxAmount: "",
level2: {
isTaxExempt: false,
purchaseId: "your internal purchase identifier", // required
purchaseOrderNumber: "customer's order number", // required
customerTaxId: "customer's tax identifier",
destinationPostalCode: "destination postal code for the transaction",
productDescription: "description for the order"
}
}
emergepay.authorizationTransaction(request)
.then((response: TransactionResponse) => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
<?php
// Ensure that you replace these with valid values before trying to issue a request
$oid = 'oid';
$authToken = 'authToken';
$environmentUrl = 'environment_url';
$url = $environmentUrl . '/orgs/' . $oid . '/transactions/authorization';
// Configure the request body
// externalTransactionId, amount, cardNumber, and cardExpirationDate are required.
$body = [
'transactionData' => [
'amount' => '1.00',
'cardNumber' => '4111111111111111',
'cardExpirationDate' => '01-24',
'externalTransactionId' => GUID(),
// Optional
'billingAddress' => '123 Main St',
'billingName' => 'John Smith',
'billingPostalCode' => '90210',
'cardSecurityCode' => '111',
'cashierId' => 'My Cashier',
'tipAmount' => '0.00',
'transactionReference' => 'My Invoice ID',
// Only applicable to level 2 transactions
'taxAmount' => '',
'level2' => [
'isTaxExempt' => false,
'purchaseId' => 'your internal purchase identifier', // required
'purchaseOrderNumber' => 'customer order number', // required
'customerTaxId' => 'customer tax identifier',
'destinationPostalCode' => 'destination postal code for the transaction',
'productDescription' => 'description for the order'
]
]
];
$payload = json_encode($body);
//Configure the request
$request = curl_init($url);
curl_setopt($request, CURLOPT_HEADER, false);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload), 'Authorization: Bearer ' . $authToken));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($request, CURLOPT_POSTFIELDS, $payload);
//Issue the request and get the result
$response = curl_exec($request);
echo $response;
curl_close($request);
//Helper function used to generate a GUID/UUID
//source: http://php.net/manual/en/function.com-create-guid.php#99425
function GUID()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
public static async Task<object> AuthorizationTransactionAsync()
{
var response = new object();
// Ensure these are set before trying to issue the request.
const string OID = "oid";
const string AUTH_TOKEN = "authToken";
const string ENDPOINT_URL = "environment_url";
string url = $"{ENDPOINT_URL}/orgs/{OID}/transactions/authorization";
var contents = new
{
transactionData = new
{
amount = "1.00",
cardNumber = "4111111111111111",
cardExpirationDate = "01-24",
externalTransactionId = Guid.NewGuid().ToString(),
// Optional
billingAddress = "123 Main St",
billingName = "John Smith",
billingPostalCode = "90210",
cardSecurityCode = "111",
cashierId = "My Cashier",
tipAmount = "0.00",
transactionReference = "My Invoice ID",
// Only applicable to level 2 transactions
taxAmount = "",
level2 = new
{
isTaxExempt = false,
purchaseId = "your internal purchase identifier", // required
purchaseOrderNumber = "customer's order number", // required
customerTaxId = "customer's tax identifier",
destinationPostalCode = "destination postal code for the transaction",
productDescription = "description for the order"
}
}
};
try
{
using (var client = new HttpClient())
{
var transactionJson = JsonConvert.SerializeObject(contents);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url);
request.Headers.Add("Authorization", $"Bearer {AUTH_TOKEN}");
request.Content = new StringContent(transactionJson, Encoding.UTF8, "application/json");
var httpResponse = await client.SendAsync(request);
var data = await httpResponse.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject(data);
}
}
catch (Exception exc)
{
throw exc;
}
return response;
}
Create a Payment
Immediately apply a charge to the supplied card for the requested amount.
// install the module below with the following command:
// npm install emergepay-sdk@^1.9
const sdk = require('emergepay-sdk').emergepaySdk;
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new sdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
emergepay.saleTransaction({
amount: "1.00",
cardNumber: "4111111111111111",
cardExpirationDate: "01-24",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
billingAddress: "123 Main St",
billingName: "John Smith",
billingPostalCode: "90210",
cardSecurityCode: "111",
cashierId: "My Cashier",
tipAmount: "0.00",
transactionReference: "My Invoice ID",
// Only applicable to level 2 transactions
taxAmount: "",
level2: {
isTaxExempt: false,
purchaseId: "your internal purchase identifier", // required
purchaseOrderNumber: "customer's order number", // required
customerTaxId: "customer's tax identifier",
destinationPostalCode: "destination postal code for the transaction",
productDescription: "description for the order"
},
// Only applicable for pfac
funding: {
splitsWith: [
{ oid: "1111111111", amount: "0.50" }
]
}
})
.then(response => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
// install the module below with the following command:
// npm install emergepay-sdk@^1.9
import {
emergepaySdk,
SaleTransactionData,
TransactionResponse,
} from "emergepay-sdk";
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new emergepaySdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
const request: SaleTransactionData = {
amount: "1.00",
cardNumber: "4111111111111111",
cardExpirationDate: "01-24",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
billingAddress: "123 Main St",
billingName: "John Smith",
billingPostalCode: "90210",
cardSecurityCode: "111",
cashierId: "My Cashier",
tipAmount: "0.00",
transactionReference: "My Invoice ID",
// Only applicable to level 2 transactions
taxAmount: "",
level2: {
isTaxExempt: false,
purchaseId: "your internal purchase identifier", // required
purchaseOrderNumber: "customer's order number", // required
customerTaxId: "customer's tax identifier",
destinationPostalCode: "destination postal code for the transaction",
productDescription: "description for the order"
},
// Only applicable for pfac
funding: {
splitsWith: [
{ oid: "1111111111", amount: "0.50" }
]
}
}
emergepay.saleTransaction(request)
.then((response: TransactionResponse) => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
<?php
// Ensure that you replace these with valid values before trying to issue a request
$oid = 'oid';
$authToken = 'authToken';
$environmentUrl = 'environment_url';
$url = $environmentUrl . '/orgs/' . $oid . '/transactions/sale';
// Configure the request body
// externalTransactionId, amount, cardNumber, and cardExpirationDate are required.
$body = [
'transactionData' => [
'amount' => '1.00',
'cardNumber' => '4111111111111111',
'cardExpirationDate' => '01-24',
'externalTransactionId' => GUID(),
// Optional
'billingAddress' => '123 Main St',
'billingName' => 'John Smith',
'billingPostalCode' => '90210',
'cardSecurityCode' => '111',
'cashierId' => 'My Cashier',
'tipAmount' => '0.00',
'transactionReference' => 'My Invoice ID',
// Only applicable to level 2 transactions
'taxAmount' => "",
'level2' => [
'isTaxExempt' => false,
'purchaseId' => 'your internal purchase identifier', // required
'purchaseOrderNumber' => 'customer order number', // required
'customerTaxId' => 'customer tax identifier',
'destinationPostalCode' => 'destination postal code for the transaction',
'productDescription' => 'description for the order'
],
// Only applicable for pfac
'funding' => [
'splitsWith' => [
[ 'oid' => '1111111111', 'amount' => '0.50' ]
]
]
]
];
$payload = json_encode($body);
//Configure the request
$request = curl_init($url);
curl_setopt($request, CURLOPT_HEADER, false);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload), 'Authorization: Bearer ' . $authToken));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($request, CURLOPT_POSTFIELDS, $payload);
//Issue the request and get the result
$response = curl_exec($request);
echo $response;
curl_close($request);
//Helper function used to generate a GUID/UUID
//source: http://php.net/manual/en/function.com-create-guid.php#99425
function GUID()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
public static async Task<object> SaleTransactionAsync()
{
var response = new object();
// Ensure these are set before trying to issue the request.
const string OID = "oid";
const string AUTH_TOKEN = "authToken";
const string ENDPOINT_URL = "environment_url";
string url = $"{ENDPOINT_URL}/orgs/{OID}/transactions/sale";
var contents = new
{
transactionData = new
{
amount = "1.00",
cardNumber = "4111111111111111",
cardExpirationDate = "01-24",
externalTransactionId = Guid.NewGuid().ToString(),
// Optional
billingAddress = "123 Main St",
billingName = "John Smith",
billingPostalCode = "90210",
cardSecurityCode = "111",
cashierId = "My Cashier",
tipAmount = "0.00",
transactionReference = "My Invoice ID",
// Only applicable to level 2 transactions
taxAmount = "",
level2 = new
{
isTaxExempt = false,
purchaseId = "your internal purchase identifier", // required
purchaseOrderNumber = "customer's order number", // required
customerTaxId = "customer's tax identifier",
destinationPostalCode = "destination postal code for the transaction",
productDescription = "description for the order"
},
// Only applicable for pfac
funding = new
{
splitsWith = new[]
{
new { oid = "1111111111", amount = "1.00" },
}
}
}
};
try
{
using (var client = new HttpClient())
{
var transactionJson = JsonConvert.SerializeObject(contents);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url);
request.Headers.Add("Authorization", $"Bearer {AUTH_TOKEN}");
request.Content = new StringContent(transactionJson, Encoding.UTF8, "application/json");
var httpResponse = await client.SendAsync(request);
var data = await httpResponse.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject(data);
}
}
catch (Exception exc)
{
throw exc;
}
return response;
}
Void a Payment
Void an existing authorization or payment prior to settlement. This will return an error if the transaction is already settled and cannot be voided.
Gravity Direct
When using the Gravity Direct gateway, voids can only occur within 25 minutes of the transaction. Void attempts after 25 minutes will automatically create a refund if the transaction has not yet settled.
// install the module below with the following command:
// npm install emergepay-sdk
const sdk = require('emergepay-sdk').emergepaySdk;
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new emergepaySdk({ oid, authToken, environmentUrl });
// Ensure uniqueTransId is set to the id of the transaction to void
emergepay.voidTransaction({
uniqueTransId: "your_unique_trans_id",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
cashierId: ""
})
.then(response => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
// install the module below with the following command:
// npm install emergepay-sdk
import {
emergepaySdk,
TransactionResponse,
VoidTransactionData
} from "emergepay-sdk";
//Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay: emergepaySdk = new emergepaySdk({ oid, authToken, environmentUrl });
// Ensure uniqueTransId is set to the id of the transaction to void
const request: VoidTransactionData = {
uniqueTransId: 'your_unique_trans_id',
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
cashierId: ''
};
emergepay.voidTransaction(request)
.then(response => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
<?php
//Configure your oid and authToken. These are supplied by Gravity Payments.
$oid = 'oid';
$authToken = 'authToken'
$environmentUrl = 'environment_url';
$url = $environmentUrl . '/orgs/' . $oid . '/transactions/void';
//Set the uniqueTransId for the transaction you want to void
$uniqueTransId = 'your_unique_trans_id';
//Configure the request body
//uniqueTransId and externalTransactionId are required.
$body = [
'transactionData' => [
'uniqueTransId' => $uniqueTransId,
'externalTransactionId' => GUID(),
// Optional
'cashierId' => ''
]
];
$payload = json_encode($body);
//Configure the request
$request = curl_init($url);
curl_setopt($request, CURLOPT_HEADER, false);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload), 'Authorization: Bearer ' . $authToken));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($request, CURLOPT_POSTFIELDS, $payload);
//Issue the request and get the result
$response = curl_exec($request);
echo $response;
curl_close($request);
//Helper function used to generate a GUID/UUID
//source: http://php.net/manual/en/function.com-create-guid.php#99425
function GUID()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
public static async Task<object> VoidTransactionAsync()
{
var response = new object();
//Ensure these are set before trying to issue the request.
//Please contact Gravity Payments to get these values.
const string OID = "oid";
const string AUTH_TOKEN = "authToken"
const string ENDPOINT_URL = "environment_url";
string url = $"{ENDPOINT_URL}/orgs/{OID}/transactions/void";
//Ensure that you supply a valid uniqueTransId before trying to void the transaction.
string uniqueTransId = "your_unique_trans_id";
var contents = new
{
transactionData = new
{
uniqueTransId = uniqueTransId,
externalTransactionId = Guid.NewGuid().ToString(),
// Optional
cashierId = ""
}
};
try
{
using (var client = new HttpClient())
{
var transactionJson = JsonConvert.SerializeObject(contents);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url);
request.Headers.Add("Authorization", $"Bearer {AUTH_TOKEN}");
request.Content = new StringContent(transactionJson, Encoding.UTF8, "application/json");
var httpResponse = await client.SendAsync(request);
var data = await httpResponse.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject(data);
}
}
catch (Exception exc)
{
throw exc;
}
return response;
}
Refund a Payment
Immediately refund the requested amount to the supplied card
// install the module below with the following command:
// npm install emergepay-sdk@^1.4
const sdk = require('emergepay-sdk').emergepaySdk;
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new sdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
emergepay.refundTransaction({
amount: "1.00",
cardNumber: "4111111111111111",
cardExpirationDate: "01-24",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
billingAddress: "123 Main St",
billingName: "John Smith",
billingPostalCode: "90210",
cardSecurityCode: "111",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
// Only applicable for pfac
funding: {
splitsWith: [
{ oid: "1111111111", amount: "0.50" }
]
},
})
.then(response => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
// install the module below with the following command:
// npm install emergepay-sdk@^1.4
import {
emergepaySdk,
RefundTransactionData,
TransactionResponse,
} from "emergepay-sdk";
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new emergepaySdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
const request: RefundTransactionData = {
amount: "1.00",
cardNumber: "4111111111111111",
cardExpirationDate: "01-24",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
billingAddress: "123 Main St",
billingName: "John Smith",
billingPostalCode: "90210",
cardSecurityCode: "111",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
// Only applicable for pfac
funding: {
splitsWith: [
{ oid: "1111111111", amount: "0.50" }
]
},
}
emergepay.refundTransaction(request)
.then((response: TransactionResponse) => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
<?php
// Ensure that you replace these with valid values before trying to issue a request
$oid = 'oid';
$authToken = 'authToken'
$environmentUrl = 'environment_url';
$url = $environmentUrl . '/orgs/' . $oid . '/transactions/refund';
// Configure the request body
// externalTransactionId, amount, cardNumber, and cardExpirationDate are required.
$body = [
'transactionData' => [
'amount' => '1.00',
'cardNumber' => '4111111111111111',
'cardExpirationDate' => '01-24',
'externalTransactionId' => GUID(),
// Optional
'billingAddress' => '123 Main St',
'billingName' => 'John Smith',
'billingPostalCode' => '90210',
'cardSecurityCode' => '111',
'cashierId' => 'My Cashier',
'transactionReference' => 'My Invoice ID',
// Only applicable for pfac
'funding' => [
'splitsWith' => [
[ 'oid' => '1111111111', 'amount' => '0.50' ]
]
]
]
];
$payload = json_encode($body);
//Configure the request
$request = curl_init($url);
curl_setopt($request, CURLOPT_HEADER, false);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload), 'Authorization: Bearer ' . $authToken));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($request, CURLOPT_POSTFIELDS, $payload);
//Issue the request and get the result
$response = curl_exec($request);
echo $response;
curl_close($request);
//Helper function used to generate a GUID/UUID
//source: http://php.net/manual/en/function.com-create-guid.php#99425
function GUID()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
public static async Task<object> RefundTransactionAsync()
{
var response = new object();
// Ensure these are set before trying to issue the request.
const string OID = "oid";
const string AUTH_TOKEN = "authToken"
const string ENDPOINT_URL = "environment_url";
string url = $"{ENDPOINT_URL}/orgs/{OID}/transactions/refund";
var contents = new
{
transactionData = new
{
amount = "1.00",
cardNumber = "4111111111111111",
cardExpirationDate = "01-24",
externalTransactionId = Guid.NewGuid().ToString(),
// Optional
billingAddress = "123 Main St",
billingName = "John Smith",
billingPostalCode = "90210",
cardSecurityCode = "111",
cashierId = "My Cashier",
transactionReference = "My Invoice ID",
// Only applicable for pfac
funding = new
{
splitsWith = new[]
{
new { oid = "1111111111", amount = "1.00" },
}
}
}
};
try
{
using (var client = new HttpClient())
{
var transactionJson = JsonConvert.SerializeObject(contents);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url);
request.Headers.Add("Authorization", $"Bearer {AUTH_TOKEN}");
request.Content = new StringContent(transactionJson, Encoding.UTF8, "application/json");
var httpResponse = await client.SendAsync(request);
var data = await httpResponse.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject(data);
}
}
catch (Exception exc)
{
throw exc;
}
return response;
}
Tokenize a Card
Tokenize the supplied card
// install the module below with the following command:
// npm install emergepay-sdk@^1.7
const sdk = require('emergepay-sdk').emergepaySdk;
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new sdk({ oid, authToken, environmentUrl });
emergepay.tokenizeAccountTransaction({
cardNumber: "4111111111111111",
cardExpirationDate: "01-24",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
billingAddress: "123 Main St",
billingName: "John Smith",
billingPostalCode: "90210",
cardSecurityCode: "111",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
})
.then(response => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
// install the module below with the following command:
// npm install emergepay-sdk@^1.7
import {
emergepaySdk,
TokenizeAccountTransactionData,
TransactionResponse,
} from "emergepay-sdk";
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new emergepaySdk({ oid, authToken, environmentUrl });
const request: TokenizeAccountTransactionData = {
cardNumber: "4111111111111111",
cardExpirationDate: "01-24",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
billingAddress: "123 Main St",
billingName: "John Smith",
billingPostalCode: "90210",
cardSecurityCode: "111",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
}
emergepay.tokenizeAccountTransaction(request)
.then((response: TransactionResponse) => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
<?php
// Ensure that you replace these with valid values before trying to issue a request
$oid = 'oid';
$authToken = 'authToken'
$environmentUrl = 'environment_url';
$url = $environmentUrl . '/orgs/' . $oid . '/transactions/tokenize';
// Configure the request body
$body = [
'accountData' => [
'cardNumber' => '4111111111111111',
'cardExpirationDate' => '01-24',
'externalTransactionId' => GUID(),
//optional
'billingAddress' => '123 Main St',
'billingName' => 'John Smith',
'billingPostalCode' => '90210',
'cardSecurityCode' => '111',
'cashierId' => 'My Cashier',
'transactionReference' => 'My Invoice ID'
]
];
$payload = json_encode($body);
//Configure the request
$request = curl_init($url);
curl_setopt($request, CURLOPT_HEADER, false);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload), 'Authorization: Bearer ' . $authToken));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($request, CURLOPT_POSTFIELDS, $payload);
//Issue the request and get the result
$response = curl_exec($request);
echo $response;
curl_close($request);
//Helper function used to generate a GUID/UUID
//source: http://php.net/manual/en/function.com-create-guid.php#99425
function GUID()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
public static async Task<object> TokenizeAccountTransactionAsync()
{
var response = new object();
// Ensure these are set before trying to issue the request.
const string OID = "oid";
const string AUTH_TOKEN = "authToken"
const string ENDPOINT_URL = "environment_url";
string url = $"{ENDPOINT_URL}/orgs/{OID}/transactions/tokenize";
var contents = new
{
accountData = new
{
cardNumber = "4111111111111111",
cardExpirationDate = "01-24",
externalTransactionId = Guid.NewGuid().ToString(),
// Optional
billingAddress = "123 Main St",
billingName = "John Smith",
billingPostalCode = "90210",
cardSecurityCode = "111",
cashierId = "My Cashier",
transactionReference = "My Invoice ID"
}
};
try
{
using (var client = new HttpClient())
{
var transactionJson = JsonConvert.SerializeObject(contents);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url);
request.Headers.Add("Authorization", $"Bearer {AUTH_TOKEN}");
request.Content = new StringContent(transactionJson, Encoding.UTF8, "application/json");
var httpResponse = await client.SendAsync(request);
var data = await httpResponse.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject(data);
}
}
catch (Exception exc)
{
throw exc;
}
return response;
}
Create an ACH Payment
Immediately initiate a transfer from the supplied bank account for the requested amount.
// install the module below with the following command:
// npm install emergepay-sdk@^1.12.0
const sdk = require('emergepay-sdk').emergepaySdk;
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new sdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
emergepay.achSaleTransaction({
amount: "1.00",
accountHolderName: "John Smith",
accountNumber: "4267876423",
routingNumber: "026009708",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
accountType: "Checking",
checkNumber: "7624",
billingAddress: "123 Main St",
billingPostalCode: "90210",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
})
.then(response => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
// install the module below with the following command:
// npm install emergepay-sdk@^1.12.0
import {
emergepaySdk,
AchTransactionData,
TransactionResponse,
} from "emergepay-sdk";
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new emergepaySdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
const request: AchTransactionData = {
amount: "1.00",
accountHolderName: "John Smith",
accountNumber: "4267876423",
routingNumber: "026009708",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
accountType: "Checking",
checkNumber: "7624",
billingAddress: "123 Main St",
billingPostalCode: "90210",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
}
emergepay.achSaleTransaction(request)
.then((response: TransactionResponse) => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
<?php
// Ensure that you replace these with valid values before trying to issue a request
$oid = 'oid';
$authToken = 'authToken';
$environmentUrl = 'environment_url';
$url = $environmentUrl . '/orgs/' . $oid . '/transactions/ach/sale';
// Configure the request body
// externalTransactionId, amount, accountHolderName, accountNumber and routingNumber are required.
$body = [
'transactionData' => [
'amount' => '1.00',
'accountHolderName' => 'John Smith',
'accountNumber' => '4267876423',
'routingNumber' => '026009708',
'externalTransactionId' => GUID(),
// Optional
'accountType' => 'Checking',
'checkNumber' => "7624",
'billingAddress' => '123 Main St',
'billingPostalCode' => '90210',
'cashierId' => 'My Cashier',
'transactionReference' => 'My Invoice ID'
]
];
$payload = json_encode($body);
//Configure the request
$request = curl_init($url);
curl_setopt($request, CURLOPT_HEADER, false);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload), 'Authorization: Bearer ' . $authToken));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($request, CURLOPT_POSTFIELDS, $payload);
//Issue the request and get the result
$response = curl_exec($request);
echo $response;
curl_close($request);
//Helper function used to generate a GUID/UUID
//source: http://php.net/manual/en/function.com-create-guid.php#99425
function GUID()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
public static async Task<object> AchSaleTransactionAsync()
{
var response = new object();
// Ensure these are set before trying to issue the request.
const string OID = "oid";
const string AUTH_TOKEN = "authToken";
const string ENDPOINT_URL = "environment_url";
string url = $"{ENDPOINT_URL}/orgs/{OID}/transactions/ach/sale";
var contents = new
{
transactionData = new
{
amount = "1.00",
accountHolderName = "John Smith",
accountNumber = "4267876423",
routingNumber = "026009708",
externalTransactionId = Guid.NewGuid().ToString(),
// Optional
accountType = "Checking",
checkNumber = "7624",
billingAddress = "123 Main St",
billingPostalCode = "90210",
cashierId = "My Cashier",
transactionReference = "My Invoice ID",
}
};
try
{
using (var client = new HttpClient())
{
var transactionJson = JsonConvert.SerializeObject(contents);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url);
request.Headers.Add("Authorization", $"Bearer {AUTH_TOKEN}");
request.Content = new StringContent(transactionJson, Encoding.UTF8, "application/json");
var httpResponse = await client.SendAsync(request);
var data = await httpResponse.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject(data);
}
}
catch (Exception exc)
{
throw exc;
}
return response;
}
Create an ACH Refund
Immediately refund the requested amount to the supplied bank account.
// install the module below with the following command:
// npm install emergepay-sdk@^1.12.0
const sdk = require('emergepay-sdk').emergepaySdk;
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new sdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
emergepay.achRefundTransaction({
amount: "1.00",
accountHolderName: "John Smith",
accountNumber: "4267876423",
routingNumber: "026009708",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
accountType: "Checking",
checkNumber: "7624",
billingAddress: "123 Main St",
billingPostalCode: "90210",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
})
.then(response => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
// install the module below with the following command:
// npm install emergepay-sdk@^1.12.0
import {
emergepaySdk,
AchTransactionData,
TransactionResponse,
} from "emergepay-sdk";
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new emergepaySdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
const request: AchTransactionData = {
amount: "1.00",
accountHolderName: "John Smith",
accountNumber: "4267876423",
routingNumber: "026009708",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
accountType: "Checking",
checkNumber: "7624",
billingAddress: "123 Main St",
billingPostalCode: "90210",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
}
emergepay.achRefundTransaction(request)
.then((response: TransactionResponse) => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
<?php
// Ensure that you replace these with valid values before trying to issue a request
$oid = 'oid';
$authToken = 'authToken';
$environmentUrl = 'environment_url';
$url = $environmentUrl . '/orgs/' . $oid . '/transactions/ach/refund';
// Configure the request body
// externalTransactionId, amount, accountHolderName, accountNumber and routingNumber are required.
$body = [
'transactionData' => [
'amount' => '1.00',
'accountHolderName' => 'John Smith',
'accountNumber' => '4267876423',
'routingNumber' => '026009708',
'externalTransactionId' => GUID(),
// Optional
'accountType' => 'Checking',
'checkNumber' => "7624",
'billingAddress' => '123 Main St',
'billingPostalCode' => '90210',
'cashierId' => 'My Cashier',
'transactionReference' => 'My Invoice ID'
]
];
$payload = json_encode($body);
//Configure the request
$request = curl_init($url);
curl_setopt($request, CURLOPT_HEADER, false);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload), 'Authorization: Bearer ' . $authToken));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($request, CURLOPT_POSTFIELDS, $payload);
//Issue the request and get the result
$response = curl_exec($request);
echo $response;
curl_close($request);
//Helper function used to generate a GUID/UUID
//source: http://php.net/manual/en/function.com-create-guid.php#99425
function GUID()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
public static async Task<object> AchRefundTransactionAsync()
{
var response = new object();
// Ensure these are set before trying to issue the request.
const string OID = "oid";
const string AUTH_TOKEN = "authToken";
const string ENDPOINT_URL = "environment_url";
string url = $"{ENDPOINT_URL}/orgs/{OID}/transactions/ach/refund";
var contents = new
{
transactionData = new
{
amount = "1.00",
accountHolderName = "John Smith",
accountNumber = "4267876423",
routingNumber = "026009708",
externalTransactionId = Guid.NewGuid().ToString(),
// Optional
accountType = "Checking",
checkNumber = "7624",
billingAddress = "123 Main St",
billingPostalCode = "90210",
cashierId = "My Cashier",
transactionReference = "My Invoice ID",
}
};
try
{
using (var client = new HttpClient())
{
var transactionJson = JsonConvert.SerializeObject(contents);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url);
request.Headers.Add("Authorization", $"Bearer {AUTH_TOKEN}");
request.Content = new StringContent(transactionJson, Encoding.UTF8, "application/json");
var httpResponse = await client.SendAsync(request);
var data = await httpResponse.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject(data);
}
}
catch (Exception exc)
{
throw exc;
}
return response;
}
Tokenize a Bank Account
Tokenize the supplied bank account.
// install the module below with the following command:
// npm install emergepay-sdk@^1.12.0
const sdk = require('emergepay-sdk').emergepaySdk;
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new sdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
emergepay.achTokenizeAccountTransaction({
accountHolderName: "John Smith",
accountNumber: "4267876423",
routingNumber: "026009708",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
accountType: "Checking",
billingAddress: "123 Main St",
billingPostalCode: "90210",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
})
.then(response => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
// install the module below with the following command:
// npm install emergepay-sdk@^1.12.0
import {
emergepaySdk,
AchTokenizeAccountTransactionData,
TransactionResponse,
} from "emergepay-sdk";
// Ensure that you replace these with valid values before trying to issue a request
const oid = "oid";
const authToken = "authToken";
const environmentUrl = "environment_url";
const emergepay = new emergepaySdk({ oid, authToken, environmentUrl });
//Ensure that you supply a valid external transaction id before trying to run the retrieval function.
const request: AchTokenizeAccountTransactionData = {
accountHolderName: "John Smith",
accountNumber: "4267876423",
routingNumber: "026009708",
externalTransactionId: emergepay.getExternalTransactionId(),
// Optional
accountType: "Checking",
billingAddress: "123 Main St",
billingPostalCode: "90210",
cashierId: "My Cashier",
transactionReference: "My Invoice ID",
}
emergepay.achTokenizeAccountTransaction(request)
.then((response: TransactionResponse) => {
const transactionResponse = response.data;
})
.catch(error => {
throw error;
});
<?php
// Ensure that you replace these with valid values before trying to issue a request
$oid = 'oid';
$authToken = 'authToken';
$environmentUrl = 'environment_url';
$url = $environmentUrl . '/orgs/' . $oid . '/transactions/ach/tokenize';
// Configure the request body
// externalTransactionId, accountHolderName, accountNumber and routingNumber are required.
$body = [
'accountData' => [
'accountHolderName' => 'John Smith',
'accountNumber' => '4267876423',
'routingNumber' => '026009708',
'externalTransactionId' => GUID(),
// Optional
'accountType' => 'Checking',
'billingAddress' => '123 Main St',
'billingPostalCode' => '90210',
'cashierId' => 'My Cashier',
'transactionReference' => 'My Invoice ID'
]
];
$payload = json_encode($body);
//Configure the request
$request = curl_init($url);
curl_setopt($request, CURLOPT_HEADER, false);
curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
curl_setopt($request, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($payload), 'Authorization: Bearer ' . $authToken));
curl_setopt($request, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($request, CURLOPT_POSTFIELDS, $payload);
//Issue the request and get the result
$response = curl_exec($request);
echo $response;
curl_close($request);
//Helper function used to generate a GUID/UUID
//source: http://php.net/manual/en/function.com-create-guid.php#99425
function GUID()
{
if (function_exists('com_create_guid') === true)
{
return trim(com_create_guid(), '{}');
}
return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
}
public static async Task<object> AchTokenizeAccountTransactionAsync()
{
var response = new object();
// Ensure these are set before trying to issue the request.
const string OID = "oid";
const string AUTH_TOKEN = "authToken";
const string ENDPOINT_URL = "environment_url";
string url = $"{ENDPOINT_URL}/orgs/{OID}/transactions/ach/tokenize";
var contents = new
{
accountData = new
{
accountHolderName = "John Smith",
accountNumber = "4267876423",
routingNumber = "026009708",
externalTransactionId = Guid.NewGuid().ToString(),
// Optional
accountType = "Checking",
billingAddress = "123 Main St",
billingPostalCode = "90210",
cashierId = "My Cashier",
transactionReference = "My Invoice ID",
}
};
try
{
using (var client = new HttpClient())
{
var transactionJson = JsonConvert.SerializeObject(contents);
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, url);
request.Headers.Add("Authorization", $"Bearer {AUTH_TOKEN}");
request.Content = new StringContent(transactionJson, Encoding.UTF8, "application/json");
var httpResponse = await client.SendAsync(request);
var data = await httpResponse.Content.ReadAsStringAsync();
response = JsonConvert.DeserializeObject(data);
}
}
catch (Exception exc)
{
throw exc;
}
return response;
}