/**
* 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 java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
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 MerchantSignupSample {
/**
* This URL would normally come from some configuration file or database.
*/
final static String ApiUrl = "https://xmltestapi.propay.com/propayapi/";
public static void main(String[] args) {
configureObjectMapper();
MerchantSignupSample program = new MerchantSignupSample();
SignupResponse response = program.signup();
System.out.println("Signup Status:" + response.Status);
System.out.println("Source email: " + response.SourceEmail);
System.out.println("Tier id: " + response.Tier);
System.out.println("Account number: " + response.AccountNumber);
System.out.println("Generated password: " + response.Password);
}
/**
* Execute a signup.
*
* @return The signup response.
*/
public SignupResponse signup() {
String resourceUrl = ApiUrl + "Signup";
SignupRequest signupRequest = new SignupRequest();
SignupAccountData accountData = this.getSignupAccountData();
Address physicalAddress = this.getPhysicalAddress();
Address mailingAddress = this.getMailingAddress();
Address businessAddress = this.getBusinessAddress();
BankAccount primaryBankAccount = this.getPrimaryBankAccount();
BankAccount secondaryBankAccount = this.getSecondaryBankAccount();
BusinessData businessData = this.getMerchantBusinessData();
PersonalData personalData = this.getPersonalData();
signupRequest.SignupAccountData = accountData;
signupRequest.Address = physicalAddress;
signupRequest.MailAddress = mailingAddress;
signupRequest.BusinessAddress = businessAddress;
signupRequest.BankAccount = primaryBankAccount;
signupRequest.SecondaryBankAccount = secondaryBankAccount;
signupRequest.BusinessData = businessData;
signupRequest.PersonalData = personalData;
CreditCardData creditCard = new CreditCardData();
creditCard.NameOnCard = "Chris Cornell";
creditCard.CreditCardNumber = "4111111111111111";
creditCard.ExpirationDate = this.generateExpirationDate();
signupRequest.CreditCardData = creditCard;
HttpRequestWithBody request = this.createRequest(resourceUrl);
request.body(signupRequest);
return this.executeRequest(request, SignupResponse.class);
}
/**
* The affiliate certificate string.
*
* Normally this would be in a database or configuration file.
*/
private String getCertString() {
return "P1r305Pc4fy6S942m0p0la3c";
}
/**
* Populate the user's basic account data.
*/
private SignupAccountData getSignupAccountData() {
String tierName = "Premium";
SignupAccountData accountData = new SignupAccountData();
accountData.ExternalId = "246820";
accountData.Tier = tierName;
accountData.CurrencyCode = "USD";
accountData.PhonePIN = "1111";
return accountData;
}
/**
* Populate the user's mailing address.
*/
private Address getMailingAddress() {
Address address = new Address();
address.Address1 = "101 Box St";
address.City = "Lehi";
address.State = "UT";
address.Country = "USA";
address.Zip = "84043";
return address;
}
/**
* Populate the user's physical address.
*/
private Address getPhysicalAddress() {
Address address = new Address();
address.Address1 = "123 Main St";
address.Address2 = "Suite 5000";
address.ApartmentNumber = "1";
address.City = "Lehi";
address.State = "UT";
address.Country = "USA";
address.Zip = "84043";
return address;
}
/**
* Populate the user's business address.
*/
private Address getBusinessAddress() {
Address address = new Address();
address.Address1 = "Business Address";
address.Address2 = "NW";
address.ApartmentNumber = "333";
address.City = "Lehi";
address.State = "UT";
address.Country = "USA";
address.Zip = "84043";
return address;
}
/**
* Populate the merchant's primary bank account.
*/
private BankAccount getPrimaryBankAccount() {
BankAccount bankAccount = new BankAccount();
bankAccount.AccountCountryCode = "USA";
bankAccount.AccountType = "Checking";
bankAccount.AccountOwnershipType = "Business";
bankAccount.BankAccountNumber = "123456789";
bankAccount.BankName = "CITIZENS BANK NA";
bankAccount.RoutingNumber = "011306829";
return bankAccount;
}
/**
* Populate the merchant's secondary bank account.
*/
private BankAccount getSecondaryBankAccount() {
BankAccount bankAccount = new BankAccount();
bankAccount.AccountCountryCode = "USA";
bankAccount.AccountType = "Checking";
bankAccount.AccountOwnershipType = "Business";
bankAccount.BankAccountNumber = "987654321";
bankAccount.BankName = "CITIZENS BANK NA";
bankAccount.RoutingNumber = "011306829";
return bankAccount;
}
/**
* Populate the merchant's business information.
*/
private BusinessData getMerchantBusinessData() {
BusinessData businessData = new BusinessData();
businessData.BusinessLegalName = "ProPay Merchant";
businessData.DoingBusinessAs = "Merchant Business";
return businessData;
}
/**
* Get the merchant's personal information
*/
private PersonalData getPersonalData() {
String birthdate = generateBirthDate();
PersonalData personalData = new PersonalData();
personalData.DateOfBirth = birthdate;
personalData.SourceEmail = "merchant90@test.com";
personalData.SocialSecurityNumber = "987654321";
personalData.FirstName = "First";
personalData.MiddleInitial = "M";
personalData.LastName = "Last";
PhoneInformation phoneInfo = new PhoneInformation();
phoneInfo.DayPhone = "8015551212";
phoneInfo.EveningPhone = "8015551212";
personalData.PhoneInformation = phoneInfo;
return personalData;
}
/**
* 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 certString = this.getCertString();
HttpRequestWithBody restRequest = Unirest.put(resourceUrl).basicAuth(certString, null)
.header("accept", "application/json").header("Content-Type", "application/json");
return restRequest;
}
/**
* 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;
}
/**
* Generate an expiration date that is always valid.
*/
private String generateExpirationDate() {
Date currentDate = new Date();
Calendar c = Calendar.getInstance();
c.setTime(currentDate);
c.add(Calendar.YEAR, 1);
Date expirationDate = c.getTime();
DateFormat format = new SimpleDateFormat("MMyy");
return format.format(expirationDate);
}
/**
* Generate a birth date for a 30 year old man.
*/
private String generateBirthDate() {
Date currentDate = new Date();
Calendar c = Calendar.getInstance();
c.setTime(currentDate);
c.add(Calendar.YEAR, -30);
Date birthDate = c.getTime();
DateFormat format = new SimpleDateFormat("MM-dd-yyyy");
String birthdate = format.format(birthDate);
return birthdate;
}
/**
* 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
// Address.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.
*/
/**
* Address contract.
*/
public class Address {
/**
* Gets or sets the ApartmentNumber.
*/
public String ApartmentNumber;
/**
* Gets or sets the Address1.
*/
public String Address1;
/**
* Gets or sets the Address2.
*/
public String Address2;
/**
* Gets or sets the City.
*/
public String City;
/**
* Gets or sets the State.
*/
public String State;
/**
* Gets or sets the Country.
*/
public String Country;
/**
* Gets or sets the Zip.
*/
public String Zip;
}
// -------------------------------------------------------------------------------------------- //
// BankAccount.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.
*/
/**
* Bank account contact.
*/
public class BankAccount {
/**
* Gets or sets the AccountCountryCode.
*/
public String AccountCountryCode;
/**
* Gets or sets the BankAccountNumber.
*/
public String BankAccountNumber;
/**
* Gets or sets the RoutingNumber.
*/
public String RoutingNumber;
/**
* Gets or sets the AccountOwnershipType.
*/
public String AccountOwnershipType;
/**
* Gets or sets the BankName.
*/
public String BankName;
/**
* Gets or sets the AccountType.
*/
public String AccountType;
/**
* Gets or sets the Account Name.
*/
public String AccountName;
/**
* Gets or sets the Description.
*/
public String Description;
}
// -------------------------------------------------------------------------------------------- //
// BusinessData.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.
*/
/**
* Class to represent the Business Data.
*/
public class BusinessData {
/**
* Gets or sets the BusinessLegalName.
*/
public String BusinessLegalName;
/**
* Gets or sets the DoingBusinessAs.
*/
public String DoingBusinessAs;
/**
* Gets or sets the EIN.
*/
public String EIN;
/**
* Gets or sets the Merchant Category Code.
*/
public String MerchantCategoryCode;
/**
* Gets or sets the website url.
*/
public String WebsiteURL;
/**
* Gets or sets the Business Description.
*/
public String BusinessDescription;
/**
* Gets or sets the Monthly Card Volume.
*/
public long MonthlyBankCardVolume;
/**
* Gets or sets the Average Ticket size.
*/
public int AverageTicket;
/**
* Gets or sets the Highest Ticket Size.
*/
public int HighestTicket;
}
// -------------------------------------------------------------------------------------------- //
// CreditCardData.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.
*/
/**
* Class for Credit Card Data.
*/
public class CreditCardData {
/**
* Gets or sets the Name on the credit card.
*/
public String NameOnCard;
/**
* Gets or sets the CreditCardNumber.
*/
public String CreditCardNumber;
/**
* Gets or sets the ExpirationDate.
*/
public String ExpirationDate;
}
// -------------------------------------------------------------------------------------------- //
// PersonalData.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.
*/
/**
* Class for personal data like name, DOB.
*/
public class PersonalData {
/**
* Gets or sets the SourceEmail.
*/
public String SourceEmail;
/**
* Gets or sets the FirstName.
*/
public String FirstName;
/**
* Gets or sets the MiddleInitial.
*/
public String MiddleInitial;
/**
* Gets or sets the LastName.
*/
public String LastName;
/**
* Gets or sets the Date of Birth (MM-DD-YYYY).
*/
public String DateOfBirth;
/**
* Gets or sets the SocialSecurityNumber.
*/
public String SocialSecurityNumber;
/**
* Gets or sets the Phone Information.
*/
public PhoneInformation PhoneInformation;
}
// -------------------------------------------------------------------------------------------- //
// PhoneInformation.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.
*/
/**
* Class to collect the Phone Data.
*/
public class PhoneInformation {
/**
* Gets or sets the DayPhone.
*/
public String DayPhone;
/**
* Gets or sets the EveningPhone.
*/
public String EveningPhone;
}
// -------------------------------------------------------------------------------------------- //
// SignupAccountData.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.
*/
/**
* Attributes for the Account.
*/
public class SignupAccountData {
/**
* Gets or sets the CurrencyCode.
*/
public String CurrencyCode;
/**
* Gets or sets the UserId.
*/
public String UserId;
/**
* Gets or sets the PhonePIN.
*/
public String PhonePIN;
/**
* Gets or sets the ExternalId.
*/
public String ExternalId;
/**
* Gets or sets the Tier.
*/
public String Tier;
}
// -------------------------------------------------------------------------------------------- //
// SignupRequest.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.
*/
/**
* Defines request body of a signup request.
*/
public class SignupRequest {
/**
* The Personal Data.
*/
public PersonalData PersonalData;
/**
* Gets or sets the Account Data.
*/
public SignupAccountData SignupAccountData;
/**
* Gets or sets the Business Data.
*/
public BusinessData BusinessData;
/**
* Gets or sets the Credit Card Information.
*/
public CreditCardData CreditCardData;
/**
* Gets or sets the Address.
*/
public Address Address;
/**
* Gets or sets the MailAddress.
*/
public Address MailAddress;
/**
* Gets or sets the BusinessAddress.
*/
public Address BusinessAddress;
/**
* Gets or sets the BankAccount.
*/
public BankAccount BankAccount;
/**
* Gets or sets the SecondaryBankAccount.
*/
public BankAccount SecondaryBankAccount;
/**
* Gets or sets the PaymentMethodId.
*/
public String PaymentMethodId;
}
// -------------------------------------------------------------------------------------------- //
// SignupResponse.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.
*/
/**
* Defines response body of a signup request.
*/
public class SignupResponse {
/**
* Gets or sets the ProPay account number.
*/
public long AccountNumber;
/**
* Gets or sets the email address.
*/
public String SourceEmail;
/**
* Gets or sets the account password.
*/
public String Password;
/**
* Gets or sets the tier name.
*/
public String Tier;
/**
* Gets or sets the response status.
*/
public String Status;
}