Ejemplo n.º 1
0
        public void DoSampleCode()
        {
            ChargifyConnect chargify = new ChargifyConnect();

            chargify.apiKey   = ConfigurationManager.AppSettings["CHARGIFY_API_KEY"];
            chargify.Password = ConfigurationManager.AppSettings["CHARGIFY_API_PASSWORD"];
            chargify.URL      = ConfigurationManager.AppSettings["CHARGIFY_URL"];
            chargify.UseJSON  = true;

            // Retrieve a dictionary of all your customers
            IDictionary <string, ICustomer> customerList = chargify.GetCustomerList();

            if (customerList.Count > 0)
            {
                ICustomer customer = customerList.First().Value as ICustomer;

                Console.WriteLine(string.Format("First Name: {0}", customer.FirstName));
                Console.WriteLine(string.Format("Last Name: {0}", customer.LastName));

                customer.FirstName = "Miguel";

                customer = chargify.UpdateCustomer(customer);

                if (customer != null)
                {
                    // update success
                    Console.WriteLine("Customer update succeeded.");
                }
                else
                {
                    // update failure.
                    Console.WriteLine("Update customer failed with response: ", chargify.LastResponse.ToString());
                }

                Console.WriteLine(string.Format("First Name: {0}", customer.FirstName));
            }

            // You can create a new customer in two steps
            //ICustomer newCustomer = new Customer("Charlie", "Bull", "*****@*****.**", "Chargify", Guid.NewGuid());
            //chargify.CreateCustomer(newCustomer);

            // Or just one ..
            ICustomer newCustomer = chargify.CreateCustomer("Charlie", "Bull", "*****@*****.**", string.Empty, "Chargify", Guid.NewGuid().ToString());
        }
Ejemplo n.º 2
0
        public void DoSampleCode()
        {
            ChargifyConnect chargify = new ChargifyConnect();
            chargify.apiKey = ConfigurationManager.AppSettings["CHARGIFY_API_KEY"];
            chargify.Password = ConfigurationManager.AppSettings["CHARGIFY_API_PASSWORD"];
            chargify.URL = ConfigurationManager.AppSettings["CHARGIFY_URL"];
            chargify.UseJSON = true;

            // Retrieve a dictionary of all your customers
            IDictionary<string, ICustomer> customerList = chargify.GetCustomerList();

            if (customerList.Count > 0) 
            {
                ICustomer customer = customerList.First().Value as ICustomer;

                Console.WriteLine(string.Format("First Name: {0}", customer.FirstName));
                Console.WriteLine(string.Format("Last Name: {0}", customer.LastName));

                customer.FirstName = "Miguel";

                customer = chargify.UpdateCustomer(customer);

                if (customer != null)
                {
                    // update success
                    Console.WriteLine("Customer update succeeded.");
                }
                else
                {
                    // update failure.
                    Console.WriteLine("Update customer failed with response: ", chargify.LastResponse.ToString());
                }

                Console.WriteLine(string.Format("First Name: {0}", customer.FirstName));
            }

            // You can create a new customer in two steps
            //ICustomer newCustomer = new Customer("Charlie", "Bull", "*****@*****.**", "Chargify", Guid.NewGuid());
            //chargify.CreateCustomer(newCustomer);

            // Or just one .. 
            ICustomer newCustomer = chargify.CreateCustomer("Charlie", "Bull", "*****@*****.**", string.Empty, "Chargify", Guid.NewGuid().ToString());
        }
