This repository has been archived by the owner on Feb 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added methods for creating, updating, getting, and deleting cards in …
…CardConnect profiles
- Loading branch information
jmauzyk
committed
Oct 21, 2020
1 parent
96f1b3b
commit 4c1b614
Showing
15 changed files
with
379 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.