Credit\Return\Refund a Transaction
URL Endpoint: https://easypay5.com/APIcardProcREST/v1.0.0/CardSale/ApplyCredit
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 process a refund to a settled charge. You will need the Transaction ID and the amount to be refunded.
Copied
{
"TxID": 56,
"CreditAmount": 5.0
}
{
"Transaction_ApplyCreditResult": {
"ErrCode": 0,
"ErrMsg": "",
"FunctionOk": true,
"RespMsg": "Successful Credit Pending Transaction ID : 000057",
"TxApproved": true,
"TxID": 57
}
}
Copied
private void RESTTransactionCredit(string SessKey, int TxID, decimal CreditAmount)
{
/// Session Key gathered using the Authenticate Command.
SessKey = "70826FC89809414BB4303231333441303331343335";
// transaction you need to refund
TxID = 1;
string json = JsonConvert.SerializeObject(new { TxID = TxID, CreditAmount = CreditAmount });
byte[] data = Encoding.UTF8.GetBytes(json);
// create Request
WebRequest request = WebRequest.Create("https://easypay5.com/APIcardProcREST/v1.0.0/CardSale/ApplyCredit");
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.Transaction_ApplyCreditResult.FunctionOk;
int ErrCode = (int)Result.Transaction_ApplyCreditResult.ErrCode;
string ErrMsg = (string)Result.Transaction_ApplyCreditResult.ErrMsg;
string RespMsg = (string)Result.Transaction_ApplyCreditResult.RespMsg;
bool TxApproved = (bool)Result.Transaction_ApplyCreditResult.TxApproved;
int respTxID = (int)Result.Transaction_ApplyCreditResult.TxID;
//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;
}
//Refund not approved. Pleasse check the response message.
if (!TxApproved)
{
MessageBox.Show(RespMsg);
/// important to insert your Logging function here
return;
}
//Successful Refund shows the TransactionID
MessageBox.Show(RespMsg + ": TXID : " + respTxID);
/// important to insert your Logging function here
return;
}