2checkout/2checkout-php
Composer 安装命令:
composer require 2checkout/2checkout-php
包简介
2Checkout PHP Library
关键字:
README 文档
README
This library provides developers with a simple set of bindings to the 2Checkout Payment API, Hosted Checkout, Instant Notification Service and Admin API.
To use, download or clone the repository.
git clone https://github.com/2Checkout/2checkout-php.git
Require in your php script.
require_once("/path/to/2checkout-php/lib/Twocheckout.php");
All methods return an Array by default or you can set the format to 'json' to get a JSON response. Example:
<?php Twocheckout::format('json');
Credentials and Options
Methods are provided to set the following credentials and options.
<?php // Your sellerId(account number) and privateKey are required to make the Payment API Authorization call. Twocheckout::privateKey('BE632CB0-BB29-11E3-AFB6-D99C28100996'); Twocheckout::sellerId('901248204'); // Your username and password are required to make any Admin API call. Twocheckout::username('testlibraryapi901248204'); Twocheckout::password('testlibraryapi901248204PASS'); // If you want to turn off SSL verification (Please don't do this in your production environment) Twocheckout::verifySSL(false); // this is set to true by default // To use your sandbox account set sandbox to true Twocheckout::sandbox(true); // All methods return an Array by default or you can set the format to 'json' to get a JSON response. Twocheckout::format('json');
Full documentation for each binding is provided in the wiki.
Example Payment API Usage
Example Request:
<?php Twocheckout::privateKey('BE632CB0-BB29-11E3-AFB6-D99C28100996'); Twocheckout::sellerId('901248204'); try { $charge = Twocheckout_Charge::auth(array( "sellerId" => "901248204", "merchantOrderId" => "123", "token" => 'MjFiYzIzYjAtYjE4YS00ZmI0LTg4YzYtNDIzMTBlMjc0MDlk', "currency" => 'USD', "total" => '10.00', "billingAddr" => array( "name" => 'Testing Tester', "addrLine1" => '123 Test St', "city" => 'Columbus', "state" => 'OH', "zipCode" => '43123', "country" => 'USA', "email" => 'testingtester@2co.com', "phoneNumber" => '555-555-5555' ), "shippingAddr" => array( "name" => 'Testing Tester', "addrLine1" => '123 Test St', "city" => 'Columbus', "state" => 'OH', "zipCode" => '43123', "country" => 'USA', "email" => 'testingtester@2co.com', "phoneNumber" => '555-555-5555' ) )); $this->assertEquals('APPROVED', $charge['response']['responseCode']); } catch (Twocheckout_Error $e) { $this->assertEquals('Unauthorized', $e->getMessage()); }
Example Response:
Array ( [validationErrors] => [exception] => [response] => Array ( [type] => AuthResponse [lineItems] => Array ( [0] => Array ( [options] => Array ( ) [price] => 10.00 [quantity] => 1 [recurrence] => [startupFee] => [productId] => [tangible] => N [name] => 123 [type] => product [description] => [duration] => ) ) [transactionId] => 205181140830 [billingAddr] => Array ( [addrLine1] => 123 Test St [addrLine2] => [city] => Columbus [zipCode] => 43123 [phoneNumber] => 555-555-5555 [phoneExtension] => [email] => testingtester@2co.com [name] => Testing Tester [state] => OH [country] => USA ) [shippingAddr] => Array ( [addrLine1] => 123 Test St [addrLine2] => [city] => Columbus [zipCode] => 43123 [phoneNumber] => [phoneExtension] => [email] => [name] => Testing Tester [state] => OH [country] => USA ) [merchantOrderId] => 123 [orderNumber] => 205181140821 [recurrentInstallmentId] => [responseMsg] => Successfully authorized the provided credit card [responseCode] => APPROVED [total] => 10.00 [currencyCode] => USD [errors] => ) )
Example Admin API Usage
Example Request:
<?php Twocheckout::username('testlibraryapi901248204'); Twocheckout::password('testlibraryapi901248204PASS'); $args = array( 'sale_id' => 4834917619 ); try { $result = Twocheckout_Sale::stop($args); } catch (Twocheckout_Error $e) { $e->getMessage(); }
Example Response:
<?php [response_code] => OK [response_message] => Array ( [0] => 4834917634 [1] => 4834917646 [2] => 4834917658 )
Example Checkout Usage:
Example Request:
<?php $params = array( 'sid' => '1817037', 'mode' => '2CO', 'li_0_name' => 'Test Product', 'li_0_price' => '0.01' ); Twocheckout_Charge::form($params, 'auto');
Example Response:
<form id="2checkout" action="https://www.2checkout.com/checkout/spurchase" method="post"> <input type="hidden" name="sid" value="1817037"/> <input type="hidden" name="mode" value="2CO"/> <input type="hidden" name="li_0_name" value="Test Product"/> <input type="hidden" name="li_0_price" value="0.01"/> <input type="submit" value="Click here if you are not redirected automatically" /></form> <script type="text/javascript">document.getElementById('2checkout').submit();</script>
Example Return Usage:
Example Request:
<?php $params = array(); foreach ($_REQUEST as $k => $v) { $params[$k] = $v; } $passback = Twocheckout_Return::check($params, "tango");
Example Response:
<?php
[response_code] => Success
[response_message] => Hash Matched
Example INS Usage:
Example Request:
<?php $params = array(); foreach ($_POST as $k => $v) { $params[$k] = $v; } $passback = Twocheckout_Notification::check($params, "tango");
Example Response:
<?php
[response_code] => Success
[response_message] => Hash Matched
Exceptions:
Twocheckout_Error exceptions are thrown by if an error has returned. It is best to catch these exceptions so that they can be gracefully handled in your application.
Example Usage
<?php Twocheckout::username('testlibraryapi901248204'); Twocheckout::password('testlibraryapi901248204PASS'); $params = array( 'sale_id' => 4774380224, 'category' => 1, 'comment' => 'Order never sent.' ); try { $sale = Twocheckout_Sale::refund($params); } catch (Twocheckout_Error $e) { $e->getMessage(); }
Full documentation for each binding is provided in the wiki.
2checkout/2checkout-php 适用场景与选型建议
2checkout/2checkout-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 799.57k 次下载、GitHub Stars 达 83, 最近一次更新时间为 2013 年 08 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「payment」 「gateway」 「2checkout」 「2co」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 2checkout/2checkout-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 2checkout/2checkout-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 2checkout/2checkout-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Payyo Gateway for the Omnipay payment processing library
2checkout Lgeacy API based on Avangate
2checkout New API based on Avangate
2Checkout PHP SDK by Verifone
Includes Omnipay payment processing library and all officially supported gateways
统计信息
- 总下载量: 799.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 83
- 点击次数: 17
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-08-21