Running Asynchronous Tokenized Transactions

Restrictions

The asynchronous tokenized transaction endpoint currently only supports supplying up to a total of 1000 CreditSale requests at a time.

Getting results

Asynchronous tokenized transactions will always return their results via postback. This is currently the only way we support getting these results.

This sample code shows how to run bulk, asynchronous tokenized transactions.
//install the module below with the following command:
//npm install emergepay-sdk
var emergepaySdk = require("emergepay-sdk").emergepaySdk;
var TransactionType = require("emergepay-sdk").TransactionType;

//Ensure that you replace these with valid values before trying to issue a request
var oid = "your_oid";
var authToken = "your_authToken";
var environmentUrl = "environment_url";

var emergepay = new emergepaySdk({oid: oid, authToken: authToken, environmentUrl: environmentUrl});

//Ensure that you supply a valid uniqueTransId per request before trying to run the tokenized request(s).
var data = {
  requests: [
    {
      transactionType: TransactionType.CreditSale,
      transactionData: {
        uniqueTransId: "your_unique_trans_id",
        externalTransactionId: emergepay.getExternalTransactionId(),
        amount: "0.01"
      }
    },
    {
      transactionType: TransactionType.CreditSale,
      transactionData: {
        uniqueTransId: "your_unique_trans_id",
        externalTransactionId: emergepay.getExternalTransactionId(),
        amount: "0.50",
  		// Only applicable for pfac
  		funding: {
	  		splitsWith: [
				{ oid: "1111111111", amount: "0.50" }
			]
 		 }
      }
    }
  ]
};

emergepay.tokenizedTransactions(data)
.then(function(response) {
    console.log(response);
})
.catch(function(error) {
    throw error;
});
//install the module below with the following command:
//npm install emergepay-sdk
import {emergepaySdk, TransactionType, TokenizedRequests} from "emergepay-sdk";

//Ensure that you replace these with valid values before trying to issue a request
const oid: string = "your_oid";
const authToken: string = "your_authToken";
const environmentUrl: string = "environment_url";
const emergepay: emergepaySdk = new emergepaySdk({oid, authToken, environmentUrl});

//Ensure that you supply a valid uniqueTransId per request before trying to run the tokenized request(s).
const data: TokenizedRequests = {
  requests: [
    {
      transactionType: TransactionType.CreditSale,
      transactionData: {
        uniqueTransId: "your_unique_trans_id",
        externalTransactionId: emergepay.getExternalTransactionId(),
        amount: "0.01"
      }
    },
    {
      transactionType: TransactionType.CreditSale,
      transactionData: {
        uniqueTransId: "your_unique_trans_id",
        externalTransactionId: emergepay.getExternalTransactionId(),
        amount: "0.50",
  		// Only applicable for pfac
  		funding: {
	  		splitsWith: [
				{ oid: "1111111111", amount: "0.50" }
			]
  		}
      }
    }
  ]
};

emergepay.tokenizedTransactions(data)
.then(function(response) {
    console.log(response);
})
.catch(function(error) {
    throw error;
});
<?php

//Configure your oid and authToken. These are supplied by Gravity Payments.
$oid = 'your_oid';
$authToken = 'your_authToken';
$environmentUrl = 'environment_url';

$url = $environmentUrl . '/orgs/' . $oid . '/transactions/tokenized/bulk';

//Ensure that you supply a valid uniqueTransId per request before trying to run the tokenized request(s)
$body = [
  'requests' => [
    [
      'transactionType' => 'CreditSale',
      'transactionData' => [
        'uniqueTransId' => 'your_unique_trans_id',
        'externalTransactionId' => GUID(),
        'amount' => '0.01'
      ]
    ],
    [
      'transactionType' => 'CreditSale',
      'transactionData' => [
        'uniqueTransId' => 'your_unique_trans_id',
        'externalTransactionId' => GUID(),
        'amount' => '0.50',
        // 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, "POST");
curl_setopt($request, CURLOPT_POSTFIELDS, $payload);

//Issue the request and get the result
$response = curl_exec($request);
curl_close($request);

echo $response;

//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> TokenizedTransactionsAsync()
{
    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 = "your_oid";
    const string AUTH_TOKEN = "your_authToken";
    const string ENDPOINT_URL = "environment_url";

    string url = $"{ENDPOINT_URL}/orgs/{OID}/transactions/tokenized/bulk";

    //Ensure that you supply a valid uniqueTransId per request before trying to run the tokenized request(s)
    var contents = new
    {
        requests = new[]
        {
            new
            {
                transactionType = "CreditSale",
                transactionData = new
                {
                    uniqueTransId = "your_unique_trans_id",
                    externalTransactionId = Guid.NewGuid().ToString(),
                    amount = "0.01"
                }
            },
            new
            {
                transactionType = "CreditSale",
                transactionData = new
                {
                    uniqueTransId = "your_unique_trans_id",
                    externalTransactionId = Guid.NewGuid().ToString(),
                    amount = "0.50",
  	  				// 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.Post, 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;
}

Input Fields

NameDetailsRequiredDescription
requestsType: object[]
Min items: 1
Max items: 1000
YesAn array of request objects (see below) to run. These requests will be validated and then scheduled to run at a later time.

Request Object Properties

NameDetailsRequiredDescription
transactionTypeType: string
Accepted values:
"CreditSale", "CreditForce"
YesThe transaction type of the request to schedule.
transactionDataType: objectYesThe contents of this object will vary depending on the transaction type supplied. See the corresponding synchronous tokenized transaction input fields above for accepted values.

At a minimum, this object must contain the uniqueTransId and externalTransactionId properties.