Skip to content

Commit

Permalink
Move source code under namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
fightmaster committed Oct 19, 2020
1 parent d0fe05a commit 566e59f
Show file tree
Hide file tree
Showing 98 changed files with 1,315 additions and 737 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ php:
- 7.1
- 7.2
- 7.3
- 7.4

before_script: composer install

Expand Down
40 changes: 20 additions & 20 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ InkRouter Workflow
InkRouter interface workflow consists of 6 actions:

- Get InkRouter client instance
- Create and fill InkRouter_Models_OrderInfo instance
- Create and fill OrderInfo instance
- Create order to InkRouter
- Update order (optional)
- Place on hold order (optional)
Expand All @@ -56,60 +56,60 @@ Where:
- `$printCustomerId` is your unique identificator from InkRouter
- `$secretKey` is your secret key

Create InkRouter_Models_OrderInfo instance (with example data)
Create OrderInfo instance (with example data)
---------------------------------

$contact = new InkRouter_Models_Contact();
$contact = new Contact();
$contact->setName('contact_name')
->setPhone('contact_phone')
->setEmail('contact_email');

$headerInfo = new InkRouter_Models_HeaderInfo();
$headerInfo = new HeaderInfo();
$headerInfo->setFromDomain('yoursite.com')
->setFromIdentity('your_identity');

$shipType = new InkRouter_Models_ShipType();
$shipType = new ShipType();
$shipType->setMethod('UPS')
->setServiceLevel('GROUND');

$shipAddress = new InkRouter_Models_ShipAddress();
$shipAddress = new ShipAddress();
$shipAddress->setAttention('Attention')
->setStreetAddress('742 Evergreen Terrace')
->setCity('Springfield')
->setState('CA')
->setZip('1234567')
->setCountry('USA');

$requester = new InkRouter_Models_Requester();
$requester = new Requester();
$requester->setName('Any Prints')
->setContract('STANDARD')
->setPayTerm('FREE');

$poInfo = new InkRouter_Models_PoInfo();
$poInfo = new PoInfo();
$poInfo->setAgentId('agentId')
->setCurrency('US');

$printAsset = new InkRouter_Models_PrintAsset();
$printAsset = new PrintAsset();
$printAsset->setPositionX(4.98)
->setPositionY(3.1)
->setRotation(-90)
->setType('BARCODE')
->setHeight(0.543)
->setWidth(2.12);

$side = new InkRouter_Models_Side();
$side = new Side();
$side->setPageNumber(10)
->setFileUrl('http://server/img.jpg')
->setFileHash('0a0825909aa15a98b00574661f23aee7')
->setCoating('NONE')
->setOrientation('Landscape')
->addPrintAsset($printAsset);

$attributes = new InkRouter_Models_Attributes_ScalarBooleanAttribute();
$attributes = new ScalarBooleanAttribute();
$attributes->setType('LABELING');
$attributes->setValue(true);
$orderItem = new InkRouter_Models_OrderItem();
$orderItem = new OrderItem();
$orderItem->setPrintGroupId('pg4f7969f8a4811')
->setProductType('business cards')
->setPaperType('14PT')
Expand All @@ -119,7 +119,7 @@ Create InkRouter_Models_OrderInfo instance (with example data)
->addAttributes($attributes)
->addSide($side);

$order = new InkRouter_Models_Order();
$order = new Order();
$order->setPrintCustomerInvoice(123456789)
->setTsCreated(date(DATE_ATOM, strtotime('now')))
->setPriority(0)
Expand All @@ -133,7 +133,7 @@ Create InkRouter_Models_OrderInfo instance (with example data)
->setShipAddress($shipAddress)
->addOrderItem($orderItem);

$orderInfo = new InkRouter_Models_OrderInfo();
$orderInfo = new OrderInfo();
$orderInfo->setHeaderInfo($headerInfo)
->setPrintCustomerId('ID')
->setPoInfo($poInfo)
Expand All @@ -145,15 +145,15 @@ After creating the instance of InkRouter Models_OrderInfo Create Order to InkRou

try {
$orderId = $InkRouterClient->createOrder($timestamp, $orderInfo);
} catch (InkRouter_Exceptions_Exception $e) {
} catch (Exception $e) {
echo 'Create operation failed';
}


Where:

- `$timestamp` is unix timestamp (result of mktime() function), if your last operation was unsuccessful, you can resend it with same timestamp
- `$orderInfo` is an instance of InkRouter_Models_OrderInfo (see example)
- `$orderInfo` is an instance of OrderInfo (see example)
- `$orderId` is an order identification, received from InkRouter

Update order
Expand All @@ -162,7 +162,7 @@ You should first create instance of InkRouter Models OrderInfo and call update m

