Skip to content

Commit

Permalink
Merge pull request #10 from caswell-wc/master
Browse files Browse the repository at this point in the history
Created messages for capture, void, and refund and created integration tests
  • Loading branch information
aperdomo authored Mar 22, 2017
2 parents 4dc978d + e3497df commit b3ad658
Show file tree
Hide file tree
Showing 20 changed files with 778 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
composer.lock
composer.phar
phpunit.xml
/tests/Mock/myCredentials.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The following gateways are provided by this package:
For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay)
repository.


## Support

If you are having general issues with Omnipay, we suggest posting on
Expand Down
30 changes: 30 additions & 0 deletions src/ConvergeGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,16 @@ public function authorize(array $parameters = array())
return $this->createRequest('\Omnipay\Elavon\Message\ConvergeAuthorizeRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\Elavon\Message\ConvergeCaptureRequest
*/
public function capture(array $parameters = array())
{
return $this->createRequest('\Omnipay\Elavon\Message\ConvergeCaptureRequest', $parameters);
}

/**
* @param array $parameters
* @return \Omnipay\Elavon\Message\ConvergePurchaseRequest
Expand All @@ -223,6 +233,26 @@ public function purchase(array $parameters = array())
return $this->createRequest('\Omnipay\Elavon\Message\ConvergePurchaseRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\Elavon\Message\ConvergeRefundRequest
*/
public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\Elavon\Message\ConvergeRefundRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\Elavon\Message\ConvergeVoidRequest
*/
public function void(array $parameters = array())
{
return $this->createRequest('\Omnipay\Elavon\Message\ConvergeVoidRequest', $parameters);
}

/**
* @param array $parameters
* @return \Omnipay\Elavon\Message\ConvergePurchaseRequest
Expand Down
35 changes: 34 additions & 1 deletion src/Message/ConvergeAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,30 @@ public function setSslLastName($value)
return $this->setParameter('ssl_last_name', $value);
}

/**
* Get the IntegrationTesting boolean value. If this is true, you can run test transactions that actually create a
* transaction in an Elavon account so you can then run tests like a refund.
*
* @return bool
*/
public function getIntegrationTesting()
{
return $this->getParameter('integrationTesting');
}

/**
* Set the IntegrationTesting boolean value. If this is true, you can run test transactions that actually create a
* transaction in an Elavon account so you can then run tests like a refund.
*
* @param bool $value
*
* @return ConvergeAbstractRequest provides a fluent interface
*/
public function setIntegrationTesting($value)
{
return $this->setParameter('integrationTesting', $value);
}

protected function createResponse($response)
{
return $this->response = new ConvergeResponse($this, $response);
Expand All @@ -324,12 +348,21 @@ protected function getBaseData()
'ssl_merchant_id' => $this->getMerchantId(),
'ssl_user_id' => $this->getUsername(),
'ssl_pin' => $this->getPassword(),
'ssl_test_mode' => ($this->getTestMode()) ? 'true' : 'false',
'ssl_test_mode' => ($this->getTestMode() && !$this->getIntegrationTesting()) ? 'true' : 'false',
'ssl_show_form' => ($this->getSslShowForm() && ($this->getSslShowForm() != 'false')) ? 'true' : 'false',
'ssl_result_format' => $this->getSslResultFormat(),
'ssl_invoice_number' => $this->getSslInvoiceNumber(),
);

return $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());
}
}
13 changes: 0 additions & 13 deletions src/Message/ConvergeAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@
* $transaction->setSslResultFormat('ASCII');
* </code>
*
* This gateway supports authorize() but does not support capture() so there is no way to capture
* a previous authorization. I am guessing that the standard procedure is to abandon the previous
* authorize and issue a purchase() request in its place.
*
* @link https://www.myvirtualmerchant.com/VirtualMerchant/
* @link https://resourcecentre.elavonpaymentgateway.com/index.php/download-developer-guide
* @see \Omnipay\Elavon\ConvergeGateway
Expand Down Expand Up @@ -148,13 +144,4 @@ public function getData()

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());
}
}
82 changes: 82 additions & 0 deletions src/Message/ConvergeCaptureRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Omnipay\Elavon\Message;

