mynameiszanders/cashflows

此包已被废弃且不再维护。未建议替代包。

Cashflows PHP API 库。

1.0.0-rc1 2014-08-15 12:44 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:38:24 UTC


README

由 Zander Baldwin 开发,用于与 Cashflows API 通信的 PHP 库,适用于 Nosco Systems,版本 1.0.0-RC1

可用的 API 请求

尽管每个请求对象都可以独立从其相应的类中实例化,但通过客户端对象(Nosco\Cashflows\Client)中的专用方法创建它更简单 - 这会自动为每个请求设置 Auth ID 和密码。

可用的专用方法和它们对应的请求类如下:

专用方法 请求对象类
paymentRequest() Nosco\Cashflows\Request\Payment.
mobilePaymentRequest() Nosco\Cashflows\Request\Payment\Mobile.
continuousPaymentRequest() Nosco\Cashflows\Request\Payment\Continuous.
alternativeRecurringPaymentRequest() Nosco\Cashflows\Request\Payment\AlternativeRecurring.
voidRequest() Nosco\Cashflows\Request\Void.
refundRequest() Nosco\Cashflows\Request\Refund.
verificationRequest() Nosco\Cashflows\Request\Verification.

发送请求

在发送请求之前,每个请求对象必须填写一组属性,这些属性在 Cashflows 的 远程 API 集成指南(版本 1.7,2014 年 4 月)中有文档记录。

可以使用请求对象的 attribute() 方法输入属性,并通过 send() 方法发送 API 调用。一旦 API 调用成功,从 send() 方法返回一个 Nosco\Cashflows\Response\Authorised 响应对象。

捕获错误

以下为异常树;只有叶节点的异常类会被抛出,其他都是用于分组捕获。所有异常都带有命名空间前缀 Nosco\Cashflows\Exceptions

  • BaseException 永远不会被抛出(仅用于分组捕获)。
    • 验证.
    • 传输.
    • CashflowsSystem.
    • Response 永远不会被抛出(仅用于分组捕获)。
      • Response\InvalidResponse.
      • Response\NotAuthorised 永远不会被抛出(仅用于分组捕获)。
        • Response\NotAuthorised\Blocked.
        • Response\NotAuthorised\Cancelled.
        • Response\NotAuthorised\Declined.
        • Response\NotAuthorised\InvalidRequest.

示例用法

<?php

    use Nosco\Cashflows\Client as CashflowsClient;
    use Nosco\Cashflows\Exceptions as Error;

    $cashflows = new CashflowsClient('authorisation_id', 'p@55w0rd');
    $request = $cashflows->paymentRequest();
    $request->attributes([
        'card_num' => '1234567890123452',
        'card_cvv' => '123',
        'card_expiry' => '0317',
        ...
    ]);

    try {
        $response = $request->send();
        var_dump($response);

        # object(Nosco\Cashflows\Response\Authorised)[1]
        #   protected 'transactionId' => string '01S00001722' (length=11)
        #   protected 'cvvCheck' => int 2
        #   protected 'addressCheck' => int 3
        #   protected 'postcodeCheck' => int 2
        #   protected 'authCode' => string '031971' (length=6)

    }

    // Catch any errors that occur before or during the API call to Cashflows (request exceptions):
    catch(Error\Validation $e) {}
    catch(Error\Transport $e) {}

    // Catch any errors that occur after the API call to Cashflows (response exceptions):
    # You can use the Error\Response\NotAuthorisedException to cover the first four, or Error\ResponseException to
    # cover all five.
    catch(Error\Response\NotAuthorised\Blocked $e) {}
    catch(Error\Response\NotAuthorised\Cancelled $e) {}
    catch(Error\Response\NotAuthorised\Declined $e) {}
    catch(Error\Response\NotAuthorised\InvalidRequest $e) {}
    catch(Error\Response\InvalidResponse $e) {}

    // Catch any errors that Cashflows had:
    catch(Error\System $e) {}

    // Catch any other errors that happened within the library during the API call:
    # You can just use this catch block to catch everything, without any of the above catch blocks.
    catch(Error\BaseException $e) {}