orkhanahmadov / goldenpay
PHP和Laravel框架的GoldenPay支付库
2.2
2021-07-31 09:50 UTC
Requires
- php: ^7.3|^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.5|^7.0
- myclabs/php-enum: ^1.8
Requires (Dev)
- blastcloud/guzzler: ^2.0
- phpunit/phpunit: ^8.0|^9.0
README
如果您正在使用Laravel,您可以使用laravel-goldenpay包来更好地集成额外的功能。
要求
PHP 7.2 或更高版本,且带有 json 扩展。
安装
composer require orkhanahmadov/goldenpay
使用
首先,实例化 Orkhanahmadov\Goldenpay\Goldenpay 并使用“认证密钥”和“商户名称”调用 authenticate() 方法。这两个都可以从Goldenpay商户仪表板获取。
use Orkhanahmadov\Goldenpay\Goldenpay; $goldenpay = new Goldenpay(); $goldenpay->authenticate('auth-key-here', 'merchant-name-here');
获取支付密钥
要获取新的支付密钥,请使用 payment 方法。
此方法接受以下参数
- 金额 - 要收取的金额。仅接受整数。例如,10.25需要转换为1025。
- 卡类型 - 需要实例化
Orkhanahmadov\Goldenpay\Enums\CardType。使用CardType::VISA()表示VISA,使用CardType::MASTERCARD()表示MasterCard。 - 描述 - 与支付相关的描述
- 语言 (可选) - 设置支付页面界面语言。需要实例化
Orkhanahmadov\Goldenpay\Enums\Language。使用Language::EN()表示英文,使用Language::RU()表示俄文,使用Language::AZ()表示阿塞拜疆文。默认为阿塞拜疆文。
$paymentKey = $goldenpay->payment(100, CardType::VISA(), 'item-description', Language::EN());
方法将返回 Orkhanahmadov\Goldenpay\Response\PaymentKey 实例。您可以从该对象实例访问支付密钥和支付URL。
$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
重要! Goldenpay仅在AZN中收取所有支付。
检查支付结果
要检查支付结果,请使用 result 方法。
此方法接受以下参数
- 支付密钥 - 之前可用的支付密钥
$paymentResult = $goldenpay->result('payment-key-here');
方法还接受 Orkhanahmadov\Goldenpay\Response\PaymentKey 实例作为参数。
方法将返回 Orkhanahmadov\Goldenpay\Response\PaymentResult 实例。您可以从该对象实例访问以下属性
$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
您还可以使用全局辅助函数。调用此函数需要传递“认证密钥”和“商户名称”。
$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 实现了 Orkhanahmadov\Goldenpay\GoldenpayInterface。您可以将此接口用作依赖注入的抽象。
测试
composer test
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
贡献
有关详细信息,请参阅CONTRIBUTING。
安全性
如果您发现任何与安全相关的问题,请通过电子邮件ahmadov90@gmail.com而不是使用问题跟踪器来报告。
致谢
许可
MIT许可(MIT)。有关更多信息,请参阅许可文件。