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

Commit

Permalink
Added methods for creating, updating, getting, and deleting cards in …
Browse files Browse the repository at this point in the history
…CardConnect profiles
  • Loading branch information
jmauzyk committed Oct 21, 2020
1 parent 96f1b3b commit 4c1b614
Show file tree
Hide file tree
Showing 15 changed files with 379 additions and 11 deletions.
46 changes: 45 additions & 1 deletion src/Gateway.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Gateway extends AbstractGateway

public function getName()
{
return 'Cardconnect';
return 'CardConnect';
}

public function getMerchantId()
Expand Down Expand Up @@ -136,4 +136,48 @@ public function refund(array $parameters = [])
{
return $this->createRequest('\Omnipay\Cardconnect\Message\RefundRequest', $parameters);
}

/**
* Create a create card request.
*
* @param array $parameters
* @return \Omnipay\Cardconnect\Message\CreateCardRequest
*/
public function createCard(array $parameters = [])
{
return $this->createRequest('\Omnipay\Cardconnect\Message\CreateCardRequest', $parameters);
}

/**
* Create a update card request.
*
* @param array $parameters
* @return \Omnipay\Cardconnect\Message\UpdateCardRequest
*/
public function updateCard(array $parameters = [])
{
return $this->createRequest('\Omnipay\Cardconnect\Message\UpdateCardRequest', $parameters);
}

/**
* Create a update card request.
*
* @param array $parameters
* @return \Omnipay\Cardconnect\Message\GetCardRequest
*/
public function getCard(array $parameters = [])
{
return $this->createRequest('\Omnipay\Cardconnect\Message\GetCardRequest', $parameters);
}

/**
* Create a delete card request.
*
* @param array $parameters
* @return \Omnipay\Cardconnect\Message\DeleteCardRequest
*/
public function deleteCard(array $parameters = [])
{
return $this->createRequest('\Omnipay\Cardconnect\Message\DeleteCardRequest', $parameters);
}
}
60 changes: 60 additions & 0 deletions src/Message/AbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,36 @@ public function getOrderId()
return $this->getParameter('orderId');
}

public function getProfile()
{
return $this->getParameter('profile');
}

public function getDefaultacct()
{
return $this->getParameter('defaultacct');
}

public function getProfileupdate()
{
return $this->getParameter('profileupdate');
}

public function getAuoptout()
{
return $this->getParameter('auoptout');
}

public function getAccttype()
{
return $this->getParameter('accttype');
}

public function getAcct()
{
return $this->getParameter('acct');
}

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

Expand Down Expand Up @@ -74,6 +104,36 @@ public function setOrderId($value)
return $this->setParameter('orderId', $value);
}

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

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

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

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

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

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

