-
-
Save dcomartin/a7e8cbc038c26bee41a3e315d4454e80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IPaymentService | |
| { | |
| Task<string> ChargeAsync(decimal amount, string token); | |
| } | |
| public class StripePaymentService : IPaymentService | |
| { | |
| public async Task<string> ChargeAsync(decimal amount, string token) | |
| { | |
| var service = new ChargeService(); | |
| var charge = await service.CreateAsync(new ChargeCreateOptions | |
| { | |
| Amount = (long)(amount * 100), | |
| Currency = "usd", | |
| Source = token | |
| }); | |
| return charge.Id; | |
| } | |
| } | |
| public class ProcessPayment | |
| { | |
| public record Command(decimal Amount, string Token); | |
| public class Handler | |
| { | |
| private readonly IPaymentService _paymentService; | |
| public Handler(IPaymentService paymentService) | |
| { | |
| _paymentService = paymentService; | |
| } | |
| public async Task Handle(Command command) | |
| { | |
| var paymentId = await _paymentService.ChargeAsync(command.Amount, command.Token); | |
| // save result, publish event, etc. | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment