Skip to content

Commit

Permalink
Added new MinFraudConfig and MinFraudAPIEnpoint classes
Browse files Browse the repository at this point in the history
  • Loading branch information
scottyrichardson committed Nov 8, 2020
1 parent b9f75d7 commit a9d2944
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 13 deletions.
103 changes: 103 additions & 0 deletions src/Config/MinFraudAPIEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

namespace Grayl\Gateway\MinFraud\Config;

use Grayl\Gateway\Common\Config\GatewayAPIEndpointAbstract;

/**
* Class MinFraudAPIEndpoint
* The class of a single MinFraud API endpoint
*
* @package Grayl\Gateway\MinFraud
*/
class MinFraudAPIEndpoint extends GatewayAPIEndpointAbstract
{

/**
* The MinFraud user ID
*
* @var string
*/
protected string $user_id;

/**
* The MinFraud license key
*
* @var string
*/
protected string $license_key;


/**
* Class constructor
*
* @param string $api_endpoint_id The ID of this API endpoint (default, provision, etc.)
* @param string $user_id The MinFraud user ID
* @param string $license_key The MinFraud license key
*/
public function __construct ( string $api_endpoint_id,
string $user_id,
string $license_key )
{

// Call the parent constructor
parent::__construct( $api_endpoint_id );

// Set the class data
$this->setUserID( $user_id );
$this->setLicenseKey( $license_key );
}


/**
* Gets the Minfraud User ID
*
* @return string
*/
public function getUserID (): string
{

// Return it
return $this->user_id;
}


/**
* Sets the MinFraud user ID
*
* @param string $user_id The MinFraud user ID
*/
public function setUserID ( string $user_id ): void
{

// Set the MinFraud user ID
$this->user_id = $user_id;
}


/**
* Gets the MinFraud license key
*
* @return string
*/
public function getLicenseKey (): string
{

// Return it
return $this->license_key;
}


/**
* Sets the MinFraud license key
*
* @param string $license_key The MinFraud license key
*/
public function setLicenseKey ( string $license_key ): void
{

// Set the MinFraud license key
$this->license_key = $license_key;
}

}
22 changes: 22 additions & 0 deletions src/Config/MinFraudConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Grayl\Gateway\MinFraud\Config;

use Grayl\Gateway\Common\Config\GatewayConfigAbstract;

/**
* Class MinFraudGatewayData
* The class of the config for MinFraud gateways
* @method MinFraudAPIEndpoint getLiveAPIEndpoint( string $api_endpoint_id )
* @method void setLiveAPIEndpoint( MinFraudAPIEndpoint $api_endpoint )
* @method MinFraudAPIEndpoint getSandboxAPIEndpoint( string $api_endpoint_id )
* @method void setSandboxAPIEndpoint( MinFraudAPIEndpoint $api_endpoint )
*
* @package Grayl\Gateway\MinFraud
*/
class MinFraudConfig extends GatewayConfigAbstract
{

// No overrides to the abstract class

}
35 changes: 22 additions & 13 deletions src/MinFraudPorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Grayl\Gateway\MinFraud;

use Grayl\Gateway\Common\GatewayPorterAbstract;
use Grayl\Gateway\MinFraud\Config\MinFraudAPIEndpoint;
use Grayl\Gateway\MinFraud\Config\MinFraudConfig;
use Grayl\Gateway\MinFraud\Controller\MinFraudInsightsRequestController;
use Grayl\Gateway\MinFraud\Entity\MinFraudGatewayData;
use Grayl\Gateway\MinFraud\Entity\MinFraudInsightsRequestData;
Expand All @@ -14,7 +16,7 @@

/**
* Front-end for the MinFraud package
* @method MinFraudGatewayData getSavedGatewayDataEntity ( string $endpoint_id )
* @method MinFraudGatewayData getSavedGatewayDataEntity ( string $api_endpoint_id )
*
* @package Grayl\Gateway\MinFraud
*/
Expand All @@ -29,53 +31,60 @@ class MinFraudPorter extends GatewayPorterAbstract
*
* @var string
*/
protected string $config_file = 'gateway.minfraud.php';
protected string $config_file = 'gateway-minfraud.php';

/**
* The MinFraudConfig instance for this gateway
*
* @var MinFraudConfig
*/
protected $config;


/**
* Creates a new MinFraud object for use in a MinFraudGatewayData entity
*
* @param array $credentials An array containing all of the credentials needed to create the gateway API
* @param MinFraudAPIEndpoint $api_endpoint A MinFraudAPIEndpoint with credentials needed to create a gateway API object
*
* @return MinFraud
* @throws \Exception
* @throws \Exception
*/
public function newGatewayAPI ( array $credentials ): object
public function newGatewayAPI ( $api_endpoint ): object
{

// Return the new API entity
return new MinFraud( $credentials[ 'user_id' ],
$credentials[ 'license_key' ] );
return new MinFraud( $api_endpoint->getUserID(),
$api_endpoint->getLicenseKey() );
}


/**
* Creates a new MinFraudGatewayData
*
* @param string $endpoint_id The API endpoint ID to use (typically "default" is there is only one API gateway)
* @param string $api_endpoint_id The API endpoint ID to use (typically "default" if there is only one API gateway)
*
* @return MinFraudGatewayData
* @throws \Exception
*/
public function newGatewayDataEntity ( string $endpoint_id ): object
public function newGatewayDataEntity ( string $api_endpoint_id ): object
{

// Grab the gateway service
$service = new MinFraudGatewayService();

// Get an API
$api = $this->newGatewayAPI( $service->getAPICredentials( $this->config,
$this->environment,
$endpoint_id ) );
// Get a new API
$api = $this->newGatewayAPI( $service->getAPIEndpoint( $this->config,
$this->environment,
$api_endpoint_id ) );

// Configure the API as needed using the service
$service->configureAPI( $api,
$this->environment );

// Return the gateway
return new MinFraudGatewayData( $api,
$this->config->getConfig( 'name' ),
$this->config->getGatewayName(),
$this->environment );
}

Expand Down
3 changes: 3 additions & 0 deletions src/Service/MinFraudGatewayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
namespace Grayl\Gateway\MinFraud\Service;

use Grayl\Gateway\Common\Service\GatewayServiceAbstract;
use Grayl\Gateway\MinFraud\Config\MinFraudAPIEndpoint;
use Grayl\Gateway\MinFraud\Config\MinFraudConfig;

/**
* Class MinFraudGatewayService
* The service for working with MinFraud API gateway
* @method MinFraudAPIEndpoint getAPIEndpoint ( MinFraudConfig $config, string $environment, string $api_endpoint_id )
*
* @package Grayl\Gateway\MinFraud
*/
Expand Down

0 comments on commit a9d2944

Please sign in to comment.