Generate a Receipt
URL Endpoint: https://easypay5.com/APIcardProcREST/v1.0.0/Receipt/ReceiptGenerate
Request Method: POST
Headers:
Session Key is passed to the API via the header:
Content-Type: application/json
Accept: application/json
SessKey: A1842D663E9A4A72XXXXXXXX303541303234373138
Use this call to request receipt details in HTML format for a particular TXID (Transaction ID). This method works for card on file documents as well as transaction receipts. You will need the TXID (Transaction ID) as well as a receipt type and a targeted recipient ( Customer or Merchant ).
The following will provide a customer receipt for TXID 123: { "REFID": 123, "ReceiptType": 1 (Sales Receipt) "Recipient": 1 (Customer Copy) }
Recipient
- Merchant
- Customer
- Both
Receipt Types
- Transaction
- Void
- Refund
- Annual Consent
- Recurring Consent
- Subscription
- ACH Transaction
- ACH Void
- ACH Refund
Important you must replace all Unicode characters to consume clean HTML
Example : CleanHtml = Regex.Replace(my, @"[^\u0000-\u007F]+", string.Empty);
{
"REFID": 158,
"ReceiptType": 1,
"Recipient": 1
}
{
"ReceiptGenerateResult": {
"ErrCode": 0,
"ErrMsg": "",
"FunctionOk": true,
"ReceiptHtml": "html",
"RespMsg": "Successfully Returned Transaction Receipt Markup"
}
}
private void RESTShowReceipt(string SessKey, int RefID, int ReceiptType, int Recipient) {
//ReceiptType 1 TRANSACTION RECEIPT
//ReceiptType 2 VOID RECEIPT
//ReceiptType 3 REFUND RECEIPT
//ReceiptType 4 ANNUAL RECEIPT
//ReceiptType 5 RECURRING RECEIPT
//ReceiptType 6 SUBSCRIPTION RECEIPT
//Recipient 1 MERCHANT COPY
//Recipient 2 CUSTOMER COPY
//Recipient 3 DUAL COPY
/// Session Key gathered using the Authenticate Command.
SessKey = "70826FC89809414BB4303231333441303331343335";
string json = JsonConvert.SerializeObject(new { REFID = RefID, ReceiptType = ReceiptType, Recipient = Recipient });
byte[] data = Encoding.UTF8.GetBytes(json);
// create Request
WebRequest request = WebRequest.Create("https://easypay5.com/APIcardProcREST/v1.0.0/Receipt/ReceiptGenerate");
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = data.Length;
// use your session key obtained when you authenticated
request.Headers.Add("SessKey: " + SessKey);
string Myheaders = request.Headers.ToString();
string responseContent = null;
// Using the Try block will catch communication errors
try {
using (Stream stream = request.GetRequestStream()) {
stream.Write(data, 0, data.Length);
}
using (WebResponse response = request.GetResponse()) {
using (Stream stream = response.GetResponseStream()) {
using (StreamReader sr99 = new StreamReader(stream)) {
responseContent = sr99.ReadToEnd();
}
}
}
} catch (Exception ee) {
MessageBox.Show("Problem communicating with EasyPay Service:" + ee.Message);
/// important to insert your Logging function here
return;
}
// Check for null Response as this would be a critical communication error as well
if (responseContent == null) {
MessageBox.Show("Critical Error!");
/// important to insert your Logging function here
return;
}
/// develop Response Object
var Result = JsonConvert.DeserializeObject<dynamic>(responseContent);
bool FunctionOk = (bool)Result.ReceiptGenerateResult.FunctionOk;
int ErrCode = (int)Result.ReceiptGenerateResult.ErrCode;
string ErrMsg = (string)Result.ReceiptGenerateResult.ErrMsg;
string RespMsg = (string)Result.ReceiptGenerateResult.RespMsg;
//Check for unexpected Errors on cloud servers. If errors found Stop Processing and check ErrorCodes
if (!FunctionOk) {
MessageBox.Show(RespMsg + " " + ErrCode + " " + ErrMsg);
/// important to insert your Logging function here
return;
}
/// retrieve desired receipt
string ReceiptHtml = Result.ReceiptGenerateResult.ReceiptHtml;
webBrowser1.DocumentText = ReceiptHtml;
}