shift4/shift4-php

v3.3.0 2024-08-31 19:14 UTC

This package is auto-updated.

Last update: 2024-09-10 12:32:53 UTC


README

如果您还没有Shift4账户,您可以在这里创建。

安装

Composer

使用此库的最佳方式是通过 Composer

composer require shift4/shift4-php

然后要使用此库,您可以使用Composer的自动加载器

require_once('vendor/autoload.php');

手动安装

如果您不想使用Composer,您可以从最新版本下载。

然后要使用此库,您可以将自动加载器配置为从lib/目录加载类,或者使用包含的自动加载器

 require_once 'lib/Shift4/Util/Shift4Autoloader.php';
 \Shift4\Util\Shift4Autoloader::register();

快速入门示例

use Shift4\Shift4Gateway;
use Shift4\Exception\Shift4Exception;

$gateway = new Shift4Gateway('sk_test_[YOUR_SECRET_KEY]');

$request = [
    'amount' => 499,
    'currency' => 'EUR',
    'card' => [
        'number' => '4242424242424242',
        'expMonth' => 11,
        'expYear' => 2022
    ]
];

try {
    $charge = $gateway->createCharge($request);

    // do something with charge object - see https://dev.shift4.com/docs/api#charge-object
    $chargeId = $charge->getId();

} catch (Shift4Exception $e) {
    // handle error response - see https://dev.shift4.com/docs/api#error-object
    $errorType = $e->getType();
    $errorCode = $e->getCode();
    $errorMessage = $e->getMessage();
}

文档

有关更多信息,请参阅我们的官方文档https://dev.shift4.com/docs