el3zahaby/payumoney

PayUMoney库用于Laravel和核心PHP

1.0.4 2020-01-17 09:21 UTC

This package is auto-updated.

Last update: 2024-09-23 07:23:20 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();