Ejemplo n.º 3
0
        public bool PostOrder(int orderId)
        {
            bool  result    = false;
            Order orderItem = new OrderManager().GetBatchProcessOrder(orderId);


            orderItem.LoadAttributeValues();
            ChargifyConnect chargify = new ChargifyConnect();

            chargify.apiKey   = config.Attributes["APIKey"].Value;
            chargify.Password = config.Attributes["Password"].Value;
            chargify.URL      = config.Attributes["site"].Value;

            // Retrieve a list of all your products
            //IDictionary<int, IProduct> products = chargify.GetProductList();

            // Create a new customer
            ICustomer newCustomer = chargify.CreateCustomer(orderItem.CustomerInfo.ShippingAddress.FirstName, orderItem.CustomerInfo.ShippingAddress.LastName, orderItem.Email, "ConversionSystems", "CS_" + "DC_" + orderItem.OrderId.ToString());

            newCustomer.Email           = orderItem.Email;
            newCustomer.ShippingAddress = orderItem.CustomerInfo.ShippingAddress.Address1 + "," + orderItem.CustomerInfo.ShippingAddress.Address2;
            newCustomer.ShippingCity    = orderItem.CustomerInfo.ShippingAddress.City;
            newCustomer.ShippingCountry = orderItem.CustomerInfo.ShippingAddress.CountryCode;
            newCustomer.ShippingState   = orderItem.CustomerInfo.ShippingAddress.StateProvinceName;
            newCustomer.ShippingZip     = orderItem.CustomerInfo.ShippingAddress.ZipPostalCode;


            // Create a new customer and subscription
            //ICustomerAttributes charlie = new CustomerAttributes(orderItem.CustomerInfo.BillingAddress.FirstName, orderItem.CustomerInfo.BillingAddress.LastName, orderItem.Email, "", "CS_" + "DC_" + orderItem.OrderId.ToString());
            //charlie.ShippingAddress = orderItem.CustomerInfo.ShippingAddress.Address1 + "," + orderItem.CustomerInfo.ShippingAddress.Address2;
            //charlie.ShippingCity = orderItem.CustomerInfo.ShippingAddress.City;
            //charlie.ShippingCountry = orderItem.CustomerInfo.ShippingAddress.CountryCode;
            //charlie.ShippingState = orderItem.CustomerInfo.ShippingAddress.StateProvinceName;
            //charlie.ShippingZip = orderItem.CustomerInfo.ShippingAddress.ZipPostalCode;

            ICreditCardAttributes charliesPaymentInfo = new CreditCardAttributes();

            charliesPaymentInfo.FirstName       = orderItem.CustomerInfo.BillingAddress.FirstName;
            charliesPaymentInfo.LastName        = orderItem.CustomerInfo.BillingAddress.LastName;
            charliesPaymentInfo.ExpirationMonth = Convert.ToInt32(orderItem.CreditInfo.CreditCardExpired.ToString("MM"));
            charliesPaymentInfo.ExpirationYear  = Convert.ToInt32(orderItem.CreditInfo.CreditCardExpired.ToString("yyyy"));
            charliesPaymentInfo.FullNumber      = orderItem.CreditInfo.CreditCardNumber;
            charliesPaymentInfo.CVV             = orderItem.CreditInfo.CreditCardCSC;
            charliesPaymentInfo.BillingAddress  = orderItem.CustomerInfo.BillingAddress.Address1 + "," + orderItem.CustomerInfo.BillingAddress.Address2;
            charliesPaymentInfo.BillingCity     = orderItem.CustomerInfo.BillingAddress.City;
            charliesPaymentInfo.BillingCountry  = orderItem.CustomerInfo.BillingAddress.CountryCode;
            charliesPaymentInfo.BillingState    = orderItem.CustomerInfo.BillingAddress.StateProvinceName;
            charliesPaymentInfo.BillingZip      = orderItem.CustomerInfo.BillingAddress.ZipPostalCode;
            ISubscription newSubscription;
            Dictionary <string, AttributeValue> orderAttributes = new Dictionary <string, AttributeValue>();

            foreach (Sku Item in orderItem.SkuItems)
            {
                try
                {
                    newSubscription = chargify.CreateSubscription(Item.SkuCode.ToLower(), newCustomer.ChargifyID, charliesPaymentInfo);
                    if (newSubscription == null)
                    {
                        orderAttributes.Add("ChargifyCustomerId", new CSBusiness.Attributes.AttributeValue(newCustomer.ChargifyID.ToString()));
                        orderAttributes.Add("ChargifySubscriptionId", new CSBusiness.Attributes.AttributeValue(newSubscription.SubscriptionID.ToString()));
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
                catch { }
            }

            if (result)
            {
                CSResolve.Resolve <IOrderService>().UpdateOrderAttributes(orderId, orderAttributes, 2);
            }
            else
            {
                CSResolve.Resolve <IOrderService>().UpdateOrderAttributes(orderId, orderAttributes, 7);
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static bool RegisterCreditCard(ChargifyConnect chargify, Guid OrgId, Guid InstId, string OrgName, string InstName, string UserEmail, string UserFirstName, string UserLastName, string CardNumber, string CardExprMonth, string CardExprYear, int GraceDays, out string errorMessage)
        {
            errorMessage = string.Empty;
            string _CustSystemId = OrgId.ToString() + "," + InstId.ToString();

            ICustomer     _cust   = chargify.LoadCustomer(_CustSystemId);
            ISubscription _subscr = null;

            try
            {
                if (_cust == null)
                {
                    errorMessage       = "Can't create Chargify Customer!";
                    _cust              = new Customer();
                    _cust.SystemID     = _CustSystemId;
                    _cust.Organization = OrgName + " " + InstName;
                    _cust.Email        = UserEmail;
                    _cust.FirstName    = UserFirstName;
                    _cust.LastName     = UserLastName;
                    _cust              = chargify.CreateCustomer(_cust);
                }
                else if (_cust.Organization != OrgName + " " + InstName || _cust.Email != UserEmail || _cust.FirstName != UserFirstName || _cust.LastName != UserLastName)
                {
                    errorMessage       = "Can't update Chargify Customer!";
                    _cust.Organization = OrgName + " " + InstName;
                    _cust.Email        = UserEmail;
                    _cust.FirstName    = UserFirstName;
                    _cust.LastName     = UserLastName;
                    _cust        = chargify.UpdateCustomer(_cust);
                    errorMessage = "Can't get Chargify Customer Substriction!";
                    _subscr      = ChargifyProvider.GetCustomerSubscription(chargify, _cust.ChargifyID);
                }
                else
                {
                    errorMessage = "Can't get Chargify Customer Substriction!";
                    _subscr      = ChargifyProvider.GetCustomerSubscription(chargify, _cust.ChargifyID);
                }
            }
            catch (ChargifyException cex)
            {
                if ((int)cex.StatusCode != 422)
                {
                    errorMessage += " " + cex.Message;
                }
                return(false);
            }
            catch (Exception ex)
            {
                errorMessage += " " + ex.Message;
                return(false);
            }

            errorMessage = string.Empty;

            if (CardNumber.Contains("XXXX"))
            {
                if (_subscr != null && _subscr.CreditCard != null && _subscr.State != SubscriptionState.Active)
                {
                    try
                    {
                        chargify.ReactivateSubscription(_subscr.SubscriptionID);
                    }
                    catch (Exception ex)
                    {
                        errorMessage = "Can't reactivate Customer Subscription! " + ex.Message;
                        return(false);
                    }
                    return(true);
                }
                errorMessage = "Invalid Credit Card Information!";
                return(false);
            }

            CreditCardAttributes _ccattr = new CreditCardAttributes(_cust.FirstName, _cust.LastName, CardNumber, 2000 + int.Parse(CardExprYear), int.Parse(CardExprMonth), string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty);

            try
            {
                if (_subscr == null)
                {
                    errorMessage = "Can't create Chargify Subscription!";
                    _subscr      = chargify.CreateSubscription(ChargifyProvider.GetProductHandle(), _cust.ChargifyID, _ccattr);
                    chargify.UpdateBillingDateForSubscription(_subscr.SubscriptionID, DateTime.UtcNow.AddDays(GraceDays));
                }
                else
                {
                    errorMessage = "Can't update Chargify Subscription!";
                    chargify.UpdateSubscriptionCreditCard(_subscr, _ccattr);
                    if (_subscr.State != SubscriptionState.Active)
                    {
                        chargify.ReactivateSubscription(_subscr.SubscriptionID);
                    }
                }
            }
            catch (ChargifyException cex)
            {
                if ((int)cex.StatusCode == 422)
                {
                    errorMessage += " Invalid Credit Card Information!";
                }
                else
                {
                    errorMessage += " " + cex.Message;
                }
                return(false);
            }
            catch (Exception ex)
            {
                errorMessage += " " + ex.Message;
                return(false);
            }

            errorMessage = string.Empty;
            return(true);
        }