112Checkout PHP Library
22=====================
33
4- This library provides developers with a simple set of bindings to the 2Checkout purchase routine, Instant Notification Service and Back Office API.
4+ This library provides developers with a simple set of bindings to the 2Checkout Payment API, Hosted Checkout, Instant Notification Service and Admin API.
55
66To use, download or clone the repository.
77
@@ -15,14 +15,44 @@ Require in your php script.
1515require_once("/path/to/2checkout-php/lib/Twocheckout.php");
1616```
1717
18- JSON is returned by default or you can add 'array' as an additional argument to each call to get an Array .
18+ All methods return an Array by default or you can set the format to 'json' to get a JSON response .
1919** Example:**
2020``` php
2121<?php
22- Twocheckout_Charge::auth($args, 'array ');
22+ Twocheckout::format('json ');
2323```
2424
25- Full documentation for each binding is provided in the [ Wiki] ( https://github.com/2checkout/2checkout-php/wiki ) .
25+
26+ Credentials and Options
27+ -----------------
28+
29+ Methods are provided to set the following credentials and options.
30+
31+ ``` php
32+ <?php
33+
34+ // Your sellerId(account number) and privateKey are required to make the Payment API Authorization call.
35+ Twocheckout::privateKey('BE632CB0-BB29-11E3-AFB6-D99C28100996');
36+ Twocheckout::sellerId('901248204');
37+
38+ // Your username and password are required to make any Admin API call.
39+ Twocheckout::username('testlibraryapi901248204');
40+ Twocheckout::password('testlibraryapi901248204PASS');
41+
42+ // If you want to turn off SSL verification (Please don't do this in your production environment)
43+ Twocheckout::verifySSL(false); // this is set to true by default
44+
45+ // To use your sandbox account set sandbox to true
46+ Twocheckout::sandbox(true);
47+
48+ // All methods return an Array by default or you can set the format to 'json' to get a JSON response.
49+ Twocheckout::format('json');
50+
51+ ```
52+
53+
54+
55+ Full documentation for each binding is provided in the [ 2Checkout Documentation] ( https://www.2checkout.com/documentation/libraries/php ) .
2656
2757Example Purchase API Usage
2858-----------------
@@ -31,12 +61,15 @@ Example Purchase API Usage
3161
3262``` php
3363<?php
34- Twocheckout::setApiCredentials('1817037', '3508079E-5383-44D4-BF69-DC619C0D9811');
64+
65+ Twocheckout::privateKey('BE632CB0-BB29-11E3-AFB6-D99C28100996');
66+ Twocheckout::sellerId('901248204');
67+
3568try {
3669 $charge = Twocheckout_Charge::auth(array(
37- "sellerId" => "1817037 ",
70+ "sellerId" => "901248204 ",
3871 "merchantOrderId" => "123",
39- "token" => 'Y2U2OTdlZjMtOGQzMi00MDdkLWJjNGQtMGJhN2IyOTdlN2Ni ',
72+ "token" => 'MjFiYzIzYjAtYjE4YS00ZmI0LTg4YzYtNDIzMTBlMjc0MDlk ',
4073 "currency" => 'USD',
4174 "total" => '10.00',
4275 "billingAddr" => array(
5992 "email" => 'testingtester@2co.com',
6093 "phoneNumber" => '555-555-5555'
6194 )
62- ), 'array' );
95+ ));
6396 $this->assertEquals('APPROVED', $charge['response']['responseCode']);
6497} catch (Twocheckout_Error $e) {
6598 $this->assertEquals('Unauthorized', $e->getMessage());
@@ -147,9 +180,18 @@ Example Admin API Usage
147180
148181``` php
149182<?php
150- Twocheckout::setCredentials("APIuser1817037", "APIpass1817037");
151- $args = array('sale_id' => 4834917619);
152- Twocheckout_Sale::stop($args, 'array');
183+
184+ Twocheckout::username('testlibraryapi901248204');
185+ Twocheckout::password('testlibraryapi901248204PASS');
186+
187+ $args = array(
188+ 'sale_id' => 4834917619
189+ );
190+ try {
191+ $result = Twocheckout_Sale::stop($args);
192+ } catch (Twocheckout_Error $e) {
193+ $e->getMessage();
194+ }
153195```
154196
155197* Example Response:*
@@ -200,11 +242,12 @@ Example Return Usage:
200242
201243``` php
202244<?php
245+
203246$params = array();
204247foreach ($_REQUEST as $k => $v) {
205248 $params[$k] = $v;
206249}
207- $passback = Twocheckout_Return::check($params, "tango", 'array' );
250+ $passback = Twocheckout_Return::check($params, "tango");
208251```
209252
210253* Example Response:*
@@ -223,11 +266,12 @@ Example INS Usage:
223266
224267``` php
225268<?php
269+
226270$params = array();
227271foreach ($_POST as $k => $v) {
228272 $params[$k] = $v;
229273}
230- $passback = Twocheckout_Notification::check($params, "tango", 'array' );
274+ $passback = Twocheckout_Notification::check($params, "tango");
231275```
232276
233277* Example Response:*
@@ -248,18 +292,19 @@ Twocheckout_Error exceptions are thrown by if an error has returned. It is best
248292``` php
249293<?php
250294
251- Twocheckout::setCredentials("APIuser1817037", "APIpass1817037");
295+ Twocheckout::username('testlibraryapi901248204');
296+ Twocheckout::password('testlibraryapi901248204PASS');
252297
253298$params = array(
254- 'sale_id' => 4774380224,
255- 'category' => 1,
256- 'comment' => 'Order never sent.'
299+ 'sale_id' => 4774380224,
300+ 'category' => 1,
301+ 'comment' => 'Order never sent.'
257302);
258303try {
259- $sale = Twocheckout_Sale::refund($params, 'array' );
304+ $sale = Twocheckout_Sale::refund($params);
260305} catch (Twocheckout_Error $e) {
261- $e->getMessage();
306+ $e->getMessage();
262307}
263308```
264309
265- Full documentation for each binding is provided in the [ Wiki ] ( https://github. com/2checkout/2checkout-php/wiki ) .
310+ Full documentation for each binding is provided in the [ 2Checkout Documentation ] ( https://www.2checkout. com/documentation/libraries/php ) .
0 commit comments