-
Notifications
You must be signed in to change notification settings - Fork 5
/
update-order.php
133 lines (124 loc) · 4.2 KB
/
update-order.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Replaces the order rows of the specified order with the new appended in the call.
*
*
* Include Library
*
* If you use Composer, include the autoload.php file from vendor folder
* require_once '../vendor/autoload.php';
*
* If you do not use Composer, include the include.php file from root of the project
* require_once '../include.php';
*/
require_once '../vendor/autoload.php';
/**
* Create connector for given
* Merchant Id - unique merchant ID
* Shared Secret - Shared Secret string between Svea and merchant
* Base Url for SVEA Api. Can be STAGE_BASE_URL and PROD_BASE_URL
*/
$checkoutMerchantId = 100002;
$checkoutSecret = "3862e010913d7c44f104ddb4b2881f810b50d5385244571c3327802e241140cc692522c04aa21c942793c8a69a8e55ca7b6131d9ac2a2ae2f4f7c52634fe30d2";
$baseUrl = \Svea\Checkout\Transport\Connector::TEST_BASE_URL;
try {
/**
* Create Connector object
*
* Exception \Svea\Checkout\Exception\SveaConnectorException will be returned if
* some of fields $merchantId, $sharedSecret and $baseUrl is missing
*
*
* Update Order
*
* Initialize getting the order information
* Possible Exceptions are:
* \Svea\Checkout\Exception\SveaInputValidationException - if $orderId is missing
* \Svea\Checkout\Exception\SveaApiException - is there is some problem with api connection or
* some error occurred with data validation on API side
* \Exception - for any other error
*/
$conn = \Svea\Checkout\Transport\Connector::init($checkoutMerchantId, $checkoutSecret, $baseUrl);
$checkoutClient = new \Svea\Checkout\CheckoutClient($conn);
/**
* Example of update the order and getting the response data
*/
$data = array(
"orderId" => 251147,
"merchantData" => "test",
"cart" => array(
"items" => array(
array(
"articleNumber" => "123456",
"name" => "Yellow rubber duck",
"quantity" => 200,
"unitPrice" => 66600,
"discountPercent" => 1000,
"vatPercent" => 2500,
"temporaryReference" => "230",
"merchantData" => "Size: M"
),
array(
"articleNumber" => "658475",
"name" => "Shipping Fee Updated",
"quantity" => 100,
"unitPrice" => 4900,
"vatPercent" => 2500,
"temporaryReference" => "231",
"merchantData" => null
)
)
)
);
$response = $checkoutClient->update($data);
/*
* Format of returned response array
*
* Response:
* - MerchantSettings
* - TermsUri
* - CheckoutUri
* - ConfirmationUri
* - PushUri
* - Cart
* - Items [..] / list of items
* - ArticleNumber
* - Name
* - Quantity
* - UnitPrice
* - DiscountPercent
* - VatPercent
* - Unit
* - TemporaryReference
* - Customer
* - ShippingAddress
* - BillingAddress
* - Gui
* - Layout
* - Snippet
* - Locale
* - Currency
* - CountryCode
* - PresetValues
* - OrderId
* - Status
* */
$orderId = $response['OrderId'];
$guiSnippet = $response['Gui']['Snippet'];
$orderStatus = $response['Status'];
echo '<pre>' . print_r($response, true) . '</pre>';
} catch (\Svea\Checkout\Exception\SveaApiException $ex) {
examplePrintError($ex, 'Api errors');
} catch (\Svea\Checkout\Exception\SveaConnectorException $ex) {
examplePrintError($ex, 'Conn errors');
} catch (\Svea\Checkout\Exception\SveaInputValidationException $ex) {
examplePrintError($ex, 'Input data errors');
} catch (Exception $ex) {
examplePrintError($ex, 'General errors');
}
function examplePrintError(Exception $ex, $errorTitle)
{
print_r('--------- ' . $errorTitle . ' ---------' . PHP_EOL);
print_r('Error message -> ' . $ex->getMessage() . PHP_EOL);
print_r('Error code -> ' . $ex->getCode() . PHP_EOL);
}