示例#1
0
        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));
        }
示例#2
0
        public async Task CreatePayment()
        {
            var payment = new PayPalPayment()
            {
                Currency  = "USD",
                ReturnUrl = "http://localhost:1230",
                CancelUrl = "http://localhost:1230",
                Total     = 0.02m
            };
            var response = await _payPalService.CreatePaymentAsync(payment);

            Assert.NotNull(response);
            Assert.NotEqual(response.Id, String.Empty);
            Assert.NotNull(response.Id);
            Assert.NotEqual(response.RedirectUrl, String.Empty);
            Assert.NotNull(response.RedirectUrl);
        }