Example #1
0
 public static void bankAccountMaskedType(bankAccountMaskedType request)
 {
     if (null != request)
     {
         if (0 <= request.accountType)
         {
             request.accountTypeSpecified = true;
         }
         if (0 <= request.echeckType)
         {
             request.echeckTypeSpecified = true;
         }
     }
 }
        public void MockgetCustomerPaymentProfileListTest()
        {
            //define all mocked objects as final
            var mockController = GetMockController <getCustomerPaymentProfileListRequest, getCustomerPaymentProfileListResponse>();
            var mockRequest    = new getCustomerPaymentProfileListRequest
            {
                merchantAuthentication = new merchantAuthenticationType()
                {
                    name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey
                },
                searchType = CustomerPaymentProfileSearchTypeEnum.cardsExpiringInMonth,
                month      = "2020-12"
            };

            var BankAccountMaskedType = new bankAccountMaskedType()
            {
                accountType          = bankAccountTypeEnum.savings,
                accountTypeSpecified = true,
                routingNumber        = "1234",
                accountNumber        = "1234",
                nameOnAccount        = "Test",
                echeckType           = echeckTypeEnum.ARC
            };

            var PaymentMaskedType = new paymentMaskedType()
            {
                Item = BankAccountMaskedType
            };

            var CustomerAddress = new customerAddressType
            {
                firstName   = GetRandomString("FName"),
                lastName    = GetRandomString("LName"),
                company     = GetRandomString("Company"),
                address     = GetRandomString("StreetAdd"),
                city        = "Bellevue",
                state       = "WA",
                zip         = "98000",
                country     = "USA",
                phoneNumber = FormatToPhone(Counter),
                faxNumber   = FormatToPhone(Counter + 1),
            };

            var paymentProfile = new customerPaymentProfileListItemType()
            {
                customerPaymentProfileId = 1234,
                customerProfileId        = 1234,
                billTo  = CustomerAddress,
                payment = PaymentMaskedType
            };

            var PaymentProfiles = new List <customerPaymentProfileListItemType> {
                paymentProfile
            };

            var mockResponse = new getCustomerPaymentProfileListResponse
            {
                refId               = "1234",
                sessionToken        = "sessiontoken",
                totalNumInResultSet = PaymentProfiles.Count,
                paymentProfiles     = PaymentProfiles.ToArray()
            };

            var errorResponse = new ANetApiResponse();
            var results       = new List <String>();
            const messageTypeEnum messageTypeOk = messageTypeEnum.Ok;

            SetMockControllerExpectations <getCustomerPaymentProfileListRequest, getCustomerPaymentProfileListResponse, getCustomerPaymentProfileListController>(
                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.totalNumInResultSet);
            Assert.IsNotNull(controllerResponse.paymentProfiles);

            LogHelper.info(Logger, "getCustomerPaymentProfileList: Details:{0}", controllerResponse.paymentProfiles);
        }
Example #3
0
        public List <SaveCardViewModel> GetCardInfo(string CustomerProfileId, string ANET_ApiLoginID, string ANET_ApiTransactionKey)
        {
            //SaveCardViewModel saveCardView = new SaveCardViewModel();
            List <SaveCardViewModel> lstsaveCards = new List <SaveCardViewModel>();

            ApiOperationBase <ANetApiRequest, ANetApiResponse> .RunEnvironment = AuthorizeNet.Environment.PRODUCTION;
            // define the merchant information (authentication / transaction id)
            ApiOperationBase <ANetApiRequest, ANetApiResponse> .MerchantAuthentication = new merchantAuthenticationType()
            {
                name            = ANET_ApiLoginID,
                ItemElementName = ItemChoiceType.transactionKey,
                Item            = ANET_ApiTransactionKey,
            };

            var request = new getCustomerProfileRequest();

            request.customerProfileId = CustomerProfileId;

            // instantiate the controller that will call the service
            var controller = new getCustomerProfileController(request);

            controller.Execute();

            // get the response from the service (errors contained if any)
            var response = controller.GetApiResponse();

            if (response != null && response.messages.resultCode == messageTypeEnum.Ok)
            {
                Console.WriteLine(response.messages.message[0].text);
                Console.WriteLine("Customer Profile Id: " + response.profile.customerProfileId);

                if (response.subscriptionIds != null && response.subscriptionIds.Length > 0)
                {
                    Console.WriteLine("List of subscriptions : ");
                    for (int i = 0; i < response.subscriptionIds.Length; i++)
                    {
                        Console.WriteLine(response.subscriptionIds[i]);
                    }
                }
                for (int i = 0; i < response.profile.paymentProfiles.Length; i++)
                {
                    SaveCardViewModel saveCardView = new SaveCardViewModel();
                    if (response.profile.paymentProfiles[i].payment.Item.GetType() == typeof(creditCardMaskedType))
                    {
                        creditCardMaskedType objItem = (creditCardMaskedType)response.profile.paymentProfiles[i].payment.Item;
                        saveCardView.cardNumber               = objItem.cardNumber;
                        saveCardView.cardType                 = objItem.cardType;
                        saveCardView.expirationDate           = objItem.expirationDate;
                        saveCardView.customerPaymentProfileId = response.profile.paymentProfiles[i].customerPaymentProfileId;
                    }
                    else if (response.profile.paymentProfiles[i].payment.Item.GetType() == typeof(bankAccountMaskedType))
                    {
                        bankAccountMaskedType objItem = (bankAccountMaskedType)response.profile.paymentProfiles[i].payment.Item;
                        saveCardView.cardNumber = objItem.accountNumber;
                        saveCardView.cardType   = objItem.bankName;
                        saveCardView.customerPaymentProfileId = response.profile.paymentProfiles[i].customerPaymentProfileId;
                    }
                    lstsaveCards.Add(saveCardView);
                }
            }
            else if (response != null)
            {
                Console.WriteLine("Error: " + response.messages.message[0].code + "  " +
                                  response.messages.message[0].text);
            }

            return(lstsaveCards);
        }