Credit Card Processing – ProtectPay Refund

This method is used to refund a completed debit or credit card transaction that has been settled. Here are the cases when you should use this method:
  • When voids are no longer possible (Many gateways will not allow you to void a transaction after it has been captured. ProPay® allows this but only until the transaction has been sent to the card brand, or until the merchant has received funds for the transaction).
  • To perform a partial refund.
How to call this method?

HTTP URL(s)
HTTP Verb PUT
HTTP Header Authorization
Example Request

Example Response

{
 "TransactionHistoryId":0,
 "OriginalTransactionId":"4",
 "MerchantProfileId":null,
 "Amount":0,
 "Comment1":null,
 "Comment2":null,
 "PaymentMethodId":null
}
{
 "TransactionDetail":
 {
"TransactionHistoryId":"10501",
"AuthorizationCode":null,
"AVSCode":"NotPresent",
"TransactionResult":"Success",
"TransactionId":"5",
"ResultCode":
{
"ResultValue":"SUCCESS",
"ResultCode":"00",
"ResultMessage":""
},
"CurrencyConvertedAmount":500,
"CurrencyConvertedCurrencyCode":"USD",
"CurrencyConversionRate":1.0,
"CVVResponseCode":"NotPresent",
"GrossAmt":null,
"NetAmt":null,
"PerTransFee":null,
"Rate":null,
"GrossAmtLessNetAmt":null
 },
 "RequestResult":
 {
"ResultValue":"SUCCESS",
"ResultCode":"00",
"ResultMessage":""
 }
}
Implementation Details
Request Submission

namespace ProtectPayApi_RefundTransaction
{
using System;
using System.Text;

using RestSharp;

/*
ProPay provides the following code “AS IS.”
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/
public class RefundTransactionProgram
{
public static void Main(string[] args)
{
var refundTransactionResponse = RefundTransaction();
}

/// <summary>
/// Refunds a transaction using the ProtectPay REST API.
/// </summary>
/// <returns>The response data from the refund call.</returns>
private static RefundTransactionResponse RefundTransaction()
{
var baseUrl = "https://xmltestapi.propay.com/ProtectPay";
var request = BuildRefundRequest();
var restRequest = CreateRestRequest("/RefundTransaction/", RestSharp.Method.PUT);
restRequest.AddBody(request);
return Execute<RefundTransactionResponse>(restRequest, baseUrl);
}

/// <summary>
/// Builds the request data.
/// </summary>
/// <returns>The request data.</returns>
private static RefundTransactionRequest BuildRefundRequest()
{
return new RefundTransactionRequest
{
Comment1 = "Comment 1",
Comment2 = "Comment 2",
OriginalTransactionId = "2",
};
}

/// <summary>
/// Request factory to ensure API key is always first parameter added.
/// </summary>
/// <param name="resource">The resource name.</param>
/// <param name="method">The HTTP method.</param>
/// <returns>Returns a new <see cref="RestRequest"/>.</returns>
private static RestRequest CreateRestRequest(string resource, Method method)
{
var restRequest = new RestRequest { Resource = resource, Method = method, RequestFormat = DataFormat.Json, };
var credentials = GetCredentials();
restRequest.AddHeader("accept", "application/json");
restRequest.AddHeader("Authorization", credentials);

return restRequest;
}

private static string GetCredentials()
{
var billerAccountId = "5114248593164903"; // biller account id
var authToken = "9d506d3e-b5f7-4474-adb1-76423e113c85"; // authentication token of biller

var encodedCredentials = Convert.ToBase64String(Encoding.Default.GetBytes(billerAccountId + ":" + authToken));

var credentials = string.Format("Basic {0}", encodedCredentials);
return credentials;
}

/// <summary>
/// Executes a particular http request to a resource.
/// </summary>
/// <typeparam name="T">The response type.</typeparam>
/// <param name="request">The REST request.</param>
/// <param name="baseUrl">The base URL.</param>
/// <returns>Returns a response of the type parameter.</returns>
private static T Execute<T>(IRestRequest request, string baseUrl) where T : class, new()
{
var client = new RestClient(baseUrl);
var response = client.Execute<T>(request);

if (response.ErrorException != null)
{
Console.WriteLine(
"Error: Exception: {0}, Headers: {1}, Content: {2}, Status Code: {3}",
response.ErrorException,
response.Headers,
response.Content,
response.StatusCode);
}

return response.Data;
}


/// <summary>
/// Request information for a call to the "RefundTransaction" method.
/// </summary>
public class RefundTransactionRequest
{
/// <summary>
/// Gets or sets Optional value to designate the amount of the refund (in pennies) - value cannot be negative. 
/// NOTE: If the amount is 0 then the entire transaction will be refunded, otherwise a partial refund will be requested.
/// </summary>
public long Amount { get; set; }

/// <summary>
/// Gets or sets Optional value to attach a comment to the transaction. To be sent to the gateway, if it supports this field.
/// </summary>
public string Comment1 { get; set; }

/// <summary>
/// Gets or sets Optional value to attach a second comment to the transaction. To be sent to the gateway, if it supports this field.
/// </summary>
public string Comment2 { get; set; }

/// <summary>
/// Gets or sets Optional value to designate the merchant profile id that should be used to process this void.
/// </summary>
public string MerchantProfileId { get; set; }

/// <summary>
/// Gets or sets Optional value to designate the transaction id passed back from the gateway. 
/// NOTE: This will NOT be used if the TransactionHistoryId is present (not null and length > 0).
/// </summary>
public string OriginalTransactionId { get; set; }

/// <summary>
/// Gets or sets Optional Value providing the Payment Method Id associated with the transaction. It will be used to retrieve the credit card number for non-ProtectPay transactions.
/// </summary>
public string PaymentMethodId { get; set; }

/// <summary>
/// Gets or sets Optional value to designate the transaction history id passed back from ProtectPay. 
/// NOTE: If this value is populated (not null and length > 0) it will always be used before the OriginalTransactionId.
/// </summary>
public long TransactionHistoryId { get; set; }
}

/// <summary>
/// The value returned from a call to the "RefundTransaction" method.
/// </summary>
public class RefundTransactionResponse
{
/// <summary>
/// The details of transaction information.
/// </summary>
public TransactionInformationDetails TransactionDetail
{
get;
set;
}

/// <summary>
/// Represents the result of the current transaction attempt.
/// </summary>
public Result RequestResult
{
get;
set;
}
}

/// <summary>
/// The details of the transaction information.
/// </summary>
public class TransactionInformationDetails
{
/// <summary>
/// Gets or sets authorization code from the system of record.
/// </summary>
public string AuthorizationCode
{
get;
set;
}

/// <summary>
/// Gets or sets address verification system (AVS) code.
/// </summary>
/// <remarks>
/// Only present if billing information is present on a payment method and.
/// system of record supports AVS.
/// </remarks>
public string AVSCode
{
get;
set;
}

/// <summary>
/// Gets or sets the conversion rate from the requested currency to the settled currency.
/// </summary>
public decimal CurrencyConversionRate
{
get;
set;
}

/// <summary>
/// Gets or sets the amount in the settled currency.
/// </summary>
public long CurrencyConvertedAmount
{
get;
set;
}

/// <summary>
/// Gets or sets the settled currency code.
/// </summary>
public string CurrencyConvertedCurrencyCode
{
get;
set;
}

/// <summary>
/// Gets or sets gross amount in the settled currency.
/// </summary>
public virtual long? GrossAmt
{
get;
set;
}

/// <summary>
/// Gets or sets gross amount less net amount in the settled currency.
/// </summary>
public virtual long? GrossAmtLessNetAmt
{
get;
set;
}
 
/// <summary>
/// Gets or sets net amount in the settled currency.
/// </summary>
public virtual long? NetAmt
{
get;
set;
}

/// <summary>
/// Gets or sets per transaction fee in the settled currency.
/// </summary>
public virtual long? PerTransFee
{
get;
set;
}

/// <summary>
/// Gets or sets rate percentage.
/// </summary>
public virtual decimal? Rate
{
get;
set;
}

/// <summary>
/// Gets or sets specific result information from the transaction.
/// </summary>
public Result ResultCode
{
get;
set;
}

/// <summary>
/// Gets or sets transaction history id in the ProPay system.
/// </summary>
public string TransactionHistoryId
{
get;
set;
}

/// <summary>
/// Gets or sets transaction ID from the system of record.
/// </summary>
public string TransactionId
{
get;
set;
}

/// <summary>
/// <c>Gets or sets result</c> of the transaction.
/// </summary>
public string TransactionResult
{
get;
set;
}
}

/// <summary>
/// The result of the call.
/// </summary>
public class Result
{
/// <summary>
/// The result of the transaction.
/// </summary>
/// <remarks>
/// Will always be SUCCESS or FAILURE.
/// </remarks>
public string ResultValue { get; set; }

/// <summary>
/// The result code of the transaction.
/// </summary>
/// <remarks>
/// Will be a two-digit string with only numbers. Allows "00" as a response.
/// </remarks>
public string ResultCode { get; set; }

/// <summary>
/// The english-text message of what went wrong (if anything).
/// </summary>
/// <remarks>
/// The documentation shows the empty string being returned in the success cases.
/// </remarks>
public string ResultMessage { get; set; }
}
}
}

Check out the online HTML CheatSheet here and save the link because you might need it while composing content for a web page.

Response Handling

Request Submission

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

<?php
class ProtectPayApi
{

/* change this to the production url for going live after testing https://api.propay.com */
private $_apiBaseUrl = 'https://xmltestapi.propay.com';

/* credentials that would normally be set from database values or a config value */
private $_billerId;
private $_authToken;

/* for refunding a settled transaction */
private $_transactionRefundData;
private $_transactionRefundInfo;

/**
* @param string $billerId
* @return $this
*/
public function setBillerId($billerId) {
$this->_billerId = $billerId;
return $this;
}

/**
* @param string $authToken
* @return $this
*/
public function setAuthToken($authToken) {
$this->_authToken = $authToken;
return $this;
}

/**
* @return string
*/
private function _getAuth() {
return $this->_billerId . ':' . $this->_authToken;
}

/**
* @return $this
* result is something like ...
* {
* "TransactionDetail":{
* "AVSCode":"NotPresent",
* "AuthorizationCode":null,
* "CurrencyConversionRate":1.0,
* "CurrencyConvertedAmount":100,
* "CurrencyConvertedCurrencyCode":"USD",
* "CVVResponseCode":"NotPresent",
* "GrossAmt ":null,
* "GrossAmtLessNetAmt ":null,
* "NetAmt ":null,
* "PerTransFee ":null,
* "Rate ":null
* "ResultCode":{
* "ResultValue":"SUCCESS",
* "ResultCode":"00",
* "ResultMessage":""
* },
* "TransactionHistoryId":"39560623",
* "TransactionId":"3",
* "TransactionResult":"Success"
* },
* "RequestResult":{
* "ResultValue":"SUCCESS",
* "ResultCode":"00",
* "ResultMessage":""
* }
* }
*/
public function processSettledTransactionRefund() {
$data_string = json_encode($this->_transactionRefundData);
$ch = curl_init($this->_apiBaseUrl . '/ProtectPay/RefundTransaction');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $this->_getAuth());
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
));

