payfort / start
Payfort Start使中东地区接受在线支付变得轻而易举
Requires (Dev)
- phpunit/phpunit: 4.2.*
- dev-master
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- 0.0.9
- 0.0.8
- 0.0.7
- v0.0.6
- v0.0.5
- 0.0.4
- v0.0.3
- v0.0.2
- v0.0.1
- dev-add-capture
- dev-add-more-functions
- dev-add-refund
- dev-use-absolute-path
- dev-remove-empty-strings-php-files
- dev-add-php-streams-to-avoid-ssl-tls-errors
- dev-add-extras-to-error
- dev-rename_payfort_to_start
- dev-payfort
This package is not auto-updated.
Last update: 2017-12-08 09:53:13 UTC
README
Start PHP
Start使中东地区接受支付变得极其简单。在https://start.payfort.com注册一个账户。
入门
使用Start与您的PHP项目一起使用非常简单。
通过Composer安装
如果您正在使用Composer(实际上,现在谁不用呢?),您可以简单地运行
php composer.phar require payfort/start
.. 或者将一行添加到您的composer.json
文件中
{ "require": { "payfort/start": "*" } }
现在,运行php composer.phar install
将直接将库拉到您的本地vendor
文件夹。
手动安装
从github仓库获取最新版本的源代码:https://github.com/payfort/start-php/releases/latest并将其复制到您的项目中。
在您的php文件中添加以下内容
<?php
require_once("path-to-start-php/Start.php");
?>
Windows注意:在您开始使用start-php进行开发之前,请检查您的php_curl是否可以与我们的ssl证书(TLSv1.2)一起工作。您可以通过运行单元测试来完成此操作。如果您看到“SSL连接错误”,则意味着您需要安装一个新的php版本(至少5.5.19)。
注意:如果您在共享主机上运行,则可能需要为php
命令设置allow_url_fopen
标志。例如,对于安装命令,这可能看起来像php -d allow_url_fopen=On composer.phar install
。这里的-d
会覆盖php.ini
设置,其中通常将allow_url_fopen
设置为Off
。
使用Start
如果您还没有账户,请创建一个账户(立即在start.payfort.com上创建一个,然后立即回来 .. 我们会等待的)。
账户有了吗?太好了 .. 让我们开始吧。
1. 初始化Start
要开始,您需要使用您的密钥API初始化Start。以下是这样做的方式(不要担心 .. 我们使用的是测试密钥,所以不会有真正的金钱交换)
require_once('vendor/autoload.php'); # At the top of your PHP file # Initialize Start object Start::setApiKey('test_sec_k_25dd497d7e657bb761ad6');
就是这样!您可能还想做些与Start对象相关的事情 -- 如果它没事可做,它会变得非常无聊。
让我们运行一笔交易,好吗。
2. 通过Start处理交易
现在,是时候玩得开心了。以下是您处理Start交易所需的所有代码
Start_Charge::create(array( "amount" => 10500, // AED 105.00 "currency" => "aed", "card" => array( "number" => "4242424242424242", "exp_month" => 11, "exp_year" => 2016, "cvc" => "123" ), "description" => "Charge for test@example.com" ));
这笔交易应该会成功,因为我们使用了 4242 4242 4242 4242
测试信用卡。关于测试卡片的完整列表及其预期输出,您可以查看此链接 此处。
您如何判断它是否成功?嗯,如果没有抛出异常,那么就没有问题。
3. 处理错误
在交易过程中可能发生的任何错误都会以异常的形式抛出。以下是如何使用 Start 处理错误的示例
try { // Use Start's bindings... } catch(Start_Error_Banking $e) { // Since it's a decline, Start_Error_Banking will be caught print('Status is:' . $e->getHttpStatus() . "\n"); print('Code is:' . $e->getErrorCode() . "\n"); print('Message is:' . $e->getMessage() . "\n"); } catch (Start_Error_Request $e) { // Invalid parameters were supplied to Start's API } catch (Start_Error_Authentication $e) { // There's a problem with that API key you provided } catch (Start_Error $e) { // Display a very generic error to the user, and maybe send // yourself an email } catch (Exception $e) { // Something else happened, completely unrelated to Start }
测试启动
运行单元测试以确保一切正常可能是个好主意。这也很简单,只需从项目文件夹的根目录运行此命令即可
php vendor/bin/phpunit tests --bootstrap vendor/autoload.php
注意:您还需要使用 composer update --dev
拉取开发依赖项,以便运行测试套件。
贡献
请参阅我们的 贡献指南 获取详细信息
版权所有 (c) Payfort。