Hosted Payment Page – Create a Payer

Merchants must create a PayerId for each of their customers. Organizing each PaymentMethodId (tokenized card number) by payer allows a merchant to make a subset of cards available to his or her customer upon login. (Consider the example that occurs when you log in to the website of a pizza parlor and it remembers more than one of your credit cards. The Pizza joint queries your "Payer" to get back a list of cards.) Not all merchants use ProtectPay® to organize their tokens, and in fact most use their own system to map tokens to users. ProtectPay, however, requires this field to proceed.

Payer ID Naming Convention Differs by ProtectPay® Method
Various ProtectPay® methods refer to the Payer ID as either PayerId or PayerAccountId. This method, to get a Payer ID, returns it as ExternalAccountId.
How to call this method?

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

Example Response

{
 "Name":"Payer name",
 "EmailAddress":"email address",
 "ExternalId1":"external id 1",
 "ExternalId2":"external id 2"
}

{
 "ExternalAccountID":"8437354423471480",
 "RequestResult":
 {
"ResultValue":"SUCCESS",
"ResultCode":"00",
"ResultMessage":""
 }
}

Implementation Details
Request Submission

namespace ProtectPayApi_CreatePayer
{
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 CreatePayerProgram
{
public static void Main(string[] args)
{
var createPayerResponse = CreatePayer();
}

private static CreateAccountInformationResult CreatePayer()
{
var baseUrl = "https://xmltestapi.propay.com/ProtectPay";
var request = BuildCreatePayerRequest();
var restRequest = CreateRestRequest("/Payers/", RestSharp.Method.PUT);
restRequest.AddBody(request);
return Execute<CreateAccountInformationResult>(restRequest, baseUrl);
}

/// <summary>
/// Builds the request data.
/// </summary>
/// <returns>The request data.</returns>
private static CreatePayerRequest BuildCreatePayerRequest()
{
return new CreatePayerRequest
{
EmailAddress = "email address",
ExternalId1 = "external id 1",
ExternalId2 = "external id 2",
Name = "Payer name",
};
}

/// <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;
}

/// <summary>
/// Gets the credentials for the call.
/// </summary>
/// <returns>The credentials.</returns>
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 data for the create payer call.
/// </summary>
public class CreatePayerRequest
{
/// <summary>
/// The Name of the payer
/// </summary>
public string Name { get; set; }

/// <summary>
/// The email address of the payer
/// </summary>
public string EmailAddress { get; set; }

/// <summary>
/// The first Id for the payer, configurable by an outside system
/// </summary>
public string ExternalId1 { get; set; }

/// <summary>
/// The second Id for the payer, configurable by an outside system
/// </summary>
public string ExternalId2 { get; set; }
}

public class CreateAccountInformationResult
{
/// <summary>
/// The new payer external account ID
/// </summary>
public string ExternalAccountID { get; set; }

/// <summary>
/// The result of the create account request
/// </summary>
public Result RequestResult { 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 documenation show 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 creating payer ID */
private $_createPayerIdData;
private $_createPayerIdInfo;

/**
* @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;
}

/**
* @param array $payerIdData
* @return $this
*/
public function setCreatePayerIdData($payerIdData) {
$this->_createPayerIdData = $payerIdData;
return $this;
}

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

/**
* Creates a payer id
* @return $this
*/
public function createPayerId() {
$data_string = json_encode($this->_createPayerIdData);

$ch = curl_init($this->_apiBaseUrl . '/ProtectPay/Payers');
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->_createPayerIdInfo = curl_exec($ch);
return $this;
}
}

$data = [
"Name" => "John Smith",
"EmailAddress" => "email@email.com",
"ExternalId1" => "CustomerNumber12",
"ExternalId2" => "234567"
];

// Create a new payer
$protectPayAPI = new ProtectPayApi();
$result = $protectPayAPI->setBillerId('9999986379225246')
->setAuthToken('16dfe8d7-889b-4380-925f-9c2c6ea4d930')
->setCreatePayerIdData($data)
->createPayerId()
->getCreatePayerIdInfo();

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 CreatePayerSample {
 /**
* 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();

CreatePayerSample program = new CreatePayerSample();

CreatePayerResponse response = program.createPayer();

System.out.println("Result: " + response.RequestResult.ResultValue);
System.out.println("Result code: " + response.RequestResult.ResultCode);
System.out.println("Result message: " + response.RequestResult.ResultMessage);
System.out.println("Payer account id: " + response.ExternalAccountID);
 }

 public CreatePayerResponse createPayer() {
String resourceUrl = baseUrl + "Payers";

HttpRequestWithBody request = this.createRequest(resourceUrl);

CreatePayerRequest payer = this.buildRequest();

request.body(payer);

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

 private CreatePayerRequest buildRequest() {
CreatePayerRequest payer = new CreatePayerRequest();
payer.Name = "John Travolta";
payer.EmailAddress = "saturday@nightfever.com";
payer.ExternalId1 = "Distributer 2";
payer.ExternalId2 = "Rep 35";

return payer;
 }

 /**
* 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.
*
*/
 private String getBillerId() {
return "9876543210987654";
 }

 /**
* 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;
 }

 /**
* 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

// CreatePayerRequest.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 create a ProtectPay payer, i.e. someone who is going to securely
 * pay for a product/service.
 */
public class CreatePayerRequest {

 /**
* A name to identify the payer.
*/
 public String Name;

 /**
* The payer's email address if supplied.
*/
 public String EmailAddress;

 /**
* Customer specific identifier.
*/
 public String ExternalId1;

 /**
* Customer specific identifier.
*/
 public String ExternalId2;
}


// -------------------------------------------------------------------------------------------- //
// 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;
}


// -------------------------------------------------------------------------------------------- //
// CreatePayerResponse.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 response to a create payer request.
 */
public class CreatePayerResponse {

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

