Exemplo n.º 1
0
        public CIMResponse AuthCapture(Int64 profileId, Int64 paymentProfileId, int orderNumber, decimal amount)
        {
            ServiceProcessContext serviceCtx = new ServiceProcessContext();

            var orderType           = ServiceTools.CreateOrderExType(orderNumber.ToString(), string.Empty, string.Empty);
            var authTransactionType = ServiceTools.CreateProfileTransAuthCaptureType(profileId, paymentProfileId, orderType, amount);
            var transactionType     = ServiceTools.CreateProfileTransactionType(authTransactionType);

            var transactionResponse = serviceCtx.Service.CreateCustomerProfileTransaction(serviceCtx.MerchantAuthenticationType, transactionType, string.Empty);

            Trace.WriteLine(transactionResponse.directResponse);

            foreach (var message in transactionResponse.messages)
            {
                Trace.WriteLine(string.Format("{0}: {1}", message.code, message.text));
            }

            if (transactionResponse.directResponse == null)
            {
                //if directResponse is empty, the first message will say why
                return(new CIMResponse()
                {
                    AuthMessage = transactionResponse.messages[0].text,
                    Success = false
                });
            }
            else
            {
                return(ServiceTools.ParseDirectResponse(transactionResponse.directResponse));
            }
        }
Exemplo n.º 2
0
        public bool UpdateProfile(string newEmail, string profileDescription)
        {
            var serviceCtx = new ServiceProcessContext();

            var customerProfile = ServiceTools.CreateCustomerProfileExType(this.ProfileId, this.CustomerId, newEmail, profileDescription);
            var response        = serviceCtx.Service.UpdateCustomerProfile(serviceCtx.MerchantAuthenticationType, customerProfile);

            return(response.resultCode == MessageTypeEnum.Ok);
        }
Exemplo n.º 3
0
        public CIMResponse UpdatePaymentProfile(long paymentProfileId, CustomerAddressType address, string creditCardNumber, string cardCode, Int32 expMonth, Int32 expYear)
        {
            var serviceCtx = new ServiceProcessContext();

            string expDate            = ServiceTools.GetAuthNetExpirationDate(expMonth, expYear);
            var    paymentType        = ServiceTools.CreatePaymentType(creditCardNumber, cardCode, expDate);
            var    paymentProfileType = ServiceTools.CreatePaymentProfileExType(paymentProfileId, address, paymentType);

            var response = serviceCtx.Service.UpdateCustomerPaymentProfile(serviceCtx.MerchantAuthenticationType, this.ProfileId, paymentProfileType, ValidationMode);

            return(ServiceTools.ParseDirectResponse(response.validationDirectResponse));
        }
Exemplo n.º 4
0
        public static ProfileManager CreateProfile(int customerId, string email, out string errorMessage)
        {
            errorMessage = string.Empty;

            //force profileDescription to always be the same
            string profileDescription = GetProfileDescription(storeName: string.Empty);
            var    customerProfile    = ServiceTools.CreateCustomerProfileType(customerId, email, profileDescription);

            var serviceCtx = new ServiceProcessContext();
            var response   = serviceCtx.Service.CreateCustomerProfile(serviceCtx.MerchantAuthenticationType, customerProfile, ValidationModeEnum.none);

            ProfileManager profile = null;

            //If we have a duplicate customer record try to delete it and re-create
            //This should solve issues caused by auth.net accounts being switched for the site
            if (response.resultCode == MessageTypeEnum.Error && response.messages[0].code.ToUpper() == "E00039")
            {
                //if we have a duplicate account try to get the account profile from the error message
                string[] strAry = response.messages[0].text.Split(' ');
                foreach (string str in strAry)
                {
                    long custProfId;
                    if (long.TryParse(str, out custProfId))
                    {
                        //if we have an existing profile then delete it and start over
                        profile = new ProfileManager(customerId, email, custProfId);
                        if (profile.DeleteProfile())
                        {
                            response = serviceCtx.Service.CreateCustomerProfile(serviceCtx.MerchantAuthenticationType, customerProfile, ValidationModeEnum.none);
                        }

                        //reset our profile for normal processing below
                        profile = null;
                    }
                }
            }

            if (response.resultCode == MessageTypeEnum.Ok)
            {
                profile = new ProfileManager(customerId, email, response.customerProfileId);
            }
            else if (response.resultCode == MessageTypeEnum.Error)
            {
                errorMessage = response.messages[0].text;
            }

            return(profile);
        }
