private void SaveECheckToProfile(string routingNumber, string accountNumber, PaymentInfo paymentInfo, Customer customer) { if (accountNumber.StartsWith("X")) { return; } var foundPaymentProfile = customer.PaymentProfiles.SingleOrDefault(p => p.ProfileID == paymentInfo.AuNetCustPayBankId.ToString()); var bankAccount = new BankAccount { accountType = BankAccountType.Checking, nameOnAccount = customer.Description, accountNumber = accountNumber, routingNumber = routingNumber }; if (foundPaymentProfile == null) { var paymentProfileId = CustomerGateway.AddECheckBankAccount(customer.ProfileID, BankAccountType.Checking, routingNumber, accountNumber, customer.Description); paymentInfo.AuNetCustPayBankId = paymentProfileId.ToInt(); } else { foundPaymentProfile.eCheckBankAccount = bankAccount; var isSaved = CustomerGateway.UpdatePaymentProfile(customer.ProfileID, foundPaymentProfile); if (!isSaved) { throw new Exception($"UpdatePaymentProfile failed to save credit card for {paymentInfo.PeopleId}"); } } }
public void AddECheckBankAccountTest() { //check login / password string sError = CheckLoginPassword(); Assert.IsTrue(sError == "", sError); string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><createCustomerPaymentProfileResponse xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"><messages><resultCode>Ok</resultCode><message><code>I00001</code><text>Successful.</text></message></messages><customerPaymentProfileId>24282439</customerPaymentProfileId><validationDirectResponse>1,1,1,(TESTMODE) This transaction has been approved.,000000,P,0,none,Test transaction for ValidateCustomerPaymentProfile.,1.00,ECHECK,auth_only,none,,,,,,,,,,,[email protected],,,,,,,,,0.00,0.00,0.00,FALSE,none,ACD21540D94325D06FDC81558F3196AD,,,,,,,,,,,,,XXXX4587,Bank Account,,,,,,,,,,,,,,,,</validationDirectResponse></createCustomerPaymentProfileResponse>"; LocalRequestObject.ResponseString = responseString; CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey); string profileID = "24232683"; string expected = "24282439"; string actual = ""; // if choose "USELOCAL", the test should pass with no exception // Otherwise, the test might fail for error, i.e. duplicated request. try { actual = target.AddECheckBankAccount(profileID, BankAccountType.Savings, "125000024", "1234588", "Sue Zhu", "Bank of Seattle", EcheckType.WEB, null); } catch (Exception e) { string s = e.Message; } Assert.AreEqual(expected, actual); }