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); }
public ActionResult Activate(string id) { if (!string.IsNullOrEmpty(id)) { var apiContext = Common.GetApiContext(); var plan = Plan.Get(apiContext, id); if (plan != null && plan.state == "CREATED") { var patchRequest = new PatchRequest(); var tempPlan = new Plan(); tempPlan.state = "ACTIVE"; patchRequest.Add(new Patch { path = "/", op = "replace", value = tempPlan }); plan.Update(apiContext, patchRequest); TempData["success"] = "Plan activated"; } } return RedirectToAction("Index"); }
protected override void RunSample() { // ### Api Context // Pass in a `APIContext` object to authenticate // the call and to send a unique request id // (that ensures idempotency). The SDK generates // a request id if you do not pass one explicitly. // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext. var apiContext = Configuration.GetAPIContext(); // In order to update the plan, you must define one or more // patches to be applied to the plan. The patches will be // applied in the order in which they're specified. // // The 'value' of each Patch object will need to be a Plan object // that contains the fields that will be modified. // More Information: https://developer.paypal.com/webapps/developer/docs/api/#patchrequest-object var tempPlan = new Plan(); tempPlan.description = "Some updated description (" + Guid.NewGuid().ToString() + ")."; // NOTE: Only the 'replace' operation is supported when updating // billing plans. var patchRequest = new PatchRequest() { new Patch() { op = "replace", path = "/", value = tempPlan } }; // Get the plan we want to update. var planId = "P-23P27073KJ353233VHEXQM4Y"; #region Track Workflow //-------------------- this.flow.AddNewRequest("Retrieve billing plan details", description: "ID: " + planId); //-------------------- #endregion var plan = Plan.Get(apiContext, planId); #region Track Workflow //-------------------- this.flow.RecordResponse(plan); this.flow.AddNewRequest("Update billing plan", patchRequest); //-------------------- #endregion // Update the plan. plan.Update(apiContext, patchRequest); #region Track Workflow //-------------------- this.flow.RecordActionSuccess("Billing plan updated successfully"); //-------------------- #endregion // After it's been updated, get it again to make sure it was updated properly (and so we can see what it looks like afterwards). var updatedPlan = Plan.Get(apiContext, planId); }
/// <summary> /// Create a new billing plan by passing the details for the plan, including the plan name, description, and type, to the request URI. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="plan">The Plan object to be used to create the billing plan resource.</param> /// <returns>Plan</returns> public static Plan Create(APIContext apiContext, Plan plan) { // Validate the arguments to be used in the request ArgumentValidator.ValidateAndSetupAPIContext(apiContext); // Configure and send the request var resourcePath = "v1/payments/billing-plans"; return PayPalResource.ConfigureAndExecute<Plan>(apiContext, HttpMethod.POST, resourcePath, plan.ConvertToJson()); }
protected override void RunSample() { // ### Api Context // Pass in a `APIContext` object to authenticate // the call and to send a unique request id // (that ensures idempotency). The SDK generates // a request id if you do not pass one explicitly. // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext. var apiContext = Configuration.GetAPIContext(); // ### Create a Billing Plan // For demonstration purposes, we'll first create a new billing plan. var plan = new Plan { name = "T-Shirt of the Month Club Plan", description = "Monthly plan for getting the t-shirt of the month.", type = "fixed", merchant_preferences = new MerchantPreferences { setup_fee = new Currency { value = "1.00", currency = "USD" }, return_url = "https://www.paypal.com", cancel_url = "https://www.paypal.com", auto_bill_amount = "YES", initial_fail_amount_action = "CONTINUE", max_fail_attempts = "0" }, payment_definitions = new List<PaymentDefinition> { new PaymentDefinition() { name = "Standard Plan", type = "REGULAR", frequency = "MONTH", frequency_interval = "1", amount = new Currency() { value = "19.99", currency = "USD" }, cycles = "11", charge_models = new List<ChargeModel> { new ChargeModel { type = "TAX", amount = new Currency() { value = "2.47", currency = "USD" } }, new ChargeModel() { type = "SHIPPING", amount = new Currency() { value = "9.99", currency = "USD" } } } } } }; #region Track Workflow //-------------------- this.flow.AddNewRequest("Create the billing plan", plan); //-------------------- #endregion // Create the billing plan. var createdPlan = plan.Create(apiContext); #region Track Workflow //-------------------- this.flow.RecordResponse(createdPlan); //-------------------- #endregion // ### Delete the Billing Plan // Deleting the plan is done by applying an update to the plan with its `state` set to `DELETED`. // > NOTE: Only the 'replace' operation is supported when updating billing plans. // For demonstration purposes, we'll create the `patchRequest` object here to show you how the plan is being deleted. var patchRequest = new PatchRequest { new Patch { op = "replace", path = "/", value = new Plan { state = "DELETED" } } }; #region Track Workflow this.flow.AddNewRequest("Delete the billing plan", patchRequest); #endregion // To make it easier for developers, this functionality has been built into the `Plan.Delete()` method. createdPlan.Delete(apiContext); #region Track Workflow this.flow.RecordActionSuccess("Billing plan deleted successfully"); #endregion // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/). }
public int CreatePlan(PlanDto planDto) { var currency = new Currency() { value = planDto.PaymentAmount, currency = planDto.PaymentCurrency }; var shippingChargeModel = new ChargeModel() { type = "SHIPPING", amount = new Currency() { value = "1", currency = planDto.PaymentCurrency } }; var paymentDefinition = new PaymentDefinition() { name = planDto.PaymentName, type = planDto.PaymentType, frequency = planDto.PaymentFrequency, frequency_interval = planDto.PaymentFrequencyInterval, amount = currency, cycles = planDto.PaymentCycles, charge_models = new List <ChargeModel> { new ChargeModel() { type = "TAX", amount = new Currency { value = "1", currency = planDto.PaymentCurrency } }, shippingChargeModel } }; var plan = new PayPal.Api.Plan { name = planDto.Name, description = planDto.Description, type = "fixed", payment_definitions = new List <PaymentDefinition> { paymentDefinition }, merchant_preferences = new MerchantPreferences() { setup_fee = new Currency() { value = "0", currency = planDto.PaymentCurrency }, return_url = "https://localhost:5001/api/values", cancel_url = "https://localhost:5001/api/houses", auto_bill_amount = "YES", initial_fail_amount_action = "CONTINUE", max_fail_attempts = "0" } }; var createdPlan = plan.Create(_apiContext); var state = new { state = "ACTIVE" }; var patchRequest = new PatchRequest() { new Patch() { op = "replace", path = "/", value = state } }; createdPlan.Update(_apiContext, patchRequest); //save plan in db var planToSave = new Models.Plan { Name = createdPlan.name, PlanId = createdPlan.id, OwnerId = planDto.OwnerId }; var planInsert = _planRepository.Insert(planToSave); return(planInsert.Id); }
/// <summary> /// Deletes the specified billing plan. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> public void Delete(APIContext apiContext) { Plan.Delete(apiContext, this.id); }
/// <summary> /// Replace specific fields within a billing plan by passing the ID of the billing plan to the request URI. In addition, pass a patch object in the request JSON that specifies the operation to perform, field to update, and new value for each update. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <param name="patchRequest">PatchRequest</param> public void Update(APIContext apiContext, PatchRequest patchRequest) { Plan.Update(apiContext, this.id, patchRequest); }
/// <summary> /// Create a new billing plan by passing the details for the plan, including the plan name, description, and type, to the request URI. /// </summary> /// <param name="apiContext">APIContext used for the API call.</param> /// <returns>Plan</returns> public Plan Create(APIContext apiContext) { return(Plan.Create(apiContext, this)); }