Skip to content

Commit

Permalink
Feature/smi integration (#24)
Browse files Browse the repository at this point in the history
* changed api end point to smi

* assign variable

* product setter and getter was missing

* created currency utill class which is serving all currencies and countries.

* changed api endpoint to smi

* fixed the issue of metadata by using constructor

* different error format handling

* check the data is an array for not

* added Canada country code and currency

* created new function setData for updating existing data

* fixing some of the hardcoded unit test

* fixed the unit test

* fixing code style and output in test

Co-authored-by: ben.zhang <[email protected]>
  • Loading branch information
mahbub-zip and benzhangzip authored Jan 5, 2021
1 parent 560c6d2 commit baf0891
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 201 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zipmoney/merchantapi-php",
"version": "1.0.8",
"version": "1.0.9",
"description": "",
"keywords": [
"zipmoney",
Expand Down Expand Up @@ -28,7 +28,7 @@
},
"require-dev": {
"squizlabs/php_codesniffer": "~2.6",
"friendsofphp/php-cs-fixer": "~1.12"
"phpunit/phpunit": "^5.0"
},
"autoload": {
"psr-4": {
Expand Down
23 changes: 22 additions & 1 deletion lib/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function callApi($resourcePath, $method, $queryParams, $postData, $header
}

throw new ApiException(
"[".$response_info['http_code']."] Error connecting to the API ($url)",
$this->generateErrorMessage(json_decode($http_body)),
$response_info['http_code'],
$http_header,
$data
Expand Down Expand Up @@ -344,4 +344,25 @@ protected function httpParseHeaders($raw_headers)

return $headers;
}

protected function generateErrorMessage($response)
{
$errorMessage = 'An error occurred while processing payment';

if (isset($response->error)) {
if (isset($response->error->message)) {
$errorMessage = (string) $response->error->message;
}

if (isset($response->error->details)) {
$errorMessage = '';

foreach ($response->error->details as $detail) {
$errorMessage .= $detail->message;
}
}
}

return $errorMessage;
}
}
32 changes: 16 additions & 16 deletions lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class Configuration
* @var array
*/
protected $supportedEnvironments = array(
"sandbox" => array("host" => "https://api.sandbox.zipmoney.com.au/merchant/v1"),
"production" => array("host" => 'https://api.zipmoney.com.au/merchant/v1')
"sandbox" => array("host" => "https://global-api.sand.au.edge.zip.co/merchant"),
"production" => array("host" => 'https://global-api.prod.au.edge.zip.co/merchant')
);

/**
Expand All @@ -101,16 +101,16 @@ class Configuration
* @var string
*/
protected $curlTimeout = 0;

/**
* Number of retries allowed if the first one fails.
* Number of retries allowed if the first one fails.
*
* @var string
*/
protected $curlNumRetries = 3;

/**
* Number of retries allowed if the first one fails.
* Number of retries allowed if the first one fails.
*
* @var string
*/
Expand All @@ -135,7 +135,7 @@ class Configuration
*
* @var bool
*/
protected $debug = false;
protected $debug = false;

/**
* Debug file location (log to STDOUT by default)
Expand Down Expand Up @@ -510,7 +510,7 @@ public function setRetryInterval($retryInterval)
$this->retryInterval = $retryInterval;
return $this;
}

/**
* Gets the Retry Interval Value
*
Expand Down Expand Up @@ -664,14 +664,14 @@ public function getEnvironment()
/**
* Sets the environment
*
* @param bool $environment
* @param bool $environment
*
* @return Configuration
*/
public function setEnvironment($environment)
{
{
$this->environment = $environment;

$host = $this->supportedEnvironments['production']['host'];

if(in_array($environment,array_keys($this->supportedEnvironments))){
Expand Down Expand Up @@ -843,14 +843,14 @@ public function setApiVersion($version)
public function setDefaultHeaders()
{
$user_agent_array = array();


if( $platform = $this->getPlatform() ){
$user_agent_array[] = $platform;
}

$default_user_agent = "merchantapi-php";

if( $package_version = $this->getPackageVersion() ){
$user_agent_array[] = $default_user_agent."/".$package_version;
} else {
Expand All @@ -870,12 +870,12 @@ public function setDefaultHeaders()
* @return string
*/
public function getPackageVersion()
{
{
$package_config = file_get_contents(dirname(__FILE__)."./../composer.json");

if($package_config){
$package_config_object = json_decode($package_config);
if(is_object($package_config_object) && isset($package_config_object->version)){
if ($package_config) {
$package_config_object = json_decode($package_config);
if (is_object($package_config_object) && isset($package_config_object->version)) {
return $package_config_object->version;
}
}
Expand Down
67 changes: 49 additions & 18 deletions lib/Model/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ class Charge implements ArrayAccess
const DISCRIMINATOR = 'subclass';

/**
* The original name of the model.
* @var string
*/
* The original name of the model.
* @var string
*/
protected static $swaggerModelName = 'Charge';

/**
* Array of property to type mappings. Used for (de)serialization
* @var string[]
*/
* Array of property to type mappings. Used for (de)serialization
* @var string[]
*/
protected static $zipTypes = array(
'id' => 'string',
'reference' => 'string',
Expand All @@ -38,7 +38,8 @@ class Charge implements ArrayAccess
'created_date' => '\DateTime',
'order' => '\zipMoney\Model\ChargeOrder',
'metadata' => 'object',
'receipt_number' => 'string'
'receipt_number' => 'string',
'product' => 'string',
);

public static function zipTypes()
Expand All @@ -61,7 +62,8 @@ public static function zipTypes()
'created_date' => 'created_date',
'order' => 'order',
'metadata' => 'metadata',
'receipt_number' => 'receipt_number'
'receipt_number' => 'receipt_number',
'product' => 'product',
);


Expand All @@ -80,7 +82,8 @@ public static function zipTypes()
'created_date' => 'setCreatedDate',
'order' => 'setOrder',
'metadata' => 'setMetadata',
'receipt_number' => 'setReceiptNumber'
'receipt_number' => 'setReceiptNumber',
'product' => 'setProduct',
);


Expand All @@ -99,7 +102,8 @@ public static function zipTypes()
'created_date' => 'getCreatedDate',
'order' => 'getOrder',
'metadata' => 'getMetadata',
'receipt_number' => 'getReceiptNumber'
'receipt_number' => 'getReceiptNumber',
'product' => 'getProduct',
);

public static function attributeMap()
Expand All @@ -122,9 +126,9 @@ public static function getters()
const STATE_CANCELLED = 'cancelled';
const STATE_DECLINED = 'declined';
const STATE_REFUNDED = 'refunded';





/**
* Gets allowable values of the enum
* @return string[]
Expand All @@ -139,7 +143,7 @@ public function getStateAllowableValues()
self::STATE_REFUNDED,
);
}


/**
* Associative array for storing property values
Expand All @@ -164,6 +168,7 @@ public function __construct(array $data = null)
$this->container['order'] = isset($data['order']) ? $data['order'] : null;
$this->container['metadata'] = isset($data['metadata']) ? $data['metadata'] : null;
$this->container['receipt_number'] = isset($data['receipt_number']) ? $data['receipt_number'] : null;
$this->container['product'] = isset($data['product']) ? $data['product'] : null;
}

/**
Expand All @@ -187,9 +192,12 @@ public function listInvalidProperties()
if ($this->container['state'] === null) {
$invalid_properties[] = "'state' can't be null";
}
$allowed_values = array("authorised", "captured", "cancelled", "refunded", "declined");

$allowed_values = $this->getStateAllowableValues();
if (!in_array($this->container['state'], $allowed_values)) {
$invalid_properties[] = "invalid value for 'state', must be one of 'authorised', 'captured', 'cancelled', 'refunded', 'declined'.";
$invalid_properties[]
= "invalid value for 'state',
must be one of '".implode("','",$allowed_values)."'.";
}

if ($this->container['captured_amount'] === null) {
Expand Down Expand Up @@ -236,7 +244,7 @@ public function valid()
if ($this->container['state'] === null) {
return false;
}
$allowed_values = array("authorised", "captured", "cancelled", "refunded", "declined");
$allowed_values = $this->getStateAllowableValues();
if (!in_array($this->container['state'], $allowed_values)) {
return false;
}
Expand Down Expand Up @@ -362,9 +370,12 @@ public function getState()
*/
public function setState($state)
{
$allowed_values = array('authorised', 'captured', 'cancelled', 'refunded', 'declined');
$allowed_values = $this->getStateAllowableValues();
if ((!in_array($state, $allowed_values))) {
throw new \InvalidArgumentException("Invalid value for 'state', must be one of 'authorised', 'captured', 'cancelled', 'refunded', 'declined'");
throw new \InvalidArgumentException(
"Invalid value for 'state',
must be one of '".implode("','",$allowed_values)."'."
);
}
$this->container['state'] = $state;

Expand Down Expand Up @@ -506,6 +517,26 @@ public function setReceiptNumber($receipt_number)

return $this;
}
/**
* Sets product
* @param string $product
* @return $this
*/
public function setProduct($product)
{
$this->container['product'] = $product;

return $this;
}

/**
* Gets product
* @return string
*/
public function getProduct()
{
return $this->container['product'];
}
/**
* Returns true if offset exists. False otherwise.
* @param integer $offset Offset
Expand Down
33 changes: 8 additions & 25 deletions lib/Model/CreateChargeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,6 @@ public static function getters()
return self::$getters;
}

const CURRENCY_AUD = 'AUD';
const CURRENCY_NZD = 'NZD';



/**
* Gets allowable values of the enum
* @return string[]
*/
public function getCurrencyAllowableValues()
{
return array(
self::CURRENCY_AUD,
self::CURRENCY_NZD,
);
}


/**
* Associative array for storing property values
Expand Down Expand Up @@ -158,9 +141,9 @@ public function listInvalidProperties()
if ($this->container['currency'] === null) {
$invalid_properties[] = "'currency' can't be null";
}
$allowed_values = array("AUD", "NZD");
if (!in_array($this->container['currency'], $allowed_values)) {
$invalid_properties[] = "invalid value for 'currency', must be one of 'AUD', 'NZD'.";
$allowed_values = currencyUtil::isValidCurrency($this->container['currency']);
if (!$allowed_values['valid']) {
$invalid_properties[] = $allowed_values['message'];
}

return $invalid_properties;
Expand All @@ -184,8 +167,8 @@ public function valid()
if ($this->container['currency'] === null) {
return false;
}
$allowed_values = array("AUD", "NZD");
if (!in_array($this->container['currency'], $allowed_values)) {
$allowed_values = currencyUtil::isValidCurrency($this->container['currency']);
if (!$allowed_values['valid']) {
return false;
}
return true;
Expand Down Expand Up @@ -271,9 +254,9 @@ public function getCurrency()
*/
public function setCurrency($currency)
{
$allowed_values = array('AUD', 'NZD');
if ((!in_array($currency, $allowed_values))) {
throw new \InvalidArgumentException("Invalid value for 'currency', must be one of 'AUD', 'NZD'");
$allowed_values = currencyUtil::isValidCurrency($currency);
if (!$allowed_values['valid']) {
throw new \InvalidArgumentException($allowed_values['message']);
}
$this->container['currency'] = $currency;

Expand Down
Loading

0 comments on commit baf0891

Please sign in to comment.