pwparsons / paygate
A Laravel package to integrate PayGate's PayWeb3 API.
Requires
- php: ^7.4
- ext-bcmath: *
- guzzlehttp/guzzle: ^6.3|^7.0.1
- illuminate/support: ^7.15|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- orchestra/testbench: ^5.0
- phpunit/phpunit: ^9.0
- psalm/plugin-laravel: ^1.2
- vimeo/psalm: ^3.11
README
This repository will not be updated. The repository will be kept available in read-only mode.
This package provides an easy way to integrate PayGate's PayWeb3 API with Laravel.
The official documentation can be found here.
Compatibility Chart
Package Version | Laravel | PHP |
---|---|---|
2.0.0 | 7.15+ | 7.4+ |
1.3.2 | 5.6 – 6.x | 7.1+ |
Installation
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
Usage
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.
Creating a transaction
// Initiate transaction $http = PayGate::initiate() ->withReference('pgtest_123456789') ->withAmount(32.99) ->withEmail('email@example.com') ->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.
Querying a transaction
$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.
Tip
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', ]; }
Helpful Methods
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@example.com') ->withReturnUrl('https://my.return.url/page');
Will result in the following:
{ "REFERENCE": "pgtest_123456789", "AMOUNT": "3299", "EMAIL": "email@example.com", "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
Change log
Please see the changelog for more information on what has changed recently.
Contributing
Please see contributing.md for details and a todolist.
Security
If you discover any security related issues, please email peterw.parsons@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see the license file for more information.