/// <summary> /// /// </summary> /// <param name="payRequest"></param> /// <param name="payDetails"></param> /// <param name="specificStatusDetails"></param> /// <param name="wasUncertainPaymentDetected"></param> /// <returns></returns> public bool Pay(PayRequest payRequest, ref PayDetails payDetails, ref SpecificStatusDetails specificStatusDetails, ref bool wasUncertainPaymentDetected) { try { _logger.Info(Constants.LOG_FILE, "Pay method started..."); _logger.Debug(Constants.LOG_FILE, $"PayRequest: {JsonConvert.SerializeObject(payRequest)}"); Result <PaymentData> result; var proxy = _channelFactory.CreateChannel(); using (proxy as IDisposable) { result = proxy.Pay(payRequest.Amount, payRequest.TransactionReference); } payDetails = new PayDetails { PaidAmount = result.Data?.PaidAmount ?? 0, HasClientReceipt = result.Data?.HasClientReceipt ?? false, HasMerchantReceipt = result.Data?.HasMerchantReceipt ?? false }; specificStatusDetails = new SpecificStatusDetails() { StatusCode = (int)result.ResultCode, Description = result.Message }; //Check the status property of the parameters object to see if the Pay was successful if ((result.ResultCode == ResultCode.Success && result.Data?.Result == PaymentResult.Successful)) { _logger.Info(Constants.LOG_FILE, "Payment has succeeded."); LastStatus = PeripheralStatus.PeripheralOK(); return(true); } else { _logger.Info(Constants.LOG_FILE, "Payment has failed."); return(false); } } catch (Exception ex) { _logger.Error(Constants.LOG_FILE, "Payment exception thrown."); _logger.Error(Constants.LOG_FILE, ex.ToString()); return(false); } }
/// <summary> /// /// </summary> /// <param name="payRequest"></param> /// <param name="payDetails"></param> /// <param name="specificStatusDetails"></param> /// <param name="wasUncertainPaymentDetected"></param> /// <returns></returns> public bool Pay(PayRequest payRequest, ref PayDetails payDetails, ref SpecificStatusDetails specificStatusDetails, ref bool wasUncertainPaymentDetected) { try { _logger.Info(Constants.LOG_FILE, "Pay method started..."); _logger.Debug(Constants.LOG_FILE, $"PayRequest: {JsonConvert.SerializeObject(payRequest)}"); //Init the paid amount and Tender Media payDetails = new PayDetails(); Result <PaymentData> result; var proxy = _channelFactory.CreateChannel(); using (proxy as IDisposable) { result = proxy.Pay(payRequest.Amount); } //Check the status property of the parameters object to see if the Pay was successful if (result.ResultCode == ResultCode.Success && result.Data.Result == PaymentResult.Successful) { _logger.Info(Constants.LOG_FILE, "Payment has been succeeded."); LastStatus = PeripheralStatus.PeripheralOK(); //Update the payment details with the ones received from the payment terminal //payDetails.TenderMediaId = result.Data.TenderMediaId; payDetails.PaidAmount = result.Data.PaidAmount; payDetails.HasClientReceipt = result.Data.HasClientReceipt; } else { _logger.Info(Constants.LOG_FILE, "Payment has been failed."); } specificStatusDetails = new SpecificStatusDetails() { StatusCode = (int)result.ResultCode, Description = result.Message }; return(result.ResultCode == ResultCode.Success && result.Data.Result == PaymentResult.Successful); } catch (Exception ex) { _logger.Error(Constants.LOG_FILE, "Payment exception has been thrown."); _logger.Error(Constants.LOG_FILE, ex.ToString()); return(false); } }
public bool Pay(PayRequest payRequest, ref PayDetails payDetails, ref SpecificStatusDetails specificStatusDetails, ref bool wasUncertainPaymentDetected) { try { logger.Info(PAYMENT_LOG, "Pay: Started payment."); //Init the payment details this.payDetails = new PayDetails(); //Check if the c3_rmp_net is started or if multiple instances of it are started. if (!c3NetManager.IsC3NetStarted() || c3NetManager.AreMultipleC3NetInstancesStarted()) { logger.Info(PAYMENT_LOG, " c3_rpm_net.exe is closed or has multiple instances opened."); if (!StartC3Net()) { logger.Info(PAYMENT_LOG, " c3_rpm_net.exe restart failed."); paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; return(false); } } //Set the flag to false until a response is received from the payment application IsPayFinished = false; WasPaySuccessful = false; //Init the object that will be updated with the specific error code and description. this.specificStatusDetails = new SpecificStatusDetails(); specificStatusDetails.StatusCode = PeripheralStatus.PeripheralGenericError().Status; specificStatusDetails.Description = PeripheralStatus.PeripheralGenericError().Description; //If the message is not received by the payment application the method will fail if (!communicator.SendMessage(CommunicatorMethods.Pay, (object)payRequest)) { paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; return(false); } //Wait until the payment application responds to the test message while (!IsPayFinished) { Thread.Sleep(0); Thread.Sleep(50); } logger.Info(PAYMENT_LOG, "Pay: Pay finished."); //Update the payment details reference payDetails = this.payDetails; if (WasPaySuccessful) { paymentStatus.CurrentStatus = PeripheralStatus.PeripheralOK().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralOK().Description; } specificStatusDetails = this.specificStatusDetails; return(WasPaySuccessful); } catch (Exception ex) { logger.Error(PAYMENT_LOG, string.Format("Pay: Failed payment.\r\n{0}", ex.ToString())); } paymentStatus.CurrentStatus = PeripheralStatus.PeripheralGenericError().Status; paymentStatus.ErrorCodesDescription = PeripheralStatus.PeripheralGenericError().Description; return(false); }