Download the PHP package orkhanahmadov/laravel-goldenpay without Composer
On this page you can find all versions of the php package orkhanahmadov/laravel-goldenpay. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download orkhanahmadov/laravel-goldenpay
More information about orkhanahmadov/laravel-goldenpay
Files in orkhanahmadov/laravel-goldenpay
Package laravel-goldenpay
Short Description Goldenpay package for Laravel
License MIT
Homepage https://github.com/orkhanahmadov/laravel-goldenpay
Informations about the package laravel-goldenpay
:credit_card: GoldenPay package for Laravel
Full-feature Laravel package for Goldenpay integration.
Table of Contents
- Requirements
- Installation
- Usage
- Controller
- Models
- Commands
- Events
- Configuration
Requirements
| Package | PHP | Laravel |
|---|---|---|
| 1.0 | ^7.2 | 5.8.* or ^6.0 |
| 2.0 | ^7.2 | ^6.0 or ^7.0 |
| 3.0 | ^7.3 or ^8.0 | ^8.0 |
Installation
You can install the package via composer:
Run this command to publish required migration file:
Usage
First, set your Goldenpay merchant name and auth key in .env file.
You can get these from Goldenpay Dashboard.
To use Goldenpay service you need instance of Orkhanahmadov\LaravelGoldenpay\Goldenpay.
You can instantiate this class using Laravel's service container, for example by injecting to your controller
Or you can use Laravel's service resolver to create instance of the class:
Available methods:
payment()
Prepares payment based on passed credentials and accepts 4 arguments:
Amount- Payment amount, only integer values accepted For example, for you want to create payment for 10.25, then pass it as 1025.Card type- Requires instance ofOrkhanahmadov\Goldenpay\Enums\CardType.CardType::VISA()for VISA,CardType::MASTERCARD()for MasterCardDescription- Payment descriptionLanguage(optional) - Sets payment page interface language. Requires instance ofOrkhanahmadov\Goldenpay\Enums\Language.Language::EN()for english,Language::RU()for russian,Language::AZ()for azerbaijani. If nothing passed service will use Laravel's active locale.
Method returns created instance of Orkhanahmadov\LaravelGoldenpay\Models\Payment model.
You can use $payment_url property to get unique payment URL and redirect user to this URL to start payment.
result()
Checks payment result based on previous payment key. Accepts single argument:
Payment- This is Goldenpay's payment key as a string, or instance of previously createdOrkhanahmadov\LaravelGoldenpay\Models\Paymentmodel.
Method returns updated instance of Orkhanahmadov\LaravelGoldenpay\Models\Payment model with Goldenpay's response.
Controller
Goldenpay requires to have endpoints for successful and unsuccessful payment.
For each of this endpoints Goldenpay sends GET request with payment_key query string attached.
To get payment result you need to create a route to accept these requests and fetch result of the payment using received payment_key.
Package ships with a controller that helps to simplify this process. To get started, first create a GET route for successful or unsuccessful payments and add full URL in Goldenpay Dashboard to corresponding field.
Create a controller class for your route and extend Orkhanahmadov\LaravelGoldenpay\Http\Controllers\GoldenpayController.
By extending Orkhanahmadov\LaravelGoldenpay\Http\Controllers\GoldenpayController,
your controller will automatically check for payment result based on payment_key query string.
In your controller you can access to $payment property which will have payment results from Goldenpay.
You can use same endpoint for both successful and unsuccessful payments and decide what you want to show user based on
$this->payment->successful state or you create separate endpoints and controllers and
extend Orkhanahmadov\LaravelGoldenpay\Http\Controllers\GoldenpayController in both controllers.
Models
Package ships with Orkhanahmadov\LaravelGoldenpay\Models\Payment Eloquent model.
Model stores following information for each payment:
payment_key- string, unique payment key provided by Goldenpayamount- integer, payment amountcard_type- enum, "m" for MasterCard, "v" for VISAlanguage- enum, "en" for English, "ru" for Russian, "lv" for Azerbaijanidescription- string, payment descriptionstatus- integer, payment status codemessage- string, payment status messagereference_number- string, payment reference numbercard_number- string, encrypted, card number used for paymentpayment_date- datetime, payment datechecks- integer, payment check count
Besides usual Eloquent functionality this model also has specific accessors, scopes and relationship abilities which you can utilize.
Accessors
successful- Returnstrueif payment marked as successful,falseotherwisepayment_url- Returns payment page url. Returnsnullif payment marked as successfulformatted_amount- Returns "amount" in decimal formcard_number_decrypted- Returns decrypted "card_number" value. Returnsnullif card number encrypting is turned off
Scopes
whereSuccessful()- Filters "successful" payments onlywherePending()- Filters "pending" payments only. Pending payments are the payments that not successful and either created within 30 minutes or have less than 3 payment checks.
Relationship
You can make any existing Eloquent model "payable" and attach Goldenpay payments to it.
Use Orkhanahmadov\LaravelGoldenpay\Traits\Payable trait in your existing model to establish direct model relationship.
Trait usage requires to have amount() description() methods to be defined in your model:
amount()- Must return payment amount in integerdescription()- Must return description for payment instance
Now Product model has direct relationship with Goldenpay payments.
By using Payable your model also gets access to payment related relationships and payment methods.
createPayment()
You can also override amount and description() for specific payment:
Method accepts following arguments:
Card type- Instance ofOrkhanahmadov\Goldenpay\Enums\CardTypeAmount(optional) - When used overridesamount()method value in modelDescription(optional) - When used overridesdescription()method value in modelLanguage(optional) - When skipped will use Laravel's locale. Instance ofOrkhanahmadov\Goldenpay\Enums\Language.
Method returns created instance of Orkhanahmadov\LaravelGoldenpay\Models\Payment.
payments()
Eloquent relationship method. Return all related payments to model.
successfulPayments()
Eloquent relationship method. Return all related successful payments to model.
Commands
Package ships with artisan command for checking payment results.
Executing above command will loop through all "pending" payments and update their results.
Command also accepts payment key as an argument to check single payment result.
Goldenpay requires manual check for payments to determine their final status.
For example, user might go to payment page then close browser window without entering anything.
These kind payment cases needs to be checked manually to finalize their status.
You can use Laravel's Task Scheduling
for running goldenpay:result command on Cron job.
Because Goldenpay states that each payment session is active only for 15 minutes, it is recommended to keep frequency to 5 or 10 minutes.
Events
Package ships with Laravel events which gets fired on specific conditions.
Available event classes:
Orkhanahmadov\LaravelGoldenpay\Events\PaymentCreatedEvent- gets fired when new payment is createdOrkhanahmadov\LaravelGoldenpay\Events\PaymentCheckedEvent- gets fired when payment is checked for resultOrkhanahmadov\LaravelGoldenpay\Events\PaymentSuccessfulEvent- gets fired when payment finalized as successful
Each event receives instance of Orkhanahmadov\LaravelGoldenpay\Models\Payment Eloquent model
as public $payment property.
You can set up event listeners to trigger when specific payment event gets fired.
Configuration
Run this command to publish package config file:
Config file contains following settings:
auth_key- Defines Goldenpay "auth key", defaults to.envvariablemerchant_name- Defines Goldenpay "merchant name", defaults to.envvariabletable_name- Defines name for Goldenpay payments database table. Default: "goldenpay_payments"encrypt_card_numbers- Defines if "card_number" field needs to be automatically encrypted when when creating payments or getting payment results. Default istrue, change tofalseif you want to disable automatic encryption. Recommended to leave ittruefor extra layer of security. Warning! If you already have records in Payments table, changing this value will break encryption/decryption. Old values won't be encrypted/decrypted automatically, you need to do it manually.payment_events- Payment events related settingsenabled- Defines if payment events are enabled. Set tofalseto disable all payment eventschecked- "Payment checked" event class. By default usesOrkhanahmadov\LaravelGoldenpay\Events\PaymentCreatedEventclasscreated- "Payment created" event class. By default usesOrkhanahmadov\LaravelGoldenpay\Events\PaymentCheckedEventclasssuccessful- "Payment successful" event class. By default usesOrkhanahmadov\LaravelGoldenpay\Events\PaymentSuccessfulEventclass
If you want to use your own event class for specific payment event you can replace class namespace with your class namespace.
Each payment event receives instance of Orkhanahmadov\LaravelGoldenpay\Models\Payment Eloquent model.
Because of this, make sure you add payment model as dependency to your event class constructor signature or
you can extend Orkhanahmadov\LaravelGoldenpay\Events\PaymentEvent class which already has payment model as dependency.
Setting specific payment event to null disables that event without interrupting others.
Testing
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Orkhan Ahmadov
- All Contributors
Support me
If you like my work, if my open-source contributions help you or your company, please consider supporting me through Github Sponsors.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-goldenpay with dependencies
illuminate/contracts Version ^8.0
illuminate/console Version ^8.0
illuminate/database Version ^8.0
illuminate/http Version ^8.0
illuminate/queue Version ^8.0
illuminate/support Version ^8.0
orkhanahmadov/goldenpay Version ^2.2