Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

...

The very step to avoid difficult integration times: unit test the external communication with ACE.

View file
nametutorial#1

Code Block
breakoutModewide
languagec
// NAME.......  Tutorial #1
// PURPOSE....	This code presents how to connect onto ACE and to use aceOut
//
//	Hypothesis and optimizations:
//		Communication between ACE and acceptance device is IP

//
// PROJECT....  Wiki
// REFERENCES.	--
//
// Copyright ©2005-2020 - 9164-4187 QUEBEC INC (“AMADIS”), All Rights Reserved
//
//---------------------------------------------------------
//            Main
//---------------------------------------------------------
int main(int argc, char** argv)
{
	// Communication
	int port, length;
	char address[50]="";

	// Get Communication parameters from ini file
	// These paramerters maybe wired inside the code for training purposes
	xgpiIniSetFilename("agnos.ini");
	xgpiIniGetString("COM", "Address", 50, address, &length);
	xgpiIniGetNumeric("COM", "Port", &port);

	// Initialize ACE
	// Initialize generic communication interface
	assert(tcpInit(0) == TCP_NO_ERROR);
	// Create server and client
	assert(comtcpOpen(&gACEServerCOMTCP, TCP_SERVER, 0, port) == COM_NO_ERROR);
	assert(comtcpOpen(&gACEClientCOMTCP, TCP_CLIENT, address, 1979) == COM_NO_ERROR);
	// Set ACE with server and client 
	aceInitializeCommunication(&gACEServerCOMTCP.com,&gACEClientCOMTCP.com);
	
	// Initialize running mode
	aceSetMode(pmSDK);

	// Set ACE option
	aceSetUIDisplay(bTRUE);

	// Trace into ACE
	aceOut("Training Session - BEGIN\n");
	aceOut("Hello World!\n");
	aceOut("Training Session - END\n");

	return 0;
}

...

For this tutorial, code examples rely on previous tutorial. Let’s focus on how to manage a transaction payment transaction. A comprehensive example is provided below.

View file
nametutorial#4