$this->_transactionRefundInfo = curl_exec($ch);
return $this;

}

/**
* @param array $transactionRefundData
* @return $this
*/
public function setTransactionRefundData($transactionRefundData) {
$this->_transactionRefundData = $transactionRefundData;
return $this;
}

/**
* @return mixed
*/
public function getTransactionRefundInfo() {
return $this->_transactionRefundInfo;
}
}

$data = [
"OriginalTransactionId" => "2",
"TransactionHistoryId" => 103271487,
"MerchantProfileId" => 12345,
"Amount" => 5545,
"CurrencyCode" => "USD",
"Comment1" => "Refund Comment 1",
"Comment2" => "Refund Comment 2"
];

// Refund a transaction
$protectPayAPI = new ProtectPayApi();
$result = $protectPayAPI->setBillerId('9999986379225246')
->setAuthToken('16dfe8d7-889b-4380-925f-9c2c6ea4d930')
->setTransactionRefundData($data)
->processSettledTransactionRefund()
->getTransactionRefundInfo();

Response Handling

Request Submission

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

import java.io.IOException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.ObjectMapper;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.request.HttpRequest;
import com.mashape.unirest.request.HttpRequestWithBody;

public class RefundTransactionSample {
 /**
* This URL would normally come from some configuration file or database.
*/
 String baseUrl = "https://xmltestapi.propay.com/protectpay";

 public static void main(String[] args) {
configureObjectMapper();

RefundTransactionSample program = new RefundTransactionSample();

RefundTransactionResponse response = program.refundTransaction();

Result requestResult = response.RequestResult;

System.out.println("Result: " + requestResult.ResultValue);
System.out.println("Result code: " + requestResult.ResultCode);
System.out.println("Result message: " + requestResult.ResultMessage);

Transaction transactionDetail = response.Transaction;
if (transactionDetail != null) {
Result transactionResult = transactionDetail.ResultCode;
System.out.println("Transaction Result: " + transactionResult.ResultValue);
System.out.println("Transaction Result code: " + transactionResult.ResultCode);

System.out.println("Transaction History Id: " + transactionDetail.TransactionHistoryId);
System.out.println("Authorization Code: " + transactionDetail.AuthorizationCode);
System.out.println("AVS Code: " + transactionDetail.AvsCode);
System.out.println("Currency Converted Amount: " + transactionDetail.CurrencyConvertedAmount);
System.out.println("Currency Converted Currency Code: " + transactionDetail.CurrencyConvertedCurrencyCode);
System.out.println("Currency Conversion Rate: " + transactionDetail.CurrencyConversionRate);
System.out.println("Gross Amount: " + transactionDetail.GrossAmount);
System.out.println("Gross Amount Less Net Amount: " + transactionDetail.GrossAmountLessNetAmount);
System.out.println("Net Amount: " + transactionDetail.NetAmount);
System.out.println("Per Transaction Fee: " + transactionDetail.PerTransactionFee);
System.out.println("Rate: " + transactionDetail.Rate);
System.out.println("Transaction Id: " + transactionDetail.TransactionId);
System.out.println("Transaction Result: " + transactionDetail.TransactionResult);
}
 }

