diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index d3a76f0..bda4d03 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -4,8 +4,10 @@ src/ApiException.php src/Configuration.php src/FormDataProcessor.php src/HeaderSelector.php +src/Model/AuthorizedTransaction.php src/Model/Currency.php src/Model/Delivery.php +src/Model/Finish200Response.php src/Model/Invoice.php src/Model/Item.php src/Model/Language.php @@ -16,8 +18,10 @@ src/Model/Transaction.php src/Model/TransactionUrls.php src/ObjectSerializer.php tests/Api/TransactionApiTest.php +tests/Model/AuthorizedTransactionTest.php tests/Model/CurrencyTest.php tests/Model/DeliveryTest.php +tests/Model/Finish200ResponseTest.php tests/Model/InvoiceTest.php tests/Model/ItemTest.php tests/Model/LanguageTest.php diff --git a/src/Api/TransactionApi.php b/src/Api/TransactionApi.php index b05d827..cfc2702 100644 --- a/src/Api/TransactionApi.php +++ b/src/Api/TransactionApi.php @@ -74,6 +74,9 @@ class TransactionApi /** @var string[] $contentTypes **/ public const contentTypes = [ + 'finish' => [ + 'application/json', + ], 'start' => [ 'application/json', ], @@ -125,13 +128,308 @@ public function getConfig(): Configuration return $this->config; } + /** + * Operation finish + * + * Finish a two-step transaction + * + * @param string $signature The signature. (required) + * @param \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction The authorized transaction object you would like to finish. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['finish'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return \Cone\SimplePay\Model\Finish200Response + */ + public function finish( + string $signature, + \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction, + string $contentType = self::contentTypes['finish'][0] + ): \Cone\SimplePay\Model\Finish200Response { + list($response) = $this->finishWithHttpInfo($signature, $authorizedTransaction, $contentType); + return $response; + } + + /** + * Operation finishWithHttpInfo + * + * Finish a two-step transaction + * + * @param string $signature The signature. (required) + * @param \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction The authorized transaction object you would like to finish. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['finish'] to see the possible values for this operation + * + * @throws ApiException on non-2xx response or if the response body is not in the expected format + * @throws InvalidArgumentException + * @return array of \Cone\SimplePay\Model\Finish200Response, HTTP status code, HTTP response headers (array of strings) + */ + public function finishWithHttpInfo( + string $signature, + \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction, + string $contentType = self::contentTypes['finish'][0] + ): array { + $request = $this->finishRequest($signature, $authorizedTransaction, $contentType); + + try { + $options = $this->createHttpClientOption(); + try { + $response = $this->client->send($request, $options); + } catch (RequestException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + $e->getResponse() ? $e->getResponse()->getHeaders() : null, + $e->getResponse() ? (string) $e->getResponse()->getBody() : null + ); + } catch (ConnectException $e) { + throw new ApiException( + "[{$e->getCode()}] {$e->getMessage()}", + (int) $e->getCode(), + null, + null + ); + } + + $statusCode = $response->getStatusCode(); + + switch ($statusCode) { + case 200: + return $this->handleResponseWithDataType( + '\Cone\SimplePay\Model\Finish200Response', + $request, + $response, + ); + } + + + if ($statusCode < 200 || $statusCode > 299) { + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + (string) $request->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + + return $this->handleResponseWithDataType( + '\Cone\SimplePay\Model\Finish200Response', + $request, + $response, + ); + } catch (ApiException $e) { + switch ($e->getCode()) { + case 200: + $data = ObjectSerializer::deserialize( + $e->getResponseBody(), + '\Cone\SimplePay\Model\Finish200Response', + $e->getResponseHeaders() + ); + $e->setResponseObject($data); + throw $e; + } + + throw $e; + } + } + + /** + * Operation finishAsync + * + * Finish a two-step transaction + * + * @param string $signature The signature. (required) + * @param \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction The authorized transaction object you would like to finish. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['finish'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function finishAsync( + string $signature, + \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction, + string $contentType = self::contentTypes['finish'][0] + ): PromiseInterface { + return $this->finishAsyncWithHttpInfo($signature, $authorizedTransaction, $contentType) + ->then( + function ($response) { + return $response[0]; + } + ); + } + + /** + * Operation finishAsyncWithHttpInfo + * + * Finish a two-step transaction + * + * @param string $signature The signature. (required) + * @param \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction The authorized transaction object you would like to finish. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['finish'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return PromiseInterface + */ + public function finishAsyncWithHttpInfo( + string $signature, + \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction, + string $contentType = self::contentTypes['finish'][0] + ): PromiseInterface { + $returnType = '\Cone\SimplePay\Model\Finish200Response'; + $request = $this->finishRequest($signature, $authorizedTransaction, $contentType); + + return $this->client + ->sendAsync($request, $this->createHttpClientOption()) + ->then( + function ($response) use ($returnType) { + if (in_array($returnType, ['\SplFileObject', '\Psr\Http\Message\StreamInterface'], true)) { + $content = $response->getBody(); //stream goes to serializer + } else { + $content = (string) $response->getBody(); + if ($returnType !== 'string') { + $content = json_decode($content); + } + } + + return [ + ObjectSerializer::deserialize($content, $returnType, []), + $response->getStatusCode(), + $response->getHeaders(), + ]; + }, + function ($exception) { + $response = $exception->getResponse(); + $statusCode = $response->getStatusCode(); + throw new ApiException( + sprintf( + '[%d] Error connecting to the API (%s)', + $statusCode, + $exception->getRequest()->getUri() + ), + $statusCode, + $response->getHeaders(), + (string) $response->getBody() + ); + } + ); + } + + /** + * Create request for operation 'finish' + * + * @param string $signature The signature. (required) + * @param \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction The authorized transaction object you would like to finish. (required) + * @param string $contentType The value for the Content-Type header. Check self::contentTypes['finish'] to see the possible values for this operation + * + * @throws InvalidArgumentException + * @return \GuzzleHttp\Psr7\Request + */ + public function finishRequest( + string $signature, + \Cone\SimplePay\Model\AuthorizedTransaction $authorizedTransaction, + string $contentType = self::contentTypes['finish'][0] + ): Request { + + // verify the required parameter 'signature' is set + if ($signature === null || (is_array($signature) && count($signature) === 0)) { + throw new InvalidArgumentException( + 'Missing the required parameter $signature when calling finish' + ); + } + + // verify the required parameter 'authorizedTransaction' is set + if ($authorizedTransaction === null || (is_array($authorizedTransaction) && count($authorizedTransaction) === 0)) { + throw new InvalidArgumentException( + 'Missing the required parameter $authorizedTransaction when calling finish' + ); + } + + + $resourcePath = '/finish'; + $formParams = []; + $queryParams = []; + $headerParams = []; + $httpBody = ''; + $multipart = false; + + + // header params + if ($signature !== null) { + $headerParams['Signature'] = ObjectSerializer::toHeaderValue($signature); + } + + + + $headers = $this->headerSelector->selectHeaders( + ['application/json', ], + $contentType, + $multipart + ); + + // for model (json/xml) + if (isset($authorizedTransaction)) { + if (stripos($headers['Content-Type'], 'application/json') !== false) { + // if Content-Type contains "application/json", json_encode the body + $httpBody = \GuzzleHttp\Utils::jsonEncode(ObjectSerializer::sanitizeForSerialization($authorizedTransaction)); + } else { + $httpBody = $authorizedTransaction; + } + } elseif (count($formParams) > 0) { + if ($multipart) { + $multipartContents = []; + foreach ($formParams as $formParamName => $formParamValue) { + $formParamValueItems = is_array($formParamValue) ? $formParamValue : [$formParamValue]; + foreach ($formParamValueItems as $formParamValueItem) { + $multipartContents[] = [ + 'name' => $formParamName, + 'contents' => $formParamValueItem, + ]; + } + } + // for HTTP post (form) + $httpBody = new MultipartStream($multipartContents); + + } elseif (stripos($headers['Content-Type'], 'application/json') !== false) { + // if Content-Type contains "application/json", json_encode the form parameters + $httpBody = \GuzzleHttp\Utils::jsonEncode($formParams); + } else { + // for HTTP post (form) + $httpBody = ObjectSerializer::buildQuery($formParams); + } + } + + + $defaultHeaders = []; + if ($this->config->getUserAgent()) { + $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); + } + + $headers = array_merge( + $defaultHeaders, + $headerParams, + $headers + ); + + $operationHost = $this->config->getHost(); + $query = ObjectSerializer::buildQuery($queryParams); + return new Request( + 'POST', + $operationHost . $resourcePath . ($query ? "?{$query}" : ''), + $headers, + $httpBody + ); + } + /** * Operation start * * Start a transaction * + * @param string $signature The signature. (required) * @param \Cone\SimplePay\Model\Transaction $transaction The transaction object you would like to start. (required) - * @param string|null $signature The signature. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['start'] to see the possible values for this operation * * @throws ApiException on non-2xx response or if the response body is not in the expected format @@ -139,11 +437,11 @@ public function getConfig(): Configuration * @return \Cone\SimplePay\Model\Start200Response */ public function start( + string $signature, \Cone\SimplePay\Model\Transaction $transaction, - ?string $signature = null, string $contentType = self::contentTypes['start'][0] ): \Cone\SimplePay\Model\Start200Response { - list($response) = $this->startWithHttpInfo($transaction, $signature, $contentType); + list($response) = $this->startWithHttpInfo($signature, $transaction, $contentType); return $response; } @@ -152,8 +450,8 @@ public function start( * * Start a transaction * + * @param string $signature The signature. (required) * @param \Cone\SimplePay\Model\Transaction $transaction The transaction object you would like to start. (required) - * @param string|null $signature The signature. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['start'] to see the possible values for this operation * * @throws ApiException on non-2xx response or if the response body is not in the expected format @@ -161,11 +459,11 @@ public function start( * @return array of \Cone\SimplePay\Model\Start200Response, HTTP status code, HTTP response headers (array of strings) */ public function startWithHttpInfo( + string $signature, \Cone\SimplePay\Model\Transaction $transaction, - ?string $signature = null, string $contentType = self::contentTypes['start'][0] ): array { - $request = $this->startRequest($transaction, $signature, $contentType); + $request = $this->startRequest($signature, $transaction, $contentType); try { $options = $this->createHttpClientOption(); @@ -238,19 +536,19 @@ public function startWithHttpInfo( * * Start a transaction * + * @param string $signature The signature. (required) * @param \Cone\SimplePay\Model\Transaction $transaction The transaction object you would like to start. (required) - * @param string|null $signature The signature. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['start'] to see the possible values for this operation * * @throws InvalidArgumentException * @return PromiseInterface */ public function startAsync( + string $signature, \Cone\SimplePay\Model\Transaction $transaction, - ?string $signature = null, string $contentType = self::contentTypes['start'][0] ): PromiseInterface { - return $this->startAsyncWithHttpInfo($transaction, $signature, $contentType) + return $this->startAsyncWithHttpInfo($signature, $transaction, $contentType) ->then( function ($response) { return $response[0]; @@ -263,20 +561,20 @@ function ($response) { * * Start a transaction * + * @param string $signature The signature. (required) * @param \Cone\SimplePay\Model\Transaction $transaction The transaction object you would like to start. (required) - * @param string|null $signature The signature. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['start'] to see the possible values for this operation * * @throws InvalidArgumentException * @return PromiseInterface */ public function startAsyncWithHttpInfo( + string $signature, \Cone\SimplePay\Model\Transaction $transaction, - ?string $signature = null, string $contentType = self::contentTypes['start'][0] ): PromiseInterface { $returnType = '\Cone\SimplePay\Model\Start200Response'; - $request = $this->startRequest($transaction, $signature, $contentType); + $request = $this->startRequest($signature, $transaction, $contentType); return $this->client ->sendAsync($request, $this->createHttpClientOption()) @@ -317,19 +615,26 @@ function ($exception) { /** * Create request for operation 'start' * + * @param string $signature The signature. (required) * @param \Cone\SimplePay\Model\Transaction $transaction The transaction object you would like to start. (required) - * @param string|null $signature The signature. (optional) * @param string $contentType The value for the Content-Type header. Check self::contentTypes['start'] to see the possible values for this operation * * @throws InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ public function startRequest( + string $signature, \Cone\SimplePay\Model\Transaction $transaction, - ?string $signature = null, string $contentType = self::contentTypes['start'][0] ): Request { + // verify the required parameter 'signature' is set + if ($signature === null || (is_array($signature) && count($signature) === 0)) { + throw new InvalidArgumentException( + 'Missing the required parameter $signature when calling start' + ); + } + // verify the required parameter 'transaction' is set if ($transaction === null || (is_array($transaction) && count($transaction) === 0)) { throw new InvalidArgumentException( @@ -338,7 +643,6 @@ public function startRequest( } - $resourcePath = '/start'; $formParams = []; $queryParams = []; diff --git a/src/Model/AuthorizedTransaction.php b/src/Model/AuthorizedTransaction.php new file mode 100644 index 0000000..0c49f37 --- /dev/null +++ b/src/Model/AuthorizedTransaction.php @@ -0,0 +1,574 @@ + + */ +class AuthorizedTransaction implements ModelInterface, ArrayAccess, JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static string $openAPIModelName = 'AuthorizedTransaction'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var array + */ + protected static array $openAPITypes = [ + 'originalTotal' => 'float', + 'approveTotal' => 'float', + 'currency' => '\Cone\SimplePay\Model\Currency', + 'orderRef' => 'string', + 'transactionId' => 'float', + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var array + */ + protected static array $openAPIFormats = [ + 'originalTotal' => null, + 'approveTotal' => null, + 'currency' => null, + 'orderRef' => null, + 'transactionId' => null, + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var array + */ + protected static array $openAPINullables = [ + 'originalTotal' => false, + 'approveTotal' => false, + 'currency' => false, + 'orderRef' => false, + 'transactionId' => false, + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var array + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes(): array + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats(): array + { + 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 array + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param array $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 array + */ + protected static array $attributeMap = [ + 'originalTotal' => 'originalTotal', + 'approveTotal' => 'approveTotal', + 'currency' => 'currency', + 'orderRef' => 'orderRef', + 'transactionId' => 'transactionId', + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var array + */ + protected static array $setters = [ + 'originalTotal' => 'setOriginalTotal', + 'approveTotal' => 'setApproveTotal', + 'currency' => 'setCurrency', + 'orderRef' => 'setOrderRef', + 'transactionId' => 'setTransactionId', + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var array + */ + protected static array $getters = [ + 'originalTotal' => 'getOriginalTotal', + 'approveTotal' => 'getApproveTotal', + 'currency' => 'getCurrency', + 'orderRef' => 'getOrderRef', + 'transactionId' => 'getTransactionId', + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap(): array + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters(): array + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters(): array + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName(): string + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var array + */ + protected array $container = []; + + /** + * Constructor + * + * @param array $data Associated array of property values initializing the model + */ + public function __construct(?array $data = null) + { + $this->setIfExists('originalTotal', $data ?? [], 0); + $this->setIfExists('approveTotal', $data ?? [], null); + $this->setIfExists('currency', $data ?? [], null); + $this->setIfExists('orderRef', $data ?? [], null); + $this->setIfExists('transactionId', $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, mixed $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 string[] invalid properties with reasons + */ + public function listInvalidProperties(): array + { + $invalidProperties = []; + + if ($this->container['originalTotal'] === null) { + $invalidProperties[] = "'originalTotal' can't be null"; + } + if (($this->container['originalTotal'] <= 0)) { + $invalidProperties[] = "invalid value for 'originalTotal', must be bigger than 0."; + } + + if ($this->container['approveTotal'] === null) { + $invalidProperties[] = "'approveTotal' can't be null"; + } + if (($this->container['approveTotal'] < 0)) { + $invalidProperties[] = "invalid value for 'approveTotal', must be bigger than or equal to 0."; + } + + if ($this->container['currency'] === null) { + $invalidProperties[] = "'currency' can't be null"; + } + if ($this->container['orderRef'] === null) { + $invalidProperties[] = "'orderRef' can't be null"; + } + if ($this->container['transactionId'] === null) { + $invalidProperties[] = "'transactionId' can't be null"; + } + 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(): bool + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets originalTotal + * + * @return float + */ + public function getOriginalTotal(): float + { + return $this->container['originalTotal']; + } + + /** + * Sets originalTotal + * + * @param float $originalTotal originalTotal + * + * @return $this + */ + public function setOriginalTotal(float $originalTotal): static + { + if (is_null($originalTotal)) { + throw new InvalidArgumentException('non-nullable originalTotal cannot be null'); + } + + if (($originalTotal <= 0)) { + throw new InvalidArgumentException('invalid value for $originalTotal when calling AuthorizedTransaction., must be bigger than 0.'); + } + + $this->container['originalTotal'] = $originalTotal; + + return $this; + } + + /** + * Gets approveTotal + * + * @return float + */ + public function getApproveTotal(): float + { + return $this->container['approveTotal']; + } + + /** + * Sets approveTotal + * + * @param float $approveTotal approveTotal + * + * @return $this + */ + public function setApproveTotal(float $approveTotal): static + { + if (is_null($approveTotal)) { + throw new InvalidArgumentException('non-nullable approveTotal cannot be null'); + } + + if (($approveTotal < 0)) { + throw new InvalidArgumentException('invalid value for $approveTotal when calling AuthorizedTransaction., must be bigger than or equal to 0.'); + } + + $this->container['approveTotal'] = $approveTotal; + + return $this; + } + + /** + * Gets currency + * + * @return \Cone\SimplePay\Model\Currency + */ + public function getCurrency(): \Cone\SimplePay\Model\Currency + { + return $this->container['currency']; + } + + /** + * Sets currency + * + * @param \Cone\SimplePay\Model\Currency $currency currency + * + * @return $this + */ + public function setCurrency(\Cone\SimplePay\Model\Currency $currency): static + { + if (is_null($currency)) { + throw new InvalidArgumentException('non-nullable currency cannot be null'); + } + $this->container['currency'] = $currency; + + return $this; + } + + /** + * Gets orderRef + * + * @return string + */ + public function getOrderRef(): string + { + return $this->container['orderRef']; + } + + /** + * Sets orderRef + * + * @param string $orderRef orderRef + * + * @return $this + */ + public function setOrderRef(string $orderRef): static + { + if (is_null($orderRef)) { + throw new InvalidArgumentException('non-nullable orderRef cannot be null'); + } + $this->container['orderRef'] = $orderRef; + + return $this; + } + + /** + * Gets transactionId + * + * @return float + */ + public function getTransactionId(): float + { + return $this->container['transactionId']; + } + + /** + * Sets transactionId + * + * @param float $transactionId transactionId + * + * @return $this + */ + public function setTransactionId(float $transactionId): static + { + if (is_null($transactionId)) { + throw new InvalidArgumentException('non-nullable transactionId cannot be null'); + } + $this->container['transactionId'] = $transactionId; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param int $offset Offset + * + * @return bool + */ + public function offsetExists(mixed $offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param int $offset Offset + * + * @return mixed|null + */ + #[ReturnTypeWillChange] + public function offsetGet(mixed $offset): mixed + { + 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(mixed $offset, mixed $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param int $offset Offset + * + * @return void + */ + public function offsetUnset(mixed $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(): mixed + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString(): string + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue(): string + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} diff --git a/src/Model/Finish200Response.php b/src/Model/Finish200Response.php new file mode 100644 index 0000000..296ea75 --- /dev/null +++ b/src/Model/Finish200Response.php @@ -0,0 +1,575 @@ + + */ +class Finish200Response implements ModelInterface, ArrayAccess, JsonSerializable +{ + public const DISCRIMINATOR = null; + + /** + * The original name of the model. + * + * @var string + */ + protected static string $openAPIModelName = 'finish_200_response'; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @var array + */ + protected static array $openAPITypes = [ + 'salt' => 'string', + 'merchant' => 'string', + 'orderRef' => 'string', + 'currency' => '\Cone\SimplePay\Model\Currency', + 'transactionId' => 'float', + 'total' => 'float', + ]; + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @var array + */ + protected static array $openAPIFormats = [ + 'salt' => null, + 'merchant' => null, + 'orderRef' => null, + 'currency' => null, + 'transactionId' => null, + 'total' => null, + ]; + + /** + * Array of nullable properties. Used for (de)serialization + * + * @var array + */ + protected static array $openAPINullables = [ + 'salt' => false, + 'merchant' => false, + 'orderRef' => false, + 'currency' => false, + 'transactionId' => false, + 'total' => false, + ]; + + /** + * If a nullable field gets set to null, insert it here + * + * @var array + */ + protected array $openAPINullablesSetToNull = []; + + /** + * Array of property to type mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPITypes(): array + { + return self::$openAPITypes; + } + + /** + * Array of property to format mappings. Used for (de)serialization + * + * @return array + */ + public static function openAPIFormats(): array + { + 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 array + */ + private function getOpenAPINullablesSetToNull(): array + { + return $this->openAPINullablesSetToNull; + } + + /** + * Setter - Array of nullable field names deliberately set to null + * + * @param array $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 array + */ + protected static array $attributeMap = [ + 'salt' => 'salt', + 'merchant' => 'merchant', + 'orderRef' => 'orderRef', + 'currency' => 'currency', + 'transactionId' => 'transactionId', + 'total' => 'total', + ]; + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @var array + */ + protected static array $setters = [ + 'salt' => 'setSalt', + 'merchant' => 'setMerchant', + 'orderRef' => 'setOrderRef', + 'currency' => 'setCurrency', + 'transactionId' => 'setTransactionId', + 'total' => 'setTotal', + ]; + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @var array + */ + protected static array $getters = [ + 'salt' => 'getSalt', + 'merchant' => 'getMerchant', + 'orderRef' => 'getOrderRef', + 'currency' => 'getCurrency', + 'transactionId' => 'getTransactionId', + 'total' => 'getTotal', + ]; + + /** + * Array of attributes where the key is the local name, + * and the value is the original name + * + * @return array + */ + public static function attributeMap(): array + { + return self::$attributeMap; + } + + /** + * Array of attributes to setter functions (for deserialization of responses) + * + * @return array + */ + public static function setters(): array + { + return self::$setters; + } + + /** + * Array of attributes to getter functions (for serialization of requests) + * + * @return array + */ + public static function getters(): array + { + return self::$getters; + } + + /** + * The original name of the model. + * + * @return string + */ + public function getModelName(): string + { + return self::$openAPIModelName; + } + + + /** + * Associative array for storing property values + * + * @var array + */ + protected array $container = []; + + /** + * Constructor + * + * @param array $data Associated array of property values initializing the model + */ + public function __construct(?array $data = null) + { + $this->setIfExists('salt', $data ?? [], null); + $this->setIfExists('merchant', $data ?? [], null); + $this->setIfExists('orderRef', $data ?? [], null); + $this->setIfExists('currency', $data ?? [], null); + $this->setIfExists('transactionId', $data ?? [], null); + $this->setIfExists('total', $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, mixed $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 string[] invalid properties with reasons + */ + public function listInvalidProperties(): array + { + $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(): bool + { + return count($this->listInvalidProperties()) === 0; + } + + + /** + * Gets salt + * + * @return string|null + */ + public function getSalt(): ?string + { + return $this->container['salt']; + } + + /** + * Sets salt + * + * @param string|null $salt salt + * + * @return $this + */ + public function setSalt(?string $salt): static + { + if (is_null($salt)) { + throw new InvalidArgumentException('non-nullable salt cannot be null'); + } + $this->container['salt'] = $salt; + + return $this; + } + + /** + * Gets merchant + * + * @return string|null + */ + public function getMerchant(): ?string + { + return $this->container['merchant']; + } + + /** + * Sets merchant + * + * @param string|null $merchant merchant + * + * @return $this + */ + public function setMerchant(?string $merchant): static + { + if (is_null($merchant)) { + throw new InvalidArgumentException('non-nullable merchant cannot be null'); + } + $this->container['merchant'] = $merchant; + + return $this; + } + + /** + * Gets orderRef + * + * @return string|null + */ + public function getOrderRef(): ?string + { + return $this->container['orderRef']; + } + + /** + * Sets orderRef + * + * @param string|null $orderRef orderRef + * + * @return $this + */ + public function setOrderRef(?string $orderRef): static + { + if (is_null($orderRef)) { + throw new InvalidArgumentException('non-nullable orderRef cannot be null'); + } + $this->container['orderRef'] = $orderRef; + + return $this; + } + + /** + * Gets currency + * + * @return \Cone\SimplePay\Model\Currency|null + */ + public function getCurrency(): ?\Cone\SimplePay\Model\Currency + { + return $this->container['currency']; + } + + /** + * Sets currency + * + * @param \Cone\SimplePay\Model\Currency|null $currency currency + * + * @return $this + */ + public function setCurrency(?\Cone\SimplePay\Model\Currency $currency): static + { + if (is_null($currency)) { + throw new InvalidArgumentException('non-nullable currency cannot be null'); + } + $this->container['currency'] = $currency; + + return $this; + } + + /** + * Gets transactionId + * + * @return float|null + */ + public function getTransactionId(): ?float + { + return $this->container['transactionId']; + } + + /** + * Sets transactionId + * + * @param float|null $transactionId transactionId + * + * @return $this + */ + public function setTransactionId(?float $transactionId): static + { + if (is_null($transactionId)) { + throw new InvalidArgumentException('non-nullable transactionId cannot be null'); + } + $this->container['transactionId'] = $transactionId; + + return $this; + } + + /** + * Gets total + * + * @return float|null + */ + public function getTotal(): ?float + { + return $this->container['total']; + } + + /** + * Sets total + * + * @param float|null $total total + * + * @return $this + */ + public function setTotal(?float $total): static + { + if (is_null($total)) { + throw new InvalidArgumentException('non-nullable total cannot be null'); + } + $this->container['total'] = $total; + + return $this; + } + /** + * Returns true if offset exists. False otherwise. + * + * @param int $offset Offset + * + * @return bool + */ + public function offsetExists(mixed $offset): bool + { + return isset($this->container[$offset]); + } + + /** + * Gets offset. + * + * @param int $offset Offset + * + * @return mixed|null + */ + #[ReturnTypeWillChange] + public function offsetGet(mixed $offset): mixed + { + 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(mixed $offset, mixed $value): void + { + if (is_null($offset)) { + $this->container[] = $value; + } else { + $this->container[$offset] = $value; + } + } + + /** + * Unsets offset. + * + * @param int $offset Offset + * + * @return void + */ + public function offsetUnset(mixed $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(): mixed + { + return ObjectSerializer::sanitizeForSerialization($this); + } + + /** + * Gets the string presentation of the object + * + * @return string + */ + public function __toString(): string + { + return json_encode( + ObjectSerializer::sanitizeForSerialization($this), + JSON_PRETTY_PRINT + ); + } + + /** + * Gets a header-safe presentation of the object + * + * @return string + */ + public function toHeaderValue(): string + { + return json_encode(ObjectSerializer::sanitizeForSerialization($this)); + } +} diff --git a/src/Model/Item.php b/src/Model/Item.php index fc93426..cea5e7c 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -61,7 +61,7 @@ class Item implements ModelInterface, ArrayAccess, JsonSerializable 'ref' => 'string', 'title' => 'string', 'desc' => 'string', - 'amount' => 'float', + 'amount' => 'int', 'price' => 'float', 'tax' => 'float', ]; @@ -316,8 +316,8 @@ public function listInvalidProperties(): array if ($this->container['amount'] === null) { $invalidProperties[] = "'amount' can't be null"; } - if (($this->container['amount'] <= 0)) { - $invalidProperties[] = "invalid value for 'amount', must be bigger than 0."; + if (($this->container['amount'] < 1)) { + $invalidProperties[] = "invalid value for 'amount', must be bigger than or equal to 1."; } if ($this->container['price'] === null) { @@ -433,9 +433,9 @@ public function setDesc(?string $desc): static /** * Gets amount * - * @return float + * @return int */ - public function getAmount(): float + public function getAmount(): int { return $this->container['amount']; } @@ -443,18 +443,18 @@ public function getAmount(): float /** * Sets amount * - * @param float $amount amount + * @param int $amount The quantity. * * @return $this */ - public function setAmount(float $amount): static + public function setAmount(int $amount): static { if (is_null($amount)) { throw new InvalidArgumentException('non-nullable amount cannot be null'); } - if (($amount <= 0)) { - throw new InvalidArgumentException('invalid value for $amount when calling Item., must be bigger than 0.'); + if (($amount < 1)) { + throw new InvalidArgumentException('invalid value for $amount when calling Item., must be bigger than or equal to 1.'); } $this->container['amount'] = $amount; diff --git a/src/Model/Start200Response.php b/src/Model/Start200Response.php index c20d5e9..2be9a9f 100644 --- a/src/Model/Start200Response.php +++ b/src/Model/Start200Response.php @@ -572,7 +572,7 @@ public function getTokens(): ?array /** * Sets tokens * - * @param string[]|null $tokens The recurring payment tokens. Provided only for the inital recurring payment. + * @param string[]|null $tokens The recurring payment tokens. Provided only for the initial recurring payment. * * @return $this */ diff --git a/src/Model/Transaction.php b/src/Model/Transaction.php index 3acd21d..e03a845 100644 --- a/src/Model/Transaction.php +++ b/src/Model/Transaction.php @@ -915,7 +915,7 @@ public function getMethods(): ?array /** * Sets methods * - * @param \Cone\SimplePay\Model\Method[]|null $methods Possible valies: CARD, WIRE or EAM. + * @param \Cone\SimplePay\Model\Method[]|null $methods Possible values: CARD, WIRE or EAM. * * @return $this */ diff --git a/tests/Api/TransactionApiTest.php b/tests/Api/TransactionApiTest.php index 60dc101..027c01c 100644 --- a/tests/Api/TransactionApiTest.php +++ b/tests/Api/TransactionApiTest.php @@ -68,6 +68,18 @@ public static function tearDownAfterClass(): void { } + /** + * Test case for finish + * + * Finish a two-step transaction. + * + */ + public function testFinish() + { + // TODO: implement + self::markTestIncomplete('Not implemented'); + } + /** * Test case for start * diff --git a/tests/Model/AuthorizedTransactionTest.php b/tests/Model/AuthorizedTransactionTest.php new file mode 100644 index 0000000..aaee533 --- /dev/null +++ b/tests/Model/AuthorizedTransactionTest.php @@ -0,0 +1,123 @@ +