From 212189960b2657e7be53aae352d5b8152e69ecd2 Mon Sep 17 00:00:00 2001 From: michaelpa Date: Thu, 6 Apr 2023 15:00:47 +0200 Subject: [PATCH 1/6] ITT-413: Data Protection API --- .../Model/DataProtection/ModelInterface.php | 93 ++++ .../Model/DataProtection/ObjectSerializer.php | 317 +++++++++++ .../Model/DataProtection/ServiceError.php | 519 ++++++++++++++++++ .../SubjectErasureByPspReferenceRequest.php | 453 +++++++++++++++ .../DataProtection/SubjectErasureResponse.php | 422 ++++++++++++++ src/Adyen/Service/DataProtectionApi.php | 56 ++ .../post-request-subject-erasure-success.json | 3 + tests/Unit/DataProtectionTest.php | 31 ++ 8 files changed, 1894 insertions(+) create mode 100644 src/Adyen/Model/DataProtection/ModelInterface.php create mode 100644 src/Adyen/Model/DataProtection/ObjectSerializer.php create mode 100644 src/Adyen/Model/DataProtection/ServiceError.php create mode 100644 src/Adyen/Model/DataProtection/SubjectErasureByPspReferenceRequest.php create mode 100644 src/Adyen/Model/DataProtection/SubjectErasureResponse.php create mode 100644 src/Adyen/Service/DataProtectionApi.php create mode 100644 tests/Resources/DataProtection/post-request-subject-erasure-success.json create mode 100644 tests/Unit/DataProtectionTest.php diff --git a/src/Adyen/Model/DataProtection/ModelInterface.php b/src/Adyen/Model/DataProtection/ModelInterface.php new file mode 100644 index 000000000..db10e3265 --- /dev/null +++ b/src/Adyen/Model/DataProtection/ModelInterface.php @@ -0,0 +1,93 @@ +format('Y-m-d') : $data->format(self::$dateTimeFormat); + } + + if (is_array($data)) { + foreach ($data as $property => $value) { + $data[$property] = self::sanitizeForSerialization($value); + } + return $data; + } + + if (is_object($data)) { + $values = []; + if ($data instanceof ModelInterface) { + $formats = $data::openAPIFormats(); + foreach ($data::openAPITypes() as $property => $openAPIType) { + $getter = $data::getters()[$property]; + $value = $data->$getter(); + if ($value !== null && !in_array($openAPIType, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + $callable = [$openAPIType, 'getAllowableEnumValues']; + if (is_callable($callable)) { + /** array $callable */ + $allowedEnumTypes = $callable(); + if (!in_array($value, $allowedEnumTypes, true)) { + $imploded = implode("', '", $allowedEnumTypes); + throw new \InvalidArgumentException("Invalid value for enum '$openAPIType', must be one of: '$imploded'"); + } + } + } + if (($data::isNullable($property) && $data->isNullableSetToNull($property)) || $value !== null) { + $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $openAPIType, $formats[$property]); + } + } + } else { + foreach($data as $property => $value) { + $values[$property] = self::sanitizeForSerialization($value); + } + } + return (object)$values; + } else { + return (string)$data; + } + } + + /** + * Sanitize filename by removing path. + * e.g. ../../sun.gif becomes sun.gif + * + * @param string $filename filename to be sanitized + * + * @return string the sanitized filename + */ + public static function sanitizeFilename($filename) + { + if (preg_match("/.*[\/\\\\](.*)$/", $filename, $match)) { + return $match[1]; + } else { + return $filename; + } + } + + /** + * Shorter timestamp microseconds to 6 digits length. + * + * @param string $timestamp Original timestamp + * + * @return string the shorten timestamp + */ + public static function sanitizeTimestamp($timestamp) + { + if (!is_string($timestamp)) return $timestamp; + + return preg_replace('/(:\d{2}.\d{6})\d*/', '$1', $timestamp); + } + + /** + * Serialize an array to a string. + * + * @param array $collection collection to serialize to a string + * @param string $style the format use for serialization (csv, + * ssv, tsv, pipes, multi) + * @param bool $allowCollectionFormatMulti allow collection format to be a multidimensional array + * + * @return string + */ + public static function serializeCollection(array $collection, $style, $allowCollectionFormatMulti = false) + { + if ($allowCollectionFormatMulti && ('multi' === $style)) { + // http_build_query() almost does the job for us. We just + // need to fix the result of multidimensional arrays. + return preg_replace('/%5B[0-9]+%5D=/', '=', http_build_query($collection, '', '&')); + } + switch ($style) { + case 'pipeDelimited': + case 'pipes': + return implode('|', $collection); + + case 'tsv': + return implode("\t", $collection); + + case 'spaceDelimited': + case 'ssv': + return implode(' ', $collection); + + case 'simple': + case 'csv': + // Deliberate fall through. CSV is default format. + default: + return implode(',', $collection); + } + } + + /** + * Deserialize a JSON string into an object + * + * @param mixed $data object or primitive to be deserialized + * @param string $class class name is passed as a string + * @param string[] $httpHeaders HTTP headers + * @param string $discriminator discriminator if polymorphism is used + * + * @return object|array|null a single or an array of $class instances + */ + public static function deserialize($data, $class, $httpHeaders = null) + { + if (null === $data) { + return null; + } + + if (strcasecmp(substr($class, -2), '[]') === 0) { + $data = is_string($data) ? json_decode($data) : $data; + + if (!is_array($data)) { + throw new \InvalidArgumentException("Invalid array '$class'"); + } + + $subClass = substr($class, 0, -2); + $values = []; + foreach ($data as $key => $value) { + $values[] = self::deserialize($value, $subClass, null); + } + return $values; + } + + if (preg_match('/^(array<|map\[)/', $class)) { // for associative array e.g. array + $data = is_string($data) ? json_decode($data) : $data; + settype($data, 'array'); + $inner = substr($class, 4, -1); + $deserialized = []; + if (strrpos($inner, ",") !== false) { + $subClass_array = explode(',', $inner, 2); + $subClass = $subClass_array[1]; + foreach ($data as $key => $value) { + $deserialized[$key] = self::deserialize($value, $subClass, null); + } + } + return $deserialized; + } + + if ($class === 'object') { + settype($data, 'array'); + return $data; + } elseif ($class === 'mixed') { + settype($data, gettype($data)); + return $data; + } + + if ($class === '\DateTime') { + // Some APIs return an invalid, empty string as a + // date-time property. DateTime::__construct() will return + // the current time for empty input which is probably not + // what is meant. The invalid empty string is probably to + // be interpreted as a missing field/value. Let's handle + // this graceful. + if (!empty($data)) { + try { + return new \DateTime($data); + } catch (\Exception $exception) { + // Some APIs return a date-time with too high nanosecond + // precision for php's DateTime to handle. + // With provided regexp 6 digits of microseconds saved + return new \DateTime(self::sanitizeTimestamp($data)); + } + } else { + return null; + } + } + + if ($class === '\SplFileObject') { + $data = Utils::streamFor($data); + + /** @var \Psr\Http\Message\StreamInterface $data */ + + // determine file name + if ( + is_array($httpHeaders) + && array_key_exists('Content-Disposition', $httpHeaders) + && preg_match('/inline; filename=[\'"]?([^\'"\s]+)[\'"]?$/i', $httpHeaders['Content-Disposition'], $match) + ) { + $filename = Configuration::getDefaultConfiguration()->getTempFolderPath() . DIRECTORY_SEPARATOR . self::sanitizeFilename($match[1]); + } else { + $filename = tempnam(Configuration::getDefaultConfiguration()->getTempFolderPath(), ''); + } + + $file = fopen($filename, 'w'); + while ($chunk = $data->read(200)) { + fwrite($file, $chunk); + } + fclose($file); + + return new \SplFileObject($filename, 'r'); + } + + /** @psalm-suppress ParadoxicalCondition */ + if (in_array($class, ['\DateTime', '\SplFileObject', 'array', 'bool', 'boolean', 'byte', 'float', 'int', 'integer', 'mixed', 'number', 'object', 'string', 'void'], true)) { + settype($data, $class); + return $data; + } + + + if (method_exists($class, 'getAllowableEnumValues')) { + if (!in_array($data, $class::getAllowableEnumValues(), true)) { + $imploded = implode("', '", $class::getAllowableEnumValues()); + throw new \InvalidArgumentException("Invalid value for enum '$class', must be one of: '$imploded'"); + } + return $data; + } else { + $data = is_string($data) ? json_decode($data) : $data; + + if (is_array($data)) { + $data = (object)$data; + } + + // If a discriminator is defined and points to a valid subclass, use it. + $discriminator = $class::DISCRIMINATOR; + if (!empty($discriminator) && isset($data->{$discriminator}) && is_string($data->{$discriminator})) { + $subclass = '\Adyen\Model\\' . $data->{$discriminator}; + if (is_subclass_of($subclass, $class)) { + $class = $subclass; + } + } + + /** @var ModelInterface $instance */ + $instance = new $class(); + foreach ($instance::openAPITypes() as $property => $type) { + $propertySetter = $instance::setters()[$property]; + + if (!isset($propertySetter)) { + continue; + } + + if (!isset($data->{$instance::attributeMap()[$property]})) { + if ($instance::isNullable($property)) { + $instance->$propertySetter(null); + } + + continue; + } + + if (isset($data->{$instance::attributeMap()[$property]})) { + $propertyValue = $data->{$instance::attributeMap()[$property]}; + $instance->$propertySetter(self::deserialize($propertyValue, $type, null)); + } + } + return $instance; + } + } +} diff --git a/src/Adyen/Model/DataProtection/ServiceError.php b/src/Adyen/Model/DataProtection/ServiceError.php new file mode 100644 index 000000000..d449696a7 --- /dev/null +++ b/src/Adyen/Model/DataProtection/ServiceError.php @@ -0,0 +1,519 @@ + + */ +class ServiceError implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'ServiceError'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'error_code' => 'string', + 'error_type' => 'string', + 'message' => 'string', + 'psp_reference' => 'string', + 'status' => 'int' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'error_code' => null, + 'error_type' => null, + 'message' => null, + 'psp_reference' => null, + 'status' => 'int32' + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static $openAPINullables = [ + 'error_code' => false, + 'error_type' => false, + 'message' => false, + 'psp_reference' => false, + 'status' => true + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'error_code' => 'errorCode', + 'error_type' => 'errorType', + 'message' => 'message', + 'psp_reference' => 'pspReference', + 'status' => 'status' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'error_code' => 'setErrorCode', + 'error_type' => 'setErrorType', + 'message' => 'setMessage', + 'psp_reference' => 'setPspReference', + 'status' => 'setStatus' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'error_code' => 'getErrorCode', + 'error_type' => 'getErrorType', + 'message' => 'getMessage', + 'psp_reference' => 'getPspReference', + 'status' => 'getStatus' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->setIfExists('error_code', $data ?? [], null); + $this->setIfExists('error_type', $data ?? [], null); + $this->setIfExists('message', $data ?? [], null); + $this->setIfExists('psp_reference', $data ?? [], null); + $this->setIfExists('status', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets error_code + * + * @return string|null + */ + public function getErrorCode() + { + return $this->container['error_code']; + } + + /** + * Sets error_code + * + * @param string|null $error_code The error code mapped to the error message. + * + * @return self + */ + public function setErrorCode($error_code) + { + if (is_null($error_code)) { + throw new \InvalidArgumentException('non-nullable error_code cannot be null'); + } + $this->container['error_code'] = $error_code; + + return $this; + } + + /** + * Gets error_type + * + * @return string|null + */ + public function getErrorType() + { + return $this->container['error_type']; + } + + /** + * Sets error_type + * + * @param string|null $error_type The category of the error. + * + * @return self + */ + public function setErrorType($error_type) + { + if (is_null($error_type)) { + throw new \InvalidArgumentException('non-nullable error_type cannot be null'); + } + $this->container['error_type'] = $error_type; + + return $this; + } + + /** + * Gets message + * + * @return string|null + */ + public function getMessage() + { + return $this->container['message']; + } + + /** + * Sets message + * + * @param string|null $message A short explanation of the issue. + * + * @return self + */ + public function setMessage($message) + { + if (is_null($message)) { + throw new \InvalidArgumentException('non-nullable message cannot be null'); + } + $this->container['message'] = $message; + + return $this; + } + + /** + * Gets psp_reference + * + * @return string|null + */ + public function getPspReference() + { + return $this->container['psp_reference']; + } + + /** + * Sets psp_reference + * + * @param string|null $psp_reference The PSP reference of the payment. + * + * @return self + */ + public function setPspReference($psp_reference) + { + if (is_null($psp_reference)) { + throw new \InvalidArgumentException('non-nullable psp_reference cannot be null'); + } + $this->container['psp_reference'] = $psp_reference; + + return $this; + } + + /** + * Gets status + * + * @return int|null + */ + public function getStatus() + { + return $this->container['status']; + } + + /** + * Sets status + * + * @param int|null $status The HTTP response status. + * + * @return self + */ + public function setStatus($status) + { + // Do nothing for nullable integers + $this->container['status'] = $status; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } +} diff --git a/src/Adyen/Model/DataProtection/SubjectErasureByPspReferenceRequest.php b/src/Adyen/Model/DataProtection/SubjectErasureByPspReferenceRequest.php new file mode 100644 index 000000000..df10a37bb --- /dev/null +++ b/src/Adyen/Model/DataProtection/SubjectErasureByPspReferenceRequest.php @@ -0,0 +1,453 @@ + + */ +class SubjectErasureByPspReferenceRequest implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'SubjectErasureByPspReferenceRequest'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'force_erasure' => 'bool', + 'merchant_account' => 'string', + 'psp_reference' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'force_erasure' => null, + 'merchant_account' => null, + 'psp_reference' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static $openAPINullables = [ + 'force_erasure' => false, + 'merchant_account' => false, + 'psp_reference' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'force_erasure' => 'forceErasure', + 'merchant_account' => 'merchantAccount', + 'psp_reference' => 'pspReference' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'force_erasure' => 'setForceErasure', + 'merchant_account' => 'setMerchantAccount', + 'psp_reference' => 'setPspReference' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'force_erasure' => 'getForceErasure', + 'merchant_account' => 'getMerchantAccount', + 'psp_reference' => 'getPspReference' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->setIfExists('force_erasure', $data ?? [], null); + $this->setIfExists('merchant_account', $data ?? [], null); + $this->setIfExists('psp_reference', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets force_erasure + * + * @return bool|null + */ + public function getForceErasure() + { + return $this->container['force_erasure']; + } + + /** + * Sets force_erasure + * + * @param bool|null $force_erasure Set this to **true** if you want to delete shopper-related data, even if the shopper has an existing recurring transaction. This only deletes the shopper-related data for the specific payment, but does not cancel the existing recurring transaction. + * + * @return self + */ + public function setForceErasure($force_erasure) + { + if (is_null($force_erasure)) { + throw new \InvalidArgumentException('non-nullable force_erasure cannot be null'); + } + $this->container['force_erasure'] = $force_erasure; + + return $this; + } + + /** + * Gets merchant_account + * + * @return string|null + */ + public function getMerchantAccount() + { + return $this->container['merchant_account']; + } + + /** + * Sets merchant_account + * + * @param string|null $merchant_account Your merchant account + * + * @return self + */ + public function setMerchantAccount($merchant_account) + { + if (is_null($merchant_account)) { + throw new \InvalidArgumentException('non-nullable merchant_account cannot be null'); + } + $this->container['merchant_account'] = $merchant_account; + + return $this; + } + + /** + * Gets psp_reference + * + * @return string|null + */ + public function getPspReference() + { + return $this->container['psp_reference']; + } + + /** + * Sets psp_reference + * + * @param string|null $psp_reference The PSP reference of the payment. We will delete all shopper-related data for this payment. + * + * @return self + */ + public function setPspReference($psp_reference) + { + if (is_null($psp_reference)) { + throw new \InvalidArgumentException('non-nullable psp_reference cannot be null'); + } + $this->container['psp_reference'] = $psp_reference; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } +} diff --git a/src/Adyen/Model/DataProtection/SubjectErasureResponse.php b/src/Adyen/Model/DataProtection/SubjectErasureResponse.php new file mode 100644 index 000000000..225563706 --- /dev/null +++ b/src/Adyen/Model/DataProtection/SubjectErasureResponse.php @@ -0,0 +1,422 @@ + + */ +class SubjectErasureResponse implements ModelInterface, ArrayAccess, \JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static $openAPIModelName = 'SubjectErasureResponse'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var string[] + */ + protected static $openAPITypes = [ + 'result' => 'string' + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var string[] + * @phpstan-var array + * @psalm-var array + */ + protected static $openAPIFormats = [ + 'result' => null + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var boolean[] + */ + protected static $openAPINullables = [ + 'result' => false + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var boolean[] + */ + protected $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes() + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats() + { + return self::$openAPIFormats; + } + + /** + * Array of nullable properties + * + * @return array + */ + protected static function openAPINullables(): array + { + return self::$openAPINullables; + } + + /** + * Array of nullable field names deliberately set to null + * + * @return boolean[] + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param boolean[] $openAPINullablesSetToNull + */ + private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void + { + $this->openAPINullablesSetToNull = $openAPINullablesSetToNull; + } + + /** + * Checks if a property is nullable + * + * @param string $property + * @return bool + */ + public static function isNullable(string $property): bool + { + return self::openAPINullables()[$property] ?? false; + } + + /** + * Checks if a nullable property is set to null. + * + * @param string $property + * @return bool + */ + public function isNullableSetToNull(string $property): bool + { + return in_array($property, $this->getOpenAPINullablesSetToNull(), true); + } + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @var string[] + */ + protected static $attributeMap = [ + 'result' => 'result' + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var string[] + */ + protected static $setters = [ + 'result' => 'setResult' + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var string[] + */ + protected static $getters = [ + 'result' => 'getResult' + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap() + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters() + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters() + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName() + { + return self::$openAPIModelName; + } + + public const RESULT_ACTIVE_RECURRING_TOKEN_EXISTS = 'ACTIVE_RECURRING_TOKEN_EXISTS'; + public const RESULT_ALREADY_PROCESSED = 'ALREADY_PROCESSED'; + public const RESULT_PAYMENT_NOT_FOUND = 'PAYMENT_NOT_FOUND'; + public const RESULT_SUCCESS = 'SUCCESS'; + + /** + * Gets allowable values of the enum + * + * @return string[] + */ + public function getResultAllowableValues() + { + return [ + self::RESULT_ACTIVE_RECURRING_TOKEN_EXISTS, + self::RESULT_ALREADY_PROCESSED, + self::RESULT_PAYMENT_NOT_FOUND, + self::RESULT_SUCCESS, + ]; + } + /** + * Associative array for storing property values + * + * @var mixed[] + */ + protected $container = []; + + /** + * Constructor + * + * @param mixed[] $data Associated array of property values + * initializing the model + */ + public function __construct(array $data = null) + { + $this->setIfExists('result', $data ?? [], null); + } + + /** + * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName + * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the + * $this->openAPINullablesSetToNull array + * + * @param string $variableName + * @param array $fields + * @param mixed $defaultValue + */ + private function setIfExists(string $variableName, array $fields, $defaultValue): void + { + if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) { + $this->openAPINullablesSetToNull[] = $variableName; + } + + $this->container[$variableName] = $fields[$variableName] ?? $defaultValue; + } + + /** + * Show all the invalid properties with reasons. + * + * @return array invalid properties with reasons + */ + public function listInvalidProperties() + { + $invalidProperties = []; + + $allowedValues = $this->getResultAllowableValues(); + if (!is_null($this->container['result']) && !in_array($this->container['result'], $allowedValues, true)) { + $invalidProperties[] = sprintf( + "invalid value '%s' for 'result', must be one of '%s'", + $this->container['result'], + implode("', '", $allowedValues) + ); + } + + return $invalidProperties; + } + + /** + * Validate all the properties in the model + * return true if all passed + * + * @return bool True if all properties are valid + */ + public function valid() + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets result + * + * @return string|null + */ + public function getResult() + { + return $this->container['result']; + } + + /** + * Sets result + * + * @param string|null $result The result of this operation. + * + * @return self + */ + public function setResult($result) + { + if (is_null($result)) { + throw new \InvalidArgumentException('non-nullable result cannot be null'); + } + $allowedValues = $this->getResultAllowableValues(); + if (!in_array($result, $allowedValues, true)) { + throw new \InvalidArgumentException( + sprintf( + "Invalid value '%s' for 'result', must be one of '%s'", + $result, + implode("', '", $allowedValues) + ) + ); + } + $this->container['result'] = $result; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param integer $offset Offset + * + * @return boolean + */ + public function offsetExists($offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param integer $offset Offset + * + * @return mixed|null + */ + #[\ReturnTypeWillChange] + public function offsetGet($offset) + { + return $this->container[$offset] ?? null; + } + + /** + * Sets value based on offset. + * + * @param int|null $offset Offset + * @param mixed $value Value to be set + * + * @return void + */ + public function offsetSet($offset, $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param integer $offset Offset + * + * @return void + */ + public function offsetUnset($offset): void + { + unset($this->container[$offset]); + } + + /** + * Serializes the object to a value that can be serialized natively by json_encode(). + * @link https://www.php.net/manual/en/jsonserializable.jsonserialize.php + * + * @return mixed Returns data which can be serialized by json_encode(), which is a value + * of any type other than a resource. + */ + #[\ReturnTypeWillChange] + public function jsonSerialize() + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString() + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } +} diff --git a/src/Adyen/Service/DataProtectionApi.php b/src/Adyen/Service/DataProtectionApi.php new file mode 100644 index 000000000..87937417f --- /dev/null +++ b/src/Adyen/Service/DataProtectionApi.php @@ -0,0 +1,56 @@ +baseURL = $this->createBaseUrl("https://ca-test.adyen.com/ca/services/DataProtectionService/v1"); + } + + /** + * Submit a Subject Erasure Request. + * + * @param \Adyen\Model\DataProtection\SubjectErasureByPspReferenceRequest $subjectErasureByPspReferenceRequest + * @param array|null $requestOptions + * @return \Adyen\Model\DataProtection\SubjectErasureResponse + * @throws AdyenException + */ + public function requestSubjectErasure(\Adyen\Model\DataProtection\SubjectErasureByPspReferenceRequest $subjectErasureByPspReferenceRequest, array $requestOptions = null): \Adyen\Model\DataProtection\SubjectErasureResponse + { + $endpoint = $this->baseURL . "/requestSubjectErasure"; + $response = $this->requestHttp($endpoint, strtolower('POST'), (array) $subjectErasureByPspReferenceRequest->jsonSerialize(), $requestOptions); + return ObjectSerializer::deserialize($response, \Adyen\Model\DataProtection\SubjectErasureResponse::class); + } +} diff --git a/tests/Resources/DataProtection/post-request-subject-erasure-success.json b/tests/Resources/DataProtection/post-request-subject-erasure-success.json new file mode 100644 index 000000000..7bb75fcaf --- /dev/null +++ b/tests/Resources/DataProtection/post-request-subject-erasure-success.json @@ -0,0 +1,3 @@ +{ + "result": "SUCCESS" +} \ No newline at end of file diff --git a/tests/Unit/DataProtectionTest.php b/tests/Unit/DataProtectionTest.php new file mode 100644 index 000000000..8f38aef6c --- /dev/null +++ b/tests/Unit/DataProtectionTest.php @@ -0,0 +1,31 @@ +createMockClient( + 'tests/Resources/DataProtection/post-request-subject-erasure-success.json', + 200 + ); + $service = new DataProtectionApi($client); + $request = new SubjectErasureByPspReferenceRequest(); + $request->setMerchantAccount("YOUR_MERCHANT_ACCOUNT"); + $request->setPspReference("9915520502347613"); + $request->setForceErasure(true); + + $response = $service->requestSubjectErasure($request); + + $this->assertSame(SubjectErasureResponse::RESULT_SUCCESS, $response->getResult()); + } +} From 63bcb75b240222cc524ced51fc2a0b605b581a97 Mon Sep 17 00:00:00 2001 From: michaelpa Date: Thu, 6 Apr 2023 16:27:50 +0200 Subject: [PATCH 2/6] ITT-413: Remove contact info --- .../Model/DataProtection/ModelInterface.php | 1 - .../Model/DataProtection/ObjectSerializer.php | 1 - .../Model/DataProtection/ServiceError.php | 1 - .../SubjectErasureByPspReferenceRequest.php | 1 - .../DataProtection/SubjectErasureResponse.php | 1 - src/Adyen/Service/DataProtectionApi.php | 1 - templates/partial_header.mustache | 3 - .../DataProtection/authorization-error.json | 6 ++ tests/Unit/DataProtectionTest.php | 78 ++++++++++++++++++- 9 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 tests/Resources/DataProtection/authorization-error.json diff --git a/src/Adyen/Model/DataProtection/ModelInterface.php b/src/Adyen/Model/DataProtection/ModelInterface.php index db10e3265..5f444796c 100644 --- a/src/Adyen/Model/DataProtection/ModelInterface.php +++ b/src/Adyen/Model/DataProtection/ModelInterface.php @@ -4,7 +4,6 @@ * Adyen Data Protection API * * The version of the OpenAPI document: 1 - * Contact: developer-experience@adyen.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.4.0 * diff --git a/src/Adyen/Model/DataProtection/ObjectSerializer.php b/src/Adyen/Model/DataProtection/ObjectSerializer.php index fe99040ec..b25b7156a 100644 --- a/src/Adyen/Model/DataProtection/ObjectSerializer.php +++ b/src/Adyen/Model/DataProtection/ObjectSerializer.php @@ -4,7 +4,6 @@ * Adyen Data Protection API * * The version of the OpenAPI document: 1 - * Contact: developer-experience@adyen.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.4.0 * diff --git a/src/Adyen/Model/DataProtection/ServiceError.php b/src/Adyen/Model/DataProtection/ServiceError.php index d449696a7..16262084b 100644 --- a/src/Adyen/Model/DataProtection/ServiceError.php +++ b/src/Adyen/Model/DataProtection/ServiceError.php @@ -4,7 +4,6 @@ * Adyen Data Protection API * * The version of the OpenAPI document: 1 - * Contact: developer-experience@adyen.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.4.0 * diff --git a/src/Adyen/Model/DataProtection/SubjectErasureByPspReferenceRequest.php b/src/Adyen/Model/DataProtection/SubjectErasureByPspReferenceRequest.php index df10a37bb..a8592cddf 100644 --- a/src/Adyen/Model/DataProtection/SubjectErasureByPspReferenceRequest.php +++ b/src/Adyen/Model/DataProtection/SubjectErasureByPspReferenceRequest.php @@ -4,7 +4,6 @@ * Adyen Data Protection API * * The version of the OpenAPI document: 1 - * Contact: developer-experience@adyen.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.4.0 * diff --git a/src/Adyen/Model/DataProtection/SubjectErasureResponse.php b/src/Adyen/Model/DataProtection/SubjectErasureResponse.php index 225563706..4d9b02b0e 100644 --- a/src/Adyen/Model/DataProtection/SubjectErasureResponse.php +++ b/src/Adyen/Model/DataProtection/SubjectErasureResponse.php @@ -4,7 +4,6 @@ * Adyen Data Protection API * * The version of the OpenAPI document: 1 - * Contact: developer-experience@adyen.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.4.0 * diff --git a/src/Adyen/Service/DataProtectionApi.php b/src/Adyen/Service/DataProtectionApi.php index 87937417f..2b2dd9ed1 100644 --- a/src/Adyen/Service/DataProtectionApi.php +++ b/src/Adyen/Service/DataProtectionApi.php @@ -3,7 +3,6 @@ * Adyen Data Protection API * * The version of the OpenAPI document: 1 - * Contact: developer-experience@adyen.com * Generated by: https://openapi-generator.tech * OpenAPI Generator version: 6.4.0 * diff --git a/templates/partial_header.mustache b/templates/partial_header.mustache index 0b64df089..af36d3366 100644 --- a/templates/partial_header.mustache +++ b/templates/partial_header.mustache @@ -6,9 +6,6 @@ {{#version}} * The version of the OpenAPI document: {{{.}}} {{/version}} - {{#infoEmail}} - * Contact: {{{.}}} - {{/infoEmail}} * Generated by: https://openapi-generator.tech * OpenAPI Generator version: {{{generatorVersion}}} * diff --git a/tests/Resources/DataProtection/authorization-error.json b/tests/Resources/DataProtection/authorization-error.json new file mode 100644 index 000000000..c03f52622 --- /dev/null +++ b/tests/Resources/DataProtection/authorization-error.json @@ -0,0 +1,6 @@ +{ + "status": 403, + "errorCode": "010", + "message": "Not allowed", + "errorType": "security" +} \ No newline at end of file diff --git a/tests/Unit/DataProtectionTest.php b/tests/Unit/DataProtectionTest.php index 8f38aef6c..78a149f20 100644 --- a/tests/Unit/DataProtectionTest.php +++ b/tests/Unit/DataProtectionTest.php @@ -3,6 +3,10 @@ namespace Adyen\Tests\Unit; use Adyen\AdyenException; +use Adyen\Client; +use Adyen\Config; +use Adyen\Environment; +use Adyen\HttpClient\ClientInterface; use Adyen\Model\DataProtection\SubjectErasureByPspReferenceRequest; use Adyen\Model\DataProtection\SubjectErasureResponse; use Adyen\Service\DataProtectionApi; @@ -12,7 +16,7 @@ class DataProtectionTest extends TestCaseMock /** * @throws AdyenException */ - public function testRequestSubjectErasure() + public function testRequestSubjectErasureSuccess() { $client = $this->createMockClient( 'tests/Resources/DataProtection/post-request-subject-erasure-success.json', @@ -28,4 +32,76 @@ public function testRequestSubjectErasure() $this->assertSame(SubjectErasureResponse::RESULT_SUCCESS, $response->getResult()); } + + public function testRequestSubjectErasureAuthorizationError() + { + $this->expectException(AdyenException::class); + $this->expectExceptionCode(403); + $this->expectExceptionMessage('Not allowed'); + $client = $this->createMockClient( + 'tests/Resources/DataProtection/authorization-error.json', + 403 + ); + $service = new DataProtectionApi($client); + $request = new SubjectErasureByPspReferenceRequest(); + $request->setMerchantAccount("NOT_YOUR_MERCHANT_ACCOUNT"); + $request->setPspReference("9915520502347613"); + + $service->requestSubjectErasure($request); + } + + /** + * @throws AdyenException + */ + public function testRequestSubjectErasureTestEndpoint() + { + $client = new Client(new Config()); + $client->setEnvironment(Environment::TEST); + $http = $this->createMock(ClientInterface::class); + $client->setHttpClient($http); + $service = new DataProtectionApi($client); + $http->expects($this->once()) + ->method('requestHttp') + ->with( + $service, + 'https://ca-test.adyen.com/ca/services/DataProtectionService/v1/requestSubjectErasure', + [ + 'merchantAccount' => "YOUR_MERCHANT_ACCOUNT", + 'forceErasure' => false + ], + 'post', + null + ) + ->willReturn([]); + $request = new SubjectErasureByPspReferenceRequest(); + $request->setMerchantAccount("YOUR_MERCHANT_ACCOUNT"); + $request->setForceErasure(false); + + $service->requestSubjectErasure($request); + } + + /** + * @throws AdyenException + */ + public function testRequestSubjectErasureLiveEndpoint() + { + $client = new Client(new Config()); + $client->setEnvironment(Environment::LIVE); + $http = $this->createMock(ClientInterface::class); + $client->setHttpClient($http); + $service = new DataProtectionApi($client); + $http->expects($this->once()) + ->method('requestHttp') + ->with( + $service, + 'https://ca-live.adyen.com/ca/services/DataProtectionService/v1/requestSubjectErasure', + [], + 'post', + null + ) + ->willReturn([]); + $request = new SubjectErasureByPspReferenceRequest(); + + $service->requestSubjectErasure($request); + } } From 9c1f42bfbacadbb633f7b828d2e9fee4666d17a3 Mon Sep 17 00:00:00 2001 From: michaelpa Date: Thu, 6 Apr 2023 17:00:44 +0200 Subject: [PATCH 3/6] ITT-413: Update readme --- README.md | 1 + tests/Unit/DataProtectionTest.php | 23 +++++++++------------- tests/Unit/TestCaseMock.php | 32 +++++++++++++------------------ 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 67cf0ed58..840c13674 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ The library supports all APIs under the following services: * [Referrals API](https://docs.adyen.com/risk-management/automate-submitting-referrals/referrals-api-reference): Endpoints to [automate submitting referrals](https://docs.adyen.com/risk-management/automate-submitting-referrals) for Adyen risk rules. * [Refunds API](https://docs.adyen.com/api-explorer/#/CheckoutService/v68/post/payments/{paymentPspReference}/refunds): Refunds a payment that has been captured, and returns a unique reference for this request. Current supported version: **v68** * [Reversals API](https://docs.adyen.com/api-explorer/#/CheckoutService/v68/post/payments/{paymentPspReference}/reversals): Refunds a payment if it has already been captured, and cancels a payment if it has not yet been captured. Current supported version: **v68** +* [Data Protection API](https://docs.adyen.com/development-resources/data-protection-api): Use our API to comply with GDPR's right to erasure mandate. Current supported version: **v1** For more information, refer to our [documentation](https://docs.adyen.com/) or the [API Explorer](https://docs.adyen.com/api-explorer/). diff --git a/tests/Unit/DataProtectionTest.php b/tests/Unit/DataProtectionTest.php index 78a149f20..c23f0f204 100644 --- a/tests/Unit/DataProtectionTest.php +++ b/tests/Unit/DataProtectionTest.php @@ -85,23 +85,18 @@ public function testRequestSubjectErasureTestEndpoint() */ public function testRequestSubjectErasureLiveEndpoint() { - $client = new Client(new Config()); - $client->setEnvironment(Environment::LIVE); - $http = $this->createMock(ClientInterface::class); - $client->setHttpClient($http); + $client = $this->createMockClientUrl( + 'tests/Resources/DataProtection/post-request-subject-erasure-success.json', + Environment::LIVE + ); $service = new DataProtectionApi($client); - $http->expects($this->once()) - ->method('requestHttp') - ->with( - $service, - 'https://ca-live.adyen.com/ca/services/DataProtectionService/v1/requestSubjectErasure', - [], - 'post', - null - ) - ->willReturn([]); $request = new SubjectErasureByPspReferenceRequest(); $service->requestSubjectErasure($request); + + $this->assertEquals( + 'https://ca-live.adyen.com/ca/services/DataProtectionService/v1/requestSubjectErasure', + $this->requestUrl + ); } } diff --git a/tests/Unit/TestCaseMock.php b/tests/Unit/TestCaseMock.php index feb18e1f7..65362b4ad 100644 --- a/tests/Unit/TestCaseMock.php +++ b/tests/Unit/TestCaseMock.php @@ -1,17 +1,5 @@ setApplicationName("My Test Application"); @@ -44,7 +37,7 @@ protected function createMockClient($jsonFile, $httpStatus, $errno = null, $envi if ($jsonFile != null) { $json = file_get_contents($jsonFile, true); } - $curlClient = $this->getMockBuilder(get_class(new CurlClient())) + $curlClient = $this->getMockBuilder(CurlClient::class) ->onlyMethods(array('curlRequest', 'curlError', 'requestJson')) ->getMock(); $curlClient->method('curlRequest') @@ -71,7 +64,7 @@ protected function createMockClient($jsonFile, $httpStatus, $errno = null, $envi if (!$client->getConfig()->getXApiKey()) { throw new AdyenException('Please provide a valid Checkout API Key'); } - if (isset($errno) && $errno !== null) { + if (isset($errno)) { throw new ConnectionException('', $errno); } return $result; @@ -81,9 +74,10 @@ protected function createMockClient($jsonFile, $httpStatus, $errno = null, $envi return $client; } - protected $requestUrl; - - protected function createMockClientUrl($jsonFile, $environment = Environment::TEST) + /** + * @throws AdyenException + */ + protected function createMockClientUrl($jsonFile, $environment = Environment::TEST): Client { $client = new Client(); $client->setApplicationName("My Test Application"); @@ -95,7 +89,7 @@ protected function createMockClientUrl($jsonFile, $environment = Environment::TE $json = file_get_contents($jsonFile, true); } - $curlClient = $this->getMockBuilder(get_class(new CurlClient())) + $curlClient = $this->getMockBuilder(CurlClient::class) ->onlyMethods(array('requestHttp')) ->getMock(); $curlClient->method('requestHttp') From d71d50df0fb3e363d4bc9733ce8e521cd151a76e Mon Sep 17 00:00:00 2001 From: michaelpa Date: Fri, 7 Apr 2023 10:01:00 +0200 Subject: [PATCH 4/6] ITT-413: Auto format generated files --- Makefile | 12 +++++------- phpcs.xml | 12 ------------ src/Adyen/Model/DataProtection/ObjectSerializer.php | 11 ++++++----- src/Adyen/Model/DataProtection/ServiceError.php | 10 +++++----- .../SubjectErasureByPspReferenceRequest.php | 6 +++--- .../Model/DataProtection/SubjectErasureResponse.php | 2 +- 6 files changed, 20 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 7271dca00..3e09459b0 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ openapi-generator-jar:=target/openapi-generator-cli.jar openapi-generator-cli:=java -jar $(openapi-generator-jar) generator:=php -modelGen:=BalancePlatform Checkout StoredValue Payments Payout Management LegalEntityManagement Transfers BalanceControl BinLookup DataProtection StoredValue POSTerminalManagement Recurring +modelGen:=BalancePlatform Checkout StoredValue Payments Payout Management LegalEntityManagement Transfers BalanceControl BinLookup StoredValue POSTerminalManagement Recurring models:=src/Adyen/Model output:=target/out @@ -43,7 +43,6 @@ $(modelGen): target/spec $(openapi-generator-jar) --model-package Model\\$@ \ --api-package Service\\$@ \ --reserved-words-mappings configuration=configuration \ - --ignore-file-override ./.openapi-generator-ignore \ --skip-validate-spec \ --additional-properties invokerPackage=Adyen \ --additional-properties packageName=Adyen @@ -56,7 +55,7 @@ $(modelGen): target/spec $(openapi-generator-jar) Services:=BalancePlatform Checkout StoredValue Payments Payout Management LegalEntityManagement Transfers SingleFileServices:=BalanceControl BinLookup DataProtection StoredValue POSTerminalManagement Recurring -all: $(Services) $(SingleFileServices)) +all: $(Services) $(SingleFileServices) $(Services): target/spec $(openapi-generator-jar) rm -rf $(models)/$@ $(output) @@ -69,13 +68,12 @@ $(Services): target/spec $(openapi-generator-jar) --model-package Model\\$@ \ --api-package Service\\$@ \ --reserved-words-mappings configuration=configuration \ - --ignore-file-override ./.openapi-generator-ignore \ --skip-validate-spec \ --additional-properties invokerPackage=Adyen \ --additional-properties packageName=Adyen rm -rf src/Adyen/Service/$@ src/Adyen/Model/$@ mv $(output)/lib/Model/$@ $(models)/$@ - mv $(output)/lib//ObjectSerializer.php $(models)/$@ + mv $(output)/lib/ObjectSerializer.php $(models)/$@ mkdir src/Adyen/Service/$@ mv $(output)/lib/Service/* src/Adyen/Service @@ -90,15 +88,15 @@ $(SingleFileServices): target/spec $(openapi-generator-jar) --api-package Service\\$@ \ --inline-schema-name-mappings PaymentDonationRequest_paymentMethod=CheckoutPaymentMethod \ --reserved-words-mappings configuration=configuration \ - --ignore-file-override ./.openapi-generator-ignore \ --skip-validate-spec \ --additional-properties customApi=$@ \ --additional-properties invokerPackage=Adyen \ --additional-properties packageName=Adyen rm -rf src/Adyen/Service/$@Api src/Adyen/Model/$@ mv $(output)/lib/Model/$@ $(models)/$@ - mv $(output)/lib//ObjectSerializer.php $(models)/$@ + mv $(output)/lib/ObjectSerializer.php $(models)/$@ mv $(output)/lib/Service/$@/GeneralApiSingle.php src/Adyen/Service/$@Api.php + vendor/bin/phpcbf $(models)/$@ src/Adyen/Service/$@Api.php || true # Checkout spec (and patch version) target/spec: diff --git a/phpcs.xml b/phpcs.xml index 1b84e8013..56b2f8f72 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,17 +1,5 @@