-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added void and refund functions for credit card payments.
- Loading branch information
Showing
7 changed files
with
157 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Omnipay\AuthorizeNetApi\Message; | ||
|
||
use Academe\AuthorizeNet\Amount\MoneyPhp; | ||
use Academe\AuthorizeNet\Amount\Amount; | ||
use Academe\AuthorizeNet\AmountInterface; | ||
use Academe\AuthorizeNet\Request\Transaction\Refund; | ||
use Academe\AuthorizeNet\Request\Model\Order; | ||
use Academe\AuthorizeNet\Payment\CreditCard; | ||
|
||
class RefundRequest extends CaptureRequest | ||
{ | ||
public function getData() | ||
{ | ||
$transaction = parent::getData(); | ||
|
||
$card = $this->getCard(); | ||
|
||
if ($card) { | ||
// A credit card has been supplied. | ||
|
||
if ($card->getNumber()) { | ||
$creditCard = new CreditCard( | ||
$card->getNumber(), | ||
// Either MMYY or MMYYYY will work. | ||
// (This will be overwritten with 'XXXX' for now) | ||
$card->getExpiryMonth() . $card->getExpiryYear() | ||
); | ||
|
||
$transaction = $transaction->withPayment($creditCard); | ||
} | ||
} | ||
|
||
// Instead of supplying the full credit card dtails, just | ||
// provide the lasy four digits of the card number. | ||
|
||
if ($this->getNumberLastFour()) { | ||
$creditCard = new CreditCard( | ||
$this->getNumberLastFour(), | ||
'XXXX' | ||
); | ||
|
||
$transaction = $transaction->withPayment($creditCard); | ||
} | ||
|
||
return $transaction; | ||
} | ||
|
||
protected function createTransaction(AmountInterface $amount, $refTransId) | ||
{ | ||
return new Refund($amount, $refTransId); | ||
} | ||
|
||
/** | ||
* The last four digits of the origonal credit card. | ||
*/ | ||
public function getNumberLastFour() | ||
{ | ||
return $this->getParameter('numberLastFour'); | ||
} | ||
|
||
public function setNumberLastFour($value) | ||
{ | ||
return $this->setParameter('numberLastFour', $value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Omnipay\AuthorizeNetApi\Message; | ||
|
||
use Academe\AuthorizeNet\Amount\MoneyPhp; | ||
use Academe\AuthorizeNet\Amount\Amount; | ||
use Academe\AuthorizeNet\AmountInterface; | ||
use Academe\AuthorizeNet\Request\Transaction\VoidTransaction; | ||
use Academe\AuthorizeNet\Request\Model\Order; | ||
|
||
class VoidRequest extends AbstractRequest | ||
{ | ||
/** | ||
* Return the complete message object. | ||
*/ | ||
public function getData() | ||
{ | ||
// Identify the original transaction being voided. | ||
$refTransId = $this->getTransactionReference(); | ||
|
||
$transaction = new VoidTransaction($refTransId); | ||
|
||
return $transaction; | ||
} | ||
|
||
/** | ||
* Accept a transaction and sends it as a request. | ||
* | ||
* @param $data TransactionRequestInterface | ||
* @returns CaptureResponse | ||
*/ | ||
public function sendData($data) | ||
{ | ||
$response_data = $this->sendTransaction($data); | ||
|
||
return new Response($this, $response_data); | ||
} | ||
} |