Example Code

// Example Program: T_REGISTER
// Description:
// This is a test program to illustrate how to call the VFN_Register()
// subprocedure. This subprocedure handles generating the required
// public-private key pair, registering with the specified device,
// and calculating the SHA-256 HMAC value for subsequent requests to
// use as part of their counter calculations. This creates a record in
// physical file VFNDVC, and the device ID can then be used with
// other VFN subprocedures.
Ctl-Opt DftActGrp(*No) ActGrp(*Caller) BndDir('PTTIBND');
/COPY QRPGLECPY,VFNCB
// This is included for demo output purposes.
Dcl-Pr WriteToJobLog Int(10) Extproc('Qp0zLprintf');
pString Pointer Value Options(*String);
End-Pr;
Dcl-C NewLine x'15';
// This will capture returned error information
Dcl-Ds ErrorDS LikeDS(VFN_ErrorDS_t) Inz(*LikeDS);
// This will be used to pass request information to the API call
Dcl-Ds RegReqDS LikeDS(VFN_RegisterReqDS_t) Inz(*LikeDS);
// This will store parsed response data from the API call
Dcl-Ds RegRspDS LikeDS(VFN_RegisterRspDS_t) Inz(*LikeDS);
reset ErrorDS;
reset RegReqDS;
reset RegRspDS;
// VFN_GenerateEntryCode() is a convenience subprocedure that generates
// a 4 character numeric code that is used to confirm the device
// registration. However, you do not need to use it and could simply
// assign a 4 character numeric string:
RegReqDS.EntryCode = '1234';
//RegReqDS.EntryCode = VFN_GenerateEntryCode();
// Device ID can be anything, and will be used by all other APIs to
// identify which device you are communicating with
RegReqDS.DeviceID = 'test';
// The URL or IP address of the device. This should not include http://
RegReqDS.DeviceHost = '24.197.176.135';
// The default ports for Verifone devices are 5015 and 5016, but if you
// configure them differently you can set those values here
RegReqDS.PrimaryPort = 25015;
RegReqDS.SecondaryPort = 25016;
// Verifone makes different functions available based on device model.
// It is important that the device model is set correctly during
// registration to avoid calling functions that do not exist on your
// device, or which may expect different fields. A complete list of
// the models supported can be found in the copybook QRPGLECPY,VFNCB
// or in the online product documentation.
RegReqDS.Model = VFN_MODEL_MX915;
// This is purely for recordkeeping purposes and is not used by the APIs
RegReqDS.DeviceDescription = 'Test device';
// By default PTTI uses a timeout of 10 seconds for each of these next
// fields, so you can ignore them unless you need to modify them to
// accomodate your implementation/network/etc.
RegReqDS.ReadTimeout = 10;
RegReqDS.WriteTimeout = 10;
RegReqDS.ConnectTimeout = 10;
// if VFN_Register() returns *Off, it means that an error occurred
// as part of the overall communication process, and the information
// will be in ErrorDS - ErrorDS.Message is the main field to look at
// for troubleshooting.
if not VFN_Register( RegReqDS : RegRspDS : ErrorDS );
// handle error
WriteToJobLog( 'Message ID: ' + ErrorDS.MessageId + NewLine );
WriteToJobLog( 'Message: ' + ErrorDS.Message + NewLine );
*INLR = *On;
return;
else;
// Now you can check the response data structure for any status info
// or data returned from the device:
WriteToJobLog( 'Response Text: ' + RegRspDS.ResponseText + NewLine );
WriteToJobLog( 'Result: ' + RegRspDS.Result + NewLine );
WriteToJobLog( 'Response Code: ' + RegRspDS.ResultCode + NewLine );
WriteToJobLog( 'Termination Status: ' +
RegRspDS.TerminationStatus + NewLine );
endif;
*INLR = *On;
return;