Adjusting a CreditSale

Warning!

Adjust only works on transactions that have not settled for the day.

Add a tip to an existing CreditSale using the adjustTransaction command.

This sample code shows how to adjust a transaction.
//install the module below with the following command:
//npm install emergepay-sdk
var emergepaySdk = require('emergepay-sdk').emergepaySdk;

//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 from a CreditSale before executing adjustTransaction.
// SaleAdjust Example
emergepay.adjustTransaction({
    uniqueTransId: 'your_unique_trans_id',
    externalTransactionId: emergepay.getExternalTransactionId(),
    adjustmentType: 'SaleAdjust',
    tipAmount: '10.13',
    //optional
    cashierId: '',
    transactionReference: '',
})
.then(function(response) {
    var transactionResponse = response.data;
})
.catch(function(error) {
    throw error;
});
//install the module below with the following command:
//npm install emergepay-sdk
import {emergepaySdk} 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 from a CreditSale before executing adjustTransaction.
// SaleAdjust Example
emergepay.adjustTransaction({
    uniqueTransId: 'your_unique_trans_id',
    externalTransactionId: emergepay.getExternalTransactionId(),
    adjustmentType: 'SaleAdjust',
    tipAmount: '10.13',
    //optional
    cashierId: '',
    transactionReference: '',
})
.then(response => {
    const transactionResponse = response.data;
})
.catch(error => {
    throw error;
});


// AuthAdjust Example
emergepay.adjustTransaction({
    uniqueTransId: 'your_unique_trans_id',
    externalTransactionId: emergepay.getExternalTransactionId(),
    adjustmentType: 'AuthAdjust',
    tipAmount: '10.13',
    amount: '123.00',
    //optional
    cashierId: '',
    transactionReference: '',
})
.then(response => {
    const transactionResponse = response.data;
})
.catch(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/adjust';

//Ensure that you supply a valid uniqueTransId from a CreditSale before executing adjustTransaction.
$uniqueTransId = 'your_unique_trans_id';

//Configure the request body
//uniqueTransId, externalTransactionId and adjustmentType are required.
$body = [
  'transactionData' => [
    'uniqueTransId' => $uniqueTransId,
    'externalTransactionId' => GUID(),
    'adjustmentType' => 'SaleAdjust',
    'tipAmount' => '0.01',
	//optional
	'cashierId' => '',
    'transactionReference' => ''
  ]
];

$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 AdjustTransactionAsync()
{
  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/adjust";

 //Ensure that you supply a valid uniqueTransId from a CreditSale before executing adjustTransaction.
  string uniqueTransId = "your_unique_trans_id";

  var contents = new
  {
    transactionData = new
    {
      uniqueTransId = uniqueTransId,
      externalTransactionId = Guid.NewGuid().ToString(),
      adjustmentType = "SaleAdjust",
      tipAmount = "0.01",
      //optional
      cashierId = "",
      transactionReference = ""
    }
  };

  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;
}

Input fields

NameDetailsRequiredDescription
uniqueTransIdType: string
Max length: 65
YesThe uniqueTransId from a previous transaction. This is the token that is used to run additional transactions or voids.
externalTransactionIdType: v4 uuidYesA unique transaction identifier (must be a Version-4 UUID) for each transaction. This value is used to look up transaction results as well as confirm to the merchant and emergepay that a transaction was completed.
adjustmentTypeType: string
Enum: "SaleAdjust" | "AuthAdjust"
YesThe adjustmentType declares the type of adjustment you want to perform.
SaleAdjust can only adjust the tipAmount of an existing CreditSale.
AuthAdjust can adjust the tipAmount and/or amount of an existing CreditAuth.
tipAmountType: string
Min length: 3
Max length: 21
Min Example: 0.01
Max Example: 9999999999.99
NoTip value can be added to an existing CreditSale and replaces the tip value if a previous tip has been performed
cashierIdType: string
Max length: 150
NoThe name of the cashier that ran the transaction.
transactionReferenceType: string
Min length: 3
Max length: 65
NoThe order id associated with the transaction.

Adjust the amount and/or add a tip to an existing CreditAuth using the adjustTransaction command.