public ActionResult Create(BillingPlan billingPlan) { if (ModelState.IsValid) { var apiContext = Common.GetApiContext(); var plan = new Plan(); plan.description = billingPlan.Description; plan.name = billingPlan.Name; plan.type = billingPlan.PlanType; plan.merchant_preferences = new MerchantPreferences { initial_fail_amount_action = "CANCEL", max_fail_attempts = "3", cancel_url = "http://localhost:50728/plans", return_url = "http://localhost:50728/plans" }; plan.payment_definitions = new List<PaymentDefinition>(); var paymentDefinition = new PaymentDefinition(); paymentDefinition.name = "Standard Plan"; paymentDefinition.amount = new Currency { currency = "USD", value = billingPlan.Amount.ToString() }; paymentDefinition.frequency = billingPlan.Frequency.ToString(); paymentDefinition.type = "REGULAR"; paymentDefinition.frequency_interval = "1"; if (billingPlan.NumberOfCycles.HasValue) { paymentDefinition.cycles = billingPlan.NumberOfCycles.Value.ToString(); } plan.payment_definitions.Add(paymentDefinition); var created = plan.Create(apiContext); if (created.state == "CREATED") { var patchRequest = new PatchRequest(); patchRequest.Add(new Patch { path = "/", op = "replace", value = new Plan() { state = "ACTIVE" } }); created.Update(apiContext, patchRequest); } TempData["success"] = "Billing plan created."; return RedirectToAction("Index"); } AddDropdowns(); return View(billingPlan); }
private static List<PaymentDefinition> GetPaymentDefinitions(bool trial, int trialLength, decimal trialPrice, string frequency, int frequencyInterval, decimal planPrice, decimal shippingAmount, decimal taxPercentage) { var paymentDefinitions = new List<PaymentDefinition>(); if (trial) { // Define a trial plan that will charge 'trialPrice' for 'trialLenght' // After that, the standard plan will take over. paymentDefinitions.Add( new PaymentDefinition() { name = "Trial", type = "TRIAL", frequency = frequency, frequency_interval = frequencyInterval.ToString(), amount = GetCurrency(trialPrice.ToString()), cycles = trialLength.ToString(), charge_models = GetChargeModels(trialPrice, shippingAmount, taxPercentage) }); } // Define the standard payment plan. It will represent a 'frequency' (monthly, etc) // plan for 'planPrice' that charges 'planPrice' (once a month) for #cycles. var regularPayment = new PaymentDefinition { name = "Standard Plan", type = "REGULAR", frequency = frequency, frequency_interval = frequencyInterval.ToString(), amount = GetCurrency(planPrice.ToString()), // > NOTE: For `IFNINITE` type plans, `cycles` should be 0 for a `REGULAR` `PaymentDefinition` object. cycles = "11", charge_models = GetChargeModels(trialPrice, shippingAmount, taxPercentage) }; paymentDefinitions.Add(regularPayment); return paymentDefinitions; }