1. Go to this page and download the library: Download rewloy/rewloy-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$r = $rewloy->rotateWebhookSecret(['params' => ['id' => $webhookId]]);
// yeni sırrı alıcınıza ekleyin, 24 saat sonra eskisini bırakın
$olay = Rewloy\Webhook::verify($hamGovde, $imzaBasligi, [$r['secret'], $eskiSir]);
use Rewloy\Exception\WebhookSignatureException;
use Rewloy\Webhook;
$govde = (string) file_get_contents('php://input');
try {
$olay = Webhook::verify($govde, $_SERVER['HTTP_REWLOY_SIGNATURE'] ?? null, (string) getenv('REWLOY_WEBHOOK_SECRET'));
} catch (WebhookSignatureException) {
http_response_code(400);
exit;
}
// Rewloy-Delivery bir teslimin her denemesinde aynıdır: işlediyseniz atlayın.
if (dahaOnceIslendi($_SERVER['HTTP_REWLOY_DELIVERY'] ?? '')) {
exit;
}
if ($olay['type'] === 'pass.activity') {
$veri = $olay['data']; // kind, card, program_id, location_id, customer_id, unit, delta…
}
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Route;
use Rewloy\Exception\WebhookSignatureException;
use Rewloy\Webhook;
Route::post('/rewloy/webhook', function (Request $request) {
try {
$olay = Webhook::verify(
$request->getContent(),
$request->headers->get('Rewloy-Signature'),
config('services.rewloy.webhook_secret'),
);
} catch (WebhookSignatureException) {
return response()->noContent(400);
}
// Aynı teslim yeniden gelirse atlayın.
if (! Cache::add('rewloy:' . $request->headers->get('Rewloy-Delivery'), true, now()->addDays(3))) {
return response()->noContent();
}
// … $olay['type'], $olay['data']
return response()->noContent();
});
use Rewloy\Exception\WebhookSignatureException;
use Rewloy\Webhook;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class RewloyWebhookController
{
public function __construct(
#[Autowire(env: 'REWLOY_WEBHOOK_SECRET')] private string $secret,
) {
}
#[Route('/rewloy/webhook', methods: ['POST'])]
public function __invoke(Request $request): Response
{
try {
$olay = Webhook::verify($request->getContent(), $request->headers->get('Rewloy-Signature'), $this->secret);
} catch (WebhookSignatureException) {
return new Response(status: 400);
}
// … $request->headers->get('Rewloy-Delivery') ile tekrarları ayıklayın.
return new Response(status: 200);
}
}
foreach ($rewloy->listWebhooks() as $w) {
if ($w['pausedUntil'] !== null) echo "{$w['url']}: {$w['pausedUntil']} anına kadar bekletiliyor\n";
if ($w['resumableUntil'] !== null) echo "{$w['url']}: {$w['resumableUntil']} öncesinde açın, kaldığı yerden sürer\n";
}
use Rewloy\Exception\RateLimitException;
use Rewloy\Exception\RewloyException;
use Rewloy\Generated\ErrorCode;
try {
$rewloy->passAction([
'params' => ['serial' => $seri],
'body' => ['action' => 'spend', 'locationId' => $subeId, 'amountMinor' => 5000],
'idempotencyKey' => 'kasa3-z0187-fis' . $fisNo,
]);
} catch (RateLimitException $e) {
echo $e->retryAfter, " saniye sonra yeniden deneyin\n";
} catch (RewloyException $e) {
if ($e->errorCode !== ErrorCode::INSUFFICIENT_BALANCE) {
throw $e;
}
echo $e->detail, "\n";
}