divido/merchant-sdk

该软件包最新版本(v4.1.1)没有可用的许可证信息。

该软件包的官方仓库似乎已不存在,因此该软件包已被冻结。


README

PHP 商户 SDK

运行 phpunit 和 phpstan

这些命令要正常工作,需要 Docker 运行。

phpunit: make ci-test
phpstan: make ci-analyze

要求

3.0.0 版本及以上支持 PHP 5.6 到 7.0

4.0.0 版本及以上支持 PHP 7.4 及以上。

入门指南

您可以使用以下命令通过 Composer 安装此 SDK:

composer require divido/merchant-sdk

基本 SDK 使用

创建商户 SDK(Divido 租户)

<?php

// find the environment
$array = explode('_', 'test_cfabc123.querty098765merchantsdk12345');
$identifier = strtoupper($array[0]);
$env =  ('LIVE' == $identifier)
    ? constant("Divido\MerchantSDK\Environment::PRODUCTION")
    : constant("Divido\MerchantSDK\Environment::$identifier");

// create a client wrapper

$httpClientWrapper = new \Divido\MerchantSDK\Wrappers\HttpWrapper(
    \Divido\MerchantSDK\Environment::CONFIGURATION[$env]['base_uri'],
    'test_cfabc123.querty098765merchantsdk12345'
);

// create the sdk
$sdk = new \Divido\MerchantSDK\Client($httpClientWrapper, $env);

创建商户 SDK(非 Divido 租户)

"TENANT_API_KEY" 和 "TENANT_URI" 的值将由 Divido 提供

<?php

// find the environment
$array = explode('_', 'TENANT_API_KEY');
$identifier = strtoupper($array[0]);
$env =  ('LIVE' == $identifier)
    ? constant("Divido\MerchantSDK\Environment::PRODUCTION")
    : constant("Divido\MerchantSDK\Environment::$identifier");

// create a client wrapper

$httpClientWrapper = new \Divido\MerchantSDK\Wrappers\HttpWrapper(
    'TENANT_URI',
    'TENANT_API_KEY'
);

// create the sdk
$sdk = new \Divido\MerchantSDK\Client($httpClientWrapper, $env);

SDK 将自动尝试发现一个兼容的请求工厂接口来使用。但在 SDK 的 4+ 版本中,您可以明确指定这作为 Wrapper 的第三个参数,即

$httpClientWrapper = new \Divido\MerchantSDK\Wrappers\HttpWrapper(
    'TENANT_URI',
    'TENANT_API_KEY',
    new \Laminas\Diactoros\RequestFactory()
);

您也可以明确指定一个 Stream Factory Interface 作为您的第四个参数

$httpClientWrapper = new \Divido\MerchantSDK\Wrappers\HttpWrapper(
    'TENANT_URI',
    'TENANT_API_KEY',
    new \Laminas\Diactoros\RequestFactory()
    new \Laminas\Diactoros\StreamFactory()
);

获取所有财务计划

<?php

// Set any request options.
$requestOptions = (new \Divido\MerchantSDK\Handlers\ApiRequestOptions());

// Retrieve all finance plans for the merchant.
$plans = $sdk->getAllPlans($requestOptions);

$plans = $plans->getResources();

获取所有应用程序

<?php

// Set any request options.
$requestOptions = (new \Divido\MerchantSDK\Handlers\ApiRequestOptions());

// Retrieve all applications for the merchant.
$applications = $sdk->getAllApplications($requestOptions);

$applications = $applications->getResources();

获取单个应用程序

<?php
$application = $sdk->applications->getSingleApplication($applicationId);
$result = json_decode($application->getBody(), true);

创建应用程序

<?php

// Create an application model with the application data.
$application = (new \Divido\MerchantSDK\Models\Application())
    ->withCountryId('GB')
    ->withFinancePlanId('F335FED7A-A266-8BF-960A-4CB56CC6DE6F')
    ->withApplicants([
        [
            'firstName' => 'John',
            'lastName' => 'Smith',
            'phoneNumber' => '07512345678',
            'email' => 'john.smith@example.com',
            'addresses' => [[
                'text' => '115 High Street Westbury BA13 3BN'
            ]]
        ],
    ])
    ->withOrderItems([
        [
            'name' => 'Sofa',
            'quantity' => 1,
            'price' => 50000,
        ],
    ])
    ->withDepositAmount(10000)
    ->withFinalisationRequired(false)
    ->withMerchantReference("foo-ref")
    ->withUrls([
        'merchant_redirect_url' => 'http://merchant-redirect-url.example.com',
        'merchant_checkout_url' => 'http://merchant-checkout-url.example.com',
        'merchant_response_url' => 'http://merchant-response-url.example.com',
    ])
    ->withMetadata([
        'foo' => 'bar',
    ]);