Exemplo n.º 5
0
        public CIMResponse Capture(Int64 profileId, Int64 paymentProfileId, string authCode, decimal amount)
        {
            ServiceProcessContext serviceCtx = new ServiceProcessContext();

            var profileTransactionType = ServiceTools.CreateProfileTransCaptureOnlyType(profileId, paymentProfileId, authCode, amount);
            var transactionType        = ServiceTools.CreateProfileTransactionType(profileTransactionType);

            var transactionResponse = serviceCtx.Service.CreateCustomerProfileTransaction(serviceCtx.MerchantAuthenticationType, transactionType, string.Empty);

            Trace.WriteLine(transactionResponse.directResponse);

            foreach (var message in transactionResponse.messages)
            {
                Trace.WriteLine(string.Format("{0}: {1}", message.code, message.text));
            }

            return(ServiceTools.ParseDirectResponse(transactionResponse.directResponse));
        }
Exemplo n.º 6
0
        public CIMResponse CreatePaymentProfile(CustomerAddressType address, string creditCardNumber, string cardCode, Int32 expMonth, Int32 expYear)
        {
            var serviceCtx = new ServiceProcessContext();

            string expDate            = ServiceTools.GetAuthNetExpirationDate(expMonth, expYear);
            var    paymentType        = ServiceTools.CreatePaymentType(creditCardNumber, cardCode, expDate);
            var    paymentProfileType = ServiceTools.CreatePaymentProfileType(address, paymentType);

            var response = serviceCtx.Service.CreateCustomerPaymentProfile(serviceCtx.MerchantAuthenticationType, this.ProfileId, paymentProfileType, ValidationMode);

            var retResponse = ServiceTools.ParseDirectResponse(response.validationDirectResponse);

            if (response.resultCode == MessageTypeEnum.Error)
            {
                retResponse.ErrorMessage = response.messages[0].text;
                retResponse.ErrorCode    = response.messages[0].code;
                retResponse.Success      = false;
            }
            retResponse.PaymentProfileId = response.customerPaymentProfileId;
            return(retResponse);
        }
        public ServiceProcessContext()
        {
            String liveUrl        = AspDotNetStorefrontCore.AppLogic.AppConfig("AUTHORIZENET_Cim_LiveServiceURL");
            String testUrl        = AspDotNetStorefrontCore.AppLogic.AppConfig("AUTHORIZENET_Cim_SandboxServiceURL");
            String merchantId     = AspDotNetStorefrontCore.AppLogic.AppConfig("AUTHORIZENET_X_Login");
            String transactionKey = AspDotNetStorefrontCore.AppLogic.AppConfig("AUTHORIZENET_X_Tran_Key");
            bool   sandboxEnabled = AspDotNetStorefrontCore.AppLogic.AppConfigBool("AUTHORIZENET_Cim_UseSandbox");

            System.ServiceModel.BasicHttpBinding binding = new System.ServiceModel.BasicHttpBinding();
            binding.Security.Mode = System.ServiceModel.BasicHttpSecurityMode.Transport;

            string url = liveUrl;

            if (sandboxEnabled)
            {
                url = testUrl;
            }

            System.ServiceModel.EndpointAddress endpointAddress = new System.ServiceModel.EndpointAddress(url);

            Service = new ServiceSoapClient(binding, endpointAddress);

            MerchantAuthenticationType = ServiceTools.CreateMerchantAuthenticationType(merchantId, transactionKey);
        }