-
Notifications
You must be signed in to change notification settings - Fork 9
New Netbanx Hosted Payments API Support #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
lukeholder
wants to merge
11
commits into
thephpleague:master
from
pixelandtonic:feature/hosted-gateway
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
767c1eb
Hosted Gateway API Support
lukeholder f387c69
Code Formatting
lukeholder b71ccb0
Spaces not tabs
lukeholder 0e60eb0
psr2
lukeholder 1326153
psr2
lukeholder 7f7396e
Line length fix
lukeholder 058f9e0
PHP 5.3 compatibility
lukeholder 0c33d2b
ignore .idea files
lukeholder ef9dec1
Code formatting fixes
lukeholder 904147a
Fix cancelUrl returnKey empty array assignment.
lukeholder 36adf99
Extract endpoint action to method
lukeholder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
composer.lock | ||
composer.phar | ||
phpunit.xml | ||
.idea |
This file contains hidden or 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 hidden or 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,76 @@ | ||
<?php | ||
|
||
namespace Omnipay\NetBanx; | ||
|
||
use Omnipay\Common\AbstractGateway; | ||
|
||
/** | ||
* NetBanx Hosted Payment Class | ||
* | ||
*/ | ||
class HostedGateway extends AbstractGateway | ||
{ | ||
public function getName() | ||
{ | ||
return 'NetBanx Hosted Payments'; | ||
} | ||
|
||
public function getDefaultParameters() | ||
{ | ||
return array( | ||
'keyId' => '', | ||
'keyPassword' => '', | ||
'testMode' => false | ||
); | ||
} | ||
|
||
public function authorize(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NetBanx\Message\HostedAuthorizeRequest', $parameters); | ||
} | ||
|
||
public function purchase(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NetBanx\Message\HostedPurchaseRequest', $parameters); | ||
} | ||
|
||
public function completeAuthorize(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NetBanx\Message\HostedCompleteAuthorizeRequest', $parameters); | ||
} | ||
|
||
public function completePurchase(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NetBanx\Message\HostedCompletePurchaseRequest', $parameters); | ||
} | ||
|
||
public function capture(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NetBanx\Message\HostedCaptureRequest', $parameters); | ||
} | ||
|
||
public function refund(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\NetBanx\Message\HostedRefundRequest', $parameters); | ||
} | ||
|
||
public function setKeyId($value) | ||
{ | ||
return $this->setParameter('keyId', $value); | ||
} | ||
|
||
public function getKeyId() | ||
{ | ||
return $this->getParameter('keyId'); | ||
} | ||
|
||
public function setKeyPassword($value) | ||
{ | ||
return $this->setParameter('keyPassword', $value); | ||
} | ||
|
||
public function getKeyPassword() | ||
{ | ||
return $this->getParameter('keyPassword'); | ||
} | ||
} |
This file contains hidden or 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,74 @@ | ||
<?php | ||
|
||
namespace Omnipay\NetBanx\Message; | ||
|
||
use Guzzle\Http\Message\RequestInterface; | ||
|
||
abstract class HostedAbstractRequest extends \Omnipay\Common\Message\AbstractRequest | ||
{ | ||
protected $liveEndpoint = 'https://api.netbanx.com/hosted/v1'; | ||
protected $testEndpoint = 'https://api.test.netbanx.com/hosted/v1'; | ||
|
||
public function setKeyId($value) | ||
{ | ||
return $this->setParameter('keyId', $value); | ||
} | ||
|
||
public function getKeyId() | ||
{ | ||
return $this->getParameter('keyId'); | ||
} | ||
|
||
public function setKeyPassword($value) | ||
{ | ||
return $this->setParameter('keyPassword', $value); | ||
} | ||
|
||
public function getKeyPassword() | ||
{ | ||
return $this->getParameter('keyPassword'); | ||
} | ||
|
||
public function sendRequest($action, $data = null, $method = RequestInterface::POST) | ||
{ | ||
// don't throw exceptions for 4xx errors, need the data for error messages | ||
$this->httpClient->getEventDispatcher()->addListener( | ||
'request.error', | ||
function ($event) { | ||
if ($event['response']->isClientError()) { | ||
$event->stopPropagation(); | ||
} | ||
} | ||
); | ||
|
||
$username = $this->getKeyId(); | ||
$password = $this->getKeyPassword(); | ||
$base64 = base64_encode($username.':'.$password); | ||
|
||
$url = $this->getEndpoint().$action; | ||
|
||
$headers = array( | ||
'Authorization' => 'Basic '.$base64, | ||
'Content-Type' => 'application/json' | ||
); | ||
|
||
// For some reason the native json encoder built into Guzzle 3 is not encoding the nested data correctly, | ||
// breaking the http request. We need to do it manually. | ||
$data = json_encode($data); | ||
|
||
// Return the response we get back | ||
return $this->httpClient->createRequest($method, $url, $headers, $data)->send(); | ||
} | ||
|
||
public function getEndpoint() | ||
{ | ||
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; | ||
} | ||
|
||
protected function getBaseData() | ||
{ | ||
$data = array(); | ||
|
||
return $data; | ||
} | ||
} |
This file contains hidden or 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,58 @@ | ||
<?php | ||
|
||
namespace Omnipay\NetBanx\Message; | ||
|
||
abstract class HostedAbstractResponse extends \Omnipay\Common\Message\AbstractResponse | ||
{ | ||
public function getRedirectMethod() | ||
{ | ||
return 'GET'; | ||
} | ||
|
||
public function isSuccessful() | ||
{ | ||
$successful = (isset($this->data['transaction']['status']) | ||
&& $this->data['transaction']['status'] == 'success'); | ||
|
||
return !$this->isRedirect() && !isset($this->data['error']) && $successful; | ||
} | ||
|
||
public function getMessage() | ||
{ | ||
$message = null; | ||
|
||
if (isset($this->data['transaction']['confirmationNumber'])) { | ||
$message = $this->data['transaction']['confirmationNumber']; | ||
} | ||
|
||
if (isset($this->data['transaction']['errorMessage'])) { | ||
$message = $this->data['transaction']['errorMessage']; | ||
} | ||
|
||
if (isset($this->data['error']['message'])) { | ||
$message = $this->data['error']['message']; | ||
} | ||
|
||
return $message; | ||
} | ||
|
||
public function getCode() | ||
{ | ||
$code = null; | ||
|
||
if (isset($this->data['transaction']['errorCode'])) { | ||
$code = $this->data['transaction']['errorCode']; | ||
} | ||
|
||
if (isset($this->data['error']['code'])) { | ||
$code = $this->data['error']['code']; | ||
} | ||
|
||
return $code; | ||
} | ||
|
||
public function getTransactionReference() | ||
{ | ||
return isset($this->data['id']) ? $this->data['id'] : null; | ||
} | ||
} |
This file contains hidden or 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,16 @@ | ||
<?php | ||
|
||
namespace Omnipay\NetBanx\Message; | ||
|
||
class HostedAuthorizeRequest extends HostedPurchaseRequest | ||
{ | ||
|
||
public function getData() | ||
{ | ||
$data = parent::getData(); | ||
|
||
$data['extendedOptions'][] = array('key' => 'authType', 'value' => 'auth'); | ||
|
||
return $data; | ||
} | ||
} |
This file contains hidden or 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,31 @@ | ||
<?php | ||
|
||
namespace Omnipay\NetBanx\Message; | ||
|
||
class HostedCaptureRequest extends HostedAbstractRequest | ||
{ | ||
public function getData() | ||
{ | ||
$this->validate('amount', 'transactionReference', 'transactionId'); | ||
|
||
$data = parent::getBaseData(); | ||
|
||
$data['amount'] = $this->getAmountInteger(); | ||
$data['merchantRefNum'] = $this->getTransactionId(); | ||
|
||
return $data; | ||
} | ||
|
||
public function sendData($data) | ||
{ | ||
$httpResponse = $this->sendRequest($this->getEndpointAction(), null, 'POST'); | ||
$responseData = json_decode($httpResponse->getBody(true), true); | ||
|
||
return $this->response = new HostedCaptureResponse($this, $responseData); | ||
} | ||
|
||
public function getEndpointAction() | ||
{ | ||
return '/orders/'.$this->getTransactionReference().'/settlement'; | ||
} | ||
} |
This file contains hidden or 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,38 @@ | ||
<?php | ||
|
||
namespace Omnipay\NetBanx\Message; | ||
|
||
class HostedCaptureResponse extends HostedAbstractResponse | ||
{ | ||
public function isSuccessful() | ||
{ | ||
$successfulTransaction = (isset($this->data['authType']) && $this->data['authType'] == 'settlement'); | ||
|
||
return !$this->isRedirect() && !isset($this->data['error']) && $successfulTransaction; | ||
} | ||
|
||
public function isRedirect() | ||
{ | ||
return false; | ||
} | ||
|
||
public function getMessage() | ||
{ | ||
$message = null; | ||
|
||
if (isset($this->data['confirmationNumber'])) { | ||
$message = $this->data['confirmationNumber']; | ||
} | ||
|
||
if (isset($this->data['error']['message'])) { | ||
$message = $this->data['error']['message']; | ||
} | ||
|
||
return $message; | ||
} | ||
|
||
public function getRedirectData() | ||
{ | ||
return null; | ||
} | ||
} |
This file contains hidden or 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,7 @@ | ||
<?php | ||
|
||
namespace Omnipay\NetBanx\Message; | ||
|
||
class HostedCompleteAuthorizeRequest extends HostedCompletePurchaseRequest | ||
{ | ||
} |
This file contains hidden or 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\NetBanx\Message; | ||
|
||
class HostedCompletePurchaseRequest extends HostedAbstractRequest | ||
{ | ||
public function getData() | ||
{ | ||
$this->validate('transactionReference'); | ||
|
||
$data = parent::getBaseData(); | ||
|
||
$data['transactionReference'] = $this->getTransactionReference(); | ||
|
||
return $data; | ||
} | ||
|
||
public function sendData($data) | ||
{ | ||
$httpResponse = $this->sendRequest($this->getEndpointAction(), null, 'GET'); | ||
$responseData = json_decode($httpResponse->getBody(true), true); | ||
|
||
return $this->response = new HostedPurchaseResponse($this, $responseData); | ||
} | ||
|
||
public function getEndpointAction() | ||
{ | ||
return "/orders/".$this->getTransactionReference(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove extra empty line