-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ravloony/master
add refund capability and referenced purchase.
- Loading branch information
Showing
5 changed files
with
133 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Omnipay\CardSave\Message; | ||
|
||
/** | ||
* CardSave Purchase Request | ||
*/ | ||
class ReferencedPurchaseRequest extends RefundRequest | ||
{ | ||
public $transactionType = 'SALE'; | ||
} |
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\CardSave\Message; | ||
|
||
use DOMDocument; | ||
use SimpleXMLElement; | ||
|
||
/** | ||
* CardSave Purchase Request | ||
*/ | ||
class RefundRequest extends PurchaseRequest | ||
{ | ||
public $transactionType = 'REFUND'; | ||
|
||
public function getData() | ||
{ | ||
$this->validate('transactionReference', 'amount', 'currency'); | ||
|
||
$data = new SimpleXMLElement('<CrossReferenceTransaction/>'); | ||
$data->addAttribute('xmlns', $this->namespace); | ||
|
||
$data->PaymentMessage->MerchantAuthentication['MerchantID'] = $this->getMerchantId(); | ||
$data->PaymentMessage->MerchantAuthentication['Password'] = $this->getPassword(); | ||
$data->PaymentMessage->TransactionDetails['Amount'] = $this->getAmountInteger(); | ||
$data->PaymentMessage->TransactionDetails['CurrencyCode'] = $this->getCurrencyNumeric(); | ||
$data->PaymentMessage->TransactionDetails->OrderID = $this->getTransactionId(); | ||
$data->PaymentMessage->TransactionDetails->OrderDescription = $this->getDescription(); | ||
$data->PaymentMessage->TransactionDetails->MessageDetails['TransactionType'] = $this->transactionType; | ||
$data->PaymentMessage->TransactionDetails->MessageDetails['NewTransaction'] = false; | ||
$data->PaymentMessage->TransactionDetails->MessageDetails['CrossReference'] = $this->getTransactionReference(); | ||
|
||
// requires numeric country code | ||
// $data->PaymentMessage->CustomerDetails->BillingAddress->CountryCode = $this->getCard()->getCountryNumeric; | ||
$data->PaymentMessage->CustomerDetails->CustomerIPAddress = $this->getClientIp(); | ||
|
||
return $data; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace Omnipay\CardSave\Message; | ||
|
||
use Omnipay\Tests\TestCase; | ||
|
||
class ReferencedPurchaseRequestTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->request = new ReferencedPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->initialize( | ||
array( | ||
'amount' => '12.00', | ||
'transactionReference' => '0987654345678900987654', | ||
'currency' => 'GBP', | ||
'testMode' => true, | ||
) | ||
); | ||
} | ||
|
||
public function testGetData() | ||
{ | ||
$data = $this->request->getData(); | ||
|
||
/* | ||
* See https://bugs.php.net/bug.php?id=29500 for why this is cast to string | ||
*/ | ||
$this->assertSame('SALE', (string)$data->PaymentMessage->TransactionDetails->MessageDetails['TransactionType']); | ||
$this->assertSame('1200', (string)$data->PaymentMessage->TransactionDetails['Amount']); | ||
$this->assertSame('826', (string)$data->PaymentMessage->TransactionDetails['CurrencyCode']); | ||
$this->assertSame('0987654345678900987654', (string)$data->PaymentMessage->TransactionDetails->MessageDetails['CrossReference']); | ||
} | ||
|
||
} |
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,37 @@ | ||
<?php | ||
|
||
namespace Omnipay\CardSave\Message; | ||
|
||
use Omnipay\Tests\TestCase; | ||
|
||
class RefundRequestTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->initialize( | ||
array( | ||
'amount' => '12.00', | ||
'transactionReference' => '0987654345678900987654', | ||
'currency' => 'GBP', | ||
'testMode' => true, | ||
) | ||
); | ||
} | ||
|
||
public function testGetData() | ||
{ | ||
$data = $this->request->getData(); | ||
|
||
/* | ||
* See https://bugs.php.net/bug.php?id=29500 for why this is cast to string | ||
*/ | ||
$this->assertSame('REFUND', (string)$data->PaymentMessage->TransactionDetails->MessageDetails['TransactionType']); | ||
$this->assertSame('1200', (string)$data->PaymentMessage->TransactionDetails['Amount']); | ||
$this->assertSame('826', (string)$data->PaymentMessage->TransactionDetails['CurrencyCode']); | ||
$this->assertSame('0987654345678900987654', (string)$data->PaymentMessage->TransactionDetails->MessageDetails['CrossReference']); | ||
} | ||
|
||
} |