try {
$InkRouterClient->updateOrder($orderId, $timestamp, $orderInfo);
} catch (InkRouter_Exceptions_Exception $e) {
} catch (Exception $e) {
echo 'Update operation failed';
}

Expand All @@ -176,7 +176,7 @@ For place on hold order with id `$orderId` you should do:

try {
$InkRouterClient->placeOnHold($orderId, $timestamp);
} catch (InkRouter_Exceptions_Exception $e) {
} catch (Exception $e) {
echo 'Place on hold operation failed';
}

Expand All @@ -186,7 +186,7 @@ For remove order from hold with id `$orderId` you should do:

try {
$InkRouterClient->removeHold($orderId, $timestamp);
} catch (InkRouter_Exceptions_Exception $e) {
} catch (Exception $e) {
echo 'Remove hold operation failed';
}

Expand All @@ -196,7 +196,7 @@ For cancel order with id `$orderId` you should do:

try {
$InkRouterClient->cancelOrder($orderId, $timestamp);
} catch (InkRouter_Exceptions_Exception $e) {
} catch (Exception $e) {
echo 'Cancel operation failed';
}

Expand Down
5 changes: 5 additions & 0 deletions Upgrade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Upgrade v1 to v2
================
- PHP-INK-Router v2 classes used namespaces.
- Deprecated method Order.setTsCreated was removed, use Order.setTsCreatedAsDate
- Deprecated method Order.setDeliveryDate was removed, use Order.setDeliveryDateAsDate
13 changes: 9 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
}
],
"autoload": {
"psr-0": {
"InkRouter_": "src/"
"psr-4": {
"InkRouter\\": "src",
"InkRouter\\Tests\\": "tests"
}
},
"extra": {
Expand All @@ -18,9 +19,13 @@
}
},
"require": {
"php": ">=5.0.0"
"php": ">=7.3",
"ext-soap": "*",
"ext-dom": "*",
"ext-xmlwriter": "*",
"ext-curl": "*"
},
"require-dev": {
"phpunit/phpunit": "5.7.*"
"phpunit/phpunit": ">=8.5"
}
}
59 changes: 59 additions & 0 deletions src/Client/ClientInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/**
* This file is part of InkRouter-PHP-SDK.
*
* Copyright (c) Opensoft (http://opensoftdev.com)
*
* The unauthorized use of this code outside the boundaries of
* Opensoft is prohibited.
*/

namespace InkRouter\Client;

use InkRouter\Exceptions\Exception;
use InkRouter\Models\OrderInfo;

interface ClientInterface
{
/**
* @param int $timestamp
* @param OrderInfo $orderInfo
* @return mixed
* @throws Exception
*/
public function createOrder($timestamp, OrderInfo $orderInfo);

/**
* @param int $orderId
* @param int $timestamp
* @param OrderInfo $orderInfo
* @return mixed
* @throws Exception
*/
public function updateOrder($orderId, $timestamp, OrderInfo $orderInfo);

/**
* @param int $orderId
* @param int $timestamp
* @return mixed
* @throws Exception
*/
public function placeOnHold($orderId, $timestamp);

/**
* @param int $orderId
* @param int $timestamp
* @return mixed
* @throws Exception
*/
public function removeHold($orderId, $timestamp);

/**
* @param int $orderId
* @param int $timestamp
* @return mixed
* @throws Exception
*/
public function cancelOrder($orderId, $timestamp);
}
54 changes: 34 additions & 20 deletions src/InkRouter/Client/RestClient.php → src/Client/RestClient.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
<?php

/**
* This file is part of InkRouter-PHP-SDK.
*
* Copyright (c) 2012 Opensoft (http://opensoftdev.com)
* Copyright (c) Opensoft (http://opensoftdev.com)
*
* The unauthorized use of this code outside the boundaries of
* Opensoft is prohibited.
*/

namespace InkRouter\Client;

use InkRouter\Exceptions\AuthenticationException;
use InkRouter\Exceptions\InkRouterNotAvailableException;
use InkRouter\Exceptions\ProcessingException;
use InkRouter\Exceptions\RejectionException;
use InkRouter\Models\OrderInfo;
use InkRouter\Exceptions\Exception;

