public async Task <ActionResult <PricingPlan> > GetPricingPlanByOrg(int id)
        {
            Organization organization = await unitOfWork.Organizations.SingleOrDefault(o => o.Id == id);

            if (organization == null)
            {
                return(NotFound());
            }
            AppUser user = await userManager.GetUserAsync(User);

            user = unitOfWork.AppUsers.GetUserWithOrgs(user.Id);
            if (user.IsOwnerOfOrg(id))
            {
                PricingPlan pricingPlan = await unitOfWork.PricingPlans.SingleOrDefault(pPlan => pPlan.Id == organization.PricingPlanId);

                if (pricingPlan == null)
                {
                    return(NotFound());
                }
                PricingPlanDto pricingPlanDto = Mapper.Map <PricingPlanDto>(pricingPlan);
                return(Ok(pricingPlanDto));
            }
            else
            {
                return(Unauthorized("You are not an owner!"));
            }
        }
        public async Task <IActionResult> PutPricingPlan(int id, [FromBody] PricingPlanDto pricingPlanVM)
        {
            PricingPlan pPlan = await unitOfWork.PricingPlans.SingleOrDefault(p => p.Id == id);

            if (pPlan == null || pPlan.Id != id)
            {
                return(NotFound());
            }
            pPlan = Mapper.Map(pricingPlanVM, pPlan);
            unitOfWork.PricingPlans.Update(pPlan);
            int result = await unitOfWork.SaveAsync();

            if (result < 1)
            {
                return(BadRequest());
            }
            else
            {
                return(Ok(pPlan));
            }
        }
        public Payment CreatePayment(APIContext apiContext, string redirectUrl, PricingPlanDto objInvoiceItem)
        {
            //similar to credit card create itemlist and add item objects to it
            var itemList = new ItemList()
            {
                items = new List <Item>()
            };

            itemList.items.Add(new Item()
            {
                name     = objInvoiceItem.PlanName,
                currency = "USD",
                quantity = "1",
                sku      = "sku",
                price    = objInvoiceItem.PlanPricing.ToString()
            });

            var payer = new Payer()
            {
                payment_method = "paypal"
            };

            // Configure Redirect Urls here with RedirectUrls object
            var redirUrls = new RedirectUrls()
            {
                cancel_url = redirectUrl,
                return_url = redirectUrl
            };

            // similar as we did for credit card, do here and create details object
            var details = new Details()
            {
                subtotal = objInvoiceItem.PlanPricing.ToString()
            };

            // similar as we did for credit card, do here and create amount object
            var amount = new Amount()
            {
                currency = "USD",
                total    = (Convert.ToDouble(objInvoiceItem.PlanPricing)).ToString(),
                details  = details
            };

            var    transactionList = new List <Transaction>();
            Random rnd             = new Random();
            int    invoiceID       = rnd.Next(1, 1300);

            transactionList.Add(new Transaction()
            {
                description    = "Transaction description.",
                invoice_number = invoiceID.ToString(),
                amount         = amount,
                item_list      = itemList
            });

            this.payment = new Payment()
            {
                intent        = "sale",
                payer         = payer,
                transactions  = transactionList,
                redirect_urls = redirUrls
            };

            // Create a payment using a APIContext
            return(this.payment.Create(apiContext));
        }