Skip to content
This repository has been archived by the owner on Feb 10, 2023. It is now read-only.

Commit

Permalink
Added user fields, added inquire request, and fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jmauzyk committed Apr 20, 2021
1 parent 217833a commit 90ad377
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ public function refund(array $parameters = [])
return $this->createRequest('\Omnipay\Cardconnect\Message\RefundRequest', $parameters);
}

/**
* Create an inquire request.
*
* @param array $parameters
* @return \Omnipay\Cardconnect\Message\InquireRequest
*/
public function inquire(array $parameters = [])
{
return $this->createRequest('\Omnipay\Cardconnect\Message\InquireRequest', $parameters);
}

/**
* Create a create card request.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public function getAcct()
return $this->getParameter('acct');
}

public function getUserfields()
{
return $this->getParameter('userfields');
}

// Setters
// =========================================================================

Expand Down Expand Up @@ -134,6 +139,11 @@ public function setAcct($value)
return $this->setParameter('acct', $value);
}

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

protected function liveEndpoint()
{
return 'https://'.$this->getApiHost().'/cardconnect/rest';
Expand Down
1 change: 1 addition & 0 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function getData()
'phone' => $card->getBillingPhone(),
'email' => $card->getEmail(),
'profile' => $this->getProfile(),
'userfields' => $this->getUserfields(),
'bin' => 'Y',
'tokenize' => 'Y',
'ecomind' => 'E'
Expand Down
2 changes: 1 addition & 1 deletion src/Message/DeleteCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function sendData($data)

public function getEndpoint($data)
{
$path = $data['profile'] . '/' . $data['acct'] . '/' . $data ['merchid'];
$path = $data['profile'] . '/' . $data['acct'] . '/' . $data['merchid'];
return $this->getEndpointBase() . '/profile/' . $path;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Message/GetCardRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function sendData($data)

public function getEndpoint($data)
{
$path = $data['profile'] . '/' . $data['acct'] . '/' . $data ['merchid'];
$path = $data['profile'] . '/' . $data['acct'] . '/' . $data['merchid'];
return $this->getEndpointBase() . '/profile/' . $path;
}

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

namespace Omnipay\Cardconnect\Message;

class InquireRequest extends AbstractRequest
{
public function getData()
{
$this->validate('transactionReference');
$data = [
'merchid' => $this->getMerchantId(),
'retref' => $this->getTransactionReference()
];
return $data;
}

public function sendData($data)
{
$authString = $this->getApiUsername() . ':' . $this->getApiPassword();
$headers = ['Authorization' => 'Basic ' . base64_encode($authString)];
$httpResponse = $this->httpClient->request('GET', $this->getEndpoint($data), $headers);
return $this->createResponse($httpResponse);
}

public function getEndpoint($data)
{
$path = $data['retref'] . '/' . $data['merchid'];
return $this->getEndpointBase() . '/inquire/' . $path;
}

protected function createResponse($data)
{
$jsonData = json_decode($data->getBody()->getContents(), true);
return $this->response = new InquireResponse($this, $jsonData);
}
}
25 changes: 25 additions & 0 deletions src/Message/InquireResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Omnipay\Cardconnect\Message;

use Omnipay\Common\Message\AbstractResponse;

/**
* Get Card Response
*
* This is the response class for CardConnect get card requests.
*
* @see \Omnipay\Cardconnect\Gateway
*/
class InquireResponse extends AbstractResponse
{
public function isSuccessful()
{
return count($this->data) && !isset($this->data['respcode']);
}

public function getMessage()
{
return isset($this->data['resptext']) ? $this->data['resptext'] : null;
}
}
9 changes: 7 additions & 2 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ class PurchaseRequest extends AbstractRequest
{
public function getData()
{
$this->validate('amount', 'card');
$this->getCard()->validate();
if ($this->getProfile()) {
$this->validate('amount');
} else {
$this->validate('amount', 'card');
$this->getCard()->validate();
}
$card = $this->getCard();
$data = [
'merchid' => $this->getMerchantId(),
Expand All @@ -27,6 +31,7 @@ public function getData()
'phone' => $card->getBillingPhone(),
'email' => $card->getEmail(),
'profile' => $this->getProfile(),
'userfields' => $this->getUserfields(),
'bin' => 'Y',
'tokenize' => 'Y',
'ecomind' => 'E',
Expand Down

0 comments on commit 90ad377

Please sign in to comment.