laravel-apcopay maintained by bornmt
Laravel ApcoPay
Laravel integration for the ApcoPay payment gateway: hosted payment page and payment status (GetPayment / PreparePayment).
Requirements
- PHP 8.2+
- Laravel 10.x, 11.x or 12.x
- GuzzleHTTP 7.x
Installation
composer require bornmt/laravel-apcopay
Publish the config file (optional; defaults are used from the package):
php artisan vendor:publish --tag=apcopay-config
Configuration
Add to your .env:
APCO_PAY_ENV=local
APCO_PAY_USERNAME=
APCO_PAY_PASSWORD=
APCO_PAY_PID=
APCOPAY_BASE_URL=https://www.apsp.biz/GPG/RESTAPI/api/OnlinePayments
APCOPAY_SANDBOX_BASE_URL=https://www.apsp.biz/GPGTest/RESTAPI/api/OnlinePayments
Set APCO_PAY_ENV=production for live payments.
After publishing the config, you can optionally customize http (e.g. timeout, connect_timeout) for the Guzzle client.
Usage
Inject BornMT\ApcoPay\Contracts\ApcoPayServiceInterface:
use BornMT\ApcoPay\Contracts\ApcoPayServiceInterface;
use BornMT\ApcoPay\Enums\PaymentStateFields;
// Get hosted page URL for redirect
$response = $apcoPay->getHostedPage(
sessionReference: $sessionReference,
amount: $amount,
returnUrl: $returnUrl
);
$paymentUrl = $response['paymentURLField'];
// Get payment status
$payment = $apcoPay->getPayment($sessionReference);
// Get payment with retries (e.g. while processing)
$payment = $apcoPay->getPaymentWithRetry($sessionReference, 3);
// Check state
PaymentStateFields::PENDING->value; // 1
PaymentStateFields::CANCELLED->value; // 2
PaymentStateFields::SUCCESS->value; // 3
PaymentStateFields::FAILED->value; // 4
Exceptions: the service throws BornMT\ApcoPay\Exceptions\ApcoPayException on API or retry failures.
Using the Facade
When the package is installed in a Laravel app, you can use the ApcoPay facade:
use BornMT\ApcoPay\Facades\ApcoPay;
$response = ApcoPay::getHostedPage($sessionReference, $amount, $returnUrl);
$payment = ApcoPay::getPayment($sessionReference);
$payment = ApcoPay::getPaymentWithRetry($sessionReference, 3); // with retries
Testing
composer test
Or with PHPUnit directly:
./vendor/bin/phpunit
License
The MIT License (MIT). Please see the License File for more information.