PHP code example of yupay / yupay-php
1. Go to this page and download the library: Download yupay/yupay-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/ */
yupay / yupay-php example snippets
use Yupay\Yupay;
use Yupay\Exceptions\YupayException;
$yupay = new Yupay(getenv('YUPAY_API_KEY'), [
'base_url' => 'https://yupay.id/api/v1', // your Yupay instance
]);
try {
$charge = $yupay->createCharge(
['amount' => 50000, 'method' => 'qris'],
idempotencyKey: 'order-1001',
);
echo $charge['payment_no']; // PAY-260626-AB12CD
echo $charge['status']; // pending
print_r($charge['artifact']); // qr_string / va_number / redirect_url …
} catch (YupayException $e) {
error_log($e->getMessage());
print_r($e->validationErrors()); // field errors on HTTP 422
}
$yupay->createCharge(array $params, ?string $idempotencyKey = null): array;
$yupay->retrieveCharge(string $paymentNo): array;
$yupay->refundCharge(string $paymentNo, ?int $amount = null, ?string $reason = null): array;
$yupay->balance(): array;
$yupay->paymentChannels(?string $category = null, bool $
use Yupay\Webhook;
use Yupay\Exceptions\YupayException;
$payload = file_get_contents('php://input');
$sig = $_SERVER['HTTP_X_YUPAY_SIGNATURE'] ?? '';
try {
$event = Webhook::constructEvent($payload, $sig, getenv('YUPAY_WEBHOOK_SECRET'));
} catch (YupayException $e) {
http_response_code(400);
exit('invalid signature');
}
if ($event['event'] === 'payment.succeeded') {
$payment = $event['data'];
// fulfill order $payment['payment_no'] … (dedupe on $event['id'])
}
http_response_code(200);
echo 'ok';
bash
composer