Skip to content

Commit

Permalink
Added the transactionHandler() method to the Payment gateway interface
Browse files Browse the repository at this point in the history
- Added experimental Transaction-related interfaces
  • Loading branch information
fulopattila122 committed Apr 24, 2024
1 parent 49428a9 commit f488b0e
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
- `getRemoteId()`
- `isOffline()`
- BC: Added the `getTransactionAmount()` method to the `PaymentResponse` interface
- BC: Added the `transactionHandler()` method to the `PaymentGateway` interface (**experimental** feature)
- BC: Added the following methods to the `Payable` interface:
- `getNumber()`
- `getPayableRemoteId()`
Expand All @@ -146,6 +147,8 @@
- `getShippingCountries()`
- Deprecated the `PaymentMethod::getConfiguration()` in favor of `configuration()`
- Deprecated the `PaymentResponse::getAmountPaid()` method in favor of `getTransactionAmount()`
- Added a series of **experimental** transaction-style interfaces. They shouldn't be used yet, but
have been added so that they can be implemented during the v4.x lifecycle without breaking existing implementations
- Added the `Schematized` interface
- Added the nette/schema package requirement (v1.2.5+)
- Fixed possible null return type on Billpayer::getName() when is_organization is true but the company name is null
Expand Down
3 changes: 3 additions & 0 deletions src/Payment/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
- `getRemoteId()`
- `isOffline()`
- BC: Added the `getTransactionAmount()` method to the `PaymentResponse` interface
- BC: Added the `transactionHandler()` method to the `PaymentGateway` interface (experimental feature)
- BC: Changed the `PaymentMethod` interface into Configurable
- Deprecated the `PaymentMethod::getConfiguration()` in favor of `configuration()`
- Deprecated the `PaymentResponse::getAmountPaid()` method in favor of `getTransactionAmount()`
- Added a series of **experimental** transaction-style interfaces. They shouldn't be used yet, but
have been added so that they can be implemented during the v4.x lifecycle without breaking existing implementations

## 3.x Series

Expand Down
25 changes: 25 additions & 0 deletions src/Payment/Contracts/PaymentAware.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

/**
* Contains the PaymentAware interface.
*
* @copyright Copyright (c) 2024 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2024-04-24
*
*/

namespace Vanilo\Payment\Contracts;

/**
* @experimental
*/
interface PaymentAware
{
public function getPaymentId(): string;

public function getPayment(): Payment;
}
3 changes: 3 additions & 0 deletions src/Payment/Contracts/PaymentGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ public function createPaymentRequest(

public function processPaymentResponse(Request $request, array $options = []): PaymentResponse;

/** @experimental */
public function transactionHandler(): ?TransactionHandler;

public function isOffline(): bool;
}
9 changes: 3 additions & 6 deletions src/Payment/Contracts/PaymentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace Vanilo\Payment\Contracts;

use Konekt\Enum\EnumInterface;

/**
* @method static PaymentStatus PENDING()
* @method static PaymentStatus AUTHORIZED()
Expand All @@ -36,11 +38,6 @@
* @method bool isRefunded()
* @method bool isPartiallyRefunded()
*/
interface PaymentStatus
interface PaymentStatus extends EnumInterface
{
/** @return string */
public function value();

/** @return string */
public function label();
}
43 changes: 43 additions & 0 deletions src/Payment/Contracts/Transaction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/**
* Contains the Transaction interface.
*
* @copyright Copyright (c) 2024 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2024-04-24
*
*/

namespace Vanilo\Payment\Contracts;

use StringBackedEnum;

/**
* @experimental is subject to change. don't use it yet!
*/
interface Transaction extends PaymentAware
{
public function wasSuccessful(): bool;

public function message(): string;

public function attemptedAmount(): float;

public function transactedAmount(): float;

public function isCharge(): bool;

public function isCredit(): bool;

public function getTransactionId(): ?string;

public function getRemoteSubjectId(): ?string;

public function getRemoteSubjectType(): ?string;

public function getNativeStatus(): StringBackedEnum;
}
25 changes: 25 additions & 0 deletions src/Payment/Contracts/TransactionHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

/**
* Contains the TransactionHandler interface.
*
* @copyright Copyright (c) 2024 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2024-04-24
*
*/

namespace Vanilo\Payment\Contracts;

/**
* @experimental don't use it yet, don't rely on it yet!
*/
interface TransactionHandler
{
public function supportsRefunds(): bool;

public function issueRefund(Payment $payment, float $amount, array $options = []): Transaction|TransactionNotCreated;
}
27 changes: 27 additions & 0 deletions src/Payment/Contracts/TransactionNotCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

/**
* Contains the FailedOperation interface.
*
* @copyright Copyright (c) 2024 Vanilo UG
* @author Attila Fulop
* @license MIT
* @since 2024-04-24
*
*/

namespace Vanilo\Payment\Contracts;

/**
* @experimental
*/
interface TransactionNotCreated extends PaymentAware
{
public function reason(): ?string;

public function shouldBeRetried(): bool;

public function getDetails();
}
6 changes: 6 additions & 0 deletions src/Payment/Gateways/NullGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Vanilo\Payment\Contracts\PaymentGateway;
use Vanilo\Payment\Contracts\PaymentRequest;
use Vanilo\Payment\Contracts\PaymentResponse;
use Vanilo\Payment\Contracts\TransactionHandler;
use Vanilo\Payment\Requests\NullRequest;
use Vanilo\Payment\Responses\NullResponse;

Expand All @@ -43,6 +44,11 @@ public function processPaymentResponse(Request $request, array $options = []): P
return new NullResponse();
}

public function transactionHandler(): ?TransactionHandler
{
return null;
}

public function isOffline(): bool
{
return true;
Expand Down
6 changes: 6 additions & 0 deletions src/Payment/Tests/Examples/PlasticPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Vanilo\Payment\Contracts\PaymentGateway;
use Vanilo\Payment\Contracts\PaymentRequest;
use Vanilo\Payment\Contracts\PaymentResponse;
use Vanilo\Payment\Contracts\TransactionHandler;
use Vanilo\Payment\Requests\NullRequest;
use Vanilo\Payment\Responses\NullResponse;

Expand All @@ -43,6 +44,11 @@ public function processPaymentResponse(Request $request, array $options = []): P
return new NullResponse();
}

public function transactionHandler(): ?TransactionHandler
{
return null;
}

public function isOffline(): bool
{
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/Payment/Tests/Examples/UnorthodoxGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Vanilo\Payment\Contracts\PaymentGateway;
use Vanilo\Payment\Contracts\PaymentRequest;
use Vanilo\Payment\Contracts\PaymentResponse;
use Vanilo\Payment\Contracts\TransactionHandler;
use Vanilo\Payment\Models\PaymentStatus;
use Vanilo\Payment\Requests\NullRequest;

Expand Down Expand Up @@ -51,6 +52,11 @@ public function processPaymentResponse(Request|UnorthodoxPaymentResponse $reques
);
}

public function transactionHandler(): ?TransactionHandler
{
return null;
}

public function isOffline(): bool
{
return false;
Expand Down

0 comments on commit f488b0e

Please sign in to comment.