Skip to content

orkhanahmadov/goldenpay

Repository files navigation

💳 GoldenPay library for PHP

If you are using Laravel, you can use laravel-goldenpay package instead for better integration with extra features.

Latest Stable Version Latest Unstable Version Total Downloads GitHub license

Build Status Test Coverage Maintainability Quality Score StyleCI

Requirements

PHP 7.2 or higher, with json extension.

Installation

composer require orkhanahmadov/goldenpay

Usage

First, instantiate Orkhanahmadov\Goldenpay\Goldenpay and call authenticate() method with "auth key" and "merchant name". Both can be acquired from Goldenpay merchant dashboard.

use Orkhanahmadov\Goldenpay\Goldenpay;

$goldenpay = new Goldenpay();
$goldenpay->authenticate('auth-key-here', 'merchant-name-here');

Getting payment key

To get new payment key use payment method.

Method accepts following arguments:

  • Amount - Amount to charge. Only integer accepted. For example 10.25 needs to be converted to 1025
  • Card type - Requires instance of Orkhanahmadov\Goldenpay\Enums\CardType. CardType::VISA() for VISA, CardType::MASTERCARD() for MasterCard
  • Description - Payment related description
  • Language (optional) - Sets payment page interface language. Requires instance of Orkhanahmadov\Goldenpay\Enums\Language. Language::EN() for english, Language::RU() for russian, Language::AZ() for azerbaijani. Default is azerbaijani
$paymentKey = $goldenpay->payment(100, CardType::VISA(), 'item-description', Language::EN());

Method will return instance of Orkhanahmadov\Goldenpay\Response\PaymentKey. You can access payment key and payment url from this object instance.

$paymentKey->getCode(); // endpoint response code
$paymentKey->getMessage(); // endpoint response message
$paymentKey->getPaymentKey(); // unique payment key
$paymentKey->paymentUrl(); // payment url. you should redirect user to this url to start payment

Important! Goldenpay charges all payments only in AZN.

Checking payment result

To check payment result use result method.

Method accepts following arguments:

  • Payment key - Previously available payment key
$paymentResult = $goldenpay->result('payment-key-here');

Method also accepts instance of Orkhanahmadov\Goldenpay\Response\PaymentKey as an argument.

Method will return instance of Orkhanahmadov\Goldenpay\Response\PaymentResult. You can access following properties from this object instance:

$paymentResult->getCode(); // status code
$paymentResult->getMessage(); // status message
$paymentResult->getPaymentKey(); // instance of Orkhanahmadov\Goldenpay\Response\PaymentKey
$paymentResult->getMerchantName(); // merchant name
$paymentResult->getAmount(); // charged amount in integer format. 100 = 1.00
$paymentResult->getCheckCount(); // shows how many times this payment key result checked
$paymentResult->getPaymentDate(); // \DateTimeImmutable instance of payment date
$paymentResult->getCardNumber(); // charged card number. only first 6 digits and last 4 digits. Example: 422865******8101
$paymentResult->getLanguage(); // 2 letter interface language: 'lv', 'en' or 'ru'
$paymentResult->getDescription(); // description used for payment
$paymentResult->getReferenceNumber(); // payment reference number

You can also use global helper function. Calling this function requires passing "auth key" and "merchant name".

$goldenpay = goldenpay('auth-key-here', 'merchant-name-here'); // returns instance of "Orkhanahmadov\Goldenpay\Goldenpay"
$goldenpay->payment(100, CardType::VISA(), 'your-description', Language::EN());

Orkhanahmadov\Goldenpay\Goldenpay implements Orkhanahmadov\Goldenpay\GoldenpayInterface. You can use this interface as abstraction for dependency injection.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

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

License

The MIT License (MIT). Please see License File for more information.