Skip to content

Commit

Permalink
MAG-745: Make sdk compatibility Post-Auth Sale API
Browse files Browse the repository at this point in the history
  • Loading branch information
ebanolopes committed Jun 2, 2022
1 parent 7339ab2 commit 12d7aaf
Show file tree
Hide file tree
Showing 48 changed files with 7,537 additions and 999 deletions.
174 changes: 174 additions & 0 deletions lib/Core/Api/ApiModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?php
/**
* CaseApi for the Signifyd SDK
*
* PHP version 5.6
*
* @category Signifyd_Fraud_Protection
* @package Signifyd\Core
* @author Signifyd <[email protected]>
* @copyright 2018 SIGNIFYD Inc. All rights reserved.
* @license See LICENSE.txt for license details.
* @link https://www.signifyd.com/
*/
namespace Signifyd\Core\Api;

use Signifyd\Core\Connection;
use Signifyd\Core\Exceptions\ApiException;
use Signifyd\Core\Exceptions\InvalidClassException;
use Signifyd\Core\Logging;
use Signifyd\Core\Response\CaseResponse;
use Signifyd\Core\Settings;
use Signifyd\Models\SaleModel;
use Signifyd\Models\Reroute;

/**
* Class ApiModel
*
* @category Signifyd_Fraud_Protection
* @package Signifyd\Core
* @author Signifyd <[email protected]>
* @license See LICENSE.txt for license details.
* @link https://www.signifyd.com/
*/
class ApiModel
{
/**
* The SDK settings
*
* @var Settings The settings object
*/
public $settings;

/**
* The curl connection class
*
* @var Connection The connection object
*/
public $connection;

/**
* The logger object
*
* @var Logging The logger class
*/
public $logger;

/**
* CaseApi constructor.
*
* @param array $args The settings values
*
* @throws \Signifyd\Core\Exceptions\LoggerException
* @throws \Signifyd\Core\Exceptions\ConnectionException
*/
public function __construct($args = [])
{
if (is_array($args) && !empty($args)) {
$this->settings = new Settings($args);
} elseif ($args instanceof Settings) {
$this->settings = $args;
} else {
$this->settings = new Settings([]);
}

$this->logger = new Logging($this->settings);
$this->connection = new Connection($this->settings);
$this->logger->info('Signifyd Api initialized');
}

public function updateOrder($order, $signifydId)
{
//TODO: implements updateOrder for v3
}

/**
* Getting the case from Signifyd
*
* @param int $signifydId
*
* @return CaseResponse
*
* @throws InvalidClassException
* @throws \Signifyd\Core\Exceptions\LoggerException
*/
public function getCase($signifydId)
{
//TODO: implements getCase for v3
}

public function reprice($repriceData)
{
$reprice = new \Signifyd\Models\Reprice($repriceData);

$this->logger->info(
'Connection call reprice with: ' . $reprice->toJson()
);

$response = $this->connection->callApi(
'orders/events/repricings',
$reprice->toJson(),
'post',
'sale'
);

return $response;
}

public function reroute($reroute)
{
$this->logger->info('SaleApi: reroute method called');
if (is_array($reroute)) {
$reroute = new Reroute($reroute);
$valid = $reroute->validate();
if (true !== $valid) {
$this->logger->error(
'Reroute not valid after array init: ' . json_encode($valid)
);
}
} elseif ($reroute instanceof Reroute) {
$valid = $reroute->validate();
if (true !== $valid) {
$this->logger->error(
'Reroute not valid after object init: ' . json_encode($valid)
);
}
} else {
$this->logger->error('Invalid parameter for create reroute');
throw new ApiException(
'Invalid parameter for create reroute'
);
}

$this->logger->info(
'Connection call reroute with: ' . $reroute->toJson()
);

$response = $this->connection->callApi(
'orders/events/reroutes',
$reroute->toJson(),
'post',
'checkouts'
);

return $response;
}

public function addFulfillment($fulfillmentsData)
{
$fulfillments = new \Signifyd\Models\Fulfillments($fulfillmentsData);

$this->logger->info(
'Connection call addFulfillments with: ' . $fulfillments->toJson()
);

$response = $this->connection->callApi(
'orders/events/fulfillments',
$fulfillments->toJson(),
'post',
'sale'
);

return $response;
}
}
133 changes: 133 additions & 0 deletions lib/Core/Api/CheckoutApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?php
/**
* CaseApi for the Signifyd SDK
*
* PHP version 5.6
*
* @category Signifyd_Fraud_Protection
* @package Signifyd\Core
* @author Signifyd <[email protected]>
* @copyright 2018 SIGNIFYD Inc. All rights reserved.
* @license See LICENSE.txt for license details.
* @link https://www.signifyd.com/
*/
namespace Signifyd\Core\Api;