/**
* Client for sending requests to InkRouter
*
* @author Kirill Gusakov
*/
class InkRouter_Client_RestClient implements InkRouter_Client_ClientInterface
class RestClient implements ClientInterface
{

private static $CREATE_PATH = 'orders/%s';
private static $UPDATE_PATH = 'orders/%s/%s';
private static $CANCEL_PATH = 'orders/%s/%s';
Expand Down Expand Up @@ -54,11 +65,11 @@ public function __construct($baseUrl, $printCustomerId, $secretKey)

/**
* @param int $timestamp
* @param InkRouter_Models_OrderInfo $orderInfo
* @param OrderInfo $orderInfo
* @return mixed
* @throws InkRouter_Exceptions_InkRouterNotAvailableException|InkRouter_Exceptions_AuthenticationException|InkRouter_Exceptions_ProcessingException|InkRouter_Exceptions_RejectionException
* @throws Exception
*/
public function createOrder($timestamp, InkRouter_Models_OrderInfo $orderInfo)
public function createOrder($timestamp, OrderInfo $orderInfo)
{
return $this->sendRequest(sprintf($this->baseUrl . self::$CREATE_PATH, $timestamp), 'POST',
array('Content-Type: application/xml'), $orderInfo->pack());
Expand All @@ -67,11 +78,11 @@ public function createOrder($timestamp, InkRouter_Models_OrderInfo $orderInfo)
/**
* @param int $orderId
* @param int $timestamp
* @param InkRouter_Models_OrderInfo $orderInfo
* @param OrderInfo $orderInfo
* @return mixed
* @throws InkRouter_Exceptions_InkRouterNotAvailableException|InkRouter_Exceptions_AuthenticationException|InkRouter_Exceptions_ProcessingException|InkRouter_Exceptions_RejectionException
* @throws Exception
*/
public function updateOrder($orderId, $timestamp, InkRouter_Models_OrderInfo $orderInfo)
public function updateOrder($orderId, $timestamp, OrderInfo $orderInfo)
{
return $this->sendRequest(sprintf($this->baseUrl . self::$UPDATE_PATH, $orderId, $timestamp), 'PUT',
array('Content-Type: application/xml'), $orderInfo->pack());
Expand All @@ -81,7 +92,7 @@ public function updateOrder($orderId, $timestamp, InkRouter_Models_OrderInfo $or
* @param int $orderId
* @param int $timestamp
* @return mixed
* @throws InkRouter_Exceptions_InkRouterNotAvailableException|InkRouter_Exceptions_AuthenticationException|InkRouter_Exceptions_ProcessingException|InkRouter_Exceptions_RejectionException
* @throws Exception
*/
public function placeOnHold($orderId, $timestamp)
{
Expand All @@ -93,7 +104,7 @@ public function placeOnHold($orderId, $timestamp)
* @param int $orderId
* @param int $timestamp
* @return mixed
* @throws InkRouter_Exceptions_InkRouterNotAvailableException|InkRouter_Exceptions_AuthenticationException|InkRouter_Exceptions_ProcessingException|InkRouter_Exceptions_RejectionException
* @throws Exception
*/
public function removeHold($orderId, $timestamp)
{
Expand All @@ -105,7 +116,7 @@ public function removeHold($orderId, $timestamp)
* @param int $orderId
* @param int $timestamp
* @return mixed
* @throws InkRouter_Exceptions_InkRouterNotAvailableException|InkRouter_Exceptions_AuthenticationException|InkRouter_Exceptions_ProcessingException|InkRouter_Exceptions_RejectionException
* @throws Exception
*/
public function cancelOrder($orderId, $timestamp)
{
Expand All @@ -114,8 +125,12 @@ public function cancelOrder($orderId, $timestamp)
}

/**
* @throws InkRouter_Exceptions_InkRouterNotAvailableException|InkRouter_Exceptions_AuthenticationException|InkRouter_Exceptions_ProcessingException|InkRouter_Exceptions_RejectionException
**/
* @param $url
* @param $httpMethod
* @param $headers
* @param null $body
* @return bool|string
*/
private function sendRequest($url, $httpMethod, $headers, $body = null) {
$curlResource = curl_init();
if ($body !== null) {
Expand Down Expand Up @@ -143,23 +158,22 @@ private function sendRequest($url, $httpMethod, $headers, $body = null) {
curl_setopt($curlResource, CURLOPT_RETURNTRANSFER, true);
$responseMessage = curl_exec($curlResource);
if ($responseMessage === false) {
throw new InkRouter_Exceptions_InkRouterNotAvailableException();
throw new InkRouterNotAvailableException();
}

$statusCode = curl_getinfo($curlResource, CURLINFO_HTTP_CODE);
switch ($statusCode) {
case 201:
return $responseMessage;
case 200:
return $responseMessage;
case 401:
throw new InkRouter_Exceptions_AuthenticationException($responseMessage);
throw new AuthenticationException($responseMessage);
case 500:
throw new InkRouter_Exceptions_ProcessingException($responseMessage);
throw new ProcessingException($responseMessage);
case 409:
throw new InkRouter_Exceptions_RejectionException($responseMessage);
throw new RejectionException($responseMessage);
default:
throw new InkRouter_Exceptions_ProcessingException('Unknown error occured');
throw new ProcessingException('Unknown error occured');
}
}
}
Loading

0 comments on commit 566e59f

Please sign in to comment.