// Note: If creating an application (credit request) on a merchant with a shared secret, you will have to pass in a correct hmac
$response = $sdk->applications()->createApplication($application, [], ['X-Divido-Hmac-Sha256' => 'EkDuBPzoelFHGYEmF30hU31G2roTr4OFoxI9efPxjKY=']);

$applicationResponseBody = $response->getBody()->getContents();

更新应用程序

<?php

// Create an application model with the application data.
$application = (new \Divido\MerchantSDK\Models\Application())
    ->withId('73bb63bf-212a-4598-afb6-cb1449280914')
    ->withCountryId('GB')
    ->withFinancePlanId('F335FED7A-A266-8BF-960A-4CB56CC6DE6F')
    ->withApplicants([
        [
            'firstName' => 'John',
            'lastName' => 'Smith',
            'phoneNumber' => '07512345678',
            'email' => 'john.smith@example.com',
            'addresses' => [[
                'text' => '115 High Street Westbury BA13 3BN'
            ]]
        ],
    ])
    ->withOrderItems([
        [
            'name' => 'Sofa',
            'quantity' => 1,
            'price' => 50000,
        ],
    ])
    ->withDepositAmount(10000)
    ->withFinalisationRequired(false)
    ->withMerchantReference("foo-ref")
    ->withUrls([
        'merchant_redirect_url' => 'http://merchant-redirect-url.example.com',
        'merchant_checkout_url' => 'http://merchant-checkout-url.example.com',
        'merchant_response_url' => 'http://merchant-response-url.example.com',
    ])
    ->withMetadata([
        'foo' => 'bar',
    ]);

// Note: If creating an application (credit request) on a merchant with a shared secret, you will have to pass in a correct hmac
$response = $sdk->applications()->updateApplication($application, [], ['X-Divido-Hmac-Sha256' => 'EkDuBPzoelFHGYEmF30hU31G2roTr4OFoxI9efPxjKY=']);

$applicationResponseBody = $response->getBody()->getContents();

激活应用程序

<?php

// First get the application you wish to create an activation for.
$application = (new \Divido\MerchantSDK\Models\Application())
    ->withId('application-id-goes-here');

// Create a new application activation model.
$applicationActivation = (new \Divido\MerchantSDK\Models\ApplicationActivation())
    ->withAmount(18000)
    ->withReference('Order 235509678096')
    ->withComment('Order was delivered to the customer.')
    ->withOrderItems([
        [
            'name' => 'Handbag',
            'quantity' => 1,
            'price' => 3000,
        ],
    ])
    ->withDeliveryMethod('delivery')
    ->withTrackingNumber('988gbqj182836');

// Create a new activation for the application.
$response = $sdk->applicationActivations()->createApplicationActivation($application, $applicationActivation);

$activationResponseBody = $response->getBody()->getContents();

取消应用程序

<?php

// First get the application you wish to create an cancellation for.
$application = (new \Divido\MerchantSDK\Models\Application())
    ->withId('application-id-goes-here');

// Create a new application cancellation model.
$applicationCancellation = (new \Divido\MerchantSDK\Models\ApplicationCancellation())
    ->withAmount(18000)
    ->withReference('Order 235509678096')
    ->withComment('As per customer request.')
    ->withOrderItems([
        [
            'name' => 'Handbag',
            'quantity' => 1,
            'price' => 3000,
        ],
    ]);

// Create a new cancellation for the application.
$response = $sdk->applicationCancellations()->createApplicationCancellation($application, $applicationCancellation);

$cancellationResponseBody = $response->getBody()->getContents();

退款应用程序

<?php

// First get the application you wish to create a refund for.
$application = (new \Divido\MerchantSDK\Models\Application())
    ->withId('application-id-goes-here');

// Create a new application refund model.
$applicationRefund = (new \Divido\MerchantSDK\Models\ApplicationRefund())
    ->withAmount(18000)
    ->withReference('Order 235509678096')
    ->withComment('As per customer request.')
    ->withOrderItems([
        [
            'name' => 'Handbag',
            'quantity' => 1,
            'price' => 3000,
        ],
    ]);

// Create a new refund for the application.
$response = $sdk->applicationRefunds()->createApplicationRefund($application, $applicationRefund);

$refundResponseBody = $response->getBody()->getContents();

分页、过滤和排序

您可以使用以下方法来进行分页、过滤和/或排序响应。

<?php

// Set any request options.
$requestOptions = (new \Divido\MerchantSDK\Handlers\ApiRequestOptions())
    // Set the page you'd like to retrieve (default page is 1)
    ->setPage(2)
    // Add an optional sort (method chaining also possible).
    ->setSort('-amount')
    // Filter responses by passing an array of arguments.
    ->setFilters([
        'current_status' => 'deposit-paid',
        'created_after' => '2015-01-01',
    ]);

// Retrieve all applications for the merchant.
$applications = $sdk->getApplicationsByPage($requestOptions);

$applications = $applications->getResources();