 /**
* Creates a payment method.
*
* @return The payment method response.
*/
 private RefundTransactionResponse refundTransaction() {

RefundTransactionRequest refundRequest = this.buildRequest();

HttpRequestWithBody request = this.createRequest(baseUrl + "/VoidedTransactions/");

request.body(refundRequest);

return this.executeRequest(request, RefundTransactionResponse.class);
 }

 /**
* Gets the authentication token. This would normally be in a configuration
* file or database.
*
* @return The authentication token.
*/
 private String getAuthToken() {
return "EFA7EEDD-065C-4361-AC24-E13BCC4EF520";
 }

 /**
* Gets the biller's id. This would normally be in a configuration file or
* database.
*
* @return
*/
 private String getBillerId() {
return "9876543210987654";
 }

 /**
* Gets the transaction history id.
*
* This would normally be in a database or generated as a result of an
* earlier call, see ProtectPay API Manual sections "PaymentMethodId
* Processing Authorization Methods" or "PaymentMethodId Processing Capture
* Methods".
*/
 private String getTransactionHistoryId() {
return "11151220";
 }

 /**
* Create the request instance. This ensures that the authentication header
* is attached to each request.
*
* @param resourceUrl
* The URL of the REST resource.
* @return The GetRequest instance.
*/
 private HttpRequestWithBody createRequest(String resourceUrl) {
String authToken = this.getAuthToken();
String billerId = this.getBillerId();

HttpRequestWithBody restRequest = Unirest.put(resourceUrl).basicAuth(billerId, authToken)
.header("accept", "application/json").header("Content-Type", "application/json");

return restRequest;
 }

 /**
* Builds the request data.
*
* @returns The request data.
*/
 private RefundTransactionRequest buildRequest() {
String transactionHistoryId = this.getTransactionHistoryId();

RefundTransactionRequest refundRequest = new RefundTransactionRequest();
refundRequest.TransactionHistoryId = transactionHistoryId;
refundRequest.Comment1 = "Customer return";

return refundRequest;
 }

 /**
* Execute a REST request.
*
* @param request
* The request to perform.
* @param responseClass
* The type instance of the return type.
* @return An instance of type T or null if there was an error.
*/
 private <T> T executeRequest(HttpRequest request, Class<T> responseClass) {
try {
HttpResponse<T> response = request.asObject(responseClass);
if (response.getStatus() != 200) { // HTTP OK response code
System.out.println(response.getStatusText());
return null;
}

return response.getBody();
} catch (UnirestException e) {
e.printStackTrace();
}

return null;
 }

