public async Task <IActionResult> Charge(PaymentChargeDTO paymentChargeDTO) { if (paymentChargeDTO.UserId != User.FindFirst(JwtRegisteredClaimNames.Jti).Value) { return(Unauthorized()); } var customers = new CustomerService(); var charges = new ChargeService(); // var options = new TokenCreateOptions // { // Card = new CreditCardOptions // { // // Number = "4242424242424242", // // ExpYear = 2020, // // ExpMonth = 3, // // Cvc = "123" // } // }; // var service = new TokenService(); // Token stripeToken = service.Create(options); var customer = customers.Create(new CustomerCreateOptions { //SourceToken = stripeToken Source = paymentChargeDTO.StripeToken }); var charge = charges.Create(new ChargeCreateOptions { Amount = 5000, Description = "إشتراك مدى الحياة", Currency = "usd", Customer = customer.Id //CustomerId = customer.Id }); var payment = new Payment { PaymentDate = DateTime.Now, Amount = charge.Amount / 100, UserId = User.FindFirst(JwtRegisteredClaimNames.Jti).Value, ReceiptUrl = charge.ReceiptUrl, Description = charge.Description, Currency = charge.Currency, IsPaid = charge.Paid }; _context.Payments.Add(payment); if (await _context.SaveChangesAsync() > 0) { return(Ok(charge.Paid)); } else { return(BadRequest()); } }
public static PaymentChargeDTO ToPaymentChargeDTO(PaymentCharge n) { var r = new PaymentChargeDTO(); r.Id = n.Id; r.Description = n.Description; r.PatientName = n.Payment.Patient.CommonName; r.Amount = n.Amount; r.ChargeDate = n.ChargeDate; r.IsPatientGenerated = !n.Payment.ManagementUserId.HasValue; return(r); }