trustly/trustly-client-php
Composer 安装命令:
composer require trustly/trustly-client-php
包简介
Implementation of communications with Trustly public API for Online bank e-payments. See https://trustly.com for more information
README 文档
README
This is an example implementation of communication with the Trustly API using PHP. It implements the standard Payments API as well as gives stubs for executing calls against the API used by the backoffice.
For full documentation on the Trustly API internals visit our developer website: https://eu.developers.trustly.com/. All information about software flows and call patters can be found on that site. The documentation within this code will only cover the code itself, not how you use the Trustly API.
This code is provided as-is, use it as inspiration, reference or drop it directly into your own project and use it.
If you find problem in the code or want to extend it feel free to fork it and send us a pull request.
This code should work with PHP 5 (>= 5.2.0). PHP modules needed are: bcmath, openssl, curl, mbstring and json.
Overview
The code provided wrappers for calling the trustly API. Create an instance of
the API call with you merchant criterias and use the stubs in that class for
calling the API. The API will default to communicate with https://api.trustly.com,
override the host parameter for the constructor to communicate with
test.trustly.com instead.
When processing an incoming notification the handleNotification() method of the
API will help with parsing and verifying the message signature, use notificationResponse()
to build a proper response object
The examples below represent a very basic usage of the calls. A minimum of error handling around this code would be to check for the following exceptions during processing.
-
Trustly_ConnectionExceptionThrown when unable to communicate with the Trustly API. This can be due to Internet or other forms of service errors.
-
Trustly_DataExceptionThrown upon various problems with the API returned data. For instance when a responding message contains a different UUID then the sent message or when the response structure is incomplete.
-
Trustly_SignatureExceptionIssued when the authenticity of messages cannot be verified. If ever this exception is caught the data in the communication should be voided as it can be a forgery.
Example deposit call
require_once('Trustly.php');
/* Change 'test.trustly.com' to 'api.trustly.com' below to use the live environment */
$api = new Trustly_Api_Signed(
$trustly_rsa_private_key,
$trustly_username,
$trustly_password,
'test.trustly.com'
);
$deposit = $api->deposit(
"$base_url/php/example.php/notification", /* NotificationURL */
'john.doe@example.com', /* EndUserID */
$messageid, /* MessageID */
'en_US', /* Locale */
$amount, /* Amount */
$currency, /* Currency */
'SE', /* Country */
NULL, /* MobilePhone */
'Sam', /* FirstName */
'Trautman', /* LastName */
NULL, /* NationalIdentificationNumber */
NULL, /* ShopperStatement */
$ip, /* IP */
"$base_url/success.html", /* SuccessURL */
"$base_url/fail.html", /* FailURL */
NULL, /* TemplateURL */
NULL, /* URLTarget */
NULL, /* SuggestedMinAmount */
NULL, /* SuggestedMaxAmount */
'trustly-client-php example/1.0', /* IntegrationModule */
FALSE, /* HoldNotifications */
'john.doe@example.com', /* Email */
'SE', /* ShippingAddressCountry */
'12345', /* ShippingAddressPostalCode */
'ExampleCity', /* ShippingAddressCity */
'123 Main St', /* ShippingAddressLine1 */
'C/O Careholder', /* ShippingAddressLine2 */
NULL /* ShippingAddress */
);
$iframe_url= $deposit->getData('url');
Example notification processing
$request = $api->handleNotification($notification_body);
# FIXME Handle the incoming notification data here
$notifyresponse = $api->notificationResponse($request, TRUE);
echo $notifyresponse->json();
Example implementation
In the example/ subdirectory is a simple implementation of a client that uses the code to make a deposit call to Trustly and processes incoming notifications. The code is well commented and contains information about what to calls that needs to be made and some caveats while doing so.
The code is runnable on Linux/OSX with Apache v2.2/2.4. Use the
example/example.sh script to control the example environment. You need to
amend example/www/php/example.php and example/example.private.pem to
contain your processing account information before giving it a test spin.
trustly/trustly-client-php 适用场景与选型建议
trustly/trustly-client-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 403.77k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2014 年 10 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「trustly」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 trustly/trustly-client-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 trustly/trustly-client-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 trustly/trustly-client-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Mollie Payment Module for Magento 2
PHP Client for Genesis Payment Processing Gateway
Implementation of communications with Trustly public API for Online bank e-payments. See https://trustly.com for more information
Implementation of communications with Trustly public API for Online bank e-payments. See https://trustly.com for more information
'Facade' for old trustly-client-php for using with Laravel
Trustly API Client
统计信息
- 总下载量: 403.77k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 30
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2014-10-28