2Checkout PHP Library
=====================
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.
```shell
git clone https://github.com/2Checkout/2checkout-php.git
```
Require in your php script.
```php
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
<?php
Twocheckout::format('json');
```
Credentials and Options
-----------------
Methods are provided to set the following credentials and options.
```php
<?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](https://github.com/2Checkout/2checkout-php/wiki)**.
Example Payment API Usage
-----------------
*Example Request:*
```php
<?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:*
```php
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
<?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
<?php
[response_code] => OK
[response_message] => Array
(
[0] => 4834917634
[1] => 4834917646
[2] => 4834917658
)
```
Example Checkout Usage:
-----------------------
*Example Request:*
```php
<?php
$params = array(
'sid' => '1817037',
'mode' => '2CO',
'li_0_name' => 'Test Product',
'li_0_price' => '0.01'
);
Twocheckout_Charge::form($params, 'auto');
```
*Example Response:*
```php
<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
<?php
$params = array();
foreach ($_REQUEST as $k => $v) {
$params[$k] = $v;
}
$passback = Twocheckout_Return::check($params, "tango");
```
*Example Response:*
```php
<?php
[response_code] => Success
[response_message] => Hash Matched
```
Example INS Usage:
------------------
*Example Request:*
```php
<?php
$params = array();
foreach ($_POST as $k => $v) {
$params[$k] = $v;
}
$passback = Twocheckout_Notification::check($params, "tango");
```
*Example Response:*
```php
<?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
<?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](https://github.com/2Checkout/2checkout-php/wiki)**.
没有合适的资源?快使用搜索试试~ 我知道了~
【WordPress插件】2022年最新版完整功能demo+插件v1.3.13.zip
共33个文件
php:23个
md:4个
js:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 191 浏览量
2022-04-04
11:07:11
上传
评论
收藏 38KB ZIP 举报
温馨提示
"【WordPress插件】2022年最新版完整功能demo+插件v1.3.13 Easy Digital Downloads 2Checkout Payment Gateway Addon 轻松数字下载2Checkout支付网关插件" ---------- 泰森云每天更新发布最新WordPress主题、HTML主题、WordPress插件、shopify主题、opencart主题、PHP项目源码、安卓项目源码、ios项目源码,更有超10000个资源可供选择,如有需要请站内联系。
资源推荐
资源详情
资源评论
收起资源包目录
【WordPress插件】2022年最新版完整功能demo+插件v1.3.13.zip (33个子文件)
edd-2checkout
sdk
composer.json 698B
test
ReturnTest.php 504B
SaleTest.php 4KB
CouponTest.php 2KB
ChargeTest.php 4KB
ProductTest.php 2KB
CompanyTest.php 717B
OptionTest.php 2KB
NotificationTest.php 572B
LICENSE 1KB
.gitignore 51B
lib
Twocheckout.php 2KB
Twocheckout
Api
TwocheckoutOption.php 1KB
TwocheckoutProduct.php 1KB
TwocheckoutCoupon.php 1KB
TwocheckoutAccount.php 633B
TwocheckoutSale.php 4KB
TwocheckoutError.php 292B
TwocheckoutUtil.php 2KB
TwocheckoutApi.php 2KB
TwocheckoutPayment.php 641B
TwocheckoutCharge.php 2KB
TwocheckoutReturn.php 674B
TwocheckoutMessage.php 305B
TwocheckoutNotification.php 673B
README.md 7KB
.github
pull_request_template.md 151B
issue_template.md 1KB
js
2co.js 34KB
script.js 2KB
tco_icon.png 888B
edd-2checkout.php 28KB
README.md 74B
共 33 条
- 1
资源评论
Lee达森
- 粉丝: 956
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功