Skip to content

Commit 03186f3

Browse files
authored
Merge branch 'main' into 21-fix-transaction-response
2 parents fe95a61 + 861c22a commit 03186f3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+8047
-1242
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "signifyd/signifyd-php",
33
"description": "Signifyd client API plugin for PHP",
44
"type": "library",
5-
"version": "3.1.1",
5+
"version": "4.0.1",
66
"license": [
77
"MIT"
88
],

lib/Core/Api/ApiModel.php

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
<?php
2+
/**
3+
* CaseApi for the Signifyd SDK
4+
*
5+
* PHP version 5.6
6+
*
7+
* @category Signifyd_Fraud_Protection
8+
* @package Signifyd\Core
9+
* @author Signifyd <[email protected]>
10+
* @copyright 2018 SIGNIFYD Inc. All rights reserved.
11+
* @license See LICENSE.txt for license details.
12+
* @link https://www.signifyd.com/
13+
*/
14+
namespace Signifyd\Core\Api;
15+
16+
use Signifyd\Core\Connection;
17+
use Signifyd\Core\Exceptions\ApiException;
18+
use Signifyd\Core\Exceptions\InvalidClassException;
19+
use Signifyd\Core\Logging;
20+
use Signifyd\Core\Response\CaseResponse;
21+
use Signifyd\Core\Settings;
22+
use Signifyd\Models\SaleModel;
23+
use Signifyd\Models\Reroute;
24+
25+
/**
26+
* Class ApiModel
27+
*
28+
* @category Signifyd_Fraud_Protection
29+
* @package Signifyd\Core
30+
* @author Signifyd <[email protected]>
31+
* @license See LICENSE.txt for license details.
32+
* @link https://www.signifyd.com/
33+
*/
34+
class ApiModel
35+
{
36+
/**
37+
* The SDK settings
38+
*
39+
* @var Settings The settings object
40+
*/
41+
public $settings;
42+
43+
/**
44+
* The curl connection class
45+
*
46+
* @var Connection The connection object
47+
*/
48+
public $connection;
49+
50+
/**
51+
* The logger object
52+
*
53+
* @var Logging The logger class
54+
*/
55+
public $logger;
56+
57+
/**
58+
* CaseApi constructor.
59+
*
60+
* @param array $args The settings values
61+
*
62+
* @throws \Signifyd\Core\Exceptions\LoggerException
63+
* @throws \Signifyd\Core\Exceptions\ConnectionException
64+
*/
65+
public function __construct($args = [])
66+
{
67+
if (is_array($args) && !empty($args)) {
68+
$this->settings = new Settings($args);
69+
} elseif ($args instanceof Settings) {
70+
$this->settings = $args;
71+
} else {
72+
$this->settings = new Settings([]);
73+
}
74+
75+
$this->logger = new Logging($this->settings);
76+
$this->connection = new Connection($this->settings);
77+
$this->logger->info('Signifyd Api initialized');
78+
}
79+
80+
public function updateOrder($order, $signifydId)
81+
{
82+
//TODO: implements updateOrder for v3
83+
}
84+
85+
/**
86+
* Getting the case from Signifyd
87+
*
88+
* @param int $signifydId
89+
*
90+
* @return CaseResponse
91+
*
92+
* @throws InvalidClassException
93+
* @throws \Signifyd\Core\Exceptions\LoggerException
94+
*/
95+
public function getCase($signifydId)
96+
{
97+
//TODO: implements getCase for v3
98+
}
99+
100+
public function reprice($repriceData)
101+
{
102+
$reprice = new \Signifyd\Models\Reprice($repriceData);
103+
104+
$this->logger->info(
105+
'Connection call reprice with: ' . $reprice->toJson()
106+
);
107+
108+
$response = $this->connection->callApi(
109+
'orders/events/repricings',
110+
$reprice->toJson(),
111+
'post',
112+
'sale'
113+
);
114+
115+
return $response;
116+
}
117+
118+
public function reroute($reroute)
119+
{
120+
$this->logger->info('SaleApi: reroute method called');
121+
if (is_array($reroute)) {
122+
$reroute = new Reroute($reroute);
123+
$valid = $reroute->validate();
124+
if (true !== $valid) {
125+
$this->logger->error(
126+
'Reroute not valid after array init: ' . json_encode($valid)
127+
);
128+
}
129+
} elseif ($reroute instanceof Reroute) {
130+
$valid = $reroute->validate();
131+
if (true !== $valid) {
132+
$this->logger->error(
133+
'Reroute not valid after object init: ' . json_encode($valid)
134+
);
135+
}
136+
} else {
137+
$this->logger->error('Invalid parameter for create reroute');
138+
throw new ApiException(
139+
'Invalid parameter for create reroute'
140+
);
141+
}
142+
143+
$this->logger->info(
144+
'Connection call reroute with: ' . $reroute->toJson()
145+
);
146+
147+
$response = $this->connection->callApi(
148+
'orders/events/reroutes',
149+
$reroute->toJson(),
150+
'post',
151+
'checkouts'
152+
);
153+
154+
return $response;
155+
}
156+
157+
public function addFulfillment($fulfillmentsData)
158+
{
159+
$fulfillments = new \Signifyd\Models\Fulfillments($fulfillmentsData);
160+
161+
$this->logger->info(
162+
'Connection call addFulfillments with: ' . $fulfillments->toJson()
163+
);
164+
165+
$response = $this->connection->callApi(
166+
'orders/events/fulfillments',
167+
$fulfillments->toJson(),
168+
'post',
169+
'sale'
170+
);
171+
172+
return $response;
173+
}
174+
}