 /**
* Configures the mapping between JSON and Classes.
*
* This is boilerplate Unirest & Jackson configuration. It should only need
* to be done once in a full solution.
*/
 private static void configureObjectMapper() {
Unirest.setObjectMapper(new ObjectMapper() {
private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper = new com.fasterxml.jackson.databind.ObjectMapper();

public <T> T readValue(String value, Class<T> valueType) {
try {
return jacksonObjectMapper.readValue(value, valueType);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public String writeValue(Object value) {
try {
return jacksonObjectMapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
});
 }
}


// -------------------------------------------------------------------------------------------- //
// Object files

// RefundTransactionRequest.java

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

/**
 * A request to void a transaction.
 *
 */
public class RefundTransactionRequest {
 /**
* The transaction history id in the ProPay system.
*/
 public String TransactionHistoryId;

 /**
* Optional comment 1.
*/
 public String Comment1;

 /**
* Optional comment 2
*/
 public String Comment2;
}

// -------------------------------------------------------------------------------------------- //
// Result.java

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

/**
 * The result of the call.
 */
public class Result {
 /**
* The result of the transaction
*
* Will always be SUCCESS or FAILURE
*/
 public String ResultValue;

 /**
* The result code of the transaction
*
*
* Will be a two-digit string with only numbers. Allows "00" as a response.
*/
 public String ResultCode;

 /**
* The English-text message of what went wrong (if anything)
*
*
* The documentation shows the empty string being returned in the success
* cases.
*/
 public String ResultMessage;
}

// -------------------------------------------------------------------------------------------- //
// Transaction.java

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

import java.math.BigDecimal;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Transaction details.
 *
 */
public class Transaction {
 /**
* The transaction history id in the ProPay system.
*/
 public String TransactionHistoryId;

 /**
* The transaction authorization code from the issuing bank.
*/
 public String AuthorizationCode;

 /**
* The address verification system (AVS) code.
*
* Only present if billing information is present on payment method, or in
* the request.
*/
 @JsonProperty("AVSCode")
 public String AvsCode;

 /**
* The card verification value (CVV) response code.
*/
 @JsonProperty("CVVResponseCode")
 public String CvvResponseCode;

 /**
* The amount in the settled currency.
*/
 public int CurrencyConvertedAmount;

 /**
* The settled currency code.
*/
 public String CurrencyConvertedCurrencyCode;

 /**
* The conversion rate from the requested currency to the settled currency.
* e.g. USD to USD = 1, JPY to USD = 0.0090 (as of 5/17/2017)
*/
 public BigDecimal CurrencyConversionRate;

 /**
* The gross amount in the settled currency.
*/
 @JsonProperty("GrossAmt")
 public Integer GrossAmount;

 /**
* The gross amount less net amount in the settled currency.
*/
 @JsonProperty("GrossAmtLessNetAmt")
 public Integer GrossAmountLessNetAmount;

 /**
* The net amount in the settled currency.
*/
 @JsonProperty("NetAmt")
 public Integer NetAmount;

 /**
* The per transaction fee in the settled currency.
*/
 @JsonProperty("PerTransFee")
 public Integer PerTransactionFee;

 /**
* The percentage fee, if any.
*/
 public BigDecimal Rate;

 /**
* Result information from the transaction.
*/
 public Result ResultCode;

 /**
* The transaction number assigned by the processor.
*/
 public String TransactionId;

 /**
* The transaction result as reported by the processor.
*/
 public String TransactionResult;
}


// -------------------------------------------------------------------------------------------- //
// RefundTransactionResponse.java

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

/**
 * The value returned from call to void a transaction.
 *
 */
public class RefundTransactionResponse {
 /**
* The transaction details
*/
 public Transaction Transaction;

 /**
* The result of the request.
*/
 public Result RequestResult;
}

Response Handling

/*
ProPay provides the following code “AS IS.”
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/
package com.propay.protectpay.rest.response;

import com.fasterxml.jackson.annotation.JsonProperty;

/*
 * The value returned from a call to the "GetTempToken" method.
 */
public class GetTempTokenResponse
{
/*
* A temporary token that will be paired with the ProtectPay PayerId used for initiating the payment method management session.
*/
private String TempToken;

/*
* The ProtectPay PayerId authorized for the temporary session.
*/
private String PayerId;

/*
* A unique credential identifier for the resulting temporary token.
*/
private int CredentialId;

/*
* The API Result from the method call.
*/
private Result RequestResult;

/*
* A temporary token that will be paired with the ProtectPay PayerId used for initiating the payment method management session.
*/
@JsonProperty("TempToken")
public String getTempToken() {
return TempToken;
 }

 /**
* @param tempToken the tempToken to set
*/
@JsonProperty("TempToken")
 public void setTempToken(String tempToken) {
TempToken = tempToken;
 }

 /*
* The ProtectPay PayerId authorized for the temporary session.
*/
@JsonProperty("PayerId")
 public String getPayerId() {
return PayerId;
 }

 /**
* @param payerId the payerId to set
*/
@JsonProperty("PayerId")
 public void setPayerId(String payerId) {
PayerId = payerId;
 }

 /*
* A unique credential identifier for the resulting temporary token.
*/
@JsonProperty("CredentialId")
 public int getCredentialId() {
return CredentialId;
 }

 /**
* @param credentialId the credentialId to set
*/
@JsonProperty("CredentialId")
 public void setCredentialId(int credentialId) {
CredentialId = credentialId;
 }

 /*
* The API Result from the method call.
*/
@JsonProperty("RequestResult")
 public Result getRequestResult() {
return RequestResult;
 }

 /**
* @param requestResult the requestResult to set
*/
@JsonProperty("RequestResult")
 public void setRequestResult(Result requestResult) {
RequestResult = requestResult;
 }
}

Request Submission

Response Handling

Request Values

Request Element

Type

Max

Required

Notes

Id.AuthenticationToken

String

100 Characters

Authorization

Valid value is a GUID. Value supplied by ProPay. Used to access the API

Id.BillerAccountId

String

16 Characters

Authorization

Value supplied by ProPay. Used to identify the correct collection of tokens.

Amount

Int(64)

Signed Int(64)

Required

The value representing the number of pennies in USD, or the number of [currency] without decimals.

Comment1

String

128 Characters

Optional

Transaction descriptor. Only passed if supported by the gateway.

Comment2

String

128 Characters

Optional

Transaction descriptor. Only passed if supported by the gateway.

MerchantProfileId

Int(64)

Signed Int(64)

Required

Used to specify which processor and merchant account to process the transaction against.

CurrencyCode

String

3 Characters

Required

ISO 4217 standard 3 character currency code.

TransactionHistoryId

Int(64)

Signed Int(64)

Optional**

ProtectPay transaction identifier for the transaction to refund.

**Do not submit this value if the original transaction was processed externally from ProtectPay

OriginalTransactionId

String

-

Optional**

Gateway transaction identifier for the transaction to refund.

**Required if the original transaction was processed externally from ProtectPay

PaymentMethodId

String

36

Required*

Valid Value is a GUID.

*This value must be passed if the original transaction was processed externally from ProtectPay

**Either the originalTransactionID or the TransactionHistoryId is required. If both are sent, the originalTransactionID is disregarded and the TransactionHistoryId is used

Response Values

Response Element

Type

Notes

RequestResult.ResultValue

 

The ProtectPay API Method Response Value; SUCCESS indicates the method completed;

FAILURE indicates the method call failed and the reason is indicated in the ResultCode and ResultMessage.

RequestResult.ResultCode

String

The ProtectPay API Method Response Code. See ProtectPay Appendix A for possible returned values

RequestResult.ResultMessage

String

The ProtectPay API Method Response Message. See ProtectPay Appendix A for possible returned Messages.

AuthorizationCode

String

Will return null as it is not applicable for Refunds.

AVSCode

String

Will return as Not Present as it is not applicable for Refunds.

CurrencyConversionRate

Decimal

The rate for currency conversion used for multi-currency transactions.

CurrencyConvertedAmount

Long

Gross converted amount of transaction in the number of [currency] without decimals for multi-currency transactions.

CurrencyConvertedCurrencyCode

String

The currency the transaction was converted to for multi-currency transactions.

CVVResponseCode

String

Will not Return as it is not applicable for Refunds.

GrossAmt

Long

Gross amount of transaction of pennies in USD, or the number of [currency] without decimals.

GrossAmtLessNetAmt

Long

Total amount of fees charged; *ProPay Gateway Only.

NetAmt

Long

Net amount of transaction after fees charged; *ProPay Gateway Only.

PerTransFee

Long

Per transaction fee; *ProPay Gateway Only.

Rate

Decimal

Percentage fee; *ProPay Gateway Only.

Transaction.ResultCode.ResultValue

String

The result value of the transaction request as reported by the ProtectPay. SUCCESS or FAILURE.

Transaction.ResultCode.ResultCode

String

The result code of the transaction request as reported by ProtectPay. See ProtectPay Appendix A for possible returned values.

Transaction.ResultCode.ResultMessage

String

The result message of the transaction request as reported by ProtectPay. See ProtectPay Appendix A for possible returned values.

TransactionHistoryId

String

Unique transaction number assigned by ProtectPay.

TransactionId

String

Transaction number assigned by processor (Gateway).

TransactionResult

String

Transaction result as reported by processor (Gateway).

How to call this method?

Example Request

Example Response

Implementation Details
Request Submission

Response Handling

Request Submission

Response Handling

Request Submission

Response Handling

Request Submission

Response Handling

Request Values
Response Values
How to call this method?

{SOAP Action}     RefundTransaction
{URL}                   https://xmltestapi.propay.com/protectpay/sps.svc
Example Request

Example Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:con="http://propay.com/SPS/contracts" xmlns:typ="http://propay.com/SPS/types">
 <soapenv:Header/>
 <soapenv:Body>
<con:RefundTransaction>
<con:id>
<typ:AuthenticationToken>MyAuthToken</typ:AuthenticationToken>
<typ:BillerAccountId>MyBillerId</typ:BillerAccountId>
</con:id>
<con:request>
<typ:Amount>100</typ:Amount>
<typ:Comment1>Comment</typ:Comment1>
<typ:Comment2>Commenta</typ:Comment2>
<typ:CurrencyCode>USD</typ:CurrencyCode>
<typ:MerchantProfileId>123456</typ:MerchantProfileId>
<typ:OriginalTransactionId>11552</typ:OriginalTransactionId>
<typ:PaymentMethodId>dcd234e6-8e5f-4ea7-b468-13eb82191f52</typ:PaymentMethodId>
<typ:TransactionHistoryId>12355545</typ:TransactionHistoryId>
</con:request>
</con:RefundTransaction>
 </soapenv:Body>
</soapenv:Envelope>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Body>
<RefundTransactionResponse xmlns="http://propay.com/SPS/contracts">
<RefundTransactionResult xmlns:a="http://propay.com/SPS/types" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:RequestResult>
<a:ResultCode>00</a:ResultCode>
<a:ResultMessage/>
<a:ResultValue>SUCCESS</a:ResultValue>
</a:RequestResult>
<a:TransactionDetail>
<a:AVSCode>NotPresent</a:AVSCode>
<a:AuthorizationCode i:nil="true"/>
<a:CVVResponseCode>NotPresent</a:CVVResponseCode>
<a:CurrencyConversionRate>0.0000757</a:CurrencyConversionRate>
<a:CurrencyConvertedAmount>189250</a:CurrencyConvertedAmount>
<a:CurrencyConvertedCurrencyCode>USD</a:CurrencyConvertedCurrencyCode>
<a:GrossAmt i:nil="true"/>
<a:GrossAmtLessNetAmt i:nil="true"/>
<a:NetAmt i:nil="true"/>
<a:PerTransFee i:nil="true"/>
<a:Rate i:nil="true"/>
<a:ResultCode>
<a:ResultCode>00</a:ResultCode>
<a:ResultMessage/>
<a:ResultValue>SUCCESS</a:ResultValue>
</a:ResultCode>
<a:TransactionHistoryId>103271488</a:TransactionHistoryId>
<a:TransactionId>3</a:TransactionId>
<a:TransactionResult>Success</a:TransactionResult>
</a:TransactionDetail>
</RefundTransactionResult>
</RefundTransactionResponse>
 </s:Body>
</s:Envelope>
Implementation Details
Request Submission

namespace ProtectPayApi_RefundTransaction
{
using System;
using System.Text;

using RestSharp;

/*
ProPay provides the following code “AS IS.”
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/
public class RefundTransactionProgram
{
public static void Main(string[] args)
{
var refundTransactionResponse = RefundTransaction();
}

/// <summary>
/// Refunds a transaction using the ProtectPay REST API.
/// </summary>
/// <returns>The response data from the refund call.</returns>
private static RefundTransactionResponse RefundTransaction()
{
var baseUrl = "https://xmltestapi.propay.com/ProtectPay";
var request = BuildRefundRequest();
var restRequest = CreateRestRequest("/RefundTransaction/", RestSharp.Method.PUT);
restRequest.AddBody(request);
return Execute<RefundTransactionResponse>(restRequest, baseUrl);
}

/// <summary>
/// Builds the request data.
/// </summary>
/// <returns>The request data.</returns>
private static RefundTransactionRequest BuildRefundRequest()
{
return new RefundTransactionRequest
{
Comment1 = "Comment 1",
Comment2 = "Comment 2",
OriginalTransactionId = "2",
};
}

/// <summary>
/// Request factory to ensure API key is always first parameter added.
/// </summary>
/// <param name="resource">The resource name.</param>
/// <param name="method">The HTTP method.</param>
/// <returns>Returns a new <see cref="RestRequest"/>.</returns>
private static RestRequest CreateRestRequest(string resource, Method method)
{
var restRequest = new RestRequest { Resource = resource, Method = method, RequestFormat = DataFormat.Json, };
var credentials = GetCredentials();
restRequest.AddHeader("accept", "application/json");
restRequest.AddHeader("Authorization", credentials);

return restRequest;
}

private static string GetCredentials()
{
var billerAccountId = "5114248593164903"; // biller account id
var authToken = "9d506d3e-b5f7-4474-adb1-76423e113c85"; // authentication token of biller

var encodedCredentials = Convert.ToBase64String(Encoding.Default.GetBytes(billerAccountId + ":" + authToken));

var credentials = string.Format("Basic {0}", encodedCredentials);
return credentials;
}

/// <summary>
/// Executes a particular http request to a resource.
/// </summary>
/// <typeparam name="T">The response type.</typeparam>
/// <param name="request">The REST request.</param>
/// <param name="baseUrl">The base URL.</param>
/// <returns>Returns a response of the type parameter.</returns>
private static T Execute<T>(IRestRequest request, string baseUrl) where T : class, new()
{
var client = new RestClient(baseUrl);
var response = client.Execute<T>(request);

if (response.ErrorException != null)
{
Console.WriteLine(
"Error: Exception: {0}, Headers: {1}, Content: {2}, Status Code: {3}",
response.ErrorException,
response.Headers,
response.Content,
response.StatusCode);
}

return response.Data;
}


/// <summary>
/// Request information for a call to the "RefundTransaction" method.
/// </summary>
public class RefundTransactionRequest
{
/// <summary>
/// Gets or sets Optional value to designate the amount of the refund (in pennies) - value cannot be negative. 
/// NOTE: If the amount is 0 then the entire transaction will be refunded, otherwise a partial refund will be requested.
/// </summary>
public long Amount { get; set; }

/// <summary>
/// Gets or sets Optional value to attach a comment to the transaction. To be sent to the gateway, if it supports this field.
/// </summary>
public string Comment1 { get; set; }

/// <summary>
/// Gets or sets Optional value to attach a second comment to the transaction. To be sent to the gateway, if it supports this field.
/// </summary>
public string Comment2 { get; set; }

/// <summary>
/// Gets or sets Optional value to designate the merchant profile id that should be used to process this void.
/// </summary>
public string MerchantProfileId { get; set; }

/// <summary>
/// Gets or sets Optional value to designate the transaction id passed back from the gateway. 
/// NOTE: This will NOT be used if the TransactionHistoryId is present (not null and length > 0).
/// </summary>
public string OriginalTransactionId { get; set; }

/// <summary>
/// Gets or sets Optional Value providing the Payment Method Id associated with the transaction. It will be used to retrieve the credit card number for non-ProtectPay transactions.
/// </summary>
public string PaymentMethodId { get; set; }

/// <summary>
/// Gets or sets Optional value to designate the transaction history id passed back from ProtectPay. 
/// NOTE: If this value is populated (not null and length > 0) it will always be used before the OriginalTransactionId.
/// </summary>
public long TransactionHistoryId { get; set; }
}

/// <summary>
/// The value returned from a call to the "RefundTransaction" method.
/// </summary>
public class RefundTransactionResponse
{
/// <summary>
/// The details of transaction information.
/// </summary>
public TransactionInformationDetails TransactionDetail
{
get;
set;
}

/// <summary>
/// Represents the result of the current transaction attempt.
/// </summary>
public Result RequestResult
{
get;
set;
}
}

/// <summary>
/// The details of the transaction information.
/// </summary>
public class TransactionInformationDetails
{
/// <summary>
/// Gets or sets authorization code from the system of record.
/// </summary>
public string AuthorizationCode
{
get;
set;
}

/// <summary>
/// Gets or sets address verification system (AVS) code.
/// </summary>
/// <remarks>
/// Only present if billing information is present on a payment method and.
/// system of record supports AVS.
/// </remarks>
public string AVSCode
{
get;
set;
}

/// <summary>
/// Gets or sets the conversion rate from the requested currency to the settled currency.
/// </summary>
public decimal CurrencyConversionRate
{
get;
set;
}

/// <summary>
/// Gets or sets the amount in the settled currency.
/// </summary>
public long CurrencyConvertedAmount
{
get;
set;
}

/// <summary>
/// Gets or sets the settled currency code.
/// </summary>
public string CurrencyConvertedCurrencyCode
{
get;
set;
}

/// <summary>
/// Gets or sets gross amount in the settled currency.
/// </summary>
public virtual long? GrossAmt
{
get;
set;
}

/// <summary>
/// Gets or sets gross amount less net amount in the settled currency.
/// </summary>
public virtual long? GrossAmtLessNetAmt
{
get;
set;
}
 
/// <summary>
/// Gets or sets net amount in the settled currency.
/// </summary>
public virtual long? NetAmt
{
get;
set;
}

/// <summary>
/// Gets or sets per transaction fee in the settled currency.
/// </summary>
public virtual long? PerTransFee
{
get;
set;
}

/// <summary>
/// Gets or sets rate percentage.
/// </summary>
public virtual decimal? Rate
{
get;
set;
}

/// <summary>
/// Gets or sets specific result information from the transaction.
/// </summary>
public Result ResultCode
{
get;
set;
}

/// <summary>
/// Gets or sets transaction history id in the ProPay system.
/// </summary>
public string TransactionHistoryId
{
get;
set;
}

/// <summary>
/// Gets or sets transaction ID from the system of record.
/// </summary>
public string TransactionId
{
get;
set;
}

/// <summary>
/// <c>Gets or sets result</c> of the transaction.
/// </summary>
public string TransactionResult
{
get;
set;
}
}

/// <summary>
/// The result of the call.
/// </summary>
public class Result
{
/// <summary>
/// The result of the transaction.
/// </summary>
/// <remarks>
/// Will always be SUCCESS or FAILURE.
/// </remarks>
public string ResultValue { get; set; }

/// <summary>
/// The result code of the transaction.
/// </summary>
/// <remarks>
/// Will be a two-digit string with only numbers. Allows "00" as a response.
/// </remarks>
public string ResultCode { get; set; }

/// <summary>
/// The english-text message of what went wrong (if anything).
/// </summary>
/// <remarks>
/// The documentation shows the empty string being returned in the success cases.
/// </remarks>
public string ResultMessage { get; set; }
}
}
}

Response Handling

Request Submission

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

<?php
class ProtectPayApi
{

/* change this to the production url for going live after testing https://api.propay.com */
private $_apiBaseUrl = 'https://xmltestapi.propay.com';

/* credentials that would normally be set from database values or a config value */
private $_billerId;
private $_authToken;

/* for refunding a settled transaction */
private $_transactionRefundData;
private $_transactionRefundInfo;

/**
* @param string $billerId
* @return $this
*/
public function setBillerId($billerId) {
$this->_billerId = $billerId;
return $this;
}

/**
* @param string $authToken
* @return $this
*/
public function setAuthToken($authToken) {
$this->_authToken = $authToken;
return $this;
}

/**
* @return string
*/
private function _getAuth() {
return $this->_billerId . ':' . $this->_authToken;
}

/**
* @return $this
* result is something like ...
* {
* "TransactionDetail":{
* "AVSCode":"NotPresent",
* "AuthorizationCode":null,
* "CurrencyConversionRate":1.0,
* "CurrencyConvertedAmount":100,
* "CurrencyConvertedCurrencyCode":"USD",
* "CVVResponseCode":"NotPresent",
* "GrossAmt ":null,
* "GrossAmtLessNetAmt ":null,
* "NetAmt ":null,
* "PerTransFee ":null,
* "Rate ":null
* "ResultCode":{
* "ResultValue":"SUCCESS",
* "ResultCode":"00",
* "ResultMessage":""
* },
* "TransactionHistoryId":"39560623",
* "TransactionId":"3",
* "TransactionResult":"Success"
* },
* "RequestResult":{
* "ResultValue":"SUCCESS",
* "ResultCode":"00",
* "ResultMessage":""
* }
* }
*/
public function processSettledTransactionRefund() {
$data_string = json_encode($this->_transactionRefundData);
$ch = curl_init($this->_apiBaseUrl . '/ProtectPay/RefundTransaction');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $this->_getAuth());
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string)
));

$this->_transactionRefundInfo = curl_exec($ch);
return $this;

}

/**
* @param array $transactionRefundData
* @return $this
*/
public function setTransactionRefundData($transactionRefundData) {
$this->_transactionRefundData = $transactionRefundData;
return $this;
}

/**
* @return mixed
*/
public function getTransactionRefundInfo() {
return $this->_transactionRefundInfo;
}
}