Code Block
breakoutModewide
languagec
void processRequest(tByte* request, tWord requestLen, tPaymentContext* ctx)
{
	tByte date[4], time[3], datetime[6];
	cursor_t cursorRequest;
	byte_t *value;

	static tByte TRD[500] = "";
	static tWord TRDLength = 0;

	if(!requestLen || !request)
		return;

	gpiMemCpy(TRD,request,requestLen);
	TRDLength = requestLen;


	// Parse TLV stream
	if(tlvInitCursor(request,requestLen,requestLen,&cursorRequest)==TLV_NO_ERROR)
	{
		// Map tags to tPaymentContext structure
		tlvResetCursor(&cursorRequest);
		if(tlvFindTag(0x9C,1,&cursorRequest)==TLV_NO_ERROR)
		{
			value = tlvGetValue(&cursorRequest);
			if(value)
			{
				if(*value==0x00)		ctx->mTransactionType = ttPURCHASE;
				else if(*value==0x01)	ctx->mTransactionType = ttCASH;
				else if(*value==0x09)	ctx->mTransactionType = ttWITH_CASHBACK;
				else					ctx->mTransactionType = ttUNDEFINED;
			}
			else
				ctx->mTransactionType = ttUNDEFINED;
		}
		// as per new GTBI as of december 2014: ctx->mTransactionType is set at initialization time from agnos.ini
		//else
			//ctx->mTransactionType = ttPURCHASE;

		if(ctx->mTransactionType == ttWITH_CASHBACK)
		{
			tlvResetCursor(&cursorRequest);
			if(tlvFindTag(0x9F02,1,&cursorRequest)==TLV_ERR_TAG_NOT_FOUND)
			{
				ctx->mAmount = NULL;
				ctx->mCashBack = NULL;
			}
			else
			{
				if(tlvGetLength(&cursorRequest))
					convertBCDToAmount(ctx->mAmount,tlvGetValue(&cursorRequest),6);
				else
					ctx->mAmount = NULL;

				if(tlvFindTag(0x9F03,1,&cursorRequest)==TLV_ERR_TAG_NOT_FOUND)
					ctx->mCashBack = NULL;
				else
				{
					if(tlvGetLength(&cursorRequest))
						convertBCDToAmount(ctx->mCashBack,tlvGetValue(&cursorRequest),6);
					else
						ctx->mCashBack = NULL;
				}
			}
		}
		else
		{	// ttPURCHASE or ttCASH or ttMANUALCASH or ttREFUND or ttDEPOSIT or dummy value
			tlvResetCursor(&cursorRequest);
			if(tlvFindTag(0x9F02,1,&cursorRequest)==TLV_ERR_TAG_NOT_FOUND)
			{
				ctx->mAmount = NULL;
				ctx->mCashBack = NULL;
			}
			else
			{
				if(tlvGetLength(&cursorRequest))
				{
					convertBCDToAmount(ctx->mAmount,tlvGetValue(&cursorRequest),6);

					tlvResetCursor(&cursorRequest);
					if(tlvFindTag(0x9F03,1,&cursorRequest)==TLV_ERR_TAG_NOT_FOUND)
						ctx->mCashBack = NULL;
					else
					{
						if(tlvGetLength(&cursorRequest))
							convertBCDToAmount(ctx->mCashBack,tlvGetValue(&cursorRequest),6);
						else
							ctx->mCashBack = NULL;
					}
				}
				else
				{
					ctx->mAmount = NULL;
					ctx->mCashBack = NULL;
				}
			}
		}

		tlvResetCursor(&cursorRequest);
		if(tlvFindTag(0x9A,1,&cursorRequest)==TLV_NO_ERROR)
		{
			if(tlvGetValue(&cursorRequest))
			{
				gpiMemCpy(ctx->mTransactionDate,tlvGetValue(&cursorRequest),3);

				// Mantis 0000142: Set date and time from ACE
				// Synchronize system's date from ACE
				datetime[0] = bcdToDecimal(ctx->mTransactionDate[0]);
				datetime[1] = bcdToDecimal(ctx->mTransactionDate[1]);
				datetime[2] = bcdToDecimal(ctx->mTransactionDate[2]);
				gpiGetTime(time);
				gpiMemCpy(datetime+3,time,3);
				gpiSetDateTime(datetime);
			}
			else
			{
				gpiGetDate(date);
				ctx->mTransactionDate[0] = toNumeric(date[1]);
				ctx->mTransactionDate[1] = toNumeric(date[2]);
				ctx->mTransactionDate[2] = toNumeric(date[3]);
			}
		}
		else
		{
			gpiGetDate(date);
			ctx->mTransactionDate[0] = toNumeric(date[1]);
			ctx->mTransactionDate[1] = toNumeric(date[2]);
			ctx->mTransactionDate[2] = toNumeric(date[3]);
		}

		tlvResetCursor(&cursorRequest);
		if(tlvFindTag(0x9F21,1,&cursorRequest)==TLV_NO_ERROR)
		{
			if(tlvGetValue(&cursorRequest))
			{
				gpiMemCpy(ctx->mTransactionTime,tlvGetValue(&cursorRequest),3);

				// Mantis 0000142: Set date and tiem from ACE
				// Synchronize system's time from ACE
				gpiGetDate(date);
				gpiMemCpy(datetime,date+1,3);
				datetime[3] = bcdToDecimal(ctx->mTransactionTime[0]);
				datetime[4] = bcdToDecimal(ctx->mTransactionTime[1]);
				datetime[5] = bcdToDecimal(ctx->mTransactionTime[2]);
				gpiSetDateTime(datetime);
			}
			else
			{
				gpiGetTime(time);
				ctx->mTransactionTime[0] = toNumeric(time[0]);
				ctx->mTransactionTime[1] = toNumeric(time[1]);
				ctx->mTransactionTime[2] = toNumeric(time[2]);
			}
		}
		else
		{
			gpiGetTime(time);
			ctx->mTransactionTime[0] = toNumeric(time[0]);
			ctx->mTransactionTime[1] = toNumeric(time[1]);
			ctx->mTransactionTime[2] = toNumeric(time[2]);
		}

		tlvResetCursor(&cursorRequest);
		if(tlvFindTag(0x5F2A,1,&cursorRequest)==TLV_NO_ERROR)
		{
			if(tlvGetValue(&cursorRequest))
				gpiMemCpy(ctx->mTransactionCurrencyCode,tlvGetValue(&cursorRequest),2);
		}

		tlvResetCursor(&cursorRequest);
		if(tlvFindTag(0x5F36,1,&cursorRequest)==TLV_NO_ERROR)
		{
			if(tlvGetValue(&cursorRequest))
					ctx->mTransactionCurrencyExponent = *(tlvGetValue(&cursorRequest));
		}
	}
}// NAME.......  Tutorial #3
// PURPOSE....	This code presents how to intialize language and payment contexts
//
//	Hypothesis and optimizations:
//		Communication between ACE and acceptance device is IP

//
// PROJECT....  Wiki
// REFERENCES.	--
//
// Copyright ©2005-2020 - 9164-4187 QUEBEC INC (“AMADIS”), All Rights Reserved
//

// See comprehensive example to get all functions used by this tutorial

//---------------------------------------------------------
//            Main
//---------------------------------------------------------
//  Main function:
//		- Initialize the platform
//		- Wait for payment trigger
//		- Initialize the data model
//		- Perform a payment
//
//  Visibility: Public
//  Hypothesis: --
//  Reference: --
//
-----------
int main(int argc, char** argv)
{
  	// DoSee allprevious initializationsexamples to get a PAYMENT request from //ACE
Wait for inbound sale request
  
	// SeeDisplay previouscontexts tutorialsBEFORE 
  // Contexts are empty
  processing ACE request
	outPaymentContext(pay);
  	outOutcomeParameter(out);

	// Process ACE request // Fill-up contextes from ACE request
  for a payment. Set pay as per TRD contents
	processRequest(buffer+1,len-1,pay);

  	// ContextsDisplay contexts areAFTER readyprocessing ACE request
	outPaymentContext(pay);
  	outOutcomeParameter(out);

  	// AcknomledgeAcknowledge payment request
  ACE
	aceSendResponse((unsigned char*)"\x30\x30",2);


 	gpiDisplayMessageByID(gpi_true,currentLanguage+1,THANKS);

  	aceOut("Training Session - END\n");

	return 0;
}

Tutorial #5: perform a transaction

...