use Signifyd\Core\Exceptions\ApiException;
use Signifyd\Core\Exceptions\InvalidClassException;
use Signifyd\Models\CheckoutModel;
use Signifyd\Models\CheckoutTransaction;
use Signifyd\Models\SendTransaction;

/**
* Class CheckoutApi
*
* @category Signifyd_Fraud_Protection
* @package Signifyd\Core
* @author Signifyd <[email protected]>
* @license See LICENSE.txt for license details.
* @link https://www.signifyd.com/
*/
class CheckoutApi extends ApiModel
{
/**
* CaseApi constructor.
*
* @param array $args The settings values
*
* @throws \Signifyd\Core\Exceptions\LoggerException
* @throws \Signifyd\Core\Exceptions\ConnectionException
*/
public function __construct($args = [])
{
parent::__construct($args);
$this->logger->info('CheckoutApi initialized');
}

/**
* Create a case in Signifyd
*
* @param \Signifyd\Models\CaseModel $order The case data
*
* @return bool|\Signifyd\Core\Response\CheckoutsResponse
*
* @throws ApiException
* @throws InvalidClassException
* @throws \Signifyd\Core\Exceptions\LoggerException
*/
public function createOrder($endpoint, $order)
{
$this->logger->info('CheckoutApi: CreateOrder method called');
if (is_array($order)) {
$order = new CheckoutModel($order);
$valid = $order->validate();
if (true !== $valid) {
$this->logger->error(
'Order not valid after array init: ' . json_encode($valid)
);
}
} elseif ($order instanceof CheckoutModel) {
$valid = $order->validate();
if (true !== $valid) {
$this->logger->error(
'Order not valid after object init: ' . json_encode($valid)
);
}
} else {
$this->logger->error('Invalid parameter for create order');
throw new ApiException(
'Invalid parameter for create order'
);
}

$this->logger->info(
'Connection call checkout api with: ' . $order->toJson()
);
$response = $this->connection->callApi(
$endpoint,
$order->toJson(),
'post',
'checkouts'
);

return $response;
}

public function createTransaction($transaction)
{
$this->logger->info('CheckoutApi: CreateTransaction method called');
if (is_array($transaction)) {
$transaction = new CheckoutTransaction($transaction);
$valid = $transaction->validate();
if (true !== $valid) {
$this->logger->error(
'Transaction not valid after array init: ' . json_encode($valid)
);
}
} elseif ($transaction instanceof CheckoutTransaction) {
$valid = $transaction->validate();
if (true !== $valid) {
$this->logger->error(
'Transaction not valid after object init: ' . json_encode($valid)
);
}
} else {
$this->logger->error('Invalid parameter for create case');
throw new ApiException(
'Invalid parameter for create transaction'
);
}

$this->logger->info(
'Connection call create case api with transaction: ' . $transaction->toJson()
);
$response = $this->connection->callApi(
'orders/events/transactions',
$transaction->toJson(),
'post',
'transactions'
);

return $response;
}
}
Loading

0 comments on commit 12d7aaf

Please sign in to comment.