thekiharani/spreedly

Spreedly API

dev-main 2023-01-11 18:03 UTC

This package is auto-updated.

Last update: 2024-09-07 15:02:41 UTC


README

变更日志 !! 从 2.0 版本开始,金额必须是整数,这是 Spreedly 所要求的。例如,$10.98 为 1098 !!

入门指南

设置/安装

通过 Composer 安装。

composer require fattmerchantorg/spreedly

Laravel 4 或 5 设置

接下来,更新 app/config/app.php,在 providers 数组中包含对该包服务提供者的引用,并在 aliases 数组中包含对外观的引用。

'providers' => [
    ...
   'Fattmerchant\Spreedly\SpreedlyServiceProvider'
]

'aliases' => [
    ...
    'Spreedly' => 'Fattmerchant\Spreedly\SpreedlyFacade'
]

登录 到您的 Spreedly 账户以检索您的 API 凭据。创建第一个网关后,您可以为默认网关设置。

添加到 app/config/services.php 配置文件。

return [

    ...

    'spreedly' => [
        'key' => '', // (required) Environment key
        'secret' => '', // (required) Signing Secret
        'gateway' => '', // (required) Default gateway
        'timeout' => '', // (optional) Default 64 seconds (recommended by Spreedly)
        'connect_timeout' => '', // (optional) Default 10 seconds
    ]

];

默认设置(非 Laravel)

$config = [
    'key' => '', // (required) Environment key
    'secret' => '', // (required) Signing Secret
    'gateway' => '', // (required) Default gateway
    'timeout' => '', // (optional) Default 64 seconds (recommended by Spreedly)
    'connect_timeout' => '', // (optional) Default 10 seconds
];

$spreedly = new Fattmerchant\Spreedly\Spreedly($config);

// The amount must be an integer as per required by Spreedly. E.g., 1098 for $10.98.
$resp = $spreedly->payment($paymentToken)->purchase(1098);

示例响应处理

// If the call to Spreedly is successful
if ($resp->success()) {
    return $resp->response();
    // $resp->transactionToken();
    // $resp->paymentToken();
    // $resp->message();
}

// If the call to Spreedly fails or payment declines
if ($resp->fails()) {

    // returns array
    return $resp->errors();

    // returns list of errors as a string
    return $resp->errors(true);
}

更多文档

网关

支付方式

交易

所有方法快速列表

注意:以下许多方法返回多个令牌。确保在存储令牌时存储正确的令牌以供以后使用。

// Gateway calls.
Spreedly::gateway()->setup();
Spreedly::gateway()->all();
Spreedly::gateway()->show();
Spreedly::gateway()->create();
Spreedly::gateway()->disable();
Spreedly::gateway()->update();
Spreedly::gateway()->transactions();

// If using multiple gateways, you can set the gateway token before the payment call.
Spreedly::gateway()->payment()->purchase();
Spreedly::gateway()->payment()->authorize();

// Uses default gateway.
Spreedly::payment()->all();
Spreedly::payment()->create();
Spreedly::payment()->update();
Spreedly::payment()->disable();
Spreedly::payment()->retain();
Spreedly::payment()->recache();
Spreedly::payment()->store();
Spreedly::payment()->get();
Spreedly::payment()->transactions();
Spreedly::payment()->purchase();
Spreedly::payment()->authorize();
Spreedly::payment()->verify();
Spreedly::payment()->generalCredit();

// Transaction calls
Spreedly::transaction()->all();
Spreedly::transaction()->get();
Spreedly::transaction()->referencing();
Spreedly::transaction()->transcript();
Spreedly::transaction()->purchase();
Spreedly::transaction()->void();
Spreedly::transaction()->credit();
Spreedly::transaction()->capture();
Spreedly::transaction()->complete();

开发

克隆仓库并运行 npm install。这将执行 composer install

测试

测试位于 spec 目录中。它们是用 phpspec 编写的。

要运行测试,只需执行 npm test。如果您不想使用 npm,也可以,只需运行 vendor/bin/phpspec run

请确保您为每个拉取请求添加了适当的测试覆盖率。

变更日志

2.4+

请参阅发行页面 https://github.com/fattmerchantorg/spreedly/releases

2.3

  • 添加了对 Laravel 5.4 的支持

2.2

  • 添加了合并配置的能力

2.1

  • 将默认超时时间从 15 秒更改为 Spreedly 推荐的 64 秒
  • 添加了超时方法以在每个 API 调用中更改超时。例如,Spreedly::timeout(25)->payment()->purchase()
  • 添加了新的 Fattmerchant\Spreedly\Exceptions\TimeoutException 用于捕获超时。

2.0

  • 金额不再转换为分
    • 金额必须是整数,这是 Spreedly 所要求的。例如,$10.98 为 1098
  • 从 Spreedly xml api 切换到 json api。
  • ->declined() 方法重命名为 ->message()