Skip to content

Commit

Permalink
Merge branch 'paytrail:master' into allow-empty-string-email
Browse files Browse the repository at this point in the history
  • Loading branch information
slipslop authored Sep 9, 2024
2 parents be9a125 + e7fc7ab commit aa2d825
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/run-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
php-version: ['7.3', '7.4', '8.0', '8.1', '8.2']
php-version: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
experimental: [false]
steps:
- uses: actions/checkout@v3
Expand All @@ -34,7 +34,7 @@ jobs:
uses: php-actions/phpstan@v3
with:
php_version: ${{ matrix.php-version }}
version: 1.9.14
version: latest
configuration: phpstan.neon
memory_limit: 256M

Expand Down
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.7.3] - 2024-07-29
### Added
- Support the new VAT in Finland

## [2.7.2] - 2024-06-06
### Changed
- Updated validation to support negative item rows

## [2.7.1] - 2024-04-16
### Added
- Run tests on PHP 8.3
### Fixed
- Fix access to possibly undefined property
- Validate too long item descriptions on client side

## [2.7.0] - 2024-03-21
### Added
- Added customProviders to createPayment() response

## [2.6.0] - 2023-10-12
### Added
- Add pay and add card endpoint
### Fixed
- Fix payment provider unit test

## [2.5.2] - 2023-05-05
### Fixed
- Improved refundRequest Validation
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ List of `Client::class` methods
| requestSettlements() | Request settlements |
| requestPaymentReport() | Request payment report |
| requestPaymentReportBySettlement() | Request payment report by settlement ID |
| createPaymentAndAddCard() | Create payment and save card details |


---
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"require": {
"php": ">=7.3",
"ext-json": "*",
"ext-curl": "*"
"ext-curl": "*",
"ext-mbstring": "*"
},
"require-dev": {
"phpunit/phpunit": "^10.0 || ^9.0",
Expand Down
22 changes: 21 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use Paytrail\SDK\Exception\ValidationException;
use Paytrail\SDK\Exception\RequestException;
use Paytrail\SDK\Exception\ClientException;
use Paytrail\SDK\Response\AddCardPaymentResponse;

/**
* Class Client
Expand Down Expand Up @@ -218,7 +219,8 @@ function ($decoded) {
->setTerms($decoded->terms ?? null)
->setGroups($decoded->groups ?? [])
->setReference($decoded->reference ?? null)
->setProviders($decoded->providers ?? []);
->setProviders($decoded->providers ?? [])
->setCustomProviders((array)($decoded->customProviders ?? []));
}
);

Expand All @@ -233,6 +235,7 @@ function ($decoded) {
* @return PaymentResponse
* @throws HmacException Thrown if HMAC calculation fails for responses.
* @throws ValidationException Thrown if payment validation fails.
* @throws ClientException Thrown if API call fails.
*/
public function createShopInShopPayment(ShopInShopPaymentRequest $payment): PaymentResponse
{
Expand Down Expand Up @@ -262,6 +265,23 @@ function ($decoded) {
return $paymentResponse;
}

public function createPaymentAndAddCard(PaymentRequest $paymentRequest): AddCardPaymentResponse
{
$this->validateRequestItem($paymentRequest);

$uri = '/tokenization/pay-and-add-card';

return $this->post(
$uri,
$paymentRequest,
function ($decoded) {
return (new AddCardPaymentResponse())
->setTransactionId($decoded->transactionId ?? null)
->setRedirectUrl($decoded->redirectUrl ?? null);
}
);
}

/**
* Create a payment status request.
*
Expand Down
8 changes: 4 additions & 4 deletions src/Interfaces/ItemInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ public function setUnits(?int $units): ItemInterface;
/**
* Get the VAT percentage.
*
* @return int
* @return float
*/
public function getVatPercentage(): ?int;
public function getVatPercentage(): ?float;

/**
* Set the VAT percentage.
*
* @param int|null $vatPercentage
* @param float|null $vatPercentage
* @return ItemInterface Return self to enable chaining.
*/
public function setVatPercentage(?int $vatPercentage): ItemInterface;
public function setVatPercentage(?float $vatPercentage): ItemInterface;

/**
* Get the product code.
Expand Down
20 changes: 12 additions & 8 deletions src/Model/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Item implements \JsonSerializable, ItemInterface
/**
* The VAT percentage.
*
* @var integer
* @var float
*/
protected $vatPercentage;

Expand Down Expand Up @@ -159,20 +159,20 @@ public function setUnits(?int $units): ItemInterface
/**
* Get the VAT percentage.
*
* @return int
* @return float
*/
public function getVatPercentage(): ?int
public function getVatPercentage(): ?float
{
return $this->vatPercentage;
}

/**
* Set the VAT percentage.
*
* @param int $vatPercentage
* @param float $vatPercentage
* @return ItemInterface Return self to enable chaining.
*/
public function setVatPercentage(?int $vatPercentage): ItemInterface
public function setVatPercentage(?float $vatPercentage): ItemInterface
{
$this->vatPercentage = $vatPercentage;

Expand Down Expand Up @@ -379,9 +379,6 @@ public function validate()
if ($props['unitPrice'] === null) {
throw new ValidationException('Item unitPrice is empty');
}
if ($props['unitPrice'] < 0) {
throw new ValidationException('Items unitPrice can\'t be a negative number');
}
if ($props['unitPrice'] > 99999999) {
throw new ValidationException('Items unitPrice can\'t be over 99999999');
}
Expand All @@ -397,6 +394,9 @@ public function validate()
if (empty($props['productCode'])) {
throw new ValidationException('productCode is empty');
}
if ($props['description'] !== null && mb_strlen($props['description']) > 1000) {
throw new ValidationException('description does not meet maximum length of 1000');
}

return true;
}
Expand All @@ -414,6 +414,10 @@ public function validateShopInShop()
throw new ValidationException('merchant is empty');
}

if ($props['unitPrice'] < 0) {
throw new ValidationException('Shop-in-shop item unitPrice can\'t be a negative number');
}

return true;
}
}
8 changes: 4 additions & 4 deletions src/Request/ReportBySettlementRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ReportBySettlementRequest implements \JsonSerializable
protected $requestType;
protected $callbackUrl;
protected $reportFields;
protected $subMerchant;
protected $submerchant;

public function validate()
{
Expand Down Expand Up @@ -74,12 +74,12 @@ public function setReportFields(array $reportFields): self
/**
* Set submerchant.
*
* @param int $subMerchant
* @param int $submerchant
* @return $this
*/
public function setSubMerchant(int $subMerchant): self
public function setSubMerchant(int $submerchant): self
{
$this->subMerchant = $subMerchant;
$this->submerchant = $submerchant;
return $this;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Request/ReportRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ReportRequest implements \JsonSerializable
private $endDate;
private $limit;
private $reportFields;
private $subMerchant;
private $submerchant;

public function validate()
{
Expand Down Expand Up @@ -164,12 +164,12 @@ public function setReportFields(array $reportFields): self
/**
* Set submerchant.
*
* @param int $subMerchant
* @param int $submerchant
* @return $this
*/
public function setSubMerchant(int $subMerchant): self
public function setSubMerchant(int $submerchant): self
{
$this->subMerchant = $subMerchant;
$this->submerchant = $submerchant;
return $this;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Request/SettlementRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SettlementRequest implements \JsonSerializable
protected $endDate;
protected $reference;
protected $limit;
protected $subMerchant;
protected $submerchant;

public function validate()
{
Expand Down Expand Up @@ -102,12 +102,12 @@ public function setLimit(int $limit): self
/**
* Set submerchant.
*
* @param int $subMerchant
* @param int $submerchant
* @return $this
*/
public function setSubMerchant(int $subMerchant): self
public function setSubMerchant(int $submerchant): self
{
$this->subMerchant = $subMerchant;
$this->submerchant = $submerchant;
return $this;
}

Expand Down
79 changes: 79 additions & 0 deletions src/Response/AddCardPaymentResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

declare(strict_types=1);

namespace Paytrail\SDK\Response;

use Paytrail\SDK\Interfaces\ResponseInterface;

/**
* Class PaymentResponse
*
* Represents a response object of payment creation.
*
* @package Paytrail\SDK\Response
*/
class AddCardPaymentResponse implements ResponseInterface
{
/**
* Assigned transaction ID for the payment.
*
* @var string|null
*/
protected $transactionId;

/**
* URL to hosted payment gateway.
*
* @var string|null
*/
protected $redirectUrl;

/**
* Get the transaction id.
*
* @return string|null
*/
public function getTransactionId(): ?string
{
return $this->transactionId;
}

/**
* Set the transaction id.
*
* @param string|null $transactionId
*
* @return self Return self to enable chaining.
*/
public function setTransactionId(?string $transactionId): AddCardPaymentResponse
{
$this->transactionId = $transactionId;

return $this;
}

/**
* Get the redirectUrl.
*
* @return string|null
*/
public function getRedirectUrl(): ?string
{
return $this->redirectUrl;
}

/**
* Set the redirectUrl.
*
* @param string|null $redirectUrl
*
* @return self Return self to enable chaining.
*/
public function setRedirectUrl(?string $redirectUrl): AddCardPaymentResponse
{
$this->redirectUrl = $redirectUrl;

return $this;
}
}
Loading

0 comments on commit aa2d825

Please sign in to comment.