stidner / php-sdk
此包已被弃用且不再维护。没有建议的替代包。
Stidner 完整 PHP SDK
dev-master
2017-04-20 11:36 UTC
Requires
- php: >=5.4.0
- ext-curl: *
- nategood/httpful: ^0.2.20
This package is not auto-updated.
Last update: 2022-02-01 13:01:25 UTC
README
Stidner PHP SDK
要求
至少 PHP 5.4。
安装
请通过 Composer 安装 SDK。
composer require stidner/php-sdk
然后使用 Composer 的自动加载功能加载 SDK
require_once('vendor/autoload.php');
依赖
SDK 依赖于
Httpful
库,- 和
curl
扩展。
使用 Composer 时,这些将自动处理。
用法
我们建议您阅读我们的完整文档,请访问 http://developer.stidner.com。
创建新订单
...但是简而言之,您需要
- 创建一个新的 API 实例;这包括您的 API 密钥和用户 ID。
$api_handle = new \Stidner\Api(API_USER_ID, 'API_KEY');
- 制作 API 所需的各种对象。请点击链接查看完整示例代码。
必需
可选
- 创建包含上述对象和一些最终变量的 订单 对象。
$order = new \Stidner\Model\Order(); $order->setMerchantReference1(null) ->setMerchantReference2(null) ->setPurchaseCountry('SE') ->setPurchaseCurrency('SEK') ->setLocale('sv_se') ->setTotalPriceExcludingTax(171000) ->setTotalPriceIncludingTax(213750) ->setTotalTaxAmount(42750) ->setBillingAddress($billingAddress) // Don't forget to add all the objects! ->addItem($item[1]) ->addItem($item[2]) ->setMerchantUrls($merchant) ->setOptions($options);
- 最后,将完整的 json 对象发送到 API 服务器!如果成功,响应应包含整个订单对象,并包含到我们 Stidner 完整支付系统的 URL;此 URL 应在您的结账页面的 iframe 中加载!
try { $request = $api_handle->createOrder($order); $iframeUrl = $request->getIframeUrl(); echo "<iframe src='$iframeUrl' width='75%' height='75%'></iframe>"; } catch (\Stidner\ApiException $e) { print $e; } catch (\Stidner\Api\ResponseException $e) { print $e; }
检查订单状态
与创建订单一样,您必须创建 API 实例
$api_handle = new \Stidner\Api(API_USER_ID, 'API_KEY');
现在执行 getOrder(),参数为 orderID。这将从 API 加载整个订单 json 对象。
$request = $api_handle->getOrder('ORDER_ID');
最后,在响应的 json 对象上调用 getStatus()。这将包括:purchase_incomplete(购买未完成)、purchase_complete(购买完成)或 purchase_refunded(购买退款)。
$orderStatus = $request->getStatus();
许可证
Stidner 的 PHP SDK 在 Apache License, Version 2 许可下发布。