This package provides an easy way to integrate PayGate's PayWeb3 API with Laravel.
The official documentation can be found here.
Package Version | Laravel | PHP |
---|---|---|
2.0.0 | 7.15+ | 7.4+ |
1.3.2 | 5.6 – 6.x | 7.1+ |
You can install this package via composer using:
composer require pwparsons/paygate
The package will automatically register itself.
To publish the config file to config/paygate.php
run:
php artisan vendor:publish --tag=paygate.config
After you've installed the package and filled in the values in the config file working with this package will be a breeze. All the following examples use the facade.
// Initiate transaction
$http = PayGate::initiate()
->withReference('pgtest_123456789')
->withAmount(32.99)
->withEmail('[email protected]')
->withCurrency('USD') // Optional: defaults to ZAR
->withCountry('USA') // Optional: defaults to ZAF
->withLocale('en-us') // Optional: defaults to 'en'
->withReturnUrl('https://website.com/return_url')
->withNotifyUrl('https://website.com/notify_url') // Optional
->create();
if ($http->fails()) {
dump($http->getErrorCode());
dump($http->getErrorMessage());
dump($http->all());
}
// Redirect to PayGate's payment page
return PayGate::redirect();
An example of the initiate response can be found in the documentation.
$http = PayGate::query()
->withPayRequestId('YOUR_PAY_REQUEST_ID_HERE')
->withReference('pgtest_123456789')
->create();
if ($http->fails()) {
dump($http->getErrorCode());
dump($http->getErrorMessage());
dump($http->all());
}
dd($http->all());
An example of the query response can be found in the documentation.
Paygate will post to the RETURN_URL and NOTIFY_URL. Exclude these URI's from CSRF verification by adding them to the VerifyCsrfToken middleware. E.g.
class VerifyCsrfToken extends Middleware
{
protected $except = [
'return_url',
'notify_url',
];
}
The with
magic method allows you to set a string after the word 'with' provided within the object it is being called on. This works in exactly the same way as the magic getter except it sets field values and returns the object so that you can chain setters, for example:
$object->withReference('pgtest_123456789')
->withAmount(32.99)
->withEmail('[email protected]')
->withReturnUrl('https://my.return.url/page');
Will result in the following:
{
"REFERENCE": "pgtest_123456789",
"AMOUNT": "3299",
"EMAIL": "[email protected]",
"RETURN_URL": "https://my.return.url/page"
}
The get
magic method allows you to call any string after the word 'get' and it will return that value, for example:
{
"PAYGATE_ID": "10011072130",
"PAY_REQUEST_ID": "23B785AE-C96C-32AF-4879-D2C9363DB6E8",
"REFERENCE": "pgtest_123456789"
}
Getting data from the object:
echo $object->getPaygateId(); // 10011072130
echo $object->getPayRequestId(); // 23B785AE-C96C-32AF-4879-D2C9363DB6E8
echo $object->getReference(); // pgtest_123456789
Please see the changelog for more information on what has changed recently.
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see the license file for more information.