-
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 #4 from CaswellWC/master
Implemented Refund, Void, and Capture methods plus added testing
- Loading branch information
Showing
16 changed files
with
732 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
composer.lock | ||
composer.phar | ||
phpunit.xml | ||
/tests/Mock/myCredentials.json |
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,27 @@ | ||
<?php | ||
|
||
namespace Omnipay\Beanstream\Message; | ||
|
||
/** | ||
* Class CaptureRequest | ||
* | ||
* The data for this is the same as an authorization except the endpoint references the original transaction id and | ||
* complete is set to true on the card. | ||
* | ||
* @package Omnipay\Beanstream\Message | ||
*/ | ||
class CaptureRequest extends AuthorizeRequest | ||
{ | ||
/** @var bool Overwrites that same value in the AuthorizeRequest */ | ||
protected $complete = true; | ||
|
||
/** | ||
* Create the endpoint for a capture AKA a completion in Beanstream | ||
* | ||
* @return string | ||
*/ | ||
public function getEndpoint() | ||
{ | ||
return $this->endpoint . '/payments/' . $this->getTransactionReference() . '/completions'; | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Omnipay\Beanstream\Message; | ||
|
||
/** | ||
* Class RefundRequest | ||
* | ||
* @package Omnipay\Beanstream\Message | ||
*/ | ||
class RefundRequest extends AbstractRequest | ||
{ | ||
|
||
/** | ||
* Get the data for a refund | ||
*/ | ||
public function getData() | ||
{ | ||
$this->validate('amount', 'transactionReference'); | ||
|
||
return array( | ||
'amount'=>$this->getAmount(), | ||
'order_number'=>$this->getOrderNumber() | ||
); | ||
} | ||
|
||
/** | ||
* Get the endpoint for a Refund. This is overwriting the method so we can add the transaction reference dynamically | ||
* | ||
* @return string | ||
*/ | ||
public function getEndpoint() | ||
{ | ||
return $this->endpoint . '/payments/' . $this->getTransactionReference() . '/returns'; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
|
||
namespace Omnipay\Beanstream\Message; | ||
|
||
/** | ||
* Class VoidRequest | ||
* | ||
* @package Omnipay\Beanstream\Message | ||
*/ | ||
class VoidRequest extends AbstractRequest | ||
{ | ||
|
||
/** | ||
* Get the data necessary for a Void | ||
* | ||
* @return array | ||
*/ | ||
public function getData() | ||
{ | ||
$this->validate('amount', 'transactionReference'); | ||
|
||
return array( | ||
'amount'=>$this->getAmount() | ||
); | ||
} | ||
|
||
/** | ||
* Get the endpoint for a Void. This is overwriting the method so we can add the transaction reference dynamically | ||
* | ||
* @return string | ||
*/ | ||
public function getEndpoint() | ||
{ | ||
return $this->endpoint . '/payments/' . $this->getTransactionReference() . '/void'; | ||
} | ||
} |
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,165 @@ | ||
<?php | ||
|
||
namespace Omnipay\Beanstream\tests; | ||
|
||
use Omnipay\Beanstream\Gateway; | ||
use Omnipay\Tests\GatewayTestCase; | ||
|
||
/** | ||
* Class IntegrationTest | ||
* | ||
* This is an integration test class so it actually sends messages to Beanstream. This means you will need to setup a | ||
* test account with them and get your Merchant ID and API Passcode. Once you have those, you can create a new file in | ||
* the Mock folder called myCredentials.json and format it as below: | ||
* | ||
* { | ||
* "merchantId":"<Your Merchant ID here>", | ||
* "apiPasscode":"<Your Passcode here>" | ||
* } | ||
* | ||
* If that file does not exist or is not formatted in this way, all tests in this class will be skipped. | ||
* | ||
* @package Omnipay\Beanstream\tests | ||
*/ | ||
class IntegrationTest extends GatewayTestCase | ||
{ | ||
/** @var Gateway */ | ||
protected $gateway; | ||
|
||
/** | ||
* Check for the credentials file. Skips the test if the credentials file is missing or not setup correctly. Otherwise, | ||
* instantiates the gateway and sets up the credentials. | ||
*/ | ||
public function setUp() | ||
{ | ||
$merchantId = ''; | ||
$apiPasscode = ''; | ||
$credentialsFilePath = dirname(__FILE__) . '/Mock/myCredentials.json'; | ||
|
||
if(file_exists($credentialsFilePath)) { | ||
$credentialsJson = file_get_contents($credentialsFilePath); | ||
if($credentialsJson) { | ||
$credentials = json_decode($credentialsJson); | ||
$merchantId = $credentials->merchantId; | ||
$apiPasscode = $credentials->apiPasscode; | ||
} | ||
} | ||
|
||
if(empty($merchantId) || empty($apiPasscode)) { | ||
$this->markTestSkipped(); | ||
} else { | ||
$this->gateway = new Gateway(); | ||
$this->gateway->setMerchantId($merchantId); | ||
$this->gateway->setApiPasscode($apiPasscode); | ||
} | ||
} | ||
|
||
/** | ||
* Test an Authorize call followed by a capture call for that transaction | ||
*/ | ||
public function testAuthCapture() | ||
{ | ||
$card = $this->getValidCard(); | ||
$card['number'] = '4030000010001234'; | ||
$card['cvv'] = '123'; | ||
$authResponse = $this->gateway->authorize( | ||
array( | ||
'amount'=>10.00, | ||
'card'=>$card, | ||
'payment_method'=>'card' | ||
) | ||
)->send(); | ||
$this->assertTrue($authResponse->isSuccessful()); | ||
$this->assertSame('Approved', $authResponse->getMessage()); | ||
|
||
$captureResponse = $this->gateway->capture( | ||
array( | ||
'transactionReference'=>$authResponse->getTransactionReference(), | ||
'amount'=>10.00 | ||
) | ||
)->send(); | ||
|
||
$this->assertTrue($captureResponse->isSuccessful()); | ||
$this->assertSame('Approved', $captureResponse->getMessage()); | ||
} | ||
|
||
/** | ||
* Test a failed purchase transaction. The card number used below is a special one for Beanstream that always declines. | ||
*/ | ||
public function testFailedPurchase() | ||
{ | ||
$card = $this->getValidCard(); | ||
$card['number'] = '4003050500040005'; | ||
$card['cvv'] = '123'; | ||
$purchaseResponse = $this->gateway->purchase( | ||
array( | ||
'amount'=>10.00, | ||
'card'=>$card, | ||
'payment_method'=>'card' | ||
) | ||
)->send(); | ||
|
||
$this->assertFalse($purchaseResponse->isSuccessful()); | ||
$this->assertSame('DECLINE', $purchaseResponse->getMessage()); | ||
} | ||
|
||
/** | ||
* Test a purchase call followed by a refund call for that purchase | ||
*/ | ||
public function testPurchaseRefund() | ||
{ | ||
$card = $this->getValidCard(); | ||
$card['number'] = '4030000010001234'; | ||
$card['cvv'] = '123'; | ||
$purchaseResponse = $this->gateway->purchase( | ||
array( | ||
'amount'=>20.00, | ||
'card'=>$card, | ||
'payment_method'=>'card' | ||
) | ||
)->send(); | ||
|
||
$this->assertTrue($purchaseResponse->isSuccessful()); | ||
$this->assertSame('Approved', $purchaseResponse->getMessage()); | ||
|
||
$refundResponse = $this->gateway->refund( | ||
array( | ||
'amount'=>20.00, | ||
'transactionReference'=>$purchaseResponse->getTransactionReference() | ||
) | ||
)->send(); | ||
|
||
$this->assertTrue($refundResponse->isSuccessful()); | ||
$this->assertSame('Approved', $refundResponse->getMessage()); | ||
} | ||
|
||
/** | ||
* Test a purchase call followed by a void call for that purchase | ||
*/ | ||
public function testPurchaseVoid() | ||
{ | ||
$card = $this->getValidCard(); | ||
$card['number'] = '4030000010001234'; | ||
$card['cvv'] = '123'; | ||
$purchaseResponse = $this->gateway->purchase( | ||
array( | ||
'amount'=>20.00, | ||
'card'=>$card, | ||
'payment_method'=>'card' | ||
) | ||
)->send(); | ||
|
||
$this->assertTrue($purchaseResponse->isSuccessful()); | ||
$this->assertSame('Approved', $purchaseResponse->getMessage()); | ||
|
||
$voidResponse = $this->gateway->void( | ||
array( | ||
'amount'=>20.00, | ||
'transactionReference'=>$purchaseResponse->getTransactionReference() | ||
) | ||
)->send(); | ||
|
||
$this->assertTrue($voidResponse->isSuccessful()); | ||
$this->assertSame('Approved', $voidResponse->getMessage()); | ||
} | ||
} |
Oops, something went wrong.