Skip to content

Commit

Permalink
Merge pull request #5 from barrycarrjr/master
Browse files Browse the repository at this point in the history
Added credit card token functionality
  • Loading branch information
aperdomo authored Sep 27, 2016
2 parents 2885db1 + 862b900 commit f4b6546
Show file tree
Hide file tree
Showing 9 changed files with 218 additions and 19 deletions.
9 changes: 9 additions & 0 deletions src/ConvergeGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\Elavon\Message\ConvergePurchaseRequest', $parameters);
}

/**
* @param array $parameters
* @return \Omnipay\Elavon\Message\PurchaseRequest
*/
public function createCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Elavon\Message\ConvergeGenerateTokenRequest', $parameters);
}
}
53 changes: 34 additions & 19 deletions src/Message/ConvergeAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,41 @@ class ConvergeAuthorizeRequest extends ConvergeAbstractRequest

public function getData()
{
$this->validate('amount', 'card');
$this->getCard()->validate();
if ($this->getCard() != null) {
$this->validate('amount', 'card');
$this->getCard()->validate();

$data = array(
'ssl_amount' => $this->getAmount(),
'ssl_salestax' => $this->getSslSalesTax(),
'ssl_transaction_type' => $this->transactionType,
'ssl_card_number' => $this->getCard()->getNumber(),
'ssl_exp_date' => $this->getCard()->getExpiryDate('my'),
'ssl_cvv2cvc2' => $this->getCard()->getCvv(),
'ssl_cvv2cvc2_indicator' => ($this->getCard()->getCvv()) ? 1 : 0,
'ssl_first_name' => $this->getCard()->getFirstName(),
'ssl_last_name' => $this->getCard()->getLastName(),
'ssl_avs_address' => $this->getCard()->getAddress1(),
'ssl_address2' => $this->getCard()->getAddress2(),
'ssl_city' => $this->getCard()->getCity(),
'ssl_state' => $this->getCard()->getState(),
'ssl_country' => $this->getCard()->getCountry(),
'ssl_avs_zip' => $this->getCard()->getPostcode()
);
$data = array(
'ssl_amount' => $this->getAmount(),
'ssl_salestax' => $this->getSslSalesTax(),
'ssl_transaction_type' => $this->transactionType,
'ssl_card_number' => $this->getCard()->getNumber(),
'ssl_exp_date' => $this->getCard()->getExpiryDate('my'),
'ssl_cvv2cvc2' => $this->getCard()->getCvv(),
'ssl_cvv2cvc2_indicator' => ($this->getCard()->getCvv()) ? 1 : 0,
'ssl_first_name' => $this->getCard()->getFirstName(),
'ssl_last_name' => $this->getCard()->getLastName(),
'ssl_avs_address' => $this->getCard()->getAddress1(),
'ssl_address2' => $this->getCard()->getAddress2(),
'ssl_city' => $this->getCard()->getCity(),
'ssl_state' => $this->getCard()->getState(),
'ssl_country' => $this->getCard()->getCountry(),
'ssl_customer_code' => $this->getDescription(),
'ssl_avs_zip' => $this->getCard()->getPostcode()
);
} elseif ($this->getCardReference() != null) {
$this->validate('amount');

$data = array(
'ssl_show_form' => 'false',
'ssl_result_format' => 'ASCII',
'ssl_amount' => $this->getAmount(),
'ssl_salestax' => $this->getSslSalesTax(),
'ssl_transaction_type' => $this->transactionType,
'ssl_token' => $this->getCardReference(),
'ssl_customer_code' => $this->getDescription(),
);
}

return array_merge($this->getBaseData(), $data);
}
Expand Down
45 changes: 45 additions & 0 deletions src/Message/ConvergeGenerateTokenRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php namespace Omnipay\Elavon\Message;

class ConvergeGenerateTokenRequest extends ConvergeAbstractRequest
{
protected $transactionType = 'ccgettoken';

public function getData()
{
$data = array(
'ssl_transaction_type' => $this->transactionType,
'ssl_amount' => $this->getAmount(),
'ssl_salestax' => $this->getSslSalesTax(),

'ssl_card_number' => $this->getCard()->getNumber(),
'ssl_exp_date' => $this->getCard()->getExpiryDate('my'),
'ssl_cvv2cvc2' => $this->getCard()->getCvv(),
'ssl_cvv2cvc2_indicator' => ($this->getCard()->getCvv()) ? 1 : 0,

'ssl_verify' => 'N',

'ssl_first_name' => $this->getCard()->getFirstName(),
'ssl_last_name' => $this->getCard()->getLastName(),
'ssl_avs_address' => $this->getCard()->getAddress1(),
'ssl_address2' => $this->getCard()->getAddress2(),
'ssl_city' => $this->getCard()->getCity(),
'ssl_state' => $this->getCard()->getState(),
'ssl_country' => $this->getCard()->getCountry(),
'ssl_add_token' => 'Y',

'ssl_show_form' => 'false',
'ssl_result_format' => 'ASCII',
);

return array_merge($this->getBaseData(), $data);
}

public function sendData($data)
{
$httpResponse = $this->httpClient->post($this->getEndpoint() . '/process.do', null, http_build_query($data))
->setHeader('Content-Type', 'application/x-www-form-urlencoded')
->send();

return $this->createResponse($httpResponse->getBody());
}
}
5 changes: 5 additions & 0 deletions src/Message/ConvergeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ public function getCode()

