Skip to content

Commit

Permalink
Payment and payment status improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopattila122 committed May 7, 2023
1 parent 49aacbe commit 63dddee
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## 3.x Series

## Unreleased
##### 2023-XX-YY

- Added missing Payment Status magic comparison annotations to the interface/model
- Added the `hasRemoteId()`, `getRemoteId()` and `isOffline()` helper methods to the Payment model (v4 interface candidates)

## 3.7.0
##### 2023-04-04

Expand Down
5 changes: 4 additions & 1 deletion Contracts/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ public function getStatus(): PaymentStatus;
public function getMethod(): PaymentMethod;

/**
* @todo add this in v4
* @todo add these in v4
* public function getSubtype(): ?string
* public function hasRemoteId(): bool
* public function getRemoteId(): ?string
* public function isOffline(): bool
*/

public function getPayable(): Payable;
Expand Down
11 changes: 11 additions & 0 deletions Contracts/PaymentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
* @method static PaymentStatus TIMEOUT()
* @method static PaymentStatus CANCELLED()
* @method static PaymentStatus REFUNDED()
*
* @method bool isPending()
* @method bool isAuthorized()
* @method bool isOnHold()
* @method bool isPaid()
* @method bool isPartiallyPaid()
* @method bool isDeclined()
* @method bool isTimeout()
* @method bool isCancelled()
* @method bool isRefunded()
* @method bool isPartiallyRefunded()
*/
interface PaymentStatus
{
Expand Down
15 changes: 15 additions & 0 deletions Models/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ public static function findByRemoteId(string $remoteId, int $paymentMethodId = n
->first();
}

public function hasRemoteId(): bool
{
return null !== $this->remote_id;
}

public function getRemoteId(): ?string
{
return $this->remote_id;
}

public function isOffline(): bool
{
return $this->method->getGateway()->isOffline();
}

public function getPaymentId(): string
{
return $this->hash;
Expand Down
22 changes: 22 additions & 0 deletions Models/PaymentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,28 @@
* @method static PaymentStatus CANCELLED()
* @method static PaymentStatus REFUNDED()
* @method static PaymentStatus PARTIALLY_REFUNDED()
*
* @method bool isPending()
* @method bool isAuthorized()
* @method bool isOnHold()
* @method bool isPaid()
* @method bool isPartiallyPaid()
* @method bool isDeclined()
* @method bool isTimeout()
* @method bool isCancelled()
* @method bool isRefunded()
* @method bool isPartiallyRefunded()
*
* @property-read bool $is_pending
* @property-read bool $is_authorized
* @property-read bool $is_on_hold
* @property-read bool $is_paid
* @property-read bool $is_partially_paid
* @property-read bool $is_declined
* @property-read bool $is_timeout
* @property-read bool $is_cancelled
* @property-read bool $is_refunded
* @property-read bool $is_partially_refunded
*/
class PaymentStatus extends Enum implements PaymentStatusContract
{
Expand Down

0 comments on commit 63dddee

Please sign in to comment.