<commit_before>﻿@using WebMatrix.WebData;
@*
    Read, create and change the logged user payment plan (membership).

    EXAMPLES {
        "Payment plan (get active plan and create first one)": {
            "url": "/api/v1/en-US/me/payment-plan",
            "get": { },
            "post": {
                "paymentPlan": "MonthlyLite",
                "paymentMethod": {
                    "paymentMethodID": "TEST: previously saved method token",
                    "cardNumber": "123443121234",
                    "nameOnCard": "Me",
                    "expirationMonth": "11",
                    "expirationYear": "2018",
                    "securityCode": "123"
                }
            }
        },
        "Payment plan: user history": {
            "url": "/api/v1/en-US/me/payment-plan/history",
            "get": { }
        }
    }
*@
@functions{
    public class RestPaymentPlan : RestWebPage
    {
        private dynamic GetActive()
        {
            return LcRest.UserPaymentPlan.GetUserActivePlan(WebSecurity.CurrentUserId);
        }

        public override dynamic Get()
        {
            if (UrlData.Count == 0) {
                var active = GetActive();
                if (active == null)
                {
                    //throw new HttpException(404, "Not found");
                    // Return a placeholder
                    return new LcRest.UserPaymentPlan
                    {
                        userID = WebSecurity.CurrentUserId
                    };
                }
            }
            else if (UrlData.Count == 1 && UrlData[0] == "history")
            {
                return LcRest.UserPaymentPlan.GetByUser(WebSecurity.CurrentUserId);
            }
            throw new HttpException(404, "Not found");
        }

        public override dynamic Post()
        {
            if (UrlData.Count > 0) {
                throw new HttpException(404, "Not found");
            }

            var userId = WebSecurity.CurrentUserId;

            // Validation
            Validation.RequireField("paymentPlan", "Choose a plan");

            // For payment, we need either a paymentMethodID or the data
            // 
            var paymentData = new LcPayment.InputPaymentMethod
            {
                paymentMethodID = Request["paymentMethod[paymentMethodID]"],
                cardNumber = Request["paymentMethod[cardNumber]"],
                nameOnCard = Request["paymentMethod[nameOnCard]"],
                expirationMonth = Request["paymentMethod[expirationMonth]"],<commit_msg>Fix: no returned data for get user payment plan #191<commit_after>﻿@using WebMatrix.WebData;
@*
    Read, create and change the logged user payment plan (membership).

    EXAMPLES {
        "Payment plan (get active plan and create first one)": {
            "url": "/api/v1/en-US/me/payment-plan",
            "get": { },
            "post": {
                "paymentPlan": "MonthlyLite",
                "paymentMethod": {
                    "paymentMethodID": "TEST: previously saved method token",
                    "cardNumber": "123443121234",
                    "nameOnCard": "Me",
                    "expirationMonth": "11",
                    "expirationYear": "2018",
                    "securityCode": "123"
                }
            }
        },
        "Payment plan: user history": {
            "url": "/api/v1/en-US/me/payment-plan/history",
            "get": { }
        }
    }
*@
@functions{
    public class RestPaymentPlan : RestWebPage
    {
        private dynamic GetActive()
        {
            return LcRest.UserPaymentPlan.GetUserActivePlan(WebSecurity.CurrentUserId);
        }

        public override dynamic Get()
        {
            if (UrlData.Count == 0) {
                var active = GetActive();
                if (active == null)
                {
                    //throw new HttpException(404, "Not found");
                    // Return a placeholder
                    return new LcRest.UserPaymentPlan
                    {
                        userID = WebSecurity.CurrentUserId
                    };
                }
                else
                {
                    return active;
                }
            }
            else if (UrlData.Count == 1 && UrlData[0] == "history")
            {
                return LcRest.UserPaymentPlan.GetByUser(WebSecurity.CurrentUserId);
            }
            throw new HttpException(404, "Not found");
        }

        public override dynamic Post()
        {
            if (UrlData.Count > 0) {
                throw new HttpException(404, "Not found");
            }

            var userId = WebSecurity.CurrentUserId;

            // Validation
            Validation.RequireField("paymentPlan", "Choose a plan");

            // For payment, we need either a paymentMethodID or the data
            // 
            var paymentData = new LcPayment.InputPaymentMethod
            {
                paymentMethodID = Request["paymentMethod[paymentMethodID]"],
                cardNumber = Request["paymentMethod[cardNumber]"],
                nameOnCard = Request["paymentMethod[nameOnCard]"],
                expirationMonth = Request["paymentMethod[expirationMonth]"],
{'fraction_non_alphanumeric': 0.10252037142315709, 'fraction_numerical': 0.014212620807276862, 'mean_word_length': 1.3657552666965487, 'pattern_counts': {'":': 30, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1060144', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1263, 'n_words': 297}