lib/Core/Api/CaseApi.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Signifyd\Core\Response\FulfillmentBulkResponse;
2323
use Signifyd\Core\Settings;
2424
use Signifyd\Models\CaseModel;
25+
use Signifyd\Models\UpdateCaseModel;
2526
use Signifyd\Models\SendTransaction;
2627
use Signifyd\Models\Fulfillment;
2728
use Signifyd\Models\PaymentUpdate;
@@ -132,6 +133,55 @@ public function createCase($case)
132133
return $response;
133134
}
134135

136+
/**
137+
* Create a case in Signifyd
138+
*
139+
* @param \Signifyd\Models\CaseModel $case The case data
140+
*
141+
* @return bool|\Signifyd\Core\Response\CaseResponse
142+
*
143+
* @throws CaseModelException
144+
* @throws InvalidClassException
145+
* @throws \Signifyd\Core\Exceptions\LoggerException
146+
*/
147+
public function updateCase($case, $caseId)
148+
{
149+
$this->logger->info('Update method called');
150+
if (is_array($case)) {
151+
$case = new UpdateCaseModel($case);
152+
$valid = $case->validate();
153+
if (true !== $valid) {
154+
$this->logger->error(
155+
'Case not valid after array init: ' . json_encode($valid)
156+
);
157+
}
158+
} elseif ($case instanceof UpdateCaseModel) {
159+
$valid = $case->validate();
160+
if (true !== $valid) {
161+
$this->logger->error(
162+
'Case not valid after object init: ' . json_encode($valid)
163+
);
164+
}
165+
} else {
166+
$this->logger->error('Invalid parameter for create case');
167+
throw new CaseModelException(
168+
'Invalid parameter for create case'
169+
);
170+
}
171+
172+
$this->logger->info(
173+
'Connection call update case api with case: ' . $case->toJson()
174+
);
175+
$response = $this->connection->callApi(
176+
'cases/' . $caseId,
177+
$case->toJson(),
178+
'put',
179+
'case'
180+
);
181+
182+
return $response;
183+
}
184+
135185
/**
136186
* Getting the case from Signifyd
137187
*

lib/Core/Api/CheckoutApi.php

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?php
2+
/**
3+
* CaseApi for the Signifyd SDK
4+
*
5+
* PHP version 5.6
6+
*
7+
* @category Signifyd_Fraud_Protection
8+
* @package Signifyd\Core
9+
* @author Signifyd <[email protected]>
10+
* @copyright 2018 SIGNIFYD Inc. All rights reserved.
11+
* @license See LICENSE.txt for license details.
12+
* @link https://www.signifyd.com/
13+
*/
14+
namespace Signifyd\Core\Api;
15+
16+
use Signifyd\Core\Exceptions\ApiException;
17+
use Signifyd\Core\Exceptions\InvalidClassException;
18+
use Signifyd\Models\CheckoutModel;
19+
use Signifyd\Models\CheckoutTransaction;
20+
use Signifyd\Models\SendTransaction;
21+
22+
/**
23+
* Class CheckoutApi
24+
*
25+
* @category Signifyd_Fraud_Protection
26+
* @package Signifyd\Core
27+
* @author Signifyd <[email protected]>
28+
* @license See LICENSE.txt for license details.
29+
* @link https://www.signifyd.com/
30+
*/
31+
class CheckoutApi extends ApiModel
32+
{
33+
/**
34+
* CaseApi constructor.
35+
*
36+
* @param array $args The settings values
37+
*
38+
* @throws \Signifyd\Core\Exceptions\LoggerException
39+
* @throws \Signifyd\Core\Exceptions\ConnectionException
40+
*/
41+
public function __construct($args = [])
42+
{
43+
parent::__construct($args);
44+
$this->logger->info('CheckoutApi initialized');
45+
}
46+
47+
/**
48+
* Create a case in Signifyd
49+
*
50+
* @param \Signifyd\Models\CaseModel $order The case data
51+
*
52+
* @return bool|\Signifyd\Core\Response\CheckoutsResponse
53+
*
54+
* @throws ApiException
55+
* @throws InvalidClassException
56+
* @throws \Signifyd\Core\Exceptions\LoggerException
57+
*/
58+
public function createOrder($endpoint, $order)
59+
{
60+
$this->logger->info('CheckoutApi: CreateOrder method called');
61+
if (is_array($order)) {
62+
$order = new CheckoutModel($order);
63+
$valid = $order->validate();
64+
if (true !== $valid) {
65+
$this->logger->error(
66+
'Order not valid after array init: ' . json_encode($valid)
67+
);
68+
}
69+
} elseif ($order instanceof CheckoutModel) {
70+
$valid = $order->validate();
71+
if (true !== $valid) {
72+
$this->logger->error(
73+
'Order not valid after object init: ' . json_encode($valid)
74+
);
75+
}
76+
} else {
77+
$this->logger->error('Invalid parameter for create order');
78+
throw new ApiException(
79+
'Invalid parameter for create order'
80+
);
81+
}
82+
83+
$this->logger->info(
84+
'Connection call checkout api with: ' . $order->toJson()
85+
);
86+
$response = $this->connection->callApi(
87+
$endpoint,
88+
$order->toJson(),
89+
'post',
90+
'checkouts'
91+
);
92+
93+
return $response;
94+
}
95+
96+
public function createTransaction($transaction)
97+
{
98+
$this->logger->info('CheckoutApi: CreateTransaction method called');
99+
if (is_array($transaction)) {
100+
$transaction = new CheckoutTransaction($transaction);
101+
$valid = $transaction->validate();
102+
if (true !== $valid) {
103+
$this->logger->error(
104+
'Transaction not valid after array init: ' . json_encode($valid)
105+
);
106+
}
107+
} elseif ($transaction instanceof CheckoutTransaction) {
108+
$valid = $transaction->validate();
109+
if (true !== $valid) {
110+
$this->logger->error(
111+
'Transaction not valid after object init: ' . json_encode($valid)
112+
);
113+
}
114+
} else {
115+
$this->logger->error('Invalid parameter for create case');
116+
throw new ApiException(
117+
'Invalid parameter for create transaction'
118+
);
119+
}
120+
121+
$this->logger->info(
122+
'Connection call create case api with transaction: ' . $transaction->toJson()
123+
);
124+
$response = $this->connection->callApi(
125+
'orders/events/transactions',
126+
$transaction->toJson(),
127+
'post',
128+
'transactions'
129+
);
130+
131+
return $response;
132+
}
133+
}

0 commit comments

Comments
 (0)