Skip to content

Commit

Permalink
Added the getTransactionAmount() method to the PaymentResponse in…
Browse files Browse the repository at this point in the history
…terface
  • Loading branch information
fulopattila122 committed Mar 30, 2024
1 parent d90a7da commit 78cf5d6
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
- `hasRemoteId()`
- `getRemoteId()`
- `isOffline()`
- BC: Added the `getTransactionAmount()` method to the `PaymentResponse` interface
- BC: Added the following methods to the `Payable` interface:
- `getNumber()`
- `getPayableRemoteId()`
Expand All @@ -121,6 +122,7 @@
- `getBillingCountries()`
- `getShippingCountries()`
- Deprecated the `PaymentMethod::getConfiguration()` in favor of `configuration()`
- Deprecated the `PaymentResponse::getAmountPaid()` method in favor of `getTransactionAmount()`
- 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
2 changes: 2 additions & 0 deletions src/Payment/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
- `hasRemoteId()`
- `getRemoteId()`
- `isOffline()`
- BC: Added the `getTransactionAmount()` method to the `PaymentResponse` interface
- BC: Changed the `PaymentMethod` interface into Configurable
- Deprecated the `PaymentMethod::getConfiguration()` in favor of `configuration()`
- Deprecated the `Payment::getAmountPaid()` method in favor of `getTransactionAmount()`

## 3.x Series

Expand Down
3 changes: 0 additions & 3 deletions src/Payment/Contracts/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public function getAmount(): float;

public function getCurrency(): string;

// "Transaction amount" would've been a better name
// since the value returned here might represent
// an amount of a full/partial refund as well
public function getAmountPaid(): float;

public function getStatus(): PaymentStatus;
Expand Down
3 changes: 3 additions & 0 deletions src/Payment/Contracts/PaymentResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public function getMessage(): ?string;

public function getTransactionId(): ?string;

/** @deprecated use getTransactionAmount() instead */
public function getAmountPaid(): ?float;

public function getTransactionAmount(): float;

public function getPaymentId(): string;

public function getStatus(): PaymentStatus;
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/Models/PaymentHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function addPaymentResponse(
'old_status' => $oldStatus ?: $payment->getStatus()->value(),
'new_status' => $response->getStatus()->value(),
'message' => $response->getMessage(),
'transaction_amount' => $response->getAmountPaid(),
'transaction_amount' => $response->getTransactionAmount(),
'native_status' => $response->getNativeStatus()->value(),
'transaction_number' => $response->getTransactionId(),
]);
Expand Down
6 changes: 3 additions & 3 deletions src/Payment/Processing/PaymentResponseHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public function writeResponseToHistory(): void
public function updatePayment(): void
{
$this->payment->status = $this->newStatus;
$amountPaid = $this->response->getAmountPaid();
if (null !== $amountPaid) {
$this->payment->amount_paid += $this->response->getAmountPaid();
$transactionAmount = $this->response->getTransactionAmount();
if (0.0 !== $transactionAmount) {
$this->payment->amount_paid += $transactionAmount;
}
$this->payment->status_message = $this->response->getMessage();
$this->payment->save();
Expand Down
5 changes: 5 additions & 0 deletions src/Payment/Responses/NullResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function getAmountPaid(): ?float
return null;
}

public function getTransactionAmount(): float
{
return 0;
}

public function getPaymentId(): string
{
return '';
Expand Down
13 changes: 9 additions & 4 deletions src/Payment/Tests/Examples/SomePaymentResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SomePaymentResponse implements PaymentResponse

private string $transactionId;

private ?float $amountPaid;
private ?float $transactionAmount;

private string $paymentId;

Expand All @@ -38,7 +38,7 @@ public function __construct(
string $message,
bool $wasSuccessful,
string $transactionId,
?float $amountPaid,
?float $transactionAmount,
string $paymentId,
SomeNativeStatus $nativeStatus,
PaymentStatus $status
Expand All @@ -47,7 +47,7 @@ public function __construct(
$this->nativeStatus = $nativeStatus;
$this->wasSuccessful = $wasSuccessful;
$this->transactionId = $transactionId;
$this->amountPaid = $amountPaid;
$this->transactionAmount = $transactionAmount;
$this->paymentId = $paymentId;
$this->status = $status;
}
Expand All @@ -69,7 +69,12 @@ public function getTransactionId(): ?string

public function getAmountPaid(): ?float
{
return $this->amountPaid;
return $this->getTransactionAmount();
}

public function getTransactionAmount(): float
{
return (float) $this->transactionAmount;
}

public function getPaymentId(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Payment/Tests/GatewaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function non_illuminate_request_type_request_objects_can_be_accepted_by_p

$this->assertInstanceOf(PaymentResponse::class, $result);
$this->assertEquals(PaymentStatus::PAID(), $result->getStatus());
$this->assertEquals(27.99, $result->getAmountPaid());
$this->assertEquals(27.99, $result->getTransactionAmount());
$this->assertEquals('C9278', $result->getTransactionId());
}
}
2 changes: 1 addition & 1 deletion src/Payment/Tests/ResponseHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function it_creates_payment_history_entries()
$this->assertEquals(PaymentStatus::TIMEOUT, $entry->new_status->value());
$this->assertEquals(PaymentStatus::PENDING, $entry->old_status->value());
$this->assertEquals('Timed out like a lion', $entry->message);
$this->assertNull($entry->transaction_amount);
$this->assertEquals(0, $entry->transaction_amount);
}

/** @test */
Expand Down

0 comments on commit 78cf5d6

Please sign in to comment.