/*
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.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator.Feature;
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 AccountPingTransactionXmlSample {
final static String ApiUrl = "https://xmltest.propay.com/API/PropayAPI.aspx";
public static void main(String[] args) {
configureObjectMapper();
AccountPingTransactionXmlSample program = new AccountPingTransactionXmlSample();
TransactionRequest transactionRequest = program.getRequest();
AccountPingTransactionRequest transaction = program.getAccountPingTransactionRequest();
transactionRequest.getTransactions().add(transaction);
AccountPingResponse response = program.sendRequest(transactionRequest);
System.out.println("Response:");
AccountPingTransactionResponse transactionResponse = response.getTransactions().get(0);
System.out.println("Transaction type: " + transactionResponse.TransType);
System.out.println("Status: " + transactionResponse.Status);
System.out.println("Account Number: " + transactionResponse.AccountNumber);
System.out.println("Affiliation: " + transactionResponse.AffiliationName);
System.out.println("Tier: " + transactionResponse.TierName);
System.out.println("Signup date: " + transactionResponse.SignupDate);
System.out.println("Expiration date: " + transactionResponse.ExpirationDate);
System.out.println("Account status: " + transactionResponse.AccountStatus);
System.out.println("Street address: " + transactionResponse.StreetAddress);
System.out.println("City: " + transactionResponse.City);
System.out.println("State: " + transactionResponse.State);
System.out.println("Zip: " + transactionResponse.Zip);
System.out.println("API Ready? " + transactionResponse.ApiReady);
System.out.println("Currency code: " + transactionResponse.CurrencyCode);
System.out.println("Credit card per transaction limit:" + transactionResponse.CreditCardTransactionLimit);
System.out.println("Credit card monthly limit: " + transactionResponse.CreditCardMonthLimit);
System.out.println("Credit card monthly volume: " + transactionResponse.CreditCardMonthlyVolume);
System.out.println("ACH per transaction limit: " + transactionResponse.ACHPaymentPerTranLimit);
System.out.println("ACH monthly limit: " + transactionResponse.ACHPaymentMonthLimit);
System.out.println("ACH monthly volume: " + transactionResponse.ACHPaymentMonthlyVolume);
System.out.println("Reserve balance: " + transactionResponse.ReserveBalance);
}
/**
* Get the affiliate credential id. This would normally be in a
* configuration file or database.
*/
private String getCertString() {
return "TiAuNrNwEjRnScCaE9RcTcS7ReI9NG";
}
/**
* Get the request container, setting up the authentication.
*
* @return The request container.
*/
private TransactionRequest getRequest() {
String certString = getCertString();
TransactionRequest transactionRequest = new TransactionRequest();
transactionRequest.CertificationString = certString;
transactionRequest.TerminalId = "ReI9NG";
return transactionRequest;
}
/**
* Get the transaction details, how much to refund, on which transaction.
*
*/
private AccountPingTransactionRequest getAccountPingTransactionRequest() {
AccountPingTransactionRequest transaction = new AccountPingTransactionRequest();
transaction.AccountNumber = "30829192";
return transaction;
}
/**
* Send the refund transaction request.
*
* @param transactionRequest
* The transaction request.
* @return The transaction response.
*/
private AccountPingResponse sendRequest(TransactionRequest transactionRequest) {
HttpRequestWithBody request = this.createRequest(ApiUrl);
request.body(transactionRequest);
AccountPingResponse response = this.executeRequest(request, AccountPingResponse.class);
return response;
}
/**
* Create the request instance. This ensures that the correct content type
* and accept headers are attached to each request.
*
* @param resourceUrl
* The URL of the resource.
* @return The request instance.
*/
public HttpRequestWithBody createRequest(String resourceUrl) {
HttpRequestWithBody request = Unirest.post(resourceUrl).header("accept", "text/xml").header("Content-Type",
"text/xml");
return request;
}
/**
* Execute a 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.
*/
public <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 XML 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 XmlMapper()
.configure(Feature.WRITE_XML_DECLARATION, true);
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
// 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 com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@JacksonXmlRootElement(localName = "XMLTrans")
public class Transaction {
@JacksonXmlProperty(localName = "transType")
public String TransType;
}
// -------------------------------------------------------------------------------------------- //
// TransactionRequest.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.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@JacksonXmlRootElement(localName = "XMLRequest")
public class TransactionRequest {
@JacksonXmlProperty(localName = "certStr")
public String CertificationString;
@JacksonXmlProperty(localName = "class")
public final String ClassType = "partner";
/**
* Omit unless specifically instructed by ProPay, Used to access the API
*/
@JacksonXmlProperty(localName = "termid")
public String TerminalId;
@JacksonXmlProperty(localName = "XMLTrans")
@JacksonXmlElementWrapper(useWrapping = false)
private List<Transaction> Transactions;
public TransactionRequest() {
this.Transactions = new ArrayList<Transaction>();
}
/**
* @return the transactions
*/
@JacksonXmlProperty(localName = "XMLTrans")
@JacksonXmlElementWrapper(useWrapping = false)
public List<Transaction> getTransactions() {
return this.Transactions;
}
}
// -------------------------------------------------------------------------------------------- //
// AccountPingTransactionRequest.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 com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
public class AccountPingTransactionRequest extends Transaction {
/**
* The account number for the account to lookup.
*
* One of accountNumber, sourceEmail or externalId is required.
*/
@JacksonXmlProperty(localName = "accountNum")
public String AccountNumber;
/**
* The merchant's email address.
*
* One of accountNumber, sourceEmail or externalId is required.
*/
@JacksonXmlProperty(localName = "sourceEmail")
public String SourceEmail;
/**
* A client specific unique identifier.
*
* One of accountNumber, sourceEmail or externalId is required.
*/
@JacksonXmlProperty(localName = "externalId")
public String ExternalId;
public AccountPingTransactionRequest() {
this.TransType = "13";
}
}
// -------------------------------------------------------------------------------------------- //
// AccountPingTransactionResponse.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 com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
public class AccountPingTransactionResponse extends Transaction {
@JacksonXmlProperty(localName = "status")
public String Status;
@JacksonXmlProperty(localName = "accountNum")
public String AccountNumber;
@JacksonXmlProperty(localName = "tier")
public String TierName;
@JacksonXmlProperty(localName = "expiration")
public String ExpirationDate;
@JacksonXmlProperty(localName = "signupDate")
public String SignupDate;
@JacksonXmlProperty(localName = "affiliation")
public String AffiliationName;
@JacksonXmlProperty(localName = "accntStatus")
public String AccountStatus;
@JacksonXmlProperty(localName = "addr")
public String StreetAddress;
@JacksonXmlProperty(localName = "city")
public String City;
@JacksonXmlProperty(localName = "state")
public String State;
@JacksonXmlProperty(localName = "zip")
public String Zip;
@JacksonXmlProperty(localName = "apiReady")
public String ApiReady;
@JacksonXmlProperty(localName = "currencyCode")
public String CurrencyCode;
public String CreditCardTransactionLimit;
public String CreditCardMonthLimit;
public String ACHPaymentPerTranLimit;
public String ACHPaymentMonthLimit;
public String CreditCardMonthlyVolume;
public String ACHPaymentMonthlyVolume;
public String ReserveBalance;
}
// -------------------------------------------------------------------------------------------- //
// AccountPingResponse.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.util.List;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
@JacksonXmlRootElement(localName = "XMLResponse")
public class AccountPingResponse {
@JacksonXmlProperty(localName = "XMLTrans")
@JacksonXmlElementWrapper(useWrapping = false)
private List<AccountPingTransactionResponse> transactions;
/**
* @return the transactions
*/
public List<AccountPingTransactionResponse> getTransactions() {
return transactions;
}
}