aliromero/perfect-money-api

此包让您轻松将PerfectMoney API集成到PHP应用中。

dev-master 2023-04-04 15:48 UTC

This package is auto-updated.

Last update: 2024-09-04 18:49:06 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

一个易于使用的PHP包,用于将PerfectMoney在线支付API集成到您的应用中。您可以使用PerfectMoney支付网关提供的标准功能。

只需安装此包,即可立即使用!无需额外工作!

要求

  • PHP >= 7.0

安装

如果您使用Composer作为依赖管理器,您可以通过在项目根目录下运行以下命令轻松下载并安装此包

$ composer require ayubirz/perfect-money-api:dev-master

目前只有dev-master版本可用。很快将会有稳定版本可供安装和使用。

使用

安装包后,您应该在代码中“使用”包的命名空间,您想在其中使用PerfectMoneyAPI方法的位置。例如,在您的Controller中,您应该在文件的开始处输入以下代码,在强类型命名空间your/name/space;之后

use AyubIRZ\PerfectMoneyAPI\PerfectMoneyAPI;

然后,您应该在任何需要的地方初始化PerfectMoneyAPI类的实例,如下所示

$PMAccountID = '1234567';      // This should be replaced with your real PerfectMoney Member ID(username that you login with).

$PMPassPhrase = 'mydummypass'; // This should be replaced with your real PerfectMoney PassPhrase(password that you login with).

$PM = new PerfectMoneyAPI($PMAccountID, $PMPassPhrase);

创建PerfectMoneyAPI类实例后,您就可以使用其中的可用方法了。

获取现有PerfectMoney账户的公开名称

$accountID = 'U123456'; // A valid PM currency account ID that you want to get it's name.

try{
  $PMname = $PM->getAccountName($accountID); // The account name(if it's valid) will return. Otherwise you have an error.
} catch (Exception $exception) {
  return $exception->getMessage();
}

return $PMname;

如果发生任何错误,将抛出异常。请检查代码以获取有关异常的更多信息。

获取您账户的完整余额(货币当前金额)

$PMbalance = $PM->getBalance(); // array of all your currency wallets(as keys) and all of their balances(as values) will return.

return json_encode($PMbalance);

获取您账户特定钱包的余额(货币当前金额)

如果您只想获取特定钱包的余额,请在以下方法中指定您的钱包ID作为唯一参数。例如,我想获取我的USD钱包的余额

$PMAccountID = 'U123456'; // Replace this with one of your wallet IDs.

$PMbalance = $PM->getBalance($PMAccountID); // A float number indicating your input wallet's balance will return(For example 250.05 USD in my case).

return json_encode($PMbalance);

将资金(货币,金额)转账到另一个现有PerfectMoney账户

如果您想向任何其他PerfectMoney账户转账金额(货币),您可以使用以下方法并指定参数

$fromAccount = 'U123456'; // Replace this with one of your own wallet IDs that you want to transfer currency from.

$toAccount = 'U654321'; // Replace this with the destination wallet ID that you want to transfer currency to.

$amount = 250; // Replace this with the amount of currency unit(in this case 250 USD) that you want to transfer.

$paymentID = microtime(); // Replace this with a unique payment ID that you've generated for this transaction. This can be the ID for the database stored record of this payment for example(Up to 50 characters). ***THIS PARAMETER IS OPTIONAL***

$memo = 250; // Replace this with a description text that will be shown for this transaction(Up to 100 characters). ***THIS PARAMETER IS OPTIONAL***

$PMtransfer = $pm->transferFund($fromAccount, $toAccount, $amount, $paymentID, $memo); // An array of previously provided data will return for a valid and successful transaction. If any error happen, an array with one item with the key "ERROR" will return.

return json_encode($PMtransfer);

创建新的PerfectMoney电子券

电子券类似于礼品卡。一个电子券可能包含一定数量的货币信用,并且它可以用于为账户充值等。要从您的钱包信用中创建一个新的电子券,请按照以下方法使用以下方法

$payerAccount = 'U123456'; // Replace this with one of your own wallet IDs that you want to create the E-Voucher from it.
    
$amount = 250; // Replace this with the amount of currency unit(in this case 250 USD) that you want to fund the created E-Voucher. E-Voucher amount unit must be greater than 1.

$PMeVoucher = $pm->createEV($payerAccount, $amount); // An array of E-Voucher data(Payer_Account, PAYMENT_AMOUNT, PAYMENT_BATCH_NUM, VOUCHER_NUM, VOUCHER_CODE, VOUCHER_AMOUNT) will return for a valid and successful transaction. If any error happen, an array with one item with the key "ERROR" will return.

return json_encode($PMeVoucher);

返回的数组如下

  • Payer_Account:您用于创建电子券的账户。

  • PAYMENT_AMOUNT:输入的电子券金额。这是您支付的总额,包括费用。

  • PAYMENT_BATCH_NUM:为此交易生成的PerfectMoney批次编号。您可以通过此编号查询/搜索账户历史。

  • VOUCHER_NUM:购买的电子券的唯一编号,包含10位数字。

  • VOUCHER_CODE:购买的电子券的激活码,包含16位数字。

  • VOUCHER_AMOUNT:电子券的票面金额。这与输入字段中的金额相同。

支持

如果您发现了一个错误或您有使用问题,请使用GitHub问题跟踪器

或通过电子邮件联系我:ayubirazeh@gmail.com

许可

本软件包采用MIT许可协议(MIT)发布。请参阅许可文件获取更多信息。