Skip to content

Commit

Permalink
Issue #11 Introduce new 'refunded' status to notification handler.
Browse files Browse the repository at this point in the history
  • Loading branch information
judgej committed Jul 12, 2020
1 parent b1388b9 commit 81ad442
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/ConstantsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,55 @@ interface ConstantsInterface
const TRANSACTION_STATE_ERROR = 'ERROR';
// The amount was reserved but not settled/billed yet.
// The transaction was successful.
// aka Authorization
const TRANSACTION_STATE_RESERVED = 'RESERVED';
// The reserved amount was complaint.
const TRANSACTION_STATE_RESERVED_REVERSAL = 'RESERVED_REVERSAL';
// The amount was settled/billed.
// The transaction was successful.
// aka Capture
const TRANSACTION_STATE_BILLED = 'BILLED';
// The amount was complaint (chargeback).
// Please get in touch with the customer.
const TRANSACTION_STATE_BILLED_REVERSAL = 'BILLED_REVERSAL';
// The reserved amount was released.
// The transaction was canceled.
// aka Cancelled
const TRANSACTION_STATE_REVERSED = 'REVERSED';
// The amount will be refunded.
// The transaction was credited.
// aka Credit
const TRANSACTION_STATE_CREDITED = 'CREDITED';
// The credited amount was complaint.
const TRANSACTION_STATE_CREDITED_REVERSAL = 'CREDITED_REVERSAL';
// Expecting external interface confirmation.
// The transaction is suspended temporarily.
// aka Waiting for confirmation
const TRANSACTION_STATE_SUSPENDED = 'SUSPENDED';
// The payout was successful.
// The amount will be transfered to the customer.
const TRANSACTION_STATE_WITHDRAWN = 'WITHDRAWN';
// Other states documented in othee places:
const TRANSACTION_STATE_INIT = 'INIT';
const TRANSACTION_STATE_AUTHORIZE = 'AUTHORIZE';
// Expecting user input on an external web-page.
// If this status remains unchanged for more than 24 hours the transaction can be considered as failed.
// Redirect
const TRANSACTION_STATE_REDIRECTED = 'REDIRECTED';
const TRANSACTION_STATE_CALLBACK = 'CALLBACK';
const TRANSACTION_STATE_EXECUTE = 'EXECUTE';
const TRANSACTION_STATE_REVOKE = 'REVOKE';
const TRANSACTION_STATE_REJECT = 'REJECT';
const TRANSACTION_STATE_ARCHIVED = 'ARCHIVED';
// The amount was withdrawn.
// The transaction was successful.
// aka Withdraw
const TRANSACTION_STATE_WITHDRAW = 'WITHDRAW';

// Plus:
// Pending Expecting external interface confirmation. The transaction is in progress. If this status remains unchanged for more than 24 hours please contact mPAY24 Support.
// Chargeback The amount was charged back by the customer.

/**
* Return codes to instructions.
*/
Expand Down
29 changes: 27 additions & 2 deletions src/Messages/AcceptNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class AcceptNotification extends AbstractMpay24Request implements NotificationIn
NotificationValuesTrait::getProfileId insteadof ParameterTrait;
}

/**
* @var string extend statuses of NotificationInterface.
*/
const STATUS_REFUNDED = 'refunded';

protected $data;

/**
Expand All @@ -39,8 +44,13 @@ public function getTransactionStatus()
switch ($this->getTransactionState()) {
case static::TRANSACTION_STATE_BILLED:
return static::STATUS_COMPLETED;

case static::TRANSACTION_STATE_RESERVED:
case static::TRANSACTION_STATE_SUSPENDED:
return static::STATUS_PENDING;

case static::TRANSACTION_STATE_CREDITED:
return static::STATUS_REFUNDED;
}

return static::STATUS_FAILED;
Expand Down Expand Up @@ -69,12 +79,16 @@ public function getCode()
public function isSuccessful()
{
return $this->getTransactionState() === static::TRANSACTION_STATE_BILLED
|| $this->getTransactionState() === static::TRANSACTION_STATE_RESERVED;
|| $this->isPending();
}

/**
* {@inheritdoc}
*/
public function isPending()
{
return $this->getTransactionState() === static::TRANSACTION_STATE_RESERVED;
return $this->getTransactionState() === static::TRANSACTION_STATE_RESERVED
|| $this->getTransactionState() === static::TRANSACTION_STATE_SUSPENDED;
}

/**
Expand All @@ -93,6 +107,17 @@ public function isRedirect()
return false;
}

/**
* An extension of the standard Omnipay statuses.
* @return bool
*/
public function isRefunded()
{
return $this->getTransactionState() === static::TRANSACTION_STATE_CREDITED
|| $this->getTransactionState() === static::TRANSACTION_STATE_REVERSED;

}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 81ad442

Please sign in to comment.