public async Task <IActionResult> CreateDonation([FromBody] DonationRequest request) { var currentHost = $"{Request.Scheme}://{Request.Host}"; var payment = new PayPalPayment { Currency = Enum.GetName(typeof(Currency), request.Currency), Total = request.Total, ReturnUrl = $"{currentHost}/api/payment/paypal/donation/confirm", CancelUrl = $"{currentHost}/api/payment/paypal/donation/cancel" }; var response = await _payPalService.CreatePaymentAsync(payment); var donation = new Payment { Currency = payment.Currency, Total = payment.Total, DateUtc = DateTime.UtcNow, ExternalId = response.Id, PaymentStatus = PaymentStatus.Created }; await _paymentsUnitOfWork.PaymentRepository.CreateAsync(donation); await _paymentsUnitOfWork.SaveAsync(); return(Ok(response)); }
public async Task <string> GetOrCreatePayPalPlanIdAsync(CreatePlanParameter parameter) { var planId = await _paymentsUnitOfWork.PayPalPlanRepository.GetPlanIdAsync(parameter.ProductName); if (!string.IsNullOrEmpty(planId)) { return(planId); } var product = await _paymentsUnitOfWork.ProductRepository.GetAsync(parameter.ProductName); var payPalPlan = new PayPalPlan { Name = product.Title, Description = product.Description, Currency = product.Currency, Frequency = 1, PeriodType = ToPeriodType(product.Period), Total = product.Price, ReturnUrl = parameter.ReturnUrl, CancelUrl = parameter.CancelUrl }; await _payPalService.CreatePlanAsync(payPalPlan); await _payPalService.ActivatePlanAsync(payPalPlan); var plan = new Core.Models.PayPalPlan { Id = payPalPlan.Id, ProductName = parameter.ProductName, }; await _paymentsUnitOfWork.PayPalPlanRepository.CreateAsync(plan); await _paymentsUnitOfWork.SaveAsync(); return(payPalPlan.Id); }