public void MockvalidateCustomerPaymentProfileTest()
        {
            //define all mocked objects as final
            var mockController = GetMockController <validateCustomerPaymentProfileRequest, validateCustomerPaymentProfileResponse>();
            var mockRequest    = new validateCustomerPaymentProfileRequest
            {
                merchantAuthentication = new merchantAuthenticationType {
                    name = "mocktest", Item = "mockKey", ItemElementName = ItemChoiceType.transactionKey
                },
            };
            var mockResponse = new validateCustomerPaymentProfileResponse
            {
                refId          = "1234",
                sessionToken   = "sessiontoken",
                directResponse = "direct",
            };

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

            SetMockControllerExpectations <validateCustomerPaymentProfileRequest, validateCustomerPaymentProfileResponse, validateCustomerPaymentProfileController>(
                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.directResponse);
            LogHelper.info(Logger, "validateCustomerPaymentProfile: Details:{0}", controllerResponse.directResponse);
        }
        private void LoadModule()
        {
            AuthNetConfig authNetConfig = new AuthNetConfig();

            ltlAuthNetName.Text           = authNetConfig.Settings.Name;
            ltlAuthNetApiKey.Text         = authNetConfig.Settings.ApiKey;
            ltlAuthNetTransactionKey.Text = authNetConfig.Settings.TransactionKey;
            ltlAuthNetMode.Text           = authNetConfig.Settings.TestMode ? "Test Mode" : "Live Mode";

            try
            {
                CustomerInformationManager cim     = new CustomerInformationManager();
                hccUserProfile             profile = hccUserProfile.GetRootProfiles().First(a => a.AuthNetProfileID != null);

                validateCustomerPaymentProfileResponse valProfile =
                    cim.ValidateProfile(profile.AuthNetProfileID, profile.ActivePaymentProfile.AuthNetPaymentProfileID, AuthorizeNet.ValidationMode.TestMode);

                if (valProfile.messages.resultCode == messageTypeEnum.Ok)
                {
                    lblTest.Text = "Test Validation Successful.";
                }
                else
                {
                    lblTest.Text = "Test Validation Failed.";
                }
            }
            catch (Exception ex)
            {
                lblTest.Text = "Test Connection Failed." + ex.Message + ex.StackTrace;
            }
            //List<TestCard> cards = new List<TestCard>();

            //foreach(TestCard card in credentials.TestCards)
            //{
            //    cards.Add(card);
            //}

            //TestCards.DataSource = cards;
            //TestCards.DataBind();
        }
