/// <summary> /// Initializes a new instance of the <see cref="PaymentProfile"/> class, using the passed-in API type to create the profile. /// </summary> /// <param name="apiType">Type of the API.</param> public PaymentProfile(customerPaymentProfileMaskedType apiType) { if (apiType.billTo != null) { this.BillingAddress = new Address(apiType.billTo); } this.ProfileID = apiType.customerPaymentProfileId; if (apiType.driversLicense != null) { this.DriversLicenseNumber = apiType.driversLicense.number; this.DriversLicenseState = apiType.driversLicense.state; this.DriversLicenseDOB = apiType.driversLicense.dateOfBirth; } if (apiType.customerTypeSpecified) { this.IsBusiness = apiType.customerType == customerTypeEnum.business; } else { this.IsBusiness = false; } if (apiType.payment != null) { var card = (creditCardMaskedType)apiType.payment.Item; this.CardType = card.cardType; this.CardNumber = card.cardNumber; this.CardExpiration = card.expirationDate; } this.TaxID = apiType.taxId; }
public static void customerPaymentProfileMaskedType(customerPaymentProfileMaskedType request) { if (null != request) { paymentMaskedType(request.payment); } }
/// <summary> /// Initializes a new instance of the <see cref="PaymentProfile"/> class, using the passed-in API type to create the profile. /// </summary> /// <param name="apiType">Type of the API.</param> public PaymentProfile(customerPaymentProfileMaskedType apiType) { if (apiType.billTo != null) { this.BillingAddress = new Address(apiType.billTo); } this.ProfileID = apiType.customerPaymentProfileId; if (apiType.driversLicense != null) { this.DriversLicenseNumber = apiType.driversLicense.number; this.DriversLicenseState = apiType.driversLicense.state; this.DriversLicenseDOB = apiType.driversLicense.dateOfBirth; } if (apiType.customerTypeSpecified) { this.IsBusiness = apiType.customerType == customerTypeEnum.business; } else { this.IsBusiness = false; } if (apiType.payment != null) { if (apiType.payment.Item is creditCardMaskedType) { var card = (creditCardMaskedType)apiType.payment.Item; this.CardType = card.cardType; this.CardNumber = card.cardNumber; this.CardExpiration = card.expirationDate; } else if (apiType.payment.Item is bankAccountMaskedType) { var bankAcct = (bankAccountMaskedType)apiType.payment.Item; this.eCheckBankAccount = new BankAccount() { accountTypeSpecified = bankAcct.accountTypeSpecified, accountType = (BankAccountType)Enum.Parse(typeof(BankAccountType), bankAcct.accountType.ToString(), true), routingNumber = bankAcct.routingNumber, accountNumber = bankAcct.accountNumber, nameOnAccount = bankAcct.nameOnAccount, echeckTypeSpecified = bankAcct.echeckTypeSpecified, echeckType = (EcheckType)Enum.Parse(typeof(EcheckType), bankAcct.echeckType.ToString(), true), bankName = bankAcct.bankName, checkNumber = "" }; } } this.TaxID = apiType.taxId; }
public void UpdatePaymentProfileTest_eCheckMask() { //check login / password string sError = CheckLoginPassword(); Assert.IsTrue(sError == "", sError); string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><updateCustomerPaymentProfileResponse 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></updateCustomerPaymentProfileResponse>"; LocalRequestObject.ResponseString = responseString; CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey); string profileID = "24236276"; customerPaymentProfileMaskedType apiType = new customerPaymentProfileMaskedType(); PaymentProfile profile = new PaymentProfile(apiType); profile.ProfileID = "24287458"; profile.eCheckBankAccount = new BankAccount() { routingNumber = "XXXX0024", accountNumber = "XXXX3456", nameOnAccount = "Sue Zhu" }; profile.BillingAddress = new Address() { First = "Sue", Last = "Zhu", Company = "Visa", Street = "123 Elm Street", City = "Bellevue", State = "WA", Country = "US", Zip = "98006" }; bool actual = false; // if choose "USELOCAL", the test should pass with no exception // Otherwise, the test might fail for error, i.e. duplicated request. try { actual = target.UpdatePaymentProfile(profileID, profile); } catch (Exception e) { string s = e.Message; } Assert.IsTrue(actual); }
public void MockgetCustomerPaymentProfileTest() { //define all mocked objects as final var mockController = GetMockController <getCustomerPaymentProfileRequest, getCustomerPaymentProfileResponse>(); var mockRequest = new getCustomerPaymentProfileRequest { merchantAuthentication = new merchantAuthenticationType { name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey }, }; var customerPaymentProfileMaskedType = new customerPaymentProfileMaskedType { customerPaymentProfileId = "1234", }; var mockResponse = new getCustomerPaymentProfileResponse { refId = "1234", sessionToken = "sessiontoken", paymentProfile = customerPaymentProfileMaskedType, }; var errorResponse = new ANetApiResponse(); var results = new List <String>(); const messageTypeEnum messageTypeOk = messageTypeEnum.Ok; SetMockControllerExpectations <getCustomerPaymentProfileRequest, getCustomerPaymentProfileResponse, getCustomerPaymentProfileController>( mockController.MockObject, mockRequest, mockResponse, errorResponse, results, messageTypeOk); mockController.MockObject.Execute(AuthorizeNet.Environment.CUSTOM); //mockController.MockObject.Execute(); // or var controllerResponse = mockController.MockObject.ExecuteWithApiResponse(AuthorizeNet.Environment.CUSTOM); var controllerResponse = mockController.MockObject.GetApiResponse(); Assert.IsNotNull(controllerResponse); Assert.IsNotNull(controllerResponse.paymentProfile); LogHelper.info(Logger, "getCustomerPaymentProfile: Details:{0}", controllerResponse.paymentProfile); }
public void UpdatePaymentProfileMinTest() { //check login / password string sError = CheckLoginPassword(); Assert.IsTrue(sError == "", sError); string responseString = "<?xml version=\"1.0\" encoding=\"utf-8\"?><updateCustomerPaymentProfileResponse 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></updateCustomerPaymentProfileResponse>"; LocalRequestObject.ResponseString = responseString; CustomerGateway target = new CustomerGateway(ApiLogin, TransactionKey); string profileID = "24232683"; customerPaymentProfileMaskedType apiType = new customerPaymentProfileMaskedType(); PaymentProfile profile = new PaymentProfile(apiType); profile.ProfileID = "22804148"; profile.CardNumber = "4111111111111112"; profile.CardExpiration = "2016-02"; bool actual = false; // if choose "USELOCAL", the test should pass with no exception // Otherwise, the test might fail for error, i.e. duplicated request. try { actual = target.UpdatePaymentProfile(profileID, profile); } catch (Exception e) { string s = e.Message; } Assert.IsTrue(actual); }
public void MockARBGetSubscriptionTest() { //define all mocked objects as final var mockController = GetMockController <ARBGetSubscriptionRequest, ARBGetSubscriptionResponse>(); var mockRequest = new ARBGetSubscriptionRequest { merchantAuthentication = new merchantAuthenticationType() { name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey }, subscriptionId = "1234" }; var customerPaymentProfileMaskedType = new customerPaymentProfileMaskedType { customerPaymentProfileId = "1234", }; Random rnd = new Random(DateTime.Now.Millisecond); var SubscriptionMaskedType = new ARBSubscriptionMaskedType() { name = "Test", paymentSchedule = new paymentScheduleType { interval = new paymentScheduleTypeInterval { length = 1, unit = ARBSubscriptionUnitEnum.months, }, startDate = DateTime.UtcNow, totalOccurrences = 12 }, amount = 9.99M, amountSpecified = true, trialAmount = 100, trialAmountSpecified = true, status = ARBSubscriptionStatusEnum.active, statusSpecified = true, profile = new subscriptionCustomerProfileType() { paymentProfile = customerPaymentProfileMaskedType, }, order = new orderType { description = string.Format("member monthly {0}", rnd.Next(99999)) } }; var mockResponse = new ARBGetSubscriptionResponse { refId = "1234", sessionToken = "sessiontoken", subscription = SubscriptionMaskedType }; var errorResponse = new ANetApiResponse(); var results = new List <String>(); const messageTypeEnum messageTypeOk = messageTypeEnum.Ok; SetMockControllerExpectations <ARBGetSubscriptionRequest, ARBGetSubscriptionResponse, ARBGetSubscriptionController>( mockController.MockObject, mockRequest, mockResponse, errorResponse, results, messageTypeOk); mockController.MockObject.Execute(AuthorizeNet.Environment.CUSTOM); //mockController.MockObject.Execute(); // or var controllerResponse = mockController.MockObject.ExecuteWithApiResponse(AuthorizeNet.Environment.CUSTOM); var controllerResponse = mockController.MockObject.GetApiResponse(); Assert.IsNotNull(controllerResponse); Assert.IsNotNull(controllerResponse.subscription); LogHelper.info(Logger, "ARBGetSubscription: Details:{0}", controllerResponse.subscription); }
private void PopulateViewModel(CreditCardViewModel viewModel, customerPaymentProfileMaskedType paymentProfile) { if (paymentProfile.billTo != null) { viewModel.Address = paymentProfile.billTo.address; viewModel.City = paymentProfile.billTo.city; viewModel.FirstName = paymentProfile.billTo.firstName; viewModel.LastName = paymentProfile.billTo.lastName; viewModel.State = paymentProfile.billTo.state; } var creditCard = paymentProfile.payment.Item as creditCardMaskedType; if (creditCard == null) return; viewModel.CreditCardNumber = creditCard.cardNumber; }