return $this->data['ssl_result'];
}

public function getCardToken()
{
return (isset($this->data['ssl_token'])) ? $this->data['ssl_token'] : null;
}
}
26 changes: 26 additions & 0 deletions tests/ConvergeGatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,30 @@ public function testPurchase()
$this->assertSame('testpassword1', $request->getPassword());
$this->assertSame('USD', $request->getCurrency());
}

public function testPurchaseChargeCard()
{
$request = $this->gateway->purchase(array(
'amount' => 10.00,
'token' => '7595301425001111',
'ssl_show_form' => 'false',
'ssl_result_format' => 'ASCII',
'merchantId' => 'testmerchant1',
'username' => 'testusername1',
'password' => 'testpassword1',
'currency' => 'USD'
));

$this->assertInstanceOf('Omnipay\Elavon\Message\ConvergePurchaseRequest', $request);
$this->assertSame('10.00', (string) $request->getAmount());
$this->assertSame('false', (string) $request->getSslShowForm());
$this->assertSame('ASCII', (string) $request->getSslResultFormat());
$this->assertSame('testmerchant1', $request->getMerchantId());
$this->assertSame('testusername1', $request->getUsername());
$this->assertSame('testpassword1', $request->getPassword());
$this->assertSame('testpassword1', $request->getPassword());
$this->assertSame('USD', $request->getCurrency());
}


}
28 changes: 28 additions & 0 deletions tests/Message/ConvergeGenerateTokenRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php namespace Omnipay\Elavon\Message;

use Omnipay\Tests\TestCase;

class ConvergeGenerateTokenRequestTest extends TestCase
{
public function setUp()
{
$this->request = new ConvergeGenerateTokenRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'card' => $this->getValidCard(),
'ssl_show_form' => 'false',
'ssl_result_format' => 'ASCII',
)
);
}

public function testCreateCardSuccess()
{
$this->setMockHttpResponse('ConvergeCreateCardResponse.txt');
$response = $this->request->send();
$this->assertTrue($response->isSuccessful());
$this->assertSame('7595301425001111', $response->getCardToken());
}

}

27 changes: 27 additions & 0 deletions tests/Message/ConvergePurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,31 @@ public function testPurchaseNoPIN()
$this->assertSame('The PIN was not supplied in the authorization request.', $response->getMessage());
$this->assertSame('4013', $response->getCode());
}

public function testPurchaseChargeCardToken()
{
$this->setMockHttpResponse('ConvergePurchaseCreditCardToken.txt');

$request = new ConvergePurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$request->initialize(
array(
'amount' => 10.00,
'token' => '7595301425001111',
'cardReference' => '7595301425001111',
'ssl_show_form' => 'false',
'ssl_result_format' => 'ASCII',
'merchantId' => 'testmerchant1',
'username' => 'testusername1',
'password' => 'testpassword1',
'currency' => 'USD'
)
);

$response = $request->send();
$this->assertTrue($response->isSuccessful());
$this->assertSame('APPROVED', $response->getMessage());
$this->assertSame('0', $response->getCode());
$this->assertSame('00000000-0000-0000-0000-00000000000', $response->getTransactionReference());
}

}
13 changes: 13 additions & 0 deletions tests/Mock/ConvergeCreateCardResponse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
HTTP/1.1 200 OK
Date: Wed, 20 Feb 2013 13:55:50 GMT
Server: Apache
Content-Length: 214
Connection: close
Content-Type: text/plain; charset=utf-8

ssl_status=TEST MODE
ssl_result=0
ssl_token=7595301425001111
ssl_card_number=41**********1111
ssl_token_response=SUCCESS
ssl_add_token_response=Card Updated
31 changes: 31 additions & 0 deletions tests/Mock/ConvergePurchaseCreditCardToken.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
HTTP/1.1 200 OK
Date: Wed, 20 Feb 2013 13:55:50 GMT
Server: Apache
Content-Length: 214
Connection: close
Content-Type: text/plain; charset=utf-8

ssl_status=TEST MODE
ssl_card_number=41**********1111
ssl_exp_date=0117
ssl_amount=10.00
ssl_salestax=1.23
ssl_invoice_number=1
ssl_departure_date=
ssl_completion_date=
ssl_issue_points=
ssl_promo_code=
ssl_enrollment=
ssl_result=0
ssl_result_message=APPROVED
ssl_txn_id=00000000-0000-0000-0000-00000000000
ssl_approval_code=123456
ssl_cvv2_response=P
ssl_avs_response=X
ssl_account_balance=0.00
ssl_txn_time=05/13/2015 07:21:58 PM
ssl_loyalty_account_balance=
ssl_loyalty_program=
ssl_access_code=
ssl_tender_amount=
ssl_account_status=

0 comments on commit f4b6546

Please sign in to comment.