$data = [
"OriginalTransactionId" => "2",
"TransactionHistoryId" => 103271487,
"MerchantProfileId" => 12345,
"Amount" => 5545,
"CurrencyCode" => "USD",
"Comment1" => "Refund Comment 1",
"Comment2" => "Refund Comment 2"
];

// Refund a transaction
$protectPayAPI = new ProtectPayApi();
$result = $protectPayAPI->setBillerId('9999986379225246')
->setAuthToken('16dfe8d7-889b-4380-925f-9c2c6ea4d930')
->setTransactionRefundData($data)
->processSettledTransactionRefund()
->getTransactionRefundInfo();

Response Handling

Request Submission

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

import java.io.IOException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.ObjectMapper;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.request.HttpRequest;
import com.mashape.unirest.request.HttpRequestWithBody;

public class RefundTransactionSample {
 /**
* This URL would normally come from some configuration file or database.
*/
 String baseUrl = "https://xmltestapi.propay.com/protectpay";

 public static void main(String[] args) {
configureObjectMapper();

RefundTransactionSample program = new RefundTransactionSample();

RefundTransactionResponse response = program.refundTransaction();

Result requestResult = response.RequestResult;

System.out.println("Result: " + requestResult.ResultValue);
System.out.println("Result code: " + requestResult.ResultCode);
System.out.println("Result message: " + requestResult.ResultMessage);

Transaction transactionDetail = response.Transaction;
if (transactionDetail != null) {
Result transactionResult = transactionDetail.ResultCode;
System.out.println("Transaction Result: " + transactionResult.ResultValue);
System.out.println("Transaction Result code: " + transactionResult.ResultCode);

System.out.println("Transaction History Id: " + transactionDetail.TransactionHistoryId);
System.out.println("Authorization Code: " + transactionDetail.AuthorizationCode);
System.out.println("AVS Code: " + transactionDetail.AvsCode);
System.out.println("Currency Converted Amount: " + transactionDetail.CurrencyConvertedAmount);
System.out.println("Currency Converted Currency Code: " + transactionDetail.CurrencyConvertedCurrencyCode);
System.out.println("Currency Conversion Rate: " + transactionDetail.CurrencyConversionRate);
System.out.println("Gross Amount: " + transactionDetail.GrossAmount);
System.out.println("Gross Amount Less Net Amount: " + transactionDetail.GrossAmountLessNetAmount);
System.out.println("Net Amount: " + transactionDetail.NetAmount);
System.out.println("Per Transaction Fee: " + transactionDetail.PerTransactionFee);
System.out.println("Rate: " + transactionDetail.Rate);
System.out.println("Transaction Id: " + transactionDetail.TransactionId);
System.out.println("Transaction Result: " + transactionDetail.TransactionResult);
}
 }

