v3labs/payubiz

0.3.1 2018-07-23 15:19 UTC

This package is auto-updated.

Last update: 2024-09-26 11:53:00 UTC


README

这是一个用于通过PayUbiz接受支付的简单库。

安装

要将此库添加到您的项目中,只需将v3labs/payubiz添加到您的项目中的composer.json文件中作为依赖项。以下是一个 composer.json 文件的示例:

{
    "require": {
        "v3labs/payubiz": "^0.3"
    }
}

用法

下面是一个最小化用法示例。

初始化购买

<?php
// purchase.php

use V3labs\PayUbiz\PayUbiz;

require 'vendor/autoload.php';

$payubiz = new PayUbiz(array(
    'merchantId' => 'YOUR_MERCHANT_ID',
    'secretKey'  => 'YOUR_SECRET_KEY',
    'testMode'   => true
));

// 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:///payubiz-php/return.php',
    'furl'        => 'https:///payubiz-php/return.php',
];

// Redirects to PayUbiz
$client->initializePurchase($params)->send();

完成购买

<?php
// return.php

use V3labs\PayUbiz\PayUbiz;

require 'vendor/autoload.php';

$payubiz = new PayUbiz([
    'merchantId' => 'YOUR_MERCHANT_ID',
    'secretKey'  => 'YOUR_SECRET_KEY',
    'testMode'   => true
]);

$result = $payubiz->completePurchase($_POST);

if ($result->checksumIsValid() && $result->getStatus() === PayUbiz::STATUS_COMPLETED) {
  print 'Payment was successful.';
} else {
  print 'Payment was not successful.';
}

PurchaseResult有几个可能很有用的方法。

$result = $payubiz->completePurchase($_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();