You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Process Payment should be impleneted as idempotent operation for production use cases
275
-
private function ProcessPayment(Payment $payment)
274
+
/**
275
+
* Process Payment should be impleneted as idempotent operation for production use cases
276
+
* This method and logic can be shared among all payment processing consumers: 1. bulk polling, 2. webhook, 3. single payment polling.
277
+
*/
278
+
private function processPayment(Payment $payment)
276
279
{
277
280
echo "\nPayment Status: " . $payment->status;
278
281
if ($payment->IsPaid()) {
@@ -296,6 +299,132 @@ $processor->Run();
296
299
297
300
```
298
301
302
+
### Webhooks - Payment processing using Webhook Callbacks
303
+
304
+
```php
305
+
306
+
<?php
307
+
308
+
require 'vendor/autoload.php';
309
+
310
+
use WeBirr\Payment;
311
+
312
+
// Webhook handler for processing payment updates from WeBirr.
313
+
// This script should be hosted on a secure server with HTTPS enabled.
314
+
315
+
class Webhook
316
+
{
317
+
/**
318
+
* Handle incoming webhook POST requests.
319
+
* Validates request method (must be POST).
320
+
* Checks authentication using the authKey from the query string, otherwise system will not know if the request is coming from WeBirr(authorized) or not
321
+
*/
322
+
public function handleRequest()
323
+
{
324
+
// Validate request method is POST
325
+
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
326
+
http_response_code(405); // Method Not Allowed
327
+
header('Content-Type: application/json');
328
+
echo json_encode(["error" => "Method Not Allowed. POST required."]);
329
+
return;
330
+
}
331
+
332
+
// Authenticate using authKey query string parameter, otherwise system will not know if the request is from WeBirr(authorized) or not
0 commit comments