public async Task CreateSubscription() { var plan = new PayPalPlan { Currency = "RUB", Total = 100m, Name = "Basic annual subscription", PeriodType = PeriodType.Month, Description = "Annual subscription plan (Russia 100r.)", Frequency = 1, CancelUrl = "http://localhost:1234", ReturnUrl = "http://localhost:1234", }; await _payPalService.CreatePlanAsync(plan); await _payPalService.ActivatePlanAsync(plan); var agreement = new PayPalAgreement { Name = "Bandmap pro-account", Description = "Annual subscription giving special features to the user on the Bandmap service", PayPalPlanId = plan.Id }; var agreementResult = await _payPalService.CreateAgreementAsync(agreement); }
//[Authorize] public async Task <IActionResult> CreateSubscription(SubscriptionRequest request) { var validationResult = await _validationService.ValidateProductAsync(request.ProductId, request.ProductId); if (!String.IsNullOrEmpty(validationResult?.ErrorMessage)) { return(BadRequest(validationResult.ErrorMessage)); } var product = await _paymentsUnitOfWork.ProductRepository.GetAsync(request.ProductId); var currentHost = $"{Request.Scheme}://{Request.Host}"; var parameter = new CreatePlanParameter { ProductName = request.ProductId, ReturnUrl = $"{currentHost}/api/payment/paypal/subscription/confirm", CancelUrl = $"{currentHost}/api/payment/paypal/subscription/cancel" }; var payPalPlanId = await _paymentsService.GetOrCreatePayPalPlanIdAsync(parameter); var agreement = new PayPalAgreement { Name = product.Title, Description = product.Description, PayPalPlanId = payPalPlanId }; var agreementResponse = await _payPalService.CreateAgreementAsync(agreement); var subscription = new Subscription { Status = SubscriptionStatus.Pending, InfluencedLogin = request.Login, ProductName = product.Name, Currency = product.Currency, PricePerPeriod = product.Price, PayPalAgreementId = agreementResponse.Id, }; await _paymentsUnitOfWork.SubscriptionRepository.CreateAsync(subscription); await _paymentsUnitOfWork.SaveAsync(); return(Ok(agreementResponse)); }