Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created April 8, 2026 16:37
Show Gist options
  • Select an option

  • Save dcomartin/a7e8cbc038c26bee41a3e315d4454e80 to your computer and use it in GitHub Desktop.

Select an option

Save dcomartin/a7e8cbc038c26bee41a3e315d4454e80 to your computer and use it in GitHub Desktop.
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