settle/settle-sdk-php

连接 Settle 支付平台的 PHP SDK。

v1.2.3 2022-05-20 13:39 UTC

This package is auto-updated.

Last update: 2024-09-20 18:54:14 UTC


README

License Build Status Coverage Status

连接 Settle 支付平台的 PHP SDK

在几秒钟内开始接受 Settle 的支付

一个易于使用的 SDK,适用于 PHP,包含了启动与 Settle 支付平台集成所需的所有最佳实践。

安装

composer require settle/settle-sdk-php

使用方法

该库提供了一个基本的 Client 类,用于处理与 Settle REST API 的通信

$settle_client = new SettleApiClient(
    SETTLE_MERCHANT_ID,
    SETTLE_USER_ID,
    SETTLE_PUBLIC_KEY,
    SETTLE_PRIVATE_KEY,
    SETTLE_IN_SANDBOX
);

该库为每个 REST API 中的部分提供了一个入口点类。目前,只有 MerchantsApi 可用,因为权限和 OAuth2 正在等待重大更改,并将很快添加。

Merchants API

以下类作为该部分所有资源的入口点

$merchant_api = new MerchantApi($settle_client);

每个资源(类)都可以通过 Merchants API 对象上的魔术属性访问

$merchant_api->api_keys->...;
$merchant_api->balance->...;
$merchant_api->payment_requests->...;
$merchant_api->payment_send->...;
$merchant_api->pos->...;
$merchant_api->profile->...;
$merchant_api->settlements->...;
$merchant_api->short_links->...;
$merchant_api->status_codes->...;

每个类实现的方法与 REST API 规范非常接近

$merchant_api->api_keys->list();
$merchant_api->api_keys->get($api_key_id);
$merchant_api->api_keys->create($api_key_data);
$merchant_api->api_keys->update($api_key_id, $api_key_data);
$merchant_api->api_keys->delete($api_key_id);

只有 PaymentRequests 类有几个额外的辅助方法

$merchant_api->payment_requests->capture($payment_request_id,$currency,$amount)
$merchant_api->payment_requests->refund($payment_request_id, $currency, $amount);
$merchant_api->payment_requests->getLink($payment_request_id);
$merchant_api->payment_requests->getDeepLink($payment_request_id);

Webhooks / 回调

为了验证来自 Settle 的回调请求,Apache 和 nginx 服务器都需要手动设置以将 Authorization 标头传递给 PHP。

以下为 Apache 的示例

RewriteEngine On
RewriteRule .* - [e=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

以下为 nginx 的示例

proxy_set_header Authorization $http_authorization;
proxy_pass_header  Authorization;

SettleApiClient 类上的两个方法可用于与回调相关联

// the following will return 
$is_valid = $settle_client->isValidCallback($callbackUrl, $body, $headers, $method);

// the following method will grab the data Settle sent in the current request
$settle_data = $settle_client->getCallbackData();  

深度链接

SettleApiClient 类提供了一个辅助方法,用于从短链接创建深度链接,以便在移动设备上使用。它们直接与 Settle 移动应用集成。示例

$short_link = 'https://settle.eu/s/gSpEb/pos123/';
$deep_link = $settle_client->getDeepLink($short_link);