RSS

Navigation



Quick Search'''



paymentkey.generate

RSS

Purpose of This Command

With PaymentKeys, you can encrypt a bank account or a credit card account and the "billing profile" information associated with that account into a single token that can be stored internally in your software and used in future payment transactions without the risk of exposing your customer's private information.
The paymentkey.generate command allows a merchant to generate a PaymentKey token for future use in live payment transactions.

A PaymentKey token may also be generated the first time a bank account or credit card account is used in a Payment transaction in the PaymentKeys Application Framework.
This command is useful if you prefer to generate a token outside of a payment transaction.



WSDL-Generated Objects Available For Use With This Command

  • PK_Command
  • PK_Response



Command Structure and Rules

The following table lists the required and optional fields for this command:

Field NameUsageData To Be Sent
CommandRequiredSet this field value to paymentkey.generate
VersionRequiredSet this field value to 1.0
api_call_idRequiredA unique ID that your software assigns to the API call which ensures that this command is only processed
once.
More information can be found in the Authentication document of this WIKI.
TestModeOptionalSet this value to On to test a command response without actually executing the command. Default value is Off.
PaymentAccountTypeRequiredMust be set to one of the following values to indicate the type of payment account being tokenized: echeck, visa, mastercard, discover, amex
Required Fields When Tokenizing an ECheck/ACH Bank Account
RoutingNumberRequiredThe ABA routing number on customer’s check.
BankAccountNumberRequiredThe customer’s bank account number .
BankAccountTypeRequiredValue must be Checking or Savings
CheckTypeRequiredValue must be Personal or Business.
Required Fields When Tokenizing a Credit Card Account
CardNumberRequiredThe full 15 or 16 digit account number on the credit card
ExpirationRequiredThe expiration date on the credit card
(format: MMYYYY).
Required/Optional Fields For All Payment Account Types
Billing_CustomerIDOptionalAn internal identifier you have assigned to this customer.
Billing_FirstNameRequiredFirst name of the bank account or credit card account holder
Billing_LastNameRequiredLast name of the bank account or credit card account holder
Billing_CompanyRequiredCompany name associate with the payment account. Required if the CheckType field above is set to Business
Billing_Address1RequiredStreet address of the payment account holder.
Billing_Address2OptionalAdditional street address information.
Billing_CityRequiredCity of the payment account holder.
Billing_StateRequired2-Letter state abbreviate for the state of the account holder.
Billing_ZipRequiredZip Code (format: ##### or #####-####)
Billing_CountryOptional2-letter country code (ISO 3166). Default is US.




Sample JSON Command String

The following is an example of what the JSON string might look like for this command:

{"Command":"paymentkey.generate",

"Version":"1.0",

"api_call_id":"1AC4F-99B543-7FC0E",

"TestMode":"On",

"PaymentAccountType":"echeck",

"RoutingNumber":"123123123",

"BankAccountNumber":"123456789",

"BankAccountType":"Checking",

"CheckType":"Personal",

"Billing_CustomerID":"12345",

"Billing_FirstName":"Jane",

"Billing_LastName":"Doe",

"Billing_Company":"Company LLC",

"Billing_Address1":"123 Some Street",

"Billing_Address2":"",

"Billing_City":"Dallas",

"Billing_State":"TX",

"Billing_Zip":"75001",

"Billing_Country":"US"
}
There are
code examples below that demonstrate how to easily convert the PK_Command object (stubbed by the WSDL for this web service) into a JSON string like this one.




Response Structure and Rules

The following table lists the fields that will be returned in a JSON string response to the paymentkey.generate command:


Field NameField ContentsMax LengthAdditional Information
CommandStatusReturns one of the following values:

Approved
• Error
10Indicates the success or failure of the command issued.
ResponseCodeA 3 digit code indicating command success or reason for command failure.3Please refer to the API Response document in this wiki for a list of possible code values, their descriptions, and what
additional information may be
available in the more_info field.
DescriptionA description of the api response code value255
ErrorInformationAdditional information to help determine the source of an error.50
PaymentKeyA unique token assigned to the bank account or credit card account provided AND the billing profile associated with that payment account.10Store this token in your system for making future tokenized payments.
For reference, the first letter of the PaymentKey corresponds to the
Command_ReferenceIDA unique reference ID assigned to each api call.30This value is only needed as a reference during support calls or questions about specific api command attempts.






Sample JSON Response String

The following is an example of what the JSON string sent in response to this command might look like:

{"CommandStatus":"Success","ResponseCode":"000","Description":"Command Successful","ErrorInformation":null,"PaymentKey":"123456","Command_ReferenceID":"45451-25141-0a0a"}

The code examples below will demonstrate how to easily convert this JSON response string into the PK_PaymentKeyAdmin_Response object stubbed by the WSDL for this web service.






Code Samples




Visual Basic .NET

Imports PaymentKeys.API_Tookit
’Define a command object for populating command parametersDim PK_Command As New PK_PaymentKeyAdmin_Command
’Build the command to send to the PaymentKeys Application Framework
PK_Command.command = "paymentkey.generate"
PK_Command.version = "1.0"
PK_Command.api_call_id = Guid.NewGuid.ToString
PK_Command.paymentkey = "v1111_00000_00000_00000.pk"’Serialize the command object to a JSON stringDim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim api_call As String = serializer.Serialize(PK_Command)
’Create HMACSHA1 signature hash for the JSON command string using the GatewayCodeDim sha1 As New System.Security.Cryptography.HMACSHA1()
’Specify the GatewayCode secret key
sha1.Key = System.Text.Encoding.UTF8.GetBytes("PK_Demo")
’Convert the JSON command string to a byte arrayDim byteArray As Byte() = System.Text.Encoding.UTF8.GetBytes(api_call)
’Generate the hash signatureDim api_sig As String = Convert.ToBase64String(sha1.ComputeHash(byteArray))
’Post HTTP Request data using the HTTPFormPost Utility from the PaymentKeys API ToolkitDim FormPost As New HTTPFormPost()
FormPost.URL = "https://www.paymentkeys.com/api.rest/appserver"
FormPost.Add_FormField("api_keyID", "PaymentKeys_Demo.pk")
FormPost.Add_FormField("api_sig", api_sig)
FormPost.Add_FormField("api_call", api_call)
FormPost.Add_FormField("api_output", "json")
Try
FormPost.Submit()
Catch ex As Exception: ’Handle HTTP communication exceptions hereEnd Try’Deserialize JSON response string into response objectIf Not (FormPost.ResponseText = String.Empty) Then
Dim PK_Response As PK_PaymentKeyAdmin_Response: PK_Response = serializer.Deserialize(Of PK_PaymentKeyAdmin_Response)(FormPost.ResponseText)
’Parse the Response per your application and policy rules: Select Case PK_Response.status: Case""Success": ’Process successful response: Case "Declined": ’Process Decline response: Case "Error": ’Process Error response: End SelectEnd If













C# .NET

using PaymentKeys.API_Tookit;
//Define a command object for populating command parameters
PK_PaymentKeyAdmin_Command PK_Command = new PK_PaymentKeyAdmin_Command();
//Build the command to send to the PaymentKeys Application Framework
PK_Command.command = "paymentkey.generate";
PK_Command.version = "1.0";
PK_Command.api_call_id = Guid.NewGuid.ToString;
PK_Command.paymentkey = "v1111_00000_00000_00000.pk";
//Serialize the command object to a JSON string
System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string api_call = serializer.Serialize(PK_Command);
//Create HMACSHA1 signature hash for the JSON command string using the GatewayCode
System.Security.Cryptography.HMACSHA1 sha1 = new System.Security.Cryptography.HMACSHA1();
//Specify the GatewayCode secret key
sha1.Key = System.Text.Encoding.UTF8.GetBytes("PK_Demo");
//Convert the JSON command string to a byte arraybyte[] byteArray = System.Text.Encoding.UTF8.GetBytes(api_call);
//Generate the hash signaturestring api_sig = Convert.ToBase64String(sha1.ComputeHash(byteArray));
//Post HTTP Request data using the HTTPFormPost Utility from the PaymentKeys API Toolkit
HTTPFormPost FormPost = new HTTPFormPost();
FormPost.URL = "https://www.paymentkeys.com/api.rest/appserver";
FormPost.Add_FormField("api_keyID", "PaymentKeys_Demo.pk");
FormPost.Add_FormField("api_sig", api_sig);
FormPost.Add_FormField("api_call", api_call);
FormPost.Add_FormField("api_output", "json");
try{
FormPost.Submit();
}catch (Exception ex)
{: //Handle HTTP communication exceptions here}//Deserialize JSON response string into response objectif (!(FormPost.ResponseText == string.Empty))
{
PK_PaymentKeyAdmin_Response PK_Response = default(PK_PaymentKeyAdmin_Response);: PK_Response = serializer.Deserialize<PK_PaymentKeyAdmin_Response>(FormPost.ResponseText);
//Parse the Response per your application and policy rules: switch (PK_Response.status): {: case "Success":: //Process successful response: break;: case "Declined":: //Process Decline response: break;: case "Error":: //Process Error response: break;: }}











 

ScrewTurn Wiki version 5.2.0.8. Some of the icons created by FamFamFam.