 /**
* Creates a payment method.
*
* @return The payment method response.
*/
 private RefundTransactionResponse refundTransaction() {

RefundTransactionRequest refundRequest = this.buildRequest();

HttpRequestWithBody request = this.createRequest(baseUrl + "/VoidedTransactions/");

request.body(refundRequest);

return this.executeRequest(request, RefundTransactionResponse.class);
 }

 /**
* Gets the authentication token. This would normally be in a configuration
* file or database.
*
* @return The authentication token.
*/
 private String getAuthToken() {
return "EFA7EEDD-065C-4361-AC24-E13BCC4EF520";
 }

 /**
* Gets the biller's id. This would normally be in a configuration file or
* database.
*
* @return
*/
 private String getBillerId() {
return "9876543210987654";
 }

 /**
* Gets the transaction history id.
*
* This would normally be in a database or generated as a result of an
* earlier call, see ProtectPay API Manual sections "PaymentMethodId
* Processing Authorization Methods" or "PaymentMethodId Processing Capture
* Methods".
*/
 private String getTransactionHistoryId() {
return "11151220";
 }

 /**
* Create the request instance. This ensures that the authentication header
* is attached to each request.
*
* @param resourceUrl
* The URL of the REST resource.
* @return The GetRequest instance.
*/
 private HttpRequestWithBody createRequest(String resourceUrl) {
String authToken = this.getAuthToken();
String billerId = this.getBillerId();

HttpRequestWithBody restRequest = Unirest.put(resourceUrl).basicAuth(billerId, authToken)
.header("accept", "application/json").header("Content-Type", "application/json");

return restRequest;
 }

