//! see CMultiXSession::OnDataReplyReceived void CISO8583AuthorizerServerSession::OnDataReplyReceived(CMultiXAppMsg &ReplyMsg,CMultiXAppMsg &ForwardedMsg) { DebugPrint(3,"Data Reply Received\n"); switch(CISO8583Msg::VersionIndependentMTI(ForwardedMsg.MsgCode())) // this will give us version independent MTI { case CISO8583Msg::MTIAuthorizationMessageRequest : case CISO8583Msg::MTIFinancialMessageRequest : { CMultiXAppMsg *AcquirerMsg = (CMultiXAppMsg *)ForwardedMsg.SavedContext(); if(ReplyMsg.AppDataSize() == 0) { AcquirerMsg->Reply(ReplyMsg.Error()); delete AcquirerMsg; break; } CISO8583Msg AcquirerISO; CISO8583Msg ReplyISO; AcquirerISO.FromISO((const byte_t *)AcquirerMsg->AppData(),AcquirerMsg->AppDataSize()); ReplyISO.FromISO((const byte_t *)ReplyMsg.AppData(),ReplyMsg.AppDataSize()); /* before we send the reply, we need to check if it is MTI 200 and if the response is positive, if so : 1. we debit the issuer account for the sales amount + commission. in this sample we derive the issuer account from the PAN. 2. we credit our own account for these amounts 3. we write transactions log. */ if(CISO8583Msg::VersionIndependentMTI(AcquirerMsg->MsgCode()) == CISO8583Msg::MTIFinancialMessageRequest) { if(CISO8583Utilities::ToInt64(ReplyISO.ActionCode()) == 0) { double Amount = (double)CISO8583Utilities::ToInt64(ReplyISO.TransactionAmount())/100; int IssuerAccount = PANToIssuerAccount(AcquirerISO.PAN()); int MerchantAccount = (int)CISO8583Utilities::ToInt64(AcquirerISO.CardAcceptorIdentificationCode().StringData()); if(!UpdateAuthorizedSale(IssuerAccount,MerchantAccount,AcquirerISO.PAN(),Amount)) { AcquirerMsg->Reply(CISO8583Msg::RequestRejected); // SendReversalToIssuer(ReplyISO); not implemented delete AcquirerMsg; return; } } } else if(CISO8583Msg::VersionIndependentMTI(AcquirerMsg->MsgCode()) == CISO8583Msg::MTIAuthorizationMessageRequest) { int IssuerAccount = PANToIssuerAccount(AcquirerISO.PAN()); double Amount = (double)CISO8583Utilities::ToInt64(AcquirerISO.TransactionAmount())/100; mysqlpp::Transaction Tran(Owner()->DBConn()); mysqlpp::Query Query = Owner()->DBConn().query(); transactions_log Log; Log.Time = TomysqlppDateTime(time(NULL)); Log.AccountNumber = IssuerAccount; Log.CardNumber = AcquirerISO.PAN(); Log.Action = 11; // Query Log.Amount = Amount; Log.NewBalance = 0; Query.insert(Log); Query.execute(); Tran.commit(); } /* We get here when we receive a response for a message we forwarded before. In this case we will forward the response back to the originator, we do not care for the content, we forward it back almost AS IS except for few fields that we need to restore because changed them before we forwarded the message, the fields are: BMP 7 - Set Transmission time BMP 11 - restore sender STAN BMP 12 - Restore sender Date and Time Local BMP 32 - Restore senders Acquiring Institution Identification Code */ /* In order to restore old values, we need to restore the message we received originaly from the acquirer or from the pos terminal. this message is saved in the SaveContext() of the ForwardedMsg. */ ReplyISO.SetTimes(time(NULL),true); ReplyISO.SetSTAN(AcquirerISO.STAN()); ReplyISO.SetDateTimeLocal(AcquirerISO.DateTimeLocal()); ReplyISO.SetAcquiringInstitutionIdentificationCode(AcquirerISO.AcquiringInstitutionIdentificationCode()); ReplyISO.ToISO(); AcquirerMsg->Reply(AcquirerMsg->MsgCode(), ReplyISO.ISOBuffer(), ReplyISO.ISOBufferSize(),0,0,0,0,0,ReplyMsg.Error()); delete AcquirerMsg; // WE MUST DELETE THE MESSAGE BECAUSE WE CALLED "Keep()" BEFORE WE FORWARDED IT. } break; } /* we reply the ReplyMsg for the case that the process that replied to us expects to receive a notification that we received the reply, if it does not wait for the reply, no reply is sent. */ ReplyMsg.Reply(); }