fersaku/fersaku-php

Official Fersaku QRIS Payment Gateway SDK for PHP

Maintainers

Package info

github.com/dasepmoch/SDK-Fersaku-php

Homepage

pkg:composer/fersaku/fersaku-php

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-05-12 14:44 UTC

This package is auto-updated.

Last update: 2026-05-12 15:04:44 UTC


README

Official PHP SDK untuk Fersaku QRIS Payment Gateway.

Instalasi

composer require fersaku/fersaku-php

Atau copy folder src/ langsung ke project Anda.

Quick Start

<?php
require_once 'vendor/autoload.php';

use Fersaku\Fersaku;

$fersaku = new Fersaku('sk_live_your_secret_key');

// Buat pembayaran
$payment = $fersaku->createPayment([
    'amount' => 50000,
    'customer_name' => 'John Doe',
    'customer_email' => 'john@example.com',
    'description' => 'Pembelian Produk A',
    'external_id' => 'order-123',
    'expired_minutes' => 30,
]);

echo $payment['checkout_url']; // Redirect customer ke sini
echo $payment['qr_string'];   // Atau tampilkan QR langsung

API Methods

createPayment(array $params)

Buat pembayaran QRIS baru.

$payment = $fersaku->createPayment([
    'amount' => 100000,           // Wajib, min 1000
    'customer_name' => 'Budi',   // Opsional
    'customer_email' => 'budi@email.com', // Opsional
    'description' => 'Order #123', // Opsional
    'external_id' => 'my-order-123', // Opsional
    'expired_minutes' => 30,      // Opsional, default 30
]);

getPayment(string $id)

Ambil detail pembayaran.

$detail = $fersaku->getPayment('payment_id_here');

listPayments(array $params)

List pembayaran dengan filter.

$list = $fersaku->listPayments(['status' => 'paid', 'limit' => 10]);

cancelPayment(string $id)

Batalkan pembayaran pending.

$fersaku->cancelPayment('payment_id_here');

checkStatus(string $id)

Cek status terbaru.

$result = $fersaku->checkStatus('payment_id_here');

simulate(string $paymentId, string $action) (Sandbox only)

Simulasi pembayaran di sandbox.

$sandbox = new Fersaku('sk_test_your_sandbox_key');
$sandbox->simulate('payment_id', 'pay'); // pay, expire, fail, cancel

Webhook Verification

<?php
use Fersaku\Fersaku;

// Laravel Controller
public function handleWebhook(Request $request)
{
    $signature = $request->header('X-Webhook-Signature');
    $webhookSecret = env('FERSAKU_WEBHOOK_SECRET');

    $isValid = Fersaku::verifyWebhook(
        $request->all(),
        $signature,
        $webhookSecret
    );

    if (!$isValid) {
        return response()->json(['message' => 'Unauthorized'], 401);
    }

    $event = $request->input('event');
    $paymentId = $request->input('payment_id');
    $orderId = $request->input('order_id');
    $status = $request->input('status');
    $amount = $request->input('amount');

    if ($event === 'payment.paid') {
        // Proses pembayaran berhasil
        // Update order di database Anda
    }

    return response()->json(['message' => 'OK']);
}

Native PHP (tanpa framework)

<?php
require_once 'src/Fersaku.php';

use Fersaku\Fersaku;

$payload = json_decode(file_get_contents('php://input'), true);
$signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '';
$webhookSecret = 'whsec_your_secret_here';

if (!Fersaku::verifyWebhook($payload, $signature, $webhookSecret)) {
    http_response_code(401);
    echo json_encode(['message' => 'Unauthorized']);
    exit;
}

if ($payload['event'] === 'payment.paid') {
    // Proses pembayaran berhasil
}

http_response_code(200);
echo json_encode(['message' => 'OK']);

Sandbox vs Production

// Production
$live = new Fersaku('sk_live_xxx');

// Sandbox (testing)
$sandbox = new Fersaku('sk_test_xxx');

Error Handling

use Fersaku\Fersaku;
use Fersaku\FersakuException;

try {
    $payment = $fersaku->createPayment(['amount' => 500]);
} catch (FersakuException $e) {
    echo $e->getMessage(); // "Amount must be at least Rp 1.000"
    echo $e->getCode();    // 400
    print_r($e->getData()); // Full error response
}

Publish ke Packagist

  1. Push ke GitHub
  2. Buka https://packagist.org
  3. Submit repository URL
  4. Done — user bisa composer require fersaku/fersaku-php

License

MIT