 /**
* The ProtectPay ID for the created payer.
*
* Note: This is referenced in other methods as 'PayerAccountId' or
* 'PayerId'.
*/
 public String ExternalAccountID;
}

Response Handling

The following sample uses the Unirest and Jackson libraries.

You can add them to your project using:

Apache Maven
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8.1</version>
</dependency>


Gradle/Grails
compile 'com.mashape.unirest:unirest-java:1.4.9'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.8.1'

Request Submission

Response Handling

Request Values

Request Element

Type

Max

Required

Notes

AuthenticationToken

String

100

Authorization

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

BillerAccountId

String

16

Authorization

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

EmailAddress

String

100

Optional

Used to identify a payer.

ExternalId1

String

50

Optional

Used to identify a payer. This is a custom identifier rather than ProtectPay’s.

*If more than 50 characters are supplied the value will be truncated to 50

ExternalId2

String

50

Optional

Used to identify a payer. This is a custom identifier rather than ProtectPay’s.

*If more than 50 characters are supplied the value will be truncated to 50

Name

String

50

Required

Used to identify a payer.

 

Response Values

Response Element

Type

Notes

RequestResult.ResultValue

String

The 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 Method Response Code. See Appendix for possible returned Values

RequestResult.ResultMessage

String

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

ExternalAccountID

String

This is the ProtectPay ID for the Payer Created and belongs to the BillerID that created it

*This is referenced in other methods as ‘PayerAccountID’ or ‘PayerID’

 

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}     CreatePayerWithData
{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:CreatePayer>
<con:identification>
<typ:AuthenticationToken>MyAuthToken</typ:AuthenticationToken>
<typ:BillerAccountId>MyBillerId</typ:BillerAccountId>
</con:identification>
<con:accountName>steve test</con:accountName>
</con:CreatePayer>
</soapenv:Body>
</soapenv:Envelope>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<CreatePayerWithDataResponse xmlns="http://propay.com/SPS/contracts">
<CreatePayerWithDataResult xmlns:a="http://propay.com/SPS/types" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:ExternalAccountID>2443795125315076</a:ExternalAccountID>
<a:RequestResult>
<a:ResultCode>00</a:ResultCode>
<a:ResultMessage/>
<a:ResultValue>SUCCESS</a:ResultValue>
</a:RequestResult>
</CreatePayerWithDataResult>
</CreatePayerWithDataResponse>
</s:Body>
</s:Envelope>
Implementation Details
Request Submission

namespace ProtectPayApi_CreatePayer
{
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 CreatePayerProgram
{
public static void Main(string[] args)
{
var createPayerResponse = CreatePayer();
}

private static CreateAccountInformationResult CreatePayer()
{
var baseUrl = "https://xmltestapi.propay.com/ProtectPay";
var request = BuildCreatePayerRequest();
var restRequest = CreateRestRequest("/Payers/", RestSharp.Method.PUT);
restRequest.AddBody(request);
return Execute<CreateAccountInformationResult>(restRequest, baseUrl);
}

/// <summary>
/// Builds the request data.
/// </summary>
/// <returns>The request data.</returns>
private static CreatePayerRequest BuildCreatePayerRequest()
{
return new CreatePayerRequest
{
EmailAddress = "email address",
ExternalId1 = "external id 1",
ExternalId2 = "external id 2",
Name = "Payer name",
};
}

/// <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;
}

/// <summary>
/// Gets the credentials for the call.
/// </summary>
/// <returns>The credentials.</returns>
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 data for the create payer call.
/// </summary>
public class CreatePayerRequest
{
/// <summary>
/// The Name of the payer
/// </summary>
public string Name { get; set; }

/// <summary>
/// The email address of the payer
/// </summary>
public string EmailAddress { get; set; }

/// <summary>
/// The first Id for the payer, configurable by an outside system
/// </summary>
public string ExternalId1 { get; set; }

/// <summary>
/// The second Id for the payer, configurable by an outside system
/// </summary>
public string ExternalId2 { get; set; }
}

public class CreateAccountInformationResult
{
/// <summary>
/// The new payer external account ID
/// </summary>
public string ExternalAccountID { get; set; }

/// <summary>
/// The result of the create account request
/// </summary>
public Result RequestResult { 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 documenation show 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 creating payer ID */
private $_createPayerIdData;
private $_createPayerIdInfo;

/**
* @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;
}

/**
* @param array $payerIdData
* @return $this
*/
public function setCreatePayerIdData($payerIdData) {
$this->_createPayerIdData = $payerIdData;
return $this;
}

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

/**
* Creates a payer id
* @return $this
*/
public function createPayerId() {
$data_string = json_encode($this->_createPayerIdData);

$ch = curl_init($this->_apiBaseUrl . '/ProtectPay/Payers');
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->_createPayerIdInfo = curl_exec($ch);
return $this;
}
}

$data = [
"Name" => "John Smith",
"EmailAddress" => "email@email.com",
"ExternalId1" => "CustomerNumber12",
"ExternalId2" => "234567"
];

// Create a new payer
$protectPayAPI = new ProtectPayApi();
$result = $protectPayAPI->setBillerId('9999986379225246')
->setAuthToken('16dfe8d7-889b-4380-925f-9c2c6ea4d930')
->setCreatePayerIdData($data)
->createPayerId()
->getCreatePayerIdInfo();

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 CreatePayerSample {
 /**
* 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();

CreatePayerSample program = new CreatePayerSample();

CreatePayerResponse response = program.createPayer();

System.out.println("Result: " + response.RequestResult.ResultValue);
System.out.println("Result code: " + response.RequestResult.ResultCode);
System.out.println("Result message: " + response.RequestResult.ResultMessage);
System.out.println("Payer account id: " + response.ExternalAccountID);
 }

 public CreatePayerResponse createPayer() {
String resourceUrl = baseUrl + "Payers";

HttpRequestWithBody request = this.createRequest(resourceUrl);

CreatePayerRequest payer = this.buildRequest();

request.body(payer);

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

 private CreatePayerRequest buildRequest() {
CreatePayerRequest payer = new CreatePayerRequest();
payer.Name = "John Travolta";
payer.EmailAddress = "saturday@nightfever.com";
payer.ExternalId1 = "Distributer 2";
payer.ExternalId2 = "Rep 35";

return payer;
 }

 /**
* 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.
*
*/
 private String getBillerId() {
return "9876543210987654";
 }

 /**
* 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;
 }

 /**
* 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

// CreatePayerRequest.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 create a ProtectPay payer, i.e. someone who is going to securely
 * pay for a product/service.
 */
public class CreatePayerRequest {

 /**
* A name to identify the payer.
*/
 public String Name;

 /**
* The payer's email address if supplied.
*/
 public String EmailAddress;

 /**
* Customer specific identifier.
*/
 public String ExternalId1;

 /**
* Customer specific identifier.
*/
 public String ExternalId2;
}


// -------------------------------------------------------------------------------------------- //
// 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;
}


// -------------------------------------------------------------------------------------------- //
// CreatePayerResponse.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 response to a create payer request.
 */
public class CreatePayerResponse {

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

 /**
* The ProtectPay ID for the created payer.
*
* Note: This is referenced in other methods as 'PayerAccountId' or
* 'PayerId'.
*/
 public String ExternalAccountID;
}

 

Response Handling

The following sample uses the Unirest and Jackson libraries.

You can add them to your project using:

Apache Maven
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8.1</version>
</dependency>


Gradle/Grails
compile 'com.mashape.unirest:unirest-java:1.4.9'
compile 'com.fasterxml.jackson.core:jackson-databind:2.8.8.1'

Request Submission

Response Handling

Request Values

Request Element

Type

Max

Required

Notes

AuthenticationToken

String

100

Authorization

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

BillerAccountId

String

16

Authorization

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

EmailAddress

String

100

Optional

Used to identify a payer.

ExternalId1

String

50

Optional

Used to identify a payer. This is a custom identifier rather than ProtectPay’s.

*If more than 50 characters are supplied the value will be truncated to 50

ExternalId2

String

50

Optional

Used to identify a payer. This is a custom identifier rather than ProtectPay’s.

*If more than 50 characters are supplied the value will be truncated to 50

Name

String

50

Required

Used to identify a payer.

Response Values

Response Element

Type

Notes

RequestResult.ResultValue

String

The 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 Method Response Code. See Appendix for possible returned Values

RequestResult.ResultMessage

String

The Method Response Message. See Appendix for possible returned Messages

ExternalAccountID

String

This is the ProtectPay ID for the Payer Created and belongs to the BillerID that created it

*This is referenced in other methods as ‘PayerAccountID’ or ‘PayerID’