-
-
Notifications
You must be signed in to change notification settings - Fork 929
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update pin gateway to add support for purchasing with card tokens fro…
…m Pin.js. Closes #128
- Loading branch information
1 parent
040938d
commit 4f5e822
Showing
2 changed files
with
65 additions
and
3 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,60 @@ | ||
<?php | ||
|
||
namespace Omnipay\Pin\Message; | ||
|
||
use Omnipay\TestCase; | ||
|
||
class PurchaseRequestTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); | ||
$this->request->initialize( | ||
array( | ||
'amount' => '10.00', | ||
'currency' => 'AUD', | ||
'card' => $this->getValidCard(), | ||
) | ||
); | ||
} | ||
|
||
public function testDataWithToken() | ||
{ | ||
$this->request->setToken('abc'); | ||
$data = $this->request->getData(); | ||
|
||
$this->assertSame('abc', $data['card_token']); | ||
} | ||
|
||
public function testDataWithCard() | ||
{ | ||
$card = $this->getValidCard(); | ||
$this->request->setCard($card); | ||
$data = $this->request->getData(); | ||
|
||
$this->assertSame($card['number'], $data['card']['number']); | ||
} | ||
|
||
public function testSendSuccess() | ||
{ | ||
$this->setMockHttpResponse('PurchaseSuccess.txt'); | ||
|
||
$response = $this->request->send(); | ||
|
||
$this->assertTrue($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertEquals('ch_fXIxWf0gj1yFHJcV1W-d-w', $response->getTransactionReference()); | ||
$this->assertSame('Success!', $response->getMessage()); | ||
} | ||
|
||
public function testSendError() | ||
{ | ||
$this->setMockHttpResponse('PurchaseFailure.txt'); | ||
$response = $this->request->send(); | ||
|
||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertFalse($response->isRedirect()); | ||
$this->assertNull($response->getTransactionReference()); | ||
$this->assertSame('The current resource was deemed invalid.', $response->getMessage()); | ||
} | ||
} |