private Boolean CG_CreateFreeCustomerAndInvoices()
    {
        try
        {
            Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];

            //Create a new customer
            CustomerPost newCustomer = new CustomerPost();

            newCustomer.Company = CompanyTextBox.Text;
            newCustomer.FirstName = FirstNameTextBox.Text;
            newCustomer.LastName = LastNameTextBox.Text;
            newCustomer.Email = EmailTextBox.Text;
            newCustomer.CCFirstName = CCFirstNameTextbox.Text;
            newCustomer.CCLastName = CCLastNameTextBox.Text;
            newCustomer.CCNumber = CCNumberTextBox.Text;
            newCustomer.CCExpiration = CCExpirationTextBox.Text;
            newCustomer.CCZip = CCZipTextBox.Text;
            newCustomer.CCCardCode = CCCardCodeTextBox.Text;
            newCustomer.Code = State["application_id"].ToString();

           //For Branding purposes create appropriate branding code.
            if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE)
            {
                newCustomer.PlanCode =  PlanCodeEnum.ANDROID_BRANDING;
            }
            else
            {
                if (State["SelectedDeviceType"].ToString() == Constants.IPHONE)
                {
                    newCustomer.PlanCode = PlanCodeEnum.IOS_BRANDING;
                }
                else
                {
                    RadNotification1.Title = "WARNING";
                    RadNotification1.Text = "This application has no device type.";
                    RadNotification1.Visible = true;
                    RadNotification1.Show();
                    return false;
                }
            }

            //Send it to the server
            CGError servererror = new CGError();
            Customer returnCustomer = CheddarGetter.CreateCustomer(newCustomer, servererror);

            //FAILURE
            if (String.IsNullOrEmpty(servererror.Code) == false)
            {

                //string clickHandler = "this.disabled = false; this.value=\'Submit\'; ";
                // SubmitButton.Attributes.Add("onclick", clickHandler);

                SubmitButton.Enabled = true;
                SubmitButton.Text = "Submit";

                //CG.InnerHtml += "<li>ERROR:" + servererror.Message;
                RadNotification1.Title = "WARNING";
                RadNotification1.Text = servererror.Message;
                RadNotification1.Visible = true;
                RadNotification1.Show();

                return false;
            }

            //SUCCESS
            if (String.IsNullOrEmpty(returnCustomer.Code) == false)
            {
                AppCGCustomerCode = returnCustomer.Code;
            }

            // IF SUCCESSFULLY ABLE TO CREATE THE FREE NATIVE CUSTOMER THEN KICK OFF A ONE TIME INVOICE FOR BRANDING

            OneTimeInvoicePost myonetimeinvoice = new OneTimeInvoicePost();

            myonetimeinvoice.InvoiceCharges = new CustomChargePost[1];

            int number_of_charges = 0;
            CustomChargePost mycustom1 = new CustomChargePost();

            mycustom1.CustomerCode = AppCGCustomerCode;
            mycustom1.Description = "Branding";
            mycustom1.ChargeCode = "BRANDING ";
            mycustom1.EachAmount = 0;
            mycustom1.Quantity = 0;

            if ((State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE || State["SelectedDeviceType"].ToString() == Constants.ANDROID_TABLET) && (String.IsNullOrEmpty(AppCGCustomerCode) == false))
            {
                mycustom1.ChargeCode += "- ANRDOID";
                mycustom1.CustomerCode = AppCGCustomerCode;
                mycustom1.Quantity = 1;
                mycustom1.EachAmount += 99;
                mycustom1.Description += "- Android";
            }

            if ((State["SelectedDeviceType"].ToString() == Constants.IPHONE || State["SelectedDeviceType"].ToString() == Constants.IPAD) && (String.IsNullOrEmpty(AppCGCustomerCode) == false))
            {
                mycustom1.ChargeCode += "- iOS";
                mycustom1.Quantity = 1;
                mycustom1.EachAmount += 99;
                mycustom1.Description += "- iOS";
            }

            myonetimeinvoice.InvoiceCharges[number_of_charges] = new CustomChargePost();
            myonetimeinvoice.InvoiceCharges[number_of_charges] = mycustom1;

            CGError servererror2 = new CGError();
            //SERVER CALL TO THE ONE TIME INVOICE for both charges at once.
            Customer returnCustomer2 = CheddarGetter.CreateOneTimeInvoice(myonetimeinvoice, servererror2);

            if (String.IsNullOrEmpty(servererror2.Code) == false)
            {
                //CG.InnerHtml += "<li>ERROR:" + servererror2.Message;

                SubmitButton.Enabled = true;
                SubmitButton.Text = "Submit";

                //string clickHandler = "this.disabled = false; this.value=\'Submit\'; ";
                //SubmitButton.Attributes.Add("onclick", clickHandler);

                RadNotification1.Title = "WARNING";
                RadNotification1.Text = servererror2.Message;
                RadNotification1.Visible = true;
                RadNotification1.Show();

                return false;
            }

            //Store in the PaidServicesDB
            BillingUtil billingutil = new BillingUtil();

            //Record the new SKU but do not turn on the 'paid' field as yet.

            string confirm = returnCustomer2.Subscriptions[0].Invoices[1].PaidTransactionId.ToString();

            string sku = returnCustomer2.Subscriptions[0].SubscriptionsPlans[0].Code.ToString();
            billingutil.StorePaidServicesDB(confirm,sku,State,false);

            //Enable 10 day grace for App store Approval.
            Util util = new Util();
            util.SetFreeProductionExpiration(State, DateTime.Now.ToUniversalTime().AddDays(10.0D));

            //Send Email to Support.
            System.Text.StringBuilder body = new System.Text.StringBuilder("Customer Username: "******"Username"].ToString() + "\n");
            body.Append("App Name: " + State["SelectedApp"].ToString() + "\n");
            body.Append("\n-- ViziApps Support");
            Email email = new Email();
            string status = email.SendEmail(State,  HttpRuntime.Cache["TechSupportEmail"].ToString(),  HttpRuntime.Cache["TechSupportEmail"].ToString(),"", "", "Customer submitted App for App Store Preparation", body.ToString(), "", false);

            return true;

        }//end try

        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message.ToString() + ex.StackTrace.ToString());

        }

        return false;
    }
