duronrulez/ginger-php

Ginger Payments PHP 5.3 SDK

0.1.0 2015-03-19 00:35 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:46:41 UTC


README

Build Status Code Coverage Scrutinizer Code Quality MIT License

您可以在 https://www.gingerpayments.com 上注册 Ginger Payments 账户

需求

  • PHP 5.4 或更高版本。

安装

您可以使用 composer 安装 PHP 绑定

composer require gingerpayments/ginger-php

您也可以通过注册自动加载函数而不使用 Composer 使用 PHP 绑定

spl_autoload_register(function($class) {
    $prefix = 'GingerPayments\\Payment\\';

    if (!substr($class, 0, 23) === $prefix) {
        return;
    }

    $class = substr($class, strlen($prefix));
    $location = __DIR__ . 'path/to/gingerpayments/ginger-php/src/' . str_replace('\\', '/', $class) . '.php';

    if (is_file($location)) {
        require_once($location);
    }
});

入门

首先使用您的 API 密钥创建一个新的 API 客户端

use \GingerPayments\Payment\Ginger;

$client = Ginger::createClient('your-api-key');

创建新订单

创建新订单非常简单

$order = $client->createOrder(
    2500,                           // The amount in cents
    'EUR',                          // The currency
    'ideal',                        // The payment method
    ['issuer_id' => 'INGBNL2A'],    // Extra details required for this payment method
    'A great order',                // A description (optional)
    'order-234192',                 // Your identifier for the order (optional)
    'http://www.example.com',       // The return URL (optional)
    'PT15M'                         // The expiration period in ISO 8601 format (optional)
);

您还可以使用 createIdealOrder 方法使用 iDEAL 支付方式创建新订单

$order = $client->createIdealOrder(
    2500,                           // The amount in cents
    'EUR',                          // The currency
    'INGBNL2A',                     // The iDEAL issuer
    'A great order',                // A description (optional)
    'order-234192',                 // Your identifier for the order (optional)
    'http://www.example.com',       // The return URL (optional)
    'PT15M'                         // The expiration period in ISO 8601 format (optional)
);

或者使用 createCreditCardOrder 方法

$order = $client->createCreditCardOrder(
    2500,                           // The amount in cents
    'EUR',                          // The currency
    'A great order',                // A description (optional)
    'order-234192',                 // Your identifier for the order (optional)
    'http://www.example.com',       // The return URL (optional)
    'PT15M'                         // The expiration period in ISO 8601 format (optional)
);

一旦您创建了订单,就会创建一个事务并将其关联。您需要将用户重定向到事务的支付 URL,如下所示

$paymentUrl = $order->firstTransactionPaymentUrl();

还建议您将订单 ID 存储在某个地方,以便您可以稍后检索有关它的信息

$orderId = $order->id();

您还可以访问与订单相关的其他信息。查看 GingerPayments\Payment\Order 类以获取更多信息。如果您只想作为简单的数组,您还可以使用 Order::toArray 方法。

获取订单

如果您想检索现有订单,请使用客户端上的 getOrder 方法

$order = $client->getOrder($orderId);

您可以如下迭代订单中的所有交易

foreach ($order->transactions() as $transaction) {
    $transaction->status()->isCompleted(); // Check the status
    $transaction->amount(); // How much paid
}

您还可以访问与订单交易相关的其他信息。查看 GingerPayments\Payment\Order\Transaction 类以获取更多信息。

获取 iDEAL 发行人

当您使用 iDEAL 支付方式创建订单时,您需要提供一个发行人 ID。发行人 ID 是用户选择的银行的标识符。您可以通过使用 getIdealIssuers 方法检索所有可能的发行人

$issuers = $client->getIdealIssuers();

然后您可以使用这些信息向用户提供一个可能的银行列表供选择。

API 文档

完整的 API 文档可在 此处 获取。

测试

为了运行测试,首先通过 Composer 安装 PHPUnit

composer install --dev

然后运行测试套件

./vendor/bin/phpunit