riazxrazor / payumoney
PayUMoney 库,适用于 Laravel 和核心 PHP
1.0.4
2020-01-17 09:21 UTC
Requires
- php: >=5.6.0
- illuminate/support: ^5.5|^6
- symfony/http-foundation: ^4.0
This package is not auto-updated.
Last update: 2024-09-27 15:25:14 UTC
README
一个简单的库/包,用于通过 PayUMoney 接收支付。
演示项目示例
https://github.com/riazXrazor/riazXrazor-payumoey-example
安装
要将此库添加到您的项目中,请简单地在项目的 composer.json
文件中添加对 riazxrazor/payumoney
的依赖。以下是一个 composer.json 文件的示例。
{
"require": {
"riazxrazor/payumoney": "1.*"
}
}
或者您可以从项目的目录中运行此命令。
composer require riazxrazor/payumoney
Laravel 使用方法 (非 Laravel 使用方法见下文)
配置
打开 config/app.php
并在 providers
部分添加此行。
Riazxrazor\Payumoney\PayumoneyServiceProvider::class,
在 aliases
部分添加此行。
'Payumoney' => Riazxrazor\Payumoney\PayumoneyFacade::class
运行此命令以获取 config
。
php artisan vendor:publish --tag=config
配置选项可以在 config/payumoney.php
中找到。
'KEY' => '',
'SALT' => '',
'TEST_MODE' => TRUE,
'DEBUG' => FALSE
基本用法
您可以使用函数如下。
// All of these parameters are required! // Redirects to PayUMoney \Payumoney::pay([ 'txnid' => 'A_UNIQUE_TRANSACTION_ID', 'amount' => 10.50, 'productinfo' => 'A book', 'firstname' => 'Peter', 'email' => 'abc@example.com', 'phone' => '1234567890', 'surl' => url('payumoney-test/return'), 'furl' => url('payumoney-test/return'), ])->send(); // In the return method of controller $result = \Payumoney::completePay($_POST); if ($result->checksumIsValid() AND isSuccess()) { print 'Payment was successful.'; } else { print 'Payment was not successful.'; } The `PayumoneyResponse` has a few more methods that might be useful: $result = \Payumoney::completePay($_POST); // Returns Complete, Pending, Failed or Tampered $result->getStatus(); // Returns an array of all the parameters of the transaction $result->getParams(); // Returns the ID of the transaction $result->getTransactionId(); // Returns true if the checksum is correct $result->checksumIsValid();
非 Laravel 使用方法
对于非 Laravel 使用
完成支付
<?php // pay.php use Riazxrazor\Payumoney; require 'vendor/autoload.php'; $payumoney = new Payumoney\Payumoney([ 'KEY' => 'YOUR_MERCHANT_KEY', 'SALT' => 'YOUR_MERCHANT_SALT', 'TEST_MODE' => true, // optional default to true 'DEBUG' => FALSE // optional default to false ]); // All of these parameters are required! $params = [ 'txnid' => 'A_UNIQUE_TRANSACTION_ID', 'amount' => 10.50, 'productinfo' => 'A book', 'firstname' => 'Peter', 'email' => 'abc@example.com', 'phone' => '1234567890', 'surl' => 'https:///payumoney-test/return.php', 'furl' => 'https:///payumoney-test/return.php', ]; // Redirects to PayUMoney $payumoney->pay($params)->send();
完成支付
<?php // return.php use Riazxrazor\Payumoney; require 'vendor/autoload.php'; $payumoney = new Payumoney\Payumoney([ 'KEY' => 'YOUR_MERCHANT_KEY', 'SALT' => 'YOUR_MERCHANT_SALT', 'TEST_MODE' => true, // optional default to true 'DEBUG' => FALSE // optional default to false ]); $result = $payumoney->completePay($_POST); if ($result->checksumIsValid() && $result->isSuccess()) { print 'Payment was successful.'; } else { print 'Payment was not successful.'; }
PayumoneyResponse
有一些可能有用的额外方法。
$result = $payumoney->completePay($_POST); // Returns Complete, Pending, Failed or Tampered $result->getStatus(); // Returns an array of all the parameters of the transaction $result->getParams(); // Returns the ID of the transaction $result->getTransactionId(); // Returns true if the checksum is correct $result->checksumIsValid();