Example #1
0
        public Transaction ChargeCardForInvoice(Invoice inv, MerchantTribe.Payment.Method method)
        {
            Transaction t = new Transaction();

            t.Action = MerchantTribe.Payment.ActionType.CreditCardCharge;

            if (inv != null)
            {
                BillingAccount account = Accounts.FindById(inv.AccountId);
                if (account != null)
                {
                    if (!account.HasValidCreditCard(DateTime.Now))
                    {
                        t.Messages += "Billing Account does not have a valid credit card on file.";
                    }
                    else
                    {
                        t.AccountId        = inv.AccountId;
                        t.InvoiceReference = inv.Id.ToString();

                        MerchantTribe.Payment.Transaction payTrans = new MerchantTribe.Payment.Transaction();
                        payTrans.Action = MerchantTribe.Payment.ActionType.CreditCardCharge;
                        payTrans.Amount = inv.TotalGrand();
                        payTrans.Card   = account.CreditCard;
                        payTrans.Customer.PostalCode   = account.BillingZipCode;
                        payTrans.MerchantDescription   = "BV Software";
                        payTrans.MerchantInvoiceNumber = inv.Id.ToString();

                        method.ProcessTransaction(payTrans);

                        t.PopulateFromPaymentTransaction(payTrans);
                    }
                }
                else
                {
                    t.Messages += "Billing Account could not be located";
                }
            }
            else
            {
                t.Messages += "Invoice was null.";
            }

            t = Transactions.CreateAndLoad(t);

            return(t);
        }
        public Store CreateAndSetupStore(string storeName,
                                         long userAccountId,
                                         string friendlyName,
                                         int plan,
                                         decimal rate,
                                         MerchantTribe.Billing.BillingAccount billingAccount)
        {
            Store s = null;

            if (StoreNameExists(storeName))
            {
                throw new CreateStoreException("That store name is not available. Please choose another name and try again.");
            }

            s             = new Store();
            s.StoreName   = Text.ForceAlphaNumericOnly(storeName).ToLower();
            s.Status      = StoreStatus.Active;
            s.DateCreated = DateTime.UtcNow;
            s.PlanId      = plan;
            s.CustomUrl   = string.Empty;

            if (!Stores.Create(s))
            {
                throw new CreateStoreException("Unable to create store. Unknown error. Please contact an administrator for assistance.");
            }

            s = Stores.FindByStoreName(s.StoreName);
            if (s != null)
            {
                AddUserToStore(s.Id, userAccountId, StoreAccessMode.Owner);

                s.Settings.FriendlyName         = friendlyName;
                s.Settings.MailServer.FromEmail = "*****@*****.**";
                s.Settings.LastOrderNumber      = 0;
                s.Settings.LogoImage            = "[[default]]";
                s.Settings.LogoRevision         = 0;
                s.Settings.UseLogoImage         = false;
                s.Settings.LogoText             = s.StoreName;
                s.Settings.MinumumOrderAmount   = 0;

                // Send Reminder of account information to new user
                Accounts.UserAccount u = AdminUsers.FindById(userAccountId);

                s.Settings.MailServer.EmailForGeneral     = u.Email;
                s.Settings.MailServer.EmailForNewOrder    = u.Email;
                s.Settings.MailServer.UseCustomMailServer = false;
                s.Settings.ProductReviewCount             = 3;
                s.Settings.ProductReviewModerate          = true;
                s.Settings.ProductReviewShowRating        = true;
                s.Settings.PayPal.FastSignupEmail         = u.Email;
                s.Settings.PayPal.Currency   = "USD";
                s.Settings.MaxItemsPerOrder  = 999;
                s.Settings.MaxWeightPerOrder = 9999;
                s.Settings.MaxOrderMessage   = "That's a really big order! Call us instead of ordering online.";

                s.CurrentPlanRate       = rate;
                s.CurrentPlanDayOfMonth = DateTime.Now.Day;
                if (s.CurrentPlanDayOfMonth > 28)
                {
                    s.CurrentPlanDayOfMonth = 28;
                }
                HostedPlan thePlan = HostedPlan.FindById(s.PlanId);
                if (thePlan != null)
                {
                    s.CurrentPlanPercent = thePlan.PercentageOfSales;
                }
                else
                {
                    if (plan == 0)
                    {
                        s.CurrentPlanPercent = 0;
                    }
                    else
                    {
                        s.CurrentPlanPercent = 0;
                    }
                }

                // Save data to store
                Stores.Update(s);

                // Create Billing Accout
                MerchantTribe.Billing.Service svc = new MerchantTribe.Billing.Service(WebAppSettings.ApplicationConnectionString);
                BillingAccount act = svc.Accounts.FindOrCreate(billingAccount);


                Utilities.MailServices.SendLeadAlert(u, s);
                Utilities.MailServices.SendAccountInformation(u, s);
            }

            return(s);
        }