 /**
* Builds the request data.
*
* @returns The request data.
*/
 private RefundTransactionRequest buildRequest() {
String transactionHistoryId = this.getTransactionHistoryId();

RefundTransactionRequest refundRequest = new RefundTransactionRequest();
refundRequest.TransactionHistoryId = transactionHistoryId;
refundRequest.Comment1 = "Customer return";

return refundRequest;
 }

 /**
* Execute a REST request.
*
* @param request
* The request to perform.
* @param responseClass
* The type instance of the return type.
* @return An instance of type T or null if there was an error.
*/
 private <T> T executeRequest(HttpRequest request, Class<T> responseClass) {
try {
HttpResponse<T> response = request.asObject(responseClass);
if (response.getStatus() != 200) { // HTTP OK response code
System.out.println(response.getStatusText());
return null;
}

return response.getBody();
} catch (UnirestException e) {
e.printStackTrace();
}

return null;
 }

 /**
* Configures the mapping between JSON and Classes.
*
* This is boilerplate Unirest & Jackson configuration. It should only need
* to be done once in a full solution.
*/
 private static void configureObjectMapper() {
Unirest.setObjectMapper(new ObjectMapper() {
private com.fasterxml.jackson.databind.ObjectMapper jacksonObjectMapper = new com.fasterxml.jackson.databind.ObjectMapper();

public <T> T readValue(String value, Class<T> valueType) {
try {
return jacksonObjectMapper.readValue(value, valueType);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public String writeValue(Object value) {
try {
return jacksonObjectMapper.writeValueAsString(value);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
}
});
 }
}


// -------------------------------------------------------------------------------------------- //
// Object files

// RefundTransactionRequest.java

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

/**
 * A request to void a transaction.
 *
 */
public class RefundTransactionRequest {
 /**
* The transaction history id in the ProPay system.
*/
 public String TransactionHistoryId;

 /**
* Optional comment 1.
*/
 public String Comment1;

 /**
* Optional comment 2
*/
 public String Comment2;
}

// -------------------------------------------------------------------------------------------- //
// Result.java

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

/**
 * The result of the call.
 */
public class Result {
 /**
* The result of the transaction
*
* Will always be SUCCESS or FAILURE
*/
 public String ResultValue;

 /**
* The result code of the transaction
*
*
* Will be a two-digit string with only numbers. Allows "00" as a response.
*/
 public String ResultCode;

 /**
* The English-text message of what went wrong (if anything)
*
*
* The documentation shows the empty string being returned in the success
* cases.
*/
 public String ResultMessage;
}

// -------------------------------------------------------------------------------------------- //
// Transaction.java

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

import java.math.BigDecimal;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * Transaction details.
 *
 */
public class Transaction {
 /**
* The transaction history id in the ProPay system.
*/
 public String TransactionHistoryId;

 /**
* The transaction authorization code from the issuing bank.
*/
 public String AuthorizationCode;

 /**
* The address verification system (AVS) code.
*
* Only present if billing information is present on payment method, or in
* the request.
*/
 @JsonProperty("AVSCode")
 public String AvsCode;

 /**
* The card verification value (CVV) response code.
*/
 @JsonProperty("CVVResponseCode")
 public String CvvResponseCode;

 /**
* The amount in the settled currency.
*/
 public int CurrencyConvertedAmount;

 /**
* The settled currency code.
*/
 public String CurrencyConvertedCurrencyCode;

 /**
* The conversion rate from the requested currency to the settled currency.
* e.g. USD to USD = 1, JPY to USD = 0.0090 (as of 5/17/2017)
*/
 public BigDecimal CurrencyConversionRate;

 /**
* The gross amount in the settled currency.
*/
 @JsonProperty("GrossAmt")
 public Integer GrossAmount;

 /**
* The gross amount less net amount in the settled currency.
*/
 @JsonProperty("GrossAmtLessNetAmt")
 public Integer GrossAmountLessNetAmount;

 /**
* The net amount in the settled currency.
*/
 @JsonProperty("NetAmt")
 public Integer NetAmount;

 /**
* The per transaction fee in the settled currency.
*/
 @JsonProperty("PerTransFee")
 public Integer PerTransactionFee;

 /**
* The percentage fee, if any.
*/
 public BigDecimal Rate;

 /**
* Result information from the transaction.
*/
 public Result ResultCode;

 /**
* The transaction number assigned by the processor.
*/
 public String TransactionId;

 /**
* The transaction result as reported by the processor.
*/
 public String TransactionResult;
}


// -------------------------------------------------------------------------------------------- //
// RefundTransactionResponse.java

/*
ProPay provides the following code "AS IS."
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/

/**
 * The value returned from call to void a transaction.
 *
 */
public class RefundTransactionResponse {
 /**
* The transaction details
*/
 public Transaction Transaction;

 /**
* The result of the request.
*/
 public Result RequestResult;
}

Response Handling

/*
ProPay provides the following code “AS IS.”
ProPay makes no warranties and ProPay disclaims all warranties and conditions, express, implied or statutory,
including without limitation the implied warranties of title, non-infringement, merchantability, and fitness for a particular purpose.
ProPay does not warrant that the code will be uninterrupted or error free,
nor does ProPay make any warranty as to the performance or any results that may be obtained by use of the code.
*/
package com.propay.protectpay.rest.response;

import com.fasterxml.jackson.annotation.JsonProperty;

/*
 * The value returned from a call to the "GetTempToken" method.
 */
public class GetTempTokenResponse
{
/*
* A temporary token that will be paired with the ProtectPay PayerId used for initiating the payment method management session.
*/
private String TempToken;

/*
* The ProtectPay PayerId authorized for the temporary session.
*/
private String PayerId;

/*
* A unique credential identifier for the resulting temporary token.
*/
private int CredentialId;

/*
* The API Result from the method call.
*/
private Result RequestResult;

/*
* A temporary token that will be paired with the ProtectPay PayerId used for initiating the payment method management session.
*/
@JsonProperty("TempToken")
public String getTempToken() {
return TempToken;
 }

 /**
* @param tempToken the tempToken to set
*/
@JsonProperty("TempToken")
 public void setTempToken(String tempToken) {
TempToken = tempToken;
 }

 /*
* The ProtectPay PayerId authorized for the temporary session.
*/
@JsonProperty("PayerId")
 public String getPayerId() {
return PayerId;
 }

 /**
* @param payerId the payerId to set
*/
@JsonProperty("PayerId")
 public void setPayerId(String payerId) {
PayerId = payerId;
 }

 /*
* A unique credential identifier for the resulting temporary token.
*/
@JsonProperty("CredentialId")
 public int getCredentialId() {
return CredentialId;
 }

 /**
* @param credentialId the credentialId to set
*/
@JsonProperty("CredentialId")
 public void setCredentialId(int credentialId) {
CredentialId = credentialId;
 }

 /*
* The API Result from the method call.
*/
@JsonProperty("RequestResult")
 public Result getRequestResult() {
return RequestResult;
 }

 /**
* @param requestResult the requestResult to set
*/
@JsonProperty("RequestResult")
 public void setRequestResult(Result requestResult) {
RequestResult = requestResult;
 }
}

Request Submission

Response Handling

Request Values

Request Element

Type

Max

Required

Notes

Id.AuthenticationToken

String

100 Characters

Authorization

Valid value is a GUID. Value supplied by ProPay. Used to access the API

Id.BillerAccountId

String

16 Characters

Authorization

Value supplied by ProPay. Used to identify the correct collection of tokens.

Amount

Int(64)

Signed Int(64)

Required

The value representing the number of pennies in USD, or the number of [currency] without decimals.

Comment1

String

128 Characters

Optional

Transaction descriptor. Only passed if supported by the gateway.

Comment2

String

128 Characters

Optional

Transaction descriptor. Only passed if supported by the gateway.

MerchantProfileId

Int(64)

Signed Int(64)

Required

Used to specify which processor and merchant account to process the transaction against.

CurrencyCode

String

3 Characters

Required

ISO 4217 standard 3 character currency code.

TransactionHistoryId

Int(64)

Signed Int(64)

Optional**

ProtectPay transaction identifier for the transaction to refund.

**Do not submit this value if the original transaction was processed externally from ProtectPay

OriginalTransactionId

String

-

Optional**

Gateway transaction identifier for the transaction to refund.

**Required if the original transaction was processed externally from ProtectPay

PaymentMethodId

String

36

Required*

Valid Value is a GUID.

*This value must be passed if the original transaction was processed externally from ProtectPay

**Either the originalTransactionID or the TransactionHistoryId is required. If both are sent, the originalTransactionID is disregarded and the TransactionHistoryId is used.

Response Values

Response Element

Type

Notes

RequestResult.ResultValue

 

The ProtectPay API Method Response Value; SUCCESS indicates the method completed;

FAILURE indicates the method call failed and the reason is indicated in the ResultCode and ResultMessage.

RequestResult.ResultCode

String

The ProtectPay API Method Response Code. See Appendix for possible returned values

RequestResult.ResultMessage

String

The ProtectPay API Method Response Message. See Appendix for possible returned Messages.

AuthorizationCode

String

Will return null as it is not applicable for Refunds.

AVSCode

String

Will return as Not Present as it is not applicable for Refunds.

CurrencyConversionRate

Decimal

The rate for currency conversion used for multi-currency transactions.

CurrencyConvertedAmount

Long

Gross converted amount of transaction in the number of [currency] without decimals for multi-currency transactions.

CurrencyConvertedCurrencyCode

String

The currency the transaction was converted to for multi-currency transactions.

CVVResponseCode

String

Will not Return as it is not applicable for Refunds.

GrossAmt

Long

Gross amount of transaction of pennies in USD, or the number of [currency] without decimals.

GrossAmtLessNetAmt

Long

Total amount of fees charged; *ProPay Gateway Only.

NetAmt

Long

Net amount of transaction after fees charged; *ProPay Gateway Only.

PerTransFee

Long

Per transaction fee; *ProPay Gateway Only.

Rate

Decimal

Percentage fee; *ProPay Gateway Only.

Transaction.ResultCode.ResultValue

String

The result value of the transaction request as reported by the ProtectPay. SUCCESS or FAILURE.

Transaction.ResultCode.ResultCode

String

The result code of the transaction request as reported by ProtectPay. See Appendix for possible returned values.

Transaction.ResultCode.ResultMessage

String

The result message of the transaction request as reported by ProtectPay. See Appendix for possible returned values.

TransactionHistoryId

String

Unique transaction number assigned by ProtectPay.

TransactionId

String

Transaction number assigned by processor (Gateway).

TransactionResult

String

Transaction result as reported by processor (Gateway).