如何使用 Codeigniter 实现 INGENICO SDK?
How to implement INGENICO SDK using Codeigniter?
对于支付网关,我使用了 Ingenico SDK,它在 CI 中没有正确实施,传递命名空间问题和 class 未找到问题。
从您的应用程序目录,运行以下命令:
composer require ingenico-epayments/connect-sdk-php
接下来,您需要让 CodeIgniter 自动加载作曲家包,因此在您的 config/config.php 文件中:
$config['composer_autoload'] = TRUE;
现在您将能够使用 composer 包,这意味着您可以在您的控制器或模型中执行类似的操作(我展示的是在控制器中的使用):
<?php
use \Ingenico\Connect\Sdk\CommunicatorConfiguration;
use \Ingenico\Connect\Sdk\DefaultConnection;
use \Ingenico\Connect\Sdk\Communicator;
use \Ingenico\Connect\Sdk\Client;
class Test extends CI_Controller {
public function __construct(){
parent::__construct();
}
/**
* This is an example of basic usage from
* https://epayments.developer-ingenico.com/documentation/sdk/server/php/
*/
public function index()
{
$communicatorConfiguration =
new CommunicatorConfiguration('ApiKeyId', 'ApiSecret', 'BaseUri', 'Integrator');
$connection = new DefaultConnection();
$communicator = new Communicator($connection, $communicatorConfiguration);
$client = new Client($communicator);
// Do something with $client ...
}
}
注意 use 语句如何位于 class 上方,但没有名称空间。通常在 CodeIgniter 中你不会有命名空间,除非它们是你自己的库或 third_party classes。由于没有名称空间,use 语句让 PHP 知道您打算按名称使用 Ingenico classes,而不是在它们前面加上前缀 \Ingenico\Connect\Sdk。如果您愿意,可以使用前缀而不是 use 语句。
对于 INGENICO SDK,有 2 个选项可用,
您还可以通过基于隐藏内容发送数据并通过 Ingenico 配置文件提供的密钥和用户名来使用它的服务。
对于支付网关,我使用了 Ingenico SDK,它在 CI 中没有正确实施,传递命名空间问题和 class 未找到问题。
从您的应用程序目录,运行以下命令:
composer require ingenico-epayments/connect-sdk-php
接下来,您需要让 CodeIgniter 自动加载作曲家包,因此在您的 config/config.php 文件中:
$config['composer_autoload'] = TRUE;
现在您将能够使用 composer 包,这意味着您可以在您的控制器或模型中执行类似的操作(我展示的是在控制器中的使用):
<?php
use \Ingenico\Connect\Sdk\CommunicatorConfiguration;
use \Ingenico\Connect\Sdk\DefaultConnection;
use \Ingenico\Connect\Sdk\Communicator;
use \Ingenico\Connect\Sdk\Client;
class Test extends CI_Controller {
public function __construct(){
parent::__construct();
}
/**
* This is an example of basic usage from
* https://epayments.developer-ingenico.com/documentation/sdk/server/php/
*/
public function index()
{
$communicatorConfiguration =
new CommunicatorConfiguration('ApiKeyId', 'ApiSecret', 'BaseUri', 'Integrator');
$connection = new DefaultConnection();
$communicator = new Communicator($connection, $communicatorConfiguration);
$client = new Client($communicator);
// Do something with $client ...
}
}
注意 use 语句如何位于 class 上方,但没有名称空间。通常在 CodeIgniter 中你不会有命名空间,除非它们是你自己的库或 third_party classes。由于没有名称空间,use 语句让 PHP 知道您打算按名称使用 Ingenico classes,而不是在它们前面加上前缀 \Ingenico\Connect\Sdk。如果您愿意,可以使用前缀而不是 use 语句。
对于 INGENICO SDK,有 2 个选项可用, 您还可以通过基于隐藏内容发送数据并通过 Ingenico 配置文件提供的密钥和用户名来使用它的服务。