/// <summary> /// Public method responsible for calling the payment gateway /// Calls private method CallGateway to perform the actual transaction processing /// </summary> public void Process() { // load the correct payment gateway based on appconfig settings // a failure here probably means that they entered an invalid appconfig, which exception logging will pick up automatically if (!string.IsNullOrEmpty(GatewayToUseBackup) && GatewayToUseBackup != Gateway.ro_GWBRAINTREE && GatewayToUsePrimary != Gateway.ro_GWBRAINTREE && GatewayToUseBackup != Gateway.ro_GWSAGEPAYPI && GatewayToUsePrimary != Gateway.ro_GWSAGEPAYPI) { m_gatewayUsed = GatewayToUsePrimary; var retryPrimary = AppLogic.AppConfigUSInt("PaymentGateway.PrimaryRetries"); var retryBackup = AppLogic.AppConfigUSInt("PaymentGateway.BackupRetries"); var attemptBackup = true; // attempt the primary gateway first for (int i = 1; i <= retryPrimary; i++) { try { // call the payment gateway m_status = CallGateway(GatewayToUsePrimary); // If there is no exception, we've contacted the gateway and received a valid response // Just because we received a valid response does not mean the transaction was authorized! attemptBackup = false; break; } catch (Exception ex) { // calling the payment gateway failed. Log any information we can. SysLog.LogMessage(GenerateLogMessage(GatewayToUseBackup), SysLog.FormatExceptionForLog(ex), MessageTypeEnum.Informational, MessageSeverityEnum.Alert); m_status = "ERROR CALLING PAYMENT GATEWAY"; } } if (attemptBackup) //we never received a response from the primary gateway { for (int i = 1; i <= retryBackup; i++) { try { //call the payment gateway m_status = CallGateway(GatewayToUseBackup); // If there is no exception, we've contacted the gateway and received a valid response // Just because we received a valid response does not mean the transaction was authorized! attemptBackup = false; m_gatewayUsed = GatewayToUseBackup; break; } catch (Exception ex) { // calling the payment gateway failed. Log any information we can. SysLog.LogMessage(GenerateLogMessage(GatewayToUsePrimary), SysLog.FormatExceptionForLog(ex), MessageTypeEnum.Informational, MessageSeverityEnum.Alert); m_status = "ERROR CALLING PAYMENT GATEWAY"; } } } } else // only a single payment gateway configured. Bypass backup gateway logic { try { m_status = CallGateway(GatewayToUsePrimary); m_gatewayUsed = GatewayToUsePrimary; } catch (Exception ex) { SysLog.LogMessage(GenerateLogMessage(GatewayToUsePrimary), SysLog.FormatExceptionForLog(ex), MessageTypeEnum.Informational, MessageSeverityEnum.Alert); m_status = "ERROR CALLING PAYMENT GATEWAY"; } } }