Пример #2
0
    //shyam
    public static Customer CreateOneTimeInvoice(OneTimeInvoicePost onetimeinvoice, CGError error)
    {
        Customers customers = new Customers();
            Customer editCustomer = new Customer();

            try
            {
                string urlBase = "https://cheddargetter.com/xml";

                string urlPath = string.Format("/invoices/new/productCode/{0}/code/{1}", _ProductCode, onetimeinvoice.InvoiceCharges[0].CustomerCode);
                string postParams = "";

                int i = 0;
                foreach (CustomChargePost charge in onetimeinvoice.InvoiceCharges)
                {
                    if (charge != null)
                    {
                        string tmp = string.Format("&charges[{0}][chargeCode]={1}&charges[{0}][quantity]={2}&charges[{0}][eachAmount]={3}&charges[{0}][description]={4}",
                                                   i++,
                                                   HttpUtility.UrlEncode(charge.ChargeCode),
                                                   HttpUtility.UrlEncode(charge.Quantity.ToString()),
                                                   HttpUtility.UrlEncode(charge.EachAmount.ToString()),
                                                   HttpUtility.UrlEncode(charge.Description));
                        postParams += tmp;
                    }
                }

                System.Diagnostics.Debug.WriteLine(postParams);

                string result = postRequest(urlBase, urlPath, postParams);
                XDocument newCustomerXML = XDocument.Parse(result);

                customers = getCustomerList(newCustomerXML);

                if (customers.CustomerList.Count > 0)
                {
                    editCustomer = customers.CustomerList[0];
                }

            }

            //shyam
            catch (System.Net.WebException ex)
            {
                processWebException(ex, error);
            }
            //shyam

            catch (Exception ex)
            {
                throw ex;
            }

            return editCustomer;
    }