edcs/mondo-php

该软件包已被弃用,不再维护。未建议替代软件包。

用 PHP 编写的 Mondo API 客户端

维护者

详细信息

github.com/edcs/mondo-php

源代码

问题

安装: 28

依赖项: 0

建议者: 0

安全性: 0

星星: 4

关注者: 1

分支: 1

开放问题: 0

类型:软件包

dev-master 2016-07-28 08:32 UTC

This package is not auto-updated.

Last update: 2021-02-19 23:06:04 UTC


README

Codeship Status for edcs/mondo-php Coverage Status StyleCI SensioLabsInsight

此软件包是一个 PHP-HTTPPSR-7 兼容的客户端,用于在您的 PHP 项目中访问 Mondo API。

此软件包目前正在开发中,请现在使用 dev-master

安装

您可以使用 Composer 安装此项目。尽管在安装此软件包之前,您需要选择您的 PHP-HTTP 客户端。要了解更多关于 PHP-HTTP 的信息,您可以在此处阅读文档 这里

此软件包已广泛使用 Guzzle 6 进行测试,如果您在项目中尚未使用 HTTP 客户端,则可以使用以下命令使用 Guzzle:

composer require php-http/guzzle6-adapter
composer require edcs/mondo-php

如果您在项目中已经使用了一个不同的 HTTP 客户端,您可以检查是否有可用的 PHP-HTTP 适配器 这里

获取访问令牌

如果您想要一个简单的方法来创建访问令牌,您可以使用 提供者来为 Legue OAuth 2.0 Client 创建访问令牌。

入门

要实例化一个新的资源,首先您需要创建您的 PHP-HTTP 客户端实例,此示例使用 Guzzle 6。如果您使用 Guzzle,您还需要在可以使用此软件包的资源类之前,将客户端实例注入到 PHP-HTTP 客户端工厂中。

$client = new \GuzzleHttp\Client([
    'base_uri' => 'https://api.getmondo.co.uk',
    'headers'  => [
        'Authorization' => 'Bearer {your-access-token}',
    ],
]);

$client = new Http\Adapter\Guzzle6\Client($client);

$ping = new Edcs\Mondo\Resources\Ping($client);

Ping 资源

此资源包含以下方法

  • whoAmI() - 返回一个 WhoAmI 实例,该实例描述了当前访问令牌。
$ping = new Edcs\Mondo\Resources\Ping($client);

$entity = $ping->whoAmI();

$entity->getAuthenticated() // true/false depending on if the current access token is authenticated.
$entity->getClientId() // A string containing the client id associated with the current access token.
$entity->getUserId() // A string containing the id of the user associated with the current access token.

账户资源

此资源包含以下方法

  • get() - 返回一个 Collection 实例,该实例描述了当前用户的 Mondo 账户。
$accounts = new Edcs\Mondo\Resources\Accounts($client);

$collection = $accounts->get()

foreach ($collection as $account) {
    $account->getId(); // A string containing the id of the account.
    $account->getDescription(); // A string containing the account description.
    $account->getAccountNumber(); // A string containing the account number.
    $account->getSortCode(); // A string containing the account sort code.
    $account->getCreated(); // A string containing the date when the account was created.
}

余额资源

此资源包含以下方法

  • find($accountId) - 返回一个 Balance 实例,该实例描述了提供的账户的账户余额。
$accountId = 'acc_00009237aqC8c5umZmrRdh';

$accounts = new Edcs\Mondo\Resources\Accounts($client);

$entity = $accounts->find($accountId);

$entity->getBalance(); // Returns the account balance in pence.
$entity->getCurrency(); // Returns the ISO currency code for this account.
$entity->getSpendToday(); // Returns the amount spent today in pence for this account.

交易资源

此资源包含以下方法

  • get($accountId) - 返回一个 Collection 实例,该实例描述了在提供的账户上的交易。
  • find($transactionId) - 返回一个 Transaction 实例,该实例描述了提供的交易。
  • annotate($transactionId, $annotation) - 创建一个新的注释和一个 Transaction 实例,该实例描述了提供的交易。
$accountId = 'acc_00009237aqC8c5umZmrRdh';

$transactions = new Edcs\Mondo\Resources\Transactions($client);

$collection = $transactions->get($accountId);

foreach ($collection as $entity) {
    $entity->getAccountBalance(); // Returns the account balance in pence after this transaction.
    $entity->getAmount(); // Returns the transaction amount in pence.
    $entity->getCreated(); // Returns a string containing the date of this transaction.
    $entity->getId(); // Returns a string containing the transaction id.
    $entity->getMerchant(); // Returns an array containing information about the merchant.
    $entity->getMetadata(); // Returns an array contianing any metadata associated with this transaction.
    $entity->getNotes(); // Returns notes which describe this tranaction.
    $entity->getIsLoad(); // Returns true if this transation is a top-up, otherwise returns false.
    $entity->getSettled(); // Returns a string containing the date this transaction was settled.
    $entity->getCategory(); // Returns the category which this transaction belongs to.
}

$transactionId = 'tx_00008zIcpb1TB4yeIFXMzx';

$entity = $this->find($transactionId); // Entity methods described above.

$metadata = [
    'metadata_key' => 'This is a metadata description.'
];

$entity = $this->annotate($transactionId , $metadata); // Entity methods described above.

测试

$ ./vendor/bin/phpunit

贡献

请参阅CONTRIBUTING获取详细信息。

安全漏洞

如果您在此软件包中发现安全漏洞,请发送电子邮件至edcoleridgesmith@gmail.com。所有安全漏洞都将得到及时处理。

许可协议

MIT许可协议(MIT)。有关更多信息,请参阅许可文件