oguzcabuk07/trustly-client-php

该包的最新版本(v1.0.2)没有提供许可信息。

实现与Trustly公共API进行在线银行电子支付的通信。更多信息请访问 https://trustly.com

v1.0.2 2016-11-01 07:02 UTC

This package is not auto-updated.

Last update: 2024-09-18 18:42:42 UTC


README

这是使用PHP实现与Trustly API通信的示例实现。它实现了标准支付API,并为后台办公室使用的API调用提供了存根。

有关Trustly API内部结构的完整文档,请访问我们的开发者网站: http://trustly.com/developer 。有关软件流程和调用模式的全部信息都可以在该网站上找到。该代码中的文档仅涵盖代码本身,而不是如何使用Trustly API。

该代码按原样提供,您可以将其用作灵感、参考或直接将其用于自己的项目。

如果您在代码中发现问题或想对其进行扩展,请随意分叉它并向我们发送拉取请求。

该代码应在PHP 5(>= 5.2.0)上运行。需要的PHP模块是:bcmath、openssl、curl、mbstring和json。

概述

提供的代码为调用Trustly API提供了包装器。使用您的商家标准创建API调用实例,并使用该类中的存根调用API。API默认与https://trustly.com通信,要与其测试.trustly.com通信,请覆盖构造函数中的host参数。

在处理传入的通知时,API的handleNotification()方法可以帮助解析和验证消息签名,使用notificationResponse()构建适当的响应对象。

以下示例代表调用非常基本的用法。在处理此代码时,至少需要检查以下异常。

  • Trustly_ConnectionException

    在无法与Trustly API通信时抛出。这可能是由于互联网或其他服务错误。

  • Trustly_DataException

    在API返回数据存在各种问题时抛出。例如,当响应消息包含与发送消息不同的UUID或当响应结构不完整时。

  • Trustly_SignatureException

    在无法验证消息的真实性时发出。如果捕获到该异常,则应取消通信中的数据,因为它可能是伪造的。

示例存款调用

require_once('Trustly.php');

/* Change 'test.trustly.com' to '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 */
                NULL,                                       /* FirstName */
                NULL,                                       /* LastName */
                NULL,                                       /* NationalIdentificationNumber */
                'Test',                                     /* ShopperStatement */
                $ip,                                        /* IP */
                "$base_url/success.html",                   /* SuccessURL */
                "$base_url/fail.html",                      /* FailURL */
                NULL,                                       /* TemplateURL */
                "0",                                        /* 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');

示例通知处理

$request = $api->handleNotification($notification_body);
    # FIXME Handle the incoming notification data here
$notifyresponse = $api->notificationResponse($request, TRUE);

echo $notifyresponse->json();

示例实现

在example/子目录中,有一个简单的客户端实现,该客户端使用代码向Trustly发出存款调用并处理传入的通知。代码注释良好,包含有关需要进行的调用以及执行这些调用时的注意事项的信息。

该代码在Linux/OSX上可运行,使用Apache v2.2/2.4。使用example/example.sh脚本控制示例环境。在测试之前,您需要修改example/www/php/example.phpexample/example.private.pem,以便包含您的处理账户信息。