/**
* Elavon's Converge Completion Request
*
* This class processes form post requests using the Elavon/Converge gateway as documented here:
* https://resourcecentre.elavonpaymentgateway.com/index.php/download-developer-guide
*
* Also here: https://www.convergepay.com/converge-webapp/developer/#/welcome
*
* ### Test Mode
*
* In order to begin testing you will need the following parameters from Elavon/Converge:
*
* * merchantId, aka ssl_merchant_id
* * username, aka ssl_user_id
* * password, aka ssl_pin
*
* These parameters are issued for a short time only. You need to contact Converge to request an extension
* a few days before these parameters expire.
*
* ### Example
*
* #### Initialize Gateway
*
* <code>
* //
* // Put your gateway credentials here.
* //
* $credentials = array(
* 'merchantId' => '000000',
* 'username' => 'USERNAME',
* 'password' => 'PASSWORD'
* 'testMode' => true, // Or false if you want to test production mode
* );
*
* // Create a gateway object
* // (routes to GatewayFactory::create)
* $gateway = Omnipay::create('Elavon_Converge');
*
* // Initialise the gateway
* $gateway->initialize($credentials);
* </code>
*
* #### Direct Credit Card Completion
*
* <code>
* try {
* $transaction = $gateway->capture(array(
* 'amount' => '10.00',
* 'transactionReference' => '123456'
* ));
* $response = $transaction->send();
* $data = $response->getData();
* echo "Gateway capture response data == " . print_r($data, true) . "\n";
*
* if ($response->isSuccessful()) {
* echo "Capture transaction was successful!\n";
* }
* } catch (\Exception $e) {
* echo "Exception caught while attempting capture.\n";
* echo "Exception type == " . get_class($e) . "\n";
* echo "Message == " . $e->getMessage() . "\n";
* }
* </code>
*
* @link https://www.myvirtualmerchant.com/VirtualMerchant/
* @link https://resourcecentre.elavonpaymentgateway.com/index.php/download-developer-guide
* @see \Omnipay\Elavon\ConvergeGateway
*/
class ConvergeCaptureRequest extends ConvergeTransactionManage
{

protected $transactionType = 'cccomplete';

protected function manageValidate()
{
$this->validate('transactionReference', 'amount');
}
}
9 changes: 0 additions & 9 deletions src/Message/ConvergeGenerateTokenRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,4 @@ public function getData()

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());
}
}
7 changes: 1 addition & 6 deletions src/Message/ConvergePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,5 @@
*/
class ConvergePurchaseRequest extends ConvergeAuthorizeRequest
{
public function getData()
{
$this->transactionType = 'ccsale';

return parent::getData();
}
protected $transactionType = 'ccsale';
}
82 changes: 82 additions & 0 deletions src/Message/ConvergeRefundRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Omnipay\Elavon\Message;

/**
* Elavon's Converge Return Request
*
* This class processes form post requests using the Elavon/Converge gateway as documented here:
* https://resourcecentre.elavonpaymentgateway.com/index.php/download-developer-guide
*
* Also here: https://www.convergepay.com/converge-webapp/developer/#/welcome
*
* ### Test Mode
*
* In order to begin testing you will need the following parameters from Elavon/Converge:
*
* * merchantId, aka ssl_merchant_id
* * username, aka ssl_user_id
* * password, aka ssl_pin
*
* These parameters are issued for a short time only. You need to contact Converge to request an extension
* a few days before these parameters expire.
*
* ### Example
*
* #### Initialize Gateway
*
* <code>
* //
* // Put your gateway credentials here.
* //
* $credentials = array(
* 'merchantId' => '000000',
* 'username' => 'USERNAME',
* 'password' => 'PASSWORD'
* 'testMode' => true, // Or false if you want to test production mode
* );
*
* // Create a gateway object
* // (routes to GatewayFactory::create)
* $gateway = Omnipay::create('Elavon_Converge');
*
* // Initialise the gateway
* $gateway->initialize($credentials);
* </code>
*
* #### Direct Credit Card Completion
*
* <code>
* try {
* $transaction = $gateway->refund(array(
* 'amount' => '10.00',
* 'transactionReference' => '123456'
* ));
* $response = $transaction->send();
* $data = $response->getData();
* echo "Gateway capture response data == " . print_r($data, true) . "\n";
*
* if ($response->isSuccessful()) {
* echo "Capture transaction was successful!\n";
* }
* } catch (\Exception $e) {
* echo "Exception caught while attempting capture.\n";
* echo "Exception type == " . get_class($e) . "\n";
* echo "Message == " . $e->getMessage() . "\n";
* }
* </code>
*
* @link https://www.myvirtualmerchant.com/VirtualMerchant/
* @link https://resourcecentre.elavonpaymentgateway.com/index.php/download-developer-guide
* @see \Omnipay\Elavon\ConvergeGateway
*/
class ConvergeRefundRequest extends ConvergeTransactionManage
{

protected $transactionType = 'ccreturn';

protected function manageValidate()
{
$this->validate('transactionReference', 'amount');
}
}
36 changes: 36 additions & 0 deletions src/Message/ConvergeTransactionManage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Omnipay\Elavon\Message;

/**
* Class ConvergeTransactionManage
*
* This is a base class used in requests that manage an existing transaction
*
* @package Omnipay\Elavon\Message
*/
abstract class ConvergeTransactionManage extends ConvergeAbstractRequest
{

protected $transactionType;

/**
* Get the data needed for a transaction modification
*
* @return array
*/
public function getData()
{
$this->manageValidate();

$data = array(
'ssl_transaction_type'=>$this->transactionType,
'ssl_txn_id'=>$this->getTransactionReference(),
'ssl_amount'=>$this->getAmount()
);

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

abstract protected function manageValidate();
}
Loading

0 comments on commit b3ad658

Please sign in to comment.