protected function liveEndpoint()
{
return 'https://'.$this->getApiHost().'/cardconnect/rest';
Expand Down
13 changes: 9 additions & 4 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ class AuthorizeRequest 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 @@ -22,10 +26,11 @@ public function getData()
'address2' => $card->getBillingAddress2(),
'city' => $card->getBillingCity(),
'region' => $card->getBillingState(),
'country' => $card->getBillingCountry(),
'postal' => $card->getBillingPostcode(),
'email' => $card->getEmail(),
'country' => $card->getBillingCountry(),
'phone' => $card->getBillingPhone(),
'email' => $card->getEmail(),
'profile' => $this->getProfile(),
'bin' => 'Y',
'tokenize' => 'Y',
'ecomind' => 'E'
Expand Down
Empty file modified src/Message/CaptureRequest.php
100755 → 100644
Empty file.
44 changes: 44 additions & 0 deletions src/Message/CreateCardRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Omnipay\Cardconnect\Message;

class CreateCardRequest extends AbstractRequest
{
public function getData()
{
$this->validate('card');
$this->getCard()->validate();
$card = $this->getCard();
$data = [
'profile' => $this->getProfile(),
'defaultacct' => $this->getDefaultacct(),
'profileupdate' => $this->getProfileupdate(),
'auoptout' => $this->getAuoptout(),
'accttype' => $this->getAccttype(),
'merchid' => $this->getMerchantId(),
'account' => $card->getNumber(),
'expiry' => $card->getExpiryDate('my'),
'name' => $card->getName(),
'company' => $card->getCompany(),
'address' => $card->getBillingAddress1(),
'city' => $card->getBillingCity(),
'region' => $card->getBillingState(),
'postal' => $card->getBillingPostcode(),
'country' => $card->getBillingCountry(),
'phone' => $card->getBillingPhone(),
'email' => $card->getEmail()
];
return $data;
}

public function getEndpoint()
{
return $this->getEndpointBase() . '/profile/';
}

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

namespace Omnipay\Cardconnect\Message;

use Omnipay\Common\Message\AbstractResponse;

/**
* Create/Update Card Response
*
* This is the response class for CardConnect create and update card requests.
*
* @see \Omnipay\Cardconnect\Gateway
*/
class CreateUpdateCardResponse extends AbstractResponse
{
public function isSuccessful()
{
return isset($this->data['respcode']) && $this->data['respcode'] == '09';
}

public function getProfileId()
{
return isset($this->data['profileid']) ? $this->data['profileid'] : null;
}

public function getAcctId()
{
return isset($this->data['acctid']) ? $this->data['acctid'] : null;
}

public function getMessage()
{
return isset($this->data['resptext']) ? $this->data['resptext'] : null;
}
}
40 changes: 40 additions & 0 deletions src/Message/DeleteCardRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Omnipay\Cardconnect\Message;

class DeleteCardRequest extends AbstractRequest
{
public function getData()
{
$this->validate('profile');
$data = [
'profile' => $this->getProfile(),
'acct' => $this->getAcct(),
'merchid' => $this->getMerchantId()
];
return $data;
}

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

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

protected function createResponse($data)
{
$jsonData = json_decode($data->getBody()->getContents(), true);
return $this->response = new DeleteCardResponse($this, $jsonData);
}
}
25 changes: 25 additions & 0 deletions src/Message/DeleteCardResponse.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;

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

public function getMessage()
{
return isset($this->data['resptext']) ? $this->data['resptext'] : null;
}
}
37 changes: 37 additions & 0 deletions src/Message/GetCardRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Omnipay\Cardconnect\Message;

class GetCardRequest extends AbstractRequest
{
public function getData()
{
$this->validate('profile');
$data = [
'profile' => $this->getProfile(),
'acct' => $this->getAcct(),
'merchid' => $this->getMerchantId()
];
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['profile'] . '/' . $data['acct'] . '/' . $data ['merchid'];
return $this->getEndpointBase() . '/profile/' . $path;
}

protected function createResponse($data)
{
$jsonData = json_decode($data->getBody()->getContents(), true);
return $this->response = new GetCardResponse($this, $jsonData);
}
}
30 changes: 30 additions & 0 deletions src/Message/GetCardResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?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 GetCardResponse extends AbstractResponse
{
public function isSuccessful()
{
return count($this->data) && !isset($this->data[0]['respcode']);
}

public function isDefaultAcct()
{
return count($this->data) === 1 && isset($this->data[0]['defaultacct']) ? $this->data[0]['defaultacct'] === 'Y' : null;
}

public function getMessage()
{
return isset($this->data[0]['resptext']) ? $this->data[0]['resptext'] : null;
}
}
6 changes: 4 additions & 2 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ public function getData()
'address2' => $card->getBillingAddress2(),
'city' => $card->getBillingCity(),
'region' => $card->getBillingState(),
'country' => $card->getBillingCountry(),
'postal' => $card->getBillingPostcode(),
'email' => $card->getEmail(),
'country' => $card->getBillingCountry(),
'phone' => $card->getBillingPhone(),
'email' => $card->getEmail(),
'profile' => $this->getProfile(),
'bin' => 'Y',
'tokenize' => 'Y',
'ecomind' => 'E',
'capture' => 'Y'
];

return $data;
}

Expand Down
Empty file modified src/Message/RefundRequest.php
100755 → 100644
Empty file.
Loading

0 comments on commit 4c1b614

Please sign in to comment.