Example #3
0
        protected override void SaveForm()
        {
            hccUserProfile userProfile = hccUserProfile.GetById(CurrentUserProfileID);
            Address        billAddr    = null;

            if (userProfile != null)
            {
                //Save CardInfo
                if (pnlCardInfo.Visible)
                {
                    CurrentCardInfo.NameOnCard   = txtNameOnCard.Text.Trim();
                    CurrentCardInfo.CardNumber   = txtCCNumber.Text.Trim();
                    CurrentCardInfo.CardType     = ValidateCardNumber(txtCCNumber.Text.Trim());
                    CurrentCardInfo.ExpMonth     = int.Parse(ddlExpMonth.SelectedValue);
                    CurrentCardInfo.ExpYear      = int.Parse(ddlExpYear.SelectedValue);
                    CurrentCardInfo.SecurityCode = txtCCAuthCode.Text.Trim();
                }

                if (userProfile.BillingAddressID.HasValue)
                {
                    billAddr = hccAddress.GetById(userProfile.BillingAddressID.Value).ToAuthNetAddress();
                }

                if (CurrentCardInfo.HasValues && billAddr != null)
                {
                    try
                    {
                        //send card to Auth.net for Auth.net profile
                        CustomerInformationManager cim = new CustomerInformationManager();
                        Customer cust         = null;
                        string   autnetResult = string.Empty;

                        if (!string.IsNullOrWhiteSpace(userProfile.AuthNetProfileID))
                        {
                            cust = cim.GetCustomer(userProfile.AuthNetProfileID);
                        }

                        //Will Martinez - Commented out on 7/30/2013.
                        //This code scans all existing Profiles generated to check for duplicated email addresses, however the site registration prevents that
                        //commented out since this process had a significant performance effect on the site.
                        //if (cust == null)
                        //    cust = cim.GetCustomerByEmail(userProfile.ASPUser.Email);

                        if (cust == null)
                        {
                            cust = cim.CreateCustomer(userProfile.ASPUser.Email, userProfile.ASPUser.UserName);
                        }

                        // had to add it back in, unable to create records with duplicate email addresses caused by IT desynching data.
                        // this should only be called infrequently since we try to create the account first.
                        if (cust.ProfileID == null)
                        {
                            cust = cim.GetCustomerByEmail(userProfile.ASPUser.Email, out autnetResult);
                        }
                        if (cust != null)
                        {
                            if (userProfile.AuthNetProfileID != cust.ProfileID)
                            {
                                userProfile.AuthNetProfileID = cust.ProfileID;
                                userProfile.Save();
                            }

                            List <PaymentProfile> payProfiles = cust.PaymentProfiles.ToList();

                            if (payProfiles.Count > 0)
                            {
                                payProfiles.ForEach(a => cim.DeletePaymentProfile(userProfile.AuthNetProfileID, a.ProfileID));
                            }

                            // create new payment profile
                            autnetResult = cim.AddCreditCard(cust, CurrentCardInfo.CardNumber, CurrentCardInfo.ExpMonth,
                                                             CurrentCardInfo.ExpYear, CurrentCardInfo.SecurityCode, billAddr);

                            if (!string.IsNullOrWhiteSpace(autnetResult))
                            {
                                // Validate card profile
                                validateCustomerPaymentProfileResponse valProfile = cim.ValidateProfile(userProfile.AuthNetProfileID,
                                                                                                        autnetResult, AuthorizeNet.ValidationMode.TestMode);

                                if (valProfile.messages.resultCode == messageTypeEnum.Ok)
                                {
                                    hccUserProfilePaymentProfile activePaymentProfile = null;
                                    activePaymentProfile = userProfile.ActivePaymentProfile;

                                    if (userProfile.ActivePaymentProfile == null)
                                    {
                                        activePaymentProfile = new hccUserProfilePaymentProfile();
                                    }

                                    activePaymentProfile.CardTypeID    = (int)CurrentCardInfo.CardType;
                                    activePaymentProfile.CCLast4       = CurrentCardInfo.CardNumber.Substring(CurrentCardInfo.CardNumber.Length - 4, 4);
                                    activePaymentProfile.ExpMon        = CurrentCardInfo.ExpMonth;
                                    activePaymentProfile.ExpYear       = CurrentCardInfo.ExpYear;
                                    activePaymentProfile.NameOnCard    = CurrentCardInfo.NameOnCard;
                                    activePaymentProfile.UserProfileID = userProfile.UserProfileID;
                                    activePaymentProfile.IsActive      = true;

                                    activePaymentProfile.AuthNetPaymentProfileID = autnetResult;
                                    activePaymentProfile.Save();
                                    this.PrimaryKeyIndex = activePaymentProfile.PaymentProfileID;

                                    OnSaved(new ControlSavedEventArgs(this.PrimaryKeyIndex));
                                    lblFeedback.Text = "Payment Profile has been created and validated.";
                                }
                                else
                                {
                                    lblFeedback.Text = "Payment Profile has been created, but validation failed.";
                                }
                            }
                            else
                            {
                                lblFeedback.Text = "Authorize.Net response is empty.";
                            }
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(autnetResult))
                            {
                                lblErrorOnAuth.Text = autnetResult;
                            }
                            OnCardInfoSaveFailed(new CardInfoSaveFailedEventArgs(new Exception(autnetResult)));
                        }
                    }
                    catch { throw; }
                }
            }
        }