private void SaveCreditCardToProfile(string cardNumber, string cardCode, DateTime expires, PaymentInfo paymentInfo, Customer customer) { var foundPaymentProfile = customer.PaymentProfiles.SingleOrDefault(p => p.ProfileID == paymentInfo.AuNetCustPayId.ToString()); if (foundPaymentProfile == null) { var paymentProfileId = CustomerGateway.AddCreditCard(customer.ProfileID, cardNumber, expires.Month, expires.Year, cardCode, customer.BillingAddress); paymentInfo.AuNetCustPayId = paymentProfileId.ToInt(); } else { if (!cardNumber.StartsWith("X")) { foundPaymentProfile.CardNumber = cardNumber; } if (cardCode != null && !cardCode.StartsWith("X")) { foundPaymentProfile.CardCode = cardCode; } foundPaymentProfile.CardExpiration = expires.ToString("MMyy"); var isSaved = CustomerGateway.UpdatePaymentProfile(customer.ProfileID, foundPaymentProfile); if (!isSaved) { throw new Exception($"UpdatePaymentProfile failed to save echeck for {paymentInfo.PeopleId}"); } } }
public void AddCreditCardTest_ValidationMode() { //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>22219473</customerPaymentProfileId></createCustomerPaymentProfileResponse>"; LocalRequestObject.ResponseString = responseString; CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey, ServiceMode.Test); string profileID = "24231938"; string cardNumber = "4111111111111111"; int expirationMonth = 1; int expirationYear = 16; string expected = "22219473"; 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.AddCreditCard(profileID, cardNumber, expirationMonth, expirationYear); } catch (Exception e) { string s = e.Message; } Assert.AreEqual(expected, actual); }
private static void AddCustomerWithPaymentProfile() { var target = new CustomerGateway(ApiKey, TransactionKey); try { //var s = target.GetCustomerIDs(); var actual = target.CreateCustomer("*****@*****.**", "new customer profile", "102"); var profileId = actual.ProfileID; target.AddCreditCard(profileId, "4111111111111111", 12, 16, "087", new Address { City = "WeiHai", State = "Shangdong", Zip = "264209", Street = "Touch Road" }); } catch (Exception e) { Console.WriteLine(e.Message); } }