Skip to content

Commit

Permalink
Merge pull request #2 from dranes/1.1.0
Browse files Browse the repository at this point in the history
Add support for echeck (ach)
  • Loading branch information
dranes authored Nov 28, 2018
2 parents bc08080 + ddc3193 commit 0fd7814
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 13 deletions.
16 changes: 13 additions & 3 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function setTerminalId($value)
* the Bank Account method or the Credit Card method.
*
* @param array|array $parameters
* @return \Omnipay\Paysimple\Message\Response
* @return \Omnipay\Ippay\Message\Response
*/
public function purchase(array $parameters = array())
{
Expand All @@ -53,13 +53,23 @@ public function purchase(array $parameters = array())
* Create Credit Card Request
*
* Create a Credit Card and associate with a customer it's important
* to save the transaction reference to ue it later on purchase request.
* to save the transaction reference to use it later on purchase request.
*
* @param array|array $parameters
* @return \Omnipay\Paysimple\Message\Response
* @return \Omnipay\Ippay\Message\Response
*/
public function createCard(array $parameters = array())
{
return $this->createRequest('\Omnipay\Ippay\Message\CreateCardRequest', $parameters);
}

/**
* Create Bank Account Request
*
*/

public function createBankAccount(array $parameters = array())
{
return $this->createRequest('\Omnipay\Ippay\Message\CreateBankAccountRequest', $parameters);
}
}
43 changes: 36 additions & 7 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ public function getHeaders()
public function send()
{
$data = $this->getData();
$xml = null;
foreach($data as $node => $value) {
$xml .= "<{$node}>{$value}</{$node}>";

if($data['TransactionType'] == 'CHECK') {
$xml = $this->dataCheck($data);
} else {
$xml = $this->dataSale($data);
}

$xml .= "<TerminalID>" . $this->getTerminalId() . "</TerminalID>";
$xml = "<ippay>" . $xml . "</ippay>";

$headers = array_merge(
$this->getHeaders(),
Expand All @@ -46,6 +45,36 @@ public function send()
return $this->sendData($xml, $headers);
}

public function dataCheck($data)
{
$xml = '';
$xml .= "<TransactionType>CHECK</TransactionType>";
$xml .= "<TerminalID>" . $this->getTerminalId() . "</TerminalID>";
$xml .= "<CardName>" . $data['BankName'] . "</CardName>";
$xml .= "<TotalAmount>" . $data['TotalAmount'] . "</TotalAmount>";
$xml .= "<ACH Type='" . $data['Type'] . "' SEC='" . $data['SEC'] . "'>";
$xml .= "<Token>" . $data['Token'] . "</Token>";
$xml .= "<CheckNumber>" . $data['CheckNumber'] . "</CheckNumber>";
$xml .= "</ACH>";
$xml = "<ippay>" . $xml . "</ippay>";

return $xml;
}

public function dataSale($data)
{

$xml = null;
foreach($data as $node => $value) {
$xml .= "<{$node}>{$value}</{$node}>";
}

$xml .= "<TerminalID>" . $this->getTerminalId() . "</TerminalID>";
$xml = "<ippay>" . $xml . "</ippay>";

return $xml;
}

public function sendData($data, array $headers = [])
{

Expand All @@ -55,7 +84,7 @@ public function sendData($data, array $headers = [])
$headers,
$data
);

return (new Response($this, $httpResponse->getBody()->getContents()));
}

Expand Down
37 changes: 37 additions & 0 deletions src/Message/CreateBankAccountRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Omnipay\Ippay\Message;

class CreateBankAccountRequest extends AbstractRequest
{

public function getAccountNumber()
{
return $this->getParameter('AccountNumber');
}

public function setAccountNumber($value)
{
return $this->setParameter('AccountNumber', $value);
}

public function getRoutingNumber()
{
return $this->getParameter('RoutingNumber');
}

public function setRoutingNumber($value)
{
return $this->setParameter('RoutingNumber', $value);
}

public function getData()
{
$data = array();
$data['TransactionType'] = 'TOKENIZE';
$data['AccountNumber'] = $this->getAccountNumber();
$data['ABA'] = $this->getRoutingNumber();

return $data;
}
}
56 changes: 55 additions & 1 deletion src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,68 @@ public function setAmount($value)
return $this->setParameter('amount', $value);
}

public function getSEC()
{
return $this->getParameter('sec');
}

public function setSEC($value)
{
return $this->setParameter('sec', $value);
}

public function getType()
{
return $this->getParameter('type');
}

public function setType($value)
{
return $this->setParameter('type', $value);
}

public function getCheckNumber()
{
return $this->getParameter('check_number');
}

public function setCheckNumber($value)
{
return $this->setParameter('check_number', $value);
}

public function getTransactionType()
{
return $this->getParameter('transaction_type');
}

public function setTransactionType($value)
{
return $this->setParameter('transaction_type', $value);
}

public function getBankName()
{
return $this->getParameter('bank_name');
}

public function setBankName($value)
{
return $this->setParameter('bank_name', $value);
}

public function getData()
{

$data = array();

$data['TransactionType'] = 'SALE';
$data['TransactionType'] = $this->getTransactionType();
$data['Token'] = $this->getToken();
$data['TotalAmount'] = number_format($this->getAmount(), 2, "", "");
$data['SEC'] = $this->getSEC();
$data['CheckNumber'] = $this->getCheckNumber();
$data['Type'] = $this->getType();
$data['BankName'] = $this->getBankName();

return $data;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Message/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public function isCancelled()

public function getMessage()
{
$response = new \SimpleXMLElement($this->response);
return $response->ResponseText;
return $this->response;
}

public function getCode()
Expand Down

0 comments on commit 0fd7814

Please sign in to comment.