Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagec
//---------------------------------------------------------
//            trigSwipeCardPayment
//---------------------------------------------------------
//  Perform a magnetic stripe transaction
//
//  Visibility: Private
//  Hypothesis: --
//  Reference: --
//
//	Return: as per definitions
//			SUCCESS = 0
//			RETRY_CAPTURE = 4
//
tByte trigSwipeCardPayment(tExecutionContext* exe, tPaymentContext* pay, tOutComeParameter* out)
{
	tByte track1[MAX_LENGTH], track2[MAX_LENGTH], track3[MAX_LENGTH];
	tWord track1Len=0, track2Len=0, track3Len=0;
	tWord retcode = 0;
	tTimerHandler timerHandler=0;
	tTimerState timerState=tsNONE;
	tTimerTime timerElapsedSecond=0, timerElapsedMicrosecond=0;

	gpiMemSet(track1,0,MAX_LENGTH);
	gpiMemSet(track2,0,MAX_LENGTH);
	gpiMemSet(track3,0,MAX_LENGTH);

	gpiGetTimer(&timerHandler); // Request a free timer
	gpiGetTimerState(timerHandler,&timerState);
	if(timerState!=tsRUNNING)
		gpiStartTimer(timerHandler,10,0); // 10 second timeout. Arbitrary

	// Wait for card to be swiped
	do
	{
		retcode = gpiReadMagstripe(0,track1,&track1Len,track2,&track2Len,track3,&track3Len);

		gpiGetTimerTime(timerHandler,&timerElapsedSecond,&timerElapsedMicrosecond);
		gpiGetTimerState(timerHandler,&timerState);

	} while ((retcode != msrNO_ERROR) && (timerState != tsTIMEOUT));

	gpiFreeTimer(timerHandler);
	if(timerState == tsTIMEOUT)
		return TIMEOUT;

	if(!track2Len && !track1Len)
	{
		gpiDisplayMessageByID(gpi_true,pmwGetLanguage(pay),CARD_ERROR);
		return RETRY_CAPTURE;
	}

	gpiDisplayMessageByID(gpi_true,pmwGetLanguage(pay),PROCESSING);

	if((pay->mPOSEntryMode != FALLBACK_MODE) && track2Len) // Not a magstripe fallback case
	{
		retcode = isThereAChip(track2);
		switch (retcode)
		{
			case CHIP:
				gpiDisplayMessageByID(gpi_true,pmwGetLanguage(pay),USE_CHIP_READER);
				return RETRY_CAPTURE;
			case ERROR:
				gpiDisplayMessageByID(gpi_true,pmwGetLanguage(pay),CARD_ERROR);
				return RETRY_CAPTURE;
			default:
				break;
		}
	}

	pay->mDataExchange.mTrack1.mLength = track1Len+2;
	pay->mDataExchange.mTrack1.mStream[0]=0x56;
	pay->mDataExchange.mTrack1.mStream[1]=track1Len;
	gpiMemCpy(pay->mDataExchange.mTrack1.mStream+2,track1,track1Len);

	pay->mDataExchange.mTrack2.mLength = track2Len+3;
	pay->mDataExchange.mTrack2.mStream[0]=0x9F;
	pay->mDataExchange.mTrack2.mStream[1]=0x6B;
	pay->mDataExchange.mTrack2.mStream[2]=track2Len;
	gpiMemCpy(pay->mDataExchange.mTrack2.mStream+3,track2,track2Len);

	aceSendMagstripeAuthorization(pay);   	if(pay->mCID==TC)
	{
		out->mOutCome = ocAPPROVED;
		gpiDisplayMessageByID(gpi_true,pmwGetLanguage(pay),APPROVED);
		ledsOn(GREEN);
		gpiBeep(BEEP_OK,NO_FREQUENCY);
	}
	else
	{
		out->mOutCome = ocDECLINED;
		gpiDisplayMessageByID(gpi_true,pmwGetLanguage(pay),DECLINED);
		ledsOn(RED);
		gpiBeep(BEEP_NOK,NO_FREQUENCY);
	}

	 // Go online and process issuer response accordingly
    // ..
    return SUCCESS;
}

Contact

Contactless

...