Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ 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.8.0] - 2026-03-04
### Added
- Support for Klarna invoice cancellation

## [2.7.6] - 2025-12-10
### Added
- Support for PHP 8.5
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ List of `Client::class` methods
| createMitPaymentAuthorizationHold() | Create MiT authorization hold |
| createMitPaymentCommit() | Commit MiT authorization hold |
| revertPaymentAuthorizationHold() | Revert existing Mit or CiT authorization hold |
| activateInvoice() | Activate pending invoice (Walley / Klarna) |
| cancelInvoice() | Cancel pending invoice (Currently only Klarna) |
| getSettlements() [Deprecated] | Deprecated Request settlements |
| requestSettlements() | Request settlements |
| requestPaymentReport() | Request payment report |
Expand Down
26 changes: 24 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use Paytrail\SDK\Response\RevertPaymentAuthHoldResponse;
use Paytrail\SDK\Response\SettlementResponse;
use Paytrail\SDK\Response\InvoiceActivationResponse;
use Paytrail\SDK\Response\InvoiceCancellationResponse;
use Paytrail\SDK\Util\Signature;
use Paytrail\SDK\Exception\HmacException;
use Paytrail\SDK\Exception\ValidationException;
Expand Down Expand Up @@ -782,13 +783,13 @@ function ($decoded) {
}

/**
* Activate invoice created with manualInvoiceActivation set to true
* Activate invoice created with manualInvoiceActivation set to true. Supported payment methods: Walley, Klarna
*
* @param string $transactionId
* @return InvoiceActivationResponse
* @throws HmacException
*/
public function activateInvoice(string $transactionId)
public function activateInvoice(string $transactionId): InvoiceActivationResponse
{
$uri = "/payments/{$transactionId}/activate-invoice";

Expand All @@ -809,6 +810,27 @@ function ($decoded) {
);
}

/**
* Cancel invoice created with manualInvoiceActivation set to true. Supported payment methods: Klarna
*
* @param string $transactionId
* @return InvoiceCancellationResponse
* @throws HmacException
*/
public function cancelInvoice(string $transactionId): InvoiceCancellationResponse
{
$uri = "/payments/{$transactionId}/cancel-order";

$response = $this->post($uri, null, null, $transactionId);

$decoded = json_decode((string) $response->getBody());

return (new InvoiceCancellationResponse())
->setStatus($decoded->status)
->setMessage($decoded->message)
->setHttpStatusCode($response->getStatusCode());
}

/**
* A proxy for the Signature class' static method
* to be used via a client instance.
Expand Down
4 changes: 2 additions & 2 deletions src/Response/InvoiceActivationResponse.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* Class RefundResponse
* Class InvoiceActivationResponse
*/

declare(strict_types=1);
Expand All @@ -11,7 +11,7 @@
use Paytrail\SDK\Interfaces\ResponseInterface;

/**
* Class RefundResponse
* Class InvoiceActivationResponse
*
* @package Paytrail\SDK\Response
*/
Expand Down
63 changes: 63 additions & 0 deletions src/Response/InvoiceCancellationResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* Class InvoiceCancellationResponse
*/

declare(strict_types=1);

namespace Paytrail\SDK\Response;

use Paytrail\SDK\Interfaces\ResponseInterface;

/**
* Class InvoiceCancellationResponse
*
* Possible HTTP status codes returned by Paytrail API:
* 201 - Invoice cancelled
* 202 - Invoice cancellation requested, status of the payment will be updated asynchronously
* 200 - Invoice already cancelled
* 400 - Invalid request. Refer to body message for more information
* 500 - Other error. Refer to body message for more information
*
* @package Paytrail\SDK\Response
*/
class InvoiceCancellationResponse implements ResponseInterface
{
protected $status;
protected $httpStatusCode;
protected $message;

public function getStatus(): ?string
{
return $this->status;
}

public function setStatus(?string $status): InvoiceCancellationResponse
{
$this->status = $status;
return $this;
}

public function getMessage(): ?string
{
return $this->message;
}

public function setMessage(?string $message): InvoiceCancellationResponse
{
$this->message = $message;
return $this;
}

public function getHttpStatusCode(): ?int
{
return $this->httpStatusCode;
}

public function setHttpStatusCode(?int $httpStatusCode): InvoiceCancellationResponse
{
$this->httpStatusCode = $httpStatusCode;
return $this;
}
}