- 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
Changes from 7 commits
767c1eb f387c69 b71ccb0 0e60eb0 1326153 7f7396e 058f9e0 0c33d2b ef9dec1 904147a 36adf99 File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| 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'); | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } |
| 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; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
| | ||
| namespace Omnipay\NetBanx\Message; | ||
| | ||
| class HostedAuthorizeRequest extends HostedPurchaseRequest | ||
| { | ||
| | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove extra empty line | ||
| public function getData() | ||
| { | ||
| $data = parent::getData(); | ||
| | ||
| $data['extendedOptions'][] = array('key' => 'authType', 'value' => 'auth'); | ||
| | ||
| return $data; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?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"; | ||
| } | ||
| } | ||
| 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; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| <?php | ||
| | ||
| namespace Omnipay\NetBanx\Message; | ||
| | ||
| class HostedCompleteAuthorizeRequest extends HostedCompletePurchaseRequest | ||
| { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?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(); | ||
| } | ||
| } |
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.
use singlequotes here and in other files