Skip to content

Update pin gateway to add support for purchasing with card tokens #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Omnipay/Pin/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public function getData()
$data['currency'] = strtolower($this->getCurrency());
$data['description'] = $this->getDescription();
$data['ip_address'] = $this->getClientIp();
$data['email'] = $this->getCard()->getEmail();

if ($this->getCard()) {
if ($this->getToken()) {
$data['card_token'] = $this->getToken();
} elseif ($this->getCard()) {
$this->getCard()->validate();

$data['card']['number'] = $this->getCard()->getNumber();
Expand All @@ -55,7 +58,6 @@ public function getData()
$data['card']['address_postcode'] = $this->getCard()->getPostcode();
$data['card']['address_state'] = $this->getCard()->getState();
$data['card']['address_country'] = $this->getCard()->getCountry();
$data['email'] = $this->getCard()->getEmail();
}

return $data;
Expand Down
60 changes: 60 additions & 0 deletions tests/Omnipay/Pin/Message/PurchaseRequestTest.php
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());
}
}