public Task <MonerisRecurringPaymentOutput> MakePaymentAsync(MonerisRecurringPaymentInput input, CancellationToken cancellationToken = default) { var output = new MonerisRecurringPaymentOutput(input); // create a unique identifier for the processing payment Moneris var transactionIdentifier = Guid.NewGuid().ToString(); output.InvoiceIdentifier = transactionIdentifier; var transaction = new TransactionDetail { CryptType = Constants.CRYPTTYPE, DataKey = input.MonerisAuthToken, Amount = String.Format("{0:0.00}", input.Amount) }; transaction.Identifier = transactionIdentifier; // This is the auth token on the payment method: transaction.CustID = input.CustID; transaction.ProcessingCountryCode = Constants.COUNTRY_CODE_CA; transaction.StoreId = input.StoreId; transaction.ApiKey = input.ServiceKey; transaction.IsTestMode = input.IsTestMode; var receipt = MonerisProcess.PurchaseWithCC(transaction); if (receipt != null) { Int32.TryParse(receipt.GetResponseCode(), out var responseCode); if (responseCode == 0) { output.SetFailure(input); output.TransactionResult = receipt.GetMessage(); output.TransactionReceiptId = "0"; } else if (responseCode < 50) { output.TransactionIdentifier = receipt.GetReferenceNum(); output.TransactionStatus = receipt.GetComplete(); output.TransactionReceiptId = receipt.GetResponseCode(); output.TransactionNumber = receipt.GetTxnNumber(); output.TransactionResult = receipt.GetResSuccess(); output.TransactionFraudCode = receipt.GetAvsResultCode(); output.Response = receipt.GetMessage(); if (Boolean.TryParse(receipt.GetResSuccess(), out var isTrue) && isTrue) { output.IsSuccessful = true; } } else if (responseCode > 49) { output.SetFailure(input); output.TransactionResult = "Payment failed."; output.TransactionReceiptId = receipt.GetResponseCode(); } } else { output.SetFailure(input); output.TransactionResult = "Payment failed."; output.TransactionReceiptId = "No receipt created."; } return(Task.FromResult(output)); }
public Task <PaymentOutput> MakePaymentAsync(MonerisCreditCardPaymentInput input, CancellationToken cancellationToken = default) { var response = new PaymentOutput(); var CCD = new CreditCardDetail(); CCD.CCNumber = input.CreditCardNo; CCD.ExpDate = input.CcExpMmYy; CCD.CryptType = CreditCardConstants.CRYPTTYPE; CCD.ProcessingCountryCode = CreditCardConstants.COUNTRY_CODE_CA; // This is currently not used, it gets commented out in MonerisProcess.AddCC function: var avsCheck = new AvsInfo(); var address1_line1 = input.BillingLine1; avsCheck.SetAvsStreetNumber(address1_line1); var address1_line2 = input.BillingLine2; if (String.IsNullOrEmpty(address1_line2)) { var strArray = address1_line1.Split(' '); if (strArray.Length > 1) { avsCheck.SetAvsStreetName(strArray[1].ToString()); } } else { avsCheck.SetAvsStreetName(address1_line2); } var address1_postalcode = input.BillingPostalCode; avsCheck.SetAvsZipCode(address1_postalcode); var monerisCCInput = new MonerisCCInput() { StoreId = input.MonerisStoreId, Key = input.ServiceKey, TestMode = input.IsTestMode, ServiceModeOptionSetId = input.ServiceModeOptionSetId }; var addCCReceipt = MonerisProcess.AddCC(CCD, avsCheck, monerisCCInput); if (addCCReceipt == null) { return(Task.FromResult(response)); } Int32.TryParse(addCCReceipt.GetResponseCode(), out var addCCResponseCode); if (addCCResponseCode != 0 && addCCResponseCode < 50) { var transaction = new TransactionDetail(); transaction.DataKey = addCCReceipt.GetDataKey(); transaction.Amount = String.Format("{0:0.00}", input.Amount); transaction.CryptType = CreditCardConstants.CRYPTTYPE; transaction.ProcessingCountryCode = CreditCardConstants.COUNTRY_CODE_CA; transaction.StoreId = input.MonerisStoreId; transaction.ApiKey = input.ServiceKey; transaction.IsTestMode = input.IsTestMode; var order_id = Guid.NewGuid().ToString(); response.InvoiceNumber = order_id; transaction.Identifier = order_id; // If there is no auth id, get it from the added CC receipt: if (transaction.CustID == null) { transaction.CustID = addCCReceipt.GetDataKey(); } var transactionReceipt = MonerisProcess.PurchaseWithCC(transaction); if (transactionReceipt != null) { Int32.TryParse(transactionReceipt.GetResponseCode(), out var responseCode); if (responseCode != 0 && responseCode < 50) { response.IsSuccessful = true; } else if (responseCode == 0 || responseCode > 49) { response.IsSuccessful = false; } response.TransactionResult = $"{transactionReceipt.GetMessage()} - Response Code: {responseCode}"; response.TransactionIdentifier = transactionReceipt.GetReferenceNum(); response.AuthToken = transactionReceipt.GetDataKey(); response.CardType = transactionReceipt.GetCardType(); } } else if (addCCResponseCode == 0 || addCCResponseCode > 49) { response.IsSuccessful = false; response.TransactionResult = addCCReceipt.GetMessage(); } return(Task.FromResult(response)); }