Exemple #1
0
 public async Task UpdatePlanTest()
 {
     var requestTester = GetRequestTester();
     var planId        = "id";
     var planRequest   = new PlanUpdateRequest()
     {
         PlanId = planId, Name = "asa"
     };
     await requestTester.TestMethod <Plan>(
         async (api) =>
     {
         await api.UpdatePlan(planRequest);
     },
         new RequestDescriptor()
     {
         Method    = HttpMethod.Post,
         Action    = string.Format("plans/{0}", planId),
         Parameter = planRequest
     }
         );
 }
        public static async Task <Plan> UpdateBillingPlan(string planId, string path, object value)
        {
            var client = PayPalConfiguration.GetClient();

            var updates = new Plan()
            {
                State = "ACTIVE"
            };
            var patch = new PayPal.v1.BillingPlans.JsonPatch <Plan>()
            {
                Op    = "replace",
                Path  = "/",
                Value = updates
            };

            PlanUpdateRequest <Plan> request = new PlanUpdateRequest <Plan>(planId);

            request.RequestBody(new List <PayPal.v1.BillingPlans.JsonPatch <Plan> > {
                patch
            });

            try
            {
                HttpResponse response = await client.Execute(request);

                var statusCode = response.StatusCode;
                return(response.Result <Plan>());
            }
            catch (HttpException httpException)
            {
                var statusCode = httpException.StatusCode;
                var debugId    = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();

                throw httpException;
            }
        }
        /// <summary>
        /// Create the default billing plans for this website
        /// </summary>
        private async Task CreatePayPalPlans()
        {
            var client = _clientFactory.GetClient();

            foreach (var plan in BillingPlanSeed.PayPalPlans("https://www.andytipster.com/Subscription/Return", "https://www.andytipster.com/Subscription/Cancel"))

            //foreach (var plan in BillingPlanSeed.PayPalPlans("https://localhost:44376/Subscription/Return", "https://localhost:44376/Subscription/Cancel"))

            {
                // Create Plan
                var request = new PlanCreateRequest().RequestBody(plan);
                BraintreeHttp.HttpResponse result = await client.Execute(request);

                var obj = result.Result <Plan>();

                // Activate Plan
                var activateRequest = new PlanUpdateRequest <Plan>(obj.Id)
                                      .RequestBody(GetActivatePlanBody());

                await client.Execute(activateRequest);



                // Add to database record
                //var dbPlan = _dbContext.BillingPlans.FirstOrDefault(x =>
                //    x.Name == obj.Name);

                //if (dbPlan != null && string.IsNullOrEmpty(dbPlan.PayPalPlanId))
                //{
                //    dbPlan.PayPalPlanId = obj.Id;
                //    await _dbContext.SaveChangesAsync();
                //}
            }

            //// Create plans
            //var justBrowsingPlanRequest = new PlanCreateRequest().RequestBody(justBrowsingPlan);
            //var justBrowsingPlanResult = await client.Execute(justBrowsingPlanRequest);
            //var justBrowsingPlanObject = justBrowsingPlanResult.Result<Plan>();

            //var letsDoThisPlanRequest = new PlanCreateRequest().RequestBody(letsDoThisPlan);
            //var letsDoThisPlanResult = await client.Execute(letsDoThisPlanRequest);
            //var letsDoThisPlanObject = letsDoThisPlanResult.Result<Plan>();

            //var beardIncludedPlanRequest = new PlanCreateRequest().RequestBody(beardIncludedPlan);
            //var beardIncludedPlanResult = await client.Execute(beardIncludedPlanRequest);
            //var beardIncludedPlanObject = beardIncludedPlanResult.Result<Plan>();

            //var hookItToMyVeinsPlanRequest = new PlanCreateRequest().RequestBody(hookItToMyVeinsPlan);
            //var hookItToMyVeinsPlanResult = await client.Execute(hookItToMyVeinsPlanRequest);
            //var hookItToMyVeinsPlanObject = hookItToMyVeinsPlanResult.Result<Plan>();

            //// Activate plans
            //var activateJustBrowsingPlanRequest = new PlanUpdateRequest<Plan>(justBrowsingPlanObject.Id)
            //    .RequestBody(GetActivatePlanBody());
            //await client.Execute(activateJustBrowsingPlanRequest);

            //var activateletsDoThisPlanRequest = new PlanUpdateRequest<Plan>(letsDoThisPlanObject.Id)
            //    .RequestBody(GetActivatePlanBody());
            //await client.Execute(activateletsDoThisPlanRequest);

            //var activateBeardIncludedPlanRequest = new PlanUpdateRequest<Plan>(beardIncludedPlanObject.Id)
            //    .RequestBody(GetActivatePlanBody());
            //await client.Execute(activateBeardIncludedPlanRequest);

            //var activateHookItToMyVeinsPlanRequest = new PlanUpdateRequest<Plan>(hookItToMyVeinsPlanObject.Id)
            //    .RequestBody(GetActivatePlanBody());
            //await client.Execute(activateHookItToMyVeinsPlanRequest);
        }
        public async Task <Plan> UpdatePlan(PlanUpdateRequest updatePlanRequest)
        {
            var url = string.Format("{0}/{1}", PLANS_PATH, updatePlanRequest.PlanId);

            return(await SendRequest <Plan>(HttpMethod.Post, url, updatePlanRequest));
        }