Skip to content

Instantly share code, notes, and snippets.

@ogu83
Created August 1, 2025 07:14
Show Gist options
  • Select an option

  • Save ogu83/397ef43dee56d8762b79babe0ad73c79 to your computer and use it in GitHub Desktop.

Select an option

Save ogu83/397ef43dee56d8762b79babe0ad73c79 to your computer and use it in GitHub Desktop.
a simplified example of how I typically structure Azure Functions for payment processing and webhook integration, using C# (.NET 8+). This pattern is representative of how I’ve integrated Worldpay and similar payment gateways:
// Azure Function for Processing Payment (HTTP Trigger)
[Function("ProcessPayment")]
public async Task<IActionResult> ProcessPayment(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req,
FunctionContext executionContext)
{
var logger = executionContext.GetLogger("ProcessPayment");
var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var paymentRequest = JsonSerializer.Deserialize<PaymentRequest>(requestBody);
// Call to external Worldpay API (pseudo-code)
var response = await _worldpayClient.ChargeAsync(paymentRequest);
if (response.Success)
{
logger.LogInformation("Payment successful for {0}", paymentRequest.MerchantId);
return new OkObjectResult(new { Status = "Success", TransactionId = response.Id });
}
else
{
logger.LogError("Payment failed: {0}", response.ErrorMessage);
return new BadRequestObjectResult(new { Status = "Error", Message = response.ErrorMessage });
}
}
// Azure Function for Handling Worldpay Webhook (HTTP Trigger)
[Function("WorldpayWebhook")]
public async Task<IActionResult> WorldpayWebhook(
[HttpTrigger(AuthorizationLevel.Function, "post")] HttpRequestData req,
FunctionContext executionContext)
{
var logger = executionContext.GetLogger("WorldpayWebhook");
var payload = await new StreamReader(req.Body).ReadToEndAsync();
var eventData = JsonSerializer.Deserialize<WorldpayWebhookEvent>(payload);
// Handle settlement, chargeback, payout, etc.
await _paymentService.HandleWebhookAsync(eventData);
logger.LogInformation("Webhook received: {0}", eventData.EventType);
return new OkResult();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment