ayubirz/perfect-money-api

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

dev-master 2022-12-08 04:31 UTC

This package is not auto-updated.

Last update: 2024-09-19 12:00:13 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中,您应该在文件的开始处输入以下代码,在 namespace 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)发布。有关更多信息,请参阅 许可证文件