public async Task <PurchaseCheckoutResponse> Post(PurchaseCheckoutRequest request)
        {
            var user = ValidateAndGetCurrentUser();

            if (user == null)
            {
                throw new UnauthorizedAccessException("You must be authenticated.");
            }

            var     billingPlanId = string.Empty; //PlanId
            decimal billingAmount = 0;

            switch (request.Target)
            {
            case "premium":
                billingPlanId = ConfigurationManager.AppSettings["BraintreePremiumPlanId"];
                break;

            case "elite":
                billingPlanId = ConfigurationManager.AppSettings["BraintreeElitePlanId"];
                break;

            default:
                throw new ArgumentException("Missing parameter 'PurchaseTarget'");
            }


            var gateway = config.CreateGateway();

            if (user.BraintreeSubscriptionId != null)
            {
                Subscription subscription = gateway.Subscription.Find(user.BraintreeSubscriptionId);
                if (subscription.Status == SubscriptionStatus.ACTIVE && subscription.PlanId == billingPlanId)
                {
                    throw new ArgumentException("You already subscribed on this plan");
                }
            }

            if (!string.IsNullOrWhiteSpace(billingPlanId))
            {
                return(CreateBraintreeSubscription(user, billingPlanId, request.Nonce));
            }
            else
            {
                return(CreateBraintreeTransaction(user, billingAmount, request.Nonce));
            }
        }