From 90ad377510d5fb0e7dec5246a7a64b11f46299e2 Mon Sep 17 00:00:00 2001 From: jmauzyk Date: Tue, 20 Apr 2021 17:48:26 -0600 Subject: [PATCH] Added user fields, added inquire request, and fixed bugs --- src/Gateway.php | 11 ++++++++++ src/Message/AbstractRequest.php | 10 +++++++++ src/Message/AuthorizeRequest.php | 1 + src/Message/DeleteCardRequest.php | 2 +- src/Message/GetCardRequest.php | 2 +- src/Message/InquireRequest.php | 36 +++++++++++++++++++++++++++++++ src/Message/InquireResponse.php | 25 +++++++++++++++++++++ src/Message/PurchaseRequest.php | 9 ++++++-- 8 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/Message/InquireRequest.php create mode 100644 src/Message/InquireResponse.php diff --git a/src/Gateway.php b/src/Gateway.php index 8d63244..092685e 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -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. * diff --git a/src/Message/AbstractRequest.php b/src/Message/AbstractRequest.php index f9cc650..c4963d1 100644 --- a/src/Message/AbstractRequest.php +++ b/src/Message/AbstractRequest.php @@ -71,6 +71,11 @@ public function getAcct() return $this->getParameter('acct'); } + public function getUserfields() + { + return $this->getParameter('userfields'); + } + // Setters // ========================================================================= @@ -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'; diff --git a/src/Message/AuthorizeRequest.php b/src/Message/AuthorizeRequest.php index e7420b3..ee88dcb 100644 --- a/src/Message/AuthorizeRequest.php +++ b/src/Message/AuthorizeRequest.php @@ -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' diff --git a/src/Message/DeleteCardRequest.php b/src/Message/DeleteCardRequest.php index e12c993..103420b 100644 --- a/src/Message/DeleteCardRequest.php +++ b/src/Message/DeleteCardRequest.php @@ -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; } diff --git a/src/Message/GetCardRequest.php b/src/Message/GetCardRequest.php index 28138f7..c60886a 100644 --- a/src/Message/GetCardRequest.php +++ b/src/Message/GetCardRequest.php @@ -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; } diff --git a/src/Message/InquireRequest.php b/src/Message/InquireRequest.php new file mode 100644 index 0000000..914ce8f --- /dev/null +++ b/src/Message/InquireRequest.php @@ -0,0 +1,36 @@ +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); + } +} diff --git a/src/Message/InquireResponse.php b/src/Message/InquireResponse.php new file mode 100644 index 0000000..3435eaa --- /dev/null +++ b/src/Message/InquireResponse.php @@ -0,0 +1,25 @@ +data) && !isset($this->data['respcode']); + } + + public function getMessage() + { + return isset($this->data['resptext']) ? $this->data['resptext'] : null; + } +} diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 26c5561..c490432 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -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(), @@ -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',