Version 4.3.6
This commit is contained in:
1 parent
fe1acf984a
commit
1a0c7fd3c2
609 files changed
+14707
-5726
No files matched your search
@@ -403,6 +403,27 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
$this->_data['partial_refund'] = (string) $amount->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get credit amount
|
||||
*
|
||||
* @return \IPS\nexus\Money
|
||||
*/
|
||||
public function get_credit()
|
||||
{
|
||||
return new \IPS\nexus\Money( $this->_data['credit'], $this->_data['currency'] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set credit amount
|
||||
*
|
||||
* @param \IPS\nexus\Money $amount The total
|
||||
* @return void
|
||||
*/
|
||||
public function set_credit( \IPS\nexus\Money $amount )
|
||||
{
|
||||
$this->_data['credit'] = (string) $amount->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date transaction must be captured by (is set after authorisation. once captured, should be NULL)
|
||||
*
|
||||
@@ -648,6 +669,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
$extra['history'][] = array( 's' => \IPS\nexus\Transaction::STATUS_REFUSED, 'on' => time(), 'by' => \IPS\Member::loggedIn()->member_id );
|
||||
$this->extra = $extra;
|
||||
$this->status = \IPS\nexus\Transaction::STATUS_REFUSED;
|
||||
$this->auth = NULL;
|
||||
$this->save();
|
||||
|
||||
/* Log it */
|
||||
@@ -672,6 +694,8 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
*/
|
||||
public function refund( $refundMethod='gateway', $amount=NULL, $reason=NULL )
|
||||
{
|
||||
$extra = $this->extra;
|
||||
|
||||
/* What's the amount? */
|
||||
if ( $amount )
|
||||
{
|
||||
@@ -684,42 +708,18 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
{
|
||||
$amount = NULL;
|
||||
}
|
||||
|
||||
/* Refund */
|
||||
$refundReference = NULL;
|
||||
|
||||
/* Actual Refund */
|
||||
if ( $refundMethod === 'gateway' and method_exists( $this->method, 'refund' ) )
|
||||
{
|
||||
/* Refund with gateway */
|
||||
$refundReference = $this->method->refund( $this, $amount, $reason );
|
||||
}
|
||||
elseif ( $refundMethod === 'credit' )
|
||||
{
|
||||
$credits = $this->member->cm_credits;
|
||||
$credits[ $this->amount->currency ]->amount = $credits[ $this->amount->currency ]->amount->add( $amount ?: $this->amount->amount );
|
||||
$this->member->cm_credits = $credits;
|
||||
$this->member->save();
|
||||
}
|
||||
|
||||
/* Update transaction */
|
||||
$extra = $this->extra;
|
||||
if ( $refundMethod === 'none' )
|
||||
{
|
||||
$this->status = static::STATUS_REFUSED;
|
||||
$extra['history'][] = array( 's' => static::STATUS_REFUSED, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time() );
|
||||
|
||||
if ( $this->member )
|
||||
{
|
||||
$this->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => static::STATUS_REFUSED,
|
||||
'id' => $this->id
|
||||
) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update transaction and log */
|
||||
if ( $amount === NULL )
|
||||
{
|
||||
$this->status = static::STATUS_REFUNDED;
|
||||
|
||||
$extra['history'][] = array( 's' => static::STATUS_REFUNDED, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'ref' => $refundReference );
|
||||
|
||||
if ( $this->member )
|
||||
@@ -733,19 +733,18 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
$this->partial_refund = new \IPS\nexus\Money( $this->partial_refund->amount->add( $amount ), $this->currency );
|
||||
|
||||
$extra['history'][] = array( 's' => static::STATUS_PART_REFUNDED, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'amount' => $amount, 'ref' => $refundReference );
|
||||
if ( $amount >= $this->amount->amount )
|
||||
{
|
||||
$this->status = static::STATUS_REFUNDED;
|
||||
$extra['history'][] = array( 's' => static::STATUS_REFUNDED );
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->status = static::STATUS_PART_REFUNDED;
|
||||
}
|
||||
$extra['history'][] = array( 's' => $this->status, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'amount' => $amount, 'ref' => $refundReference );
|
||||
|
||||
if ( $this->member )
|
||||
{
|
||||
@@ -759,8 +758,89 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* Credit */
|
||||
elseif ( $refundMethod === 'credit' )
|
||||
{
|
||||
$amount = $amount ?: $this->amount->amount->subtract( $this->credit->amount );
|
||||
|
||||
/* Add the credit */
|
||||
$credits = $this->member->cm_credits;
|
||||
$credits[ $this->amount->currency ]->amount = $credits[ $this->amount->currency ]->amount->add( $amount );
|
||||
$this->member->cm_credits = $credits;
|
||||
$this->member->save();
|
||||
|
||||
/* Update transaction */
|
||||
$this->status = static::STATUS_PART_REFUNDED;
|
||||
$this->credit = new \IPS\nexus\Money( $this->credit->amount->add( $amount ), $this->currency );
|
||||
|
||||
/* Log */
|
||||
$extra['history'][] = array( 's' => static::STATUS_PART_REFUNDED, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'to' => $refundMethod, 'amount' => $amount, 'ref' => NULL );
|
||||
if ( $this->member )
|
||||
{
|
||||
$this->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => static::STATUS_PART_REFUNDED,
|
||||
'id' => $this->id,
|
||||
'refund' => $refundMethod,
|
||||
'amount' => $amount,
|
||||
'currency' => $this->currency
|
||||
) );
|
||||
}
|
||||
}
|
||||
/* Mark refused, but don't actually do anything */
|
||||
elseif ( $refundMethod === 'none' )
|
||||
{
|
||||
/* Update transaction */
|
||||
$this->status = static::STATUS_REFUSED;
|
||||
$extra['history'][] = array( 's' => static::STATUS_REFUSED, 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time() );
|
||||
|
||||
/* Log */
|
||||
if ( $this->member )
|
||||
{
|
||||
$this->member->log( 'transaction', array(
|
||||
'type' => 'status',
|
||||
'status' => static::STATUS_REFUSED,
|
||||
'id' => $this->id
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Save */
|
||||
$this->extra = $extra;
|
||||
$this->auth = NULL;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse previously given credit (will log, but does not change status - status must be set separately)
|
||||
*
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function reverseCredit()
|
||||
{
|
||||
$credits = $this->member->cm_credits;
|
||||
$credits[ $this->amount->currency ]->amount = $credits[ $this->amount->currency ]->amount->subtract( $this->credit->amount );
|
||||
$this->member->cm_credits = $credits;
|
||||
$this->member->save();
|
||||
|
||||
$extra = $this->extra;
|
||||
$extra['history'][] = array( 's' => 'undo_credit', 'by' => \IPS\Member::loggedIn()->member_id, 'on' => time(), 'amount' => $this->credit->amount );
|
||||
if ( $this->member )
|
||||
{
|
||||
$this->member->log( 'transaction', array(
|
||||
'type' => 'undo_credit',
|
||||
'id' => $this->id,
|
||||
'amount' => $this->credit->amount,
|
||||
'currency' => $this->currency
|
||||
) );
|
||||
}
|
||||
$this->extra = $extra;
|
||||
|
||||
$this->credit = new \IPS\nexus\Money( 0, $this->currency );
|
||||
|
||||
$this->save();
|
||||
}
|
||||
|
||||
@@ -911,13 +991,13 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
elseif ( in_array( $this->status, array( static::STATUS_PAID, static::STATUS_HELD, static::STATUS_REVIEW, static::STATUS_PART_REFUNDED ) ) and \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_refund' ) )
|
||||
{
|
||||
$return['refund'] = array(
|
||||
'title' => 'transaction_refund',
|
||||
'title' => 'transaction_refund_credit',
|
||||
'icon' => 'reply',
|
||||
'link' => $url->setQueryString( array( 'do' => 'refund' ) ),
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( 'transaction_refund_title', FALSE, array( 'sprintf' => array( $this->amount ) ) ) )
|
||||
'data' => array( 'ipsDialog' => '', 'ipsDialog-title' => \IPS\Member::loggedIn()->language()->addToStack( 'transaction_refund_credit_title', FALSE, array( 'sprintf' => array( $this->amount ) ) ) )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/* Delete button */
|
||||
if ( \IPS\Member::loggedIn()->hasAcpRestriction( 'nexus', 'payments', 'transactions_delete' ) )
|
||||
{
|
||||
@@ -971,6 +1051,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
* @apiresponse int invoiceId Invoice ID Number
|
||||
* @apiresponse \IPS\nexus\Money amount Amount
|
||||
* @apiresponse \IPS\nexus\Money refundAmount If partially refunded, the amount that has been refunded
|
||||
* @apiresponse \IPS\nexus\Money credit If credited, the amount that has been credited
|
||||
* @apiresponse \IPS\nexus\Gateway gateway The gateway
|
||||
* @clientapiresponse string gatewayId Any ID number provided by the gateway to identify the transaction on their end
|
||||
* @apiresponse datetime date Date
|
||||
@@ -984,6 +1065,7 @@ class _Transaction extends \IPS\Patterns\ActiveRecord
|
||||
'invoiceId' => $this->invoice->id,
|
||||
'amount' => $this->amount->apiOutput( $authorizedMember ),
|
||||
'refundAmount' => $this->partial_refund ? $this->partial_refund->apiOutput( $authorizedMember ) : null,
|
||||
'creditAmount' => $this->credit ? $this->credit->apiOutput( $authorizedMember ) : null,
|
||||
'gateway' => $this->method ? $this->method->apiOutput( $authorizedMember ) : null,
|
||||
'gatewayId' => $this->gw_id,
|
||||
'date' => $this->date->rfc3339(),
|
||||
|
||||
Reference in new issue
Block a user