/// <summary> /// Posts the transaction to the server. /// </summary> /// <returns>The transaction result.</returns> public async Task <BluePayResponse> ProcessAsync() { var postData = new QueryStringBuilder(); switch (_api) { // A switch section can have more than one case label. case "bpdailyreport2": CalcReportTPS(); _url = new Uri("https://secure.bluepay.com/interfaces/bpdailyreport2", UriKind.Absolute); postData.AppendKeyValue("ACCOUNT_ID", _accountID) .AppendKeyValue("MODE", _mode) .AppendKeyValue("TAMPER_PROOF_SEAL", _tps) .AppendKeyValue("REPORT_START_DATE", _reportStartDate) .AppendKeyValue("REPORT_END_DATE", _reportEndDate) .AppendKeyValue("DO_NOT_ESCAPE", _doNotEscape) .AppendKeyValue("QUERY_BY_SETTLEMENT", _queryBySettlement) .AppendKeyValue("QUERY_BY_HIERARCHY", _queryByHierarchy) .AppendKeyValue("TPS_HASH_TYPE", _tpsHashType) .AppendKeyValue("EXCLUDE_ERRORS", _excludeErrors); break; case "stq": CalcReportTPS(); _url = new Uri("https://secure.bluepay.com/interfaces/stq", UriKind.Absolute); postData.AppendKeyValue("ACCOUNT_ID", _accountID) .AppendKeyValue("MODE", _mode) .AppendKeyValue("TAMPER_PROOF_SEAL", _tps) .AppendKeyValue("REPORT_START_DATE", _reportStartDate) .AppendKeyValue("REPORT_END_DATE", _reportEndDate) .AppendKeyValue("TPS_HASH_TYPE", _tpsHashType) .AppendKeyValue("EXCLUDE_ERRORS", _excludeErrors) .AppendKeyValue("id", _masterID) .AppendKeyValue("payment_type", _paymentType) .AppendKeyValue("trans_type", _transType) .AppendKeyValue("amount", _amount) .AppendKeyValue("name1", _firstName) .AppendKeyValue("name2", _lastName); break; case "bp10emu": CalcTPS(); _url = new Uri("https://secure.bluepay.com/interfaces/bp10emu", UriKind.Absolute); postData.AppendKeyValue("MERCHANT", _accountID) .AppendKeyValue("MODE", _mode) .AppendKeyValue("TRANSACTION_TYPE", _transType) .AppendKeyValue("TAMPER_PROOF_SEAL", _tps) .AppendKeyValue("NAME1", _firstName) .AppendKeyValue("NAME2", _lastName) .AppendKeyValue("COMPANY_NAME", _companyName) .AppendKeyValue("AMOUNT", _amount) .AppendKeyValue("ADDR1", _addr1) .AppendKeyValue("ADDR2", _addr2) .AppendKeyValue("CITY", _city) .AppendKeyValue("STATE", _state) .AppendKeyValue("COUNTRY", _country) .AppendKeyValue("ZIPCODE", _zip) .AppendKeyValue("COMMENT", _memo) .AppendKeyValue("PHONE", _phone) .AppendKeyValue("EMAIL", _email) .AppendKeyValue("REBILLING", _doRebill) .AppendKeyValue("REB_FIRST_DATE", _rebillFirstDate) .AppendKeyValue("REB_EXPR", _rebillExpr) .AppendKeyValue("REB_CYCLES", _rebillCycles) .AppendKeyValue("REB_AMOUNT", _rebillAmount) .AppendKeyValue("RRNO", _masterID) .AppendKeyValue("PAYMENT_TYPE", _paymentType) .AppendKeyValue("INVOICE_ID", _invoiceID) .AppendKeyValue("ORDER_ID", _orderID) .AppendKeyValue("CUSTOM_ID", _customID1) .AppendKeyValue("CUSTOM_ID2", _customID2) .AppendKeyValue("AMOUNT_TIP", _amountTip) .AppendKeyValue("AMOUNT_TAX", _amountTax) .AppendKeyValue("AMOUNT_FOOD", _amountFood) .AppendKeyValue("AMOUNT_MISC", _amountMisc) .AppendKeyValue("CUSTOMER_IP", _environment.PublicIpAddress) .AppendKeyValue("TPS_HASH_TYPE", _tpsHashType) .AppendKeyValue("RESPONSEVERSION", 5); if (_swipeData.HasValue()) { var matchTrack1And2 = _track1And2.Match(_swipeData); var matchTrack2 = _track2Only.Match(_swipeData); if (matchTrack1And2.Success || matchTrack2.Success) { postData.AppendKeyValue("SWIPE", _swipeData); } } else if (_paymentType == "CREDIT") { postData.AppendKeyValue("CC_NUM", _paymentAccount) .AppendKeyValue("CC_EXPIRES", _cardExpire) .AppendKeyValue("CVCCVV2", _cvv2); } else { postData.AppendKeyValue("ACH_ROUTING", _routingNum) .AppendKeyValue("ACH_ACCOUNT", _accountNum) .AppendKeyValue("ACH_ACCOUNT_TYPE", _accountType) .AppendKeyValue("DOC_TYPE", _docType); } break; case "bp20rebadmin": CalcRebillTPS(); _url = new Uri("https://secure.bluepay.com/interfaces/bp20rebadmin", UriKind.Absolute); postData.AppendKeyValue("ACCOUNT_ID", _accountID) .AppendKeyValue("TAMPER_PROOF_SEAL", _tps) .AppendKeyValue("TRANS_TYPE", _transType) .AppendKeyValue("REBILL_ID", _rebillID) .AppendKeyValue("TEMPLATE_ID", _templateID) .AppendKeyValue("REB_EXPR", _rebillExpr) .AppendKeyValue("REB_CYCLES", _rebillCycles) .AppendKeyValue("REB_AMOUNT", _rebillAmount) .AppendKeyValue("NEXT_AMOUNT", _rebillNextAmount) .AppendKeyValue("NEXT_DATE", _rebillNextDate) .AppendKeyValue("TPS_HASH_TYPE", _tpsHashType) .AppendKeyValue("STATUS", _rebillStatus); break; default: throw new InvalidOperationException(Res.BluePayInvalidApi); } // Add Level 2 data, if available. foreach (var field in _level2Info) { postData.AppendKeyValue(field.Key, field.Value); } // Add Level 3 item data, if available. foreach (var item in _lineItems) { foreach (var field in item) { postData.AppendKeyValue(field.Key, field.Value); } } // Add customer token data, if available. postData.AppendKeyValue("NEW_CUST_TOKEN", _newCustToken); postData.AppendKeyValue("CUST_TOKEN", _custToken); return(await PerformPostAsync(postData.ToString()).ConfigureAwait(false)); }