Skip to content

Commit 933d0c6

Browse files
authored
Merge pull request #106 from paytrail/add-cancel-order-functionality
Add support for invoice cancellation
2 parents 1f7eabe + de5e52c commit 933d0c6

File tree

5 files changed

+95
-4
lines changed

5 files changed

+95
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.8.0] - 2026-03-04
8+
### Added
9+
- Support for Klarna invoice cancellation
10+
711
## [2.7.6] - 2025-12-10
812
### Added
913
- Support for PHP 8.5

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ List of `Client::class` methods
109109
| createMitPaymentAuthorizationHold() | Create MiT authorization hold |
110110
| createMitPaymentCommit() | Commit MiT authorization hold |
111111
| revertPaymentAuthorizationHold() | Revert existing Mit or CiT authorization hold |
112+
| activateInvoice() | Activate pending invoice (Walley / Klarna) |
113+
| cancelInvoice() | Cancel pending invoice (Currently only Klarna) |
112114
| getSettlements() [Deprecated] | Deprecated Request settlements |
113115
| requestSettlements() | Request settlements |
114116
| requestPaymentReport() | Request payment report |

src/Client.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use Paytrail\SDK\Response\RevertPaymentAuthHoldResponse;
3434
use Paytrail\SDK\Response\SettlementResponse;
3535
use Paytrail\SDK\Response\InvoiceActivationResponse;
36+
use Paytrail\SDK\Response\InvoiceCancellationResponse;
3637
use Paytrail\SDK\Util\Signature;
3738
use Paytrail\SDK\Exception\HmacException;
3839
use Paytrail\SDK\Exception\ValidationException;
@@ -782,13 +783,13 @@ function ($decoded) {
782783
}
783784

784785
/**
785-
* Activate invoice created with manualInvoiceActivation set to true
786+
* Activate invoice created with manualInvoiceActivation set to true. Supported payment methods: Walley, Klarna
786787
*
787788
* @param string $transactionId
788789
* @return InvoiceActivationResponse
789790
* @throws HmacException
790791
*/
791-
public function activateInvoice(string $transactionId)
792+
public function activateInvoice(string $transactionId): InvoiceActivationResponse
792793
{
793794
$uri = "/payments/{$transactionId}/activate-invoice";
794795

@@ -809,6 +810,27 @@ function ($decoded) {
809810
);
810811
}
811812

813+
/**
814+
* Cancel invoice created with manualInvoiceActivation set to true. Supported payment methods: Klarna
815+
*
816+
* @param string $transactionId
817+
* @return InvoiceCancellationResponse
818+
* @throws HmacException
819+
*/
820+
public function cancelInvoice(string $transactionId): InvoiceCancellationResponse
821+
{
822+
$uri = "/payments/{$transactionId}/cancel-order";
823+
824+
$response = $this->post($uri, null, null, $transactionId);
825+
826+
$decoded = json_decode((string) $response->getBody());
827+
828+
return (new InvoiceCancellationResponse())
829+
->setStatus($decoded->status)
830+
->setMessage($decoded->message)
831+
->setHttpStatusCode($response->getStatusCode());
832+
}
833+
812834
/**
813835
* A proxy for the Signature class' static method
814836
* to be used via a client instance.

src/Response/InvoiceActivationResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/**
4-
* Class RefundResponse
4+
* Class InvoiceActivationResponse
55
*/
66

77
declare(strict_types=1);
@@ -11,7 +11,7 @@
1111
use Paytrail\SDK\Interfaces\ResponseInterface;
1212

1313
/**
14-
* Class RefundResponse
14+
* Class InvoiceActivationResponse
1515
*
1616
* @package Paytrail\SDK\Response
1717
*/
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
/**
4+
* Class InvoiceCancellationResponse
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Paytrail\SDK\Response;
10+
11+
use Paytrail\SDK\Interfaces\ResponseInterface;
12+
13+
/**
14+
* Class InvoiceCancellationResponse
15+
*
16+
* Possible HTTP status codes returned by Paytrail API:
17+
* 201 - Invoice cancelled
18+
* 202 - Invoice cancellation requested, status of the payment will be updated asynchronously
19+
* 200 - Invoice already cancelled
20+
* 400 - Invalid request. Refer to body message for more information
21+
* 500 - Other error. Refer to body message for more information
22+
*
23+
* @package Paytrail\SDK\Response
24+
*/
25+
class InvoiceCancellationResponse implements ResponseInterface
26+
{
27+
protected $status;
28+
protected $httpStatusCode;
29+
protected $message;
30+
31+
public function getStatus(): ?string
32+
{
33+
return $this->status;
34+
}
35+
36+
public function setStatus(?string $status): InvoiceCancellationResponse
37+
{
38+
$this->status = $status;
39+
return $this;
40+
}
41+
42+
public function getMessage(): ?string
43+
{
44+
return $this->message;
45+
}
46+
47+
public function setMessage(?string $message): InvoiceCancellationResponse
48+
{
49+
$this->message = $message;
50+
return $this;
51+
}
52+
53+
public function getHttpStatusCode(): ?int
54+
{
55+
return $this->httpStatusCode;
56+
}
57+
58+
public function setHttpStatusCode(?int $httpStatusCode): InvoiceCancellationResponse
59+
{
60+
$this->httpStatusCode = $httpStatusCode;
61+
return $this;
62+
}
63+
}

0 commit comments

Comments
 (0)