Skip to content

Addded docblocks to Hosted Payment Gateway #6

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

Merged
merged 1 commit into from
Sep 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/HostedGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
*/
class HostedGateway extends AbstractGateway
{
/**
* @return string
*/
public function getName()
{
return 'NetBanx Hosted Payments';
}

/**
* @return array
*/
public function getDefaultParameters()
{
return array(
Expand All @@ -24,51 +30,97 @@ public function getDefaultParameters()
);
}

/**
* @param array $parameters
*
* @return \Omnipay\NetBanx\Message\HostedAuthorizeRequest
*/
public function authorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\NetBanx\Message\HostedAuthorizeRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function purchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\NetBanx\Message\HostedPurchaseRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\NetBanx\Message\HostedCompleteAuthorizeRequest
*/
public function completeAuthorize(array $parameters = array())
{
return $this->createRequest('\Omnipay\NetBanx\Message\HostedCompleteAuthorizeRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\NetBanx\Message\HostedCompletePurchaseRequest
*/
public function completePurchase(array $parameters = array())
{
return $this->createRequest('\Omnipay\NetBanx\Message\HostedCompletePurchaseRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\NetBanx\Message\HostedCaptureRequest
*/
public function capture(array $parameters = array())
{
return $this->createRequest('\Omnipay\NetBanx\Message\HostedCaptureRequest', $parameters);
}

/**
* @param array $parameters
*
* @return \Omnipay\NetBanx\Message\HostedRefundRequest
*/
public function refund(array $parameters = array())
{
return $this->createRequest('\Omnipay\NetBanx\Message\HostedRefundRequest', $parameters);
}

/**
* @param $value
*
* @return $this
*/
public function setKeyId($value)
{
return $this->setParameter('keyId', $value);
}

/**
* @return mixed
*/
public function getKeyId()
{
return $this->getParameter('keyId');
}

/**
* @param $value
*
* @return $this
*/
public function setKeyPassword($value)
{
return $this->setParameter('keyPassword', $value);
}

/**
* @return mixed
*/
public function getKeyPassword()
{
return $this->getParameter('keyPassword');
Expand Down
29 changes: 29 additions & 0 deletions src/Message/HostedAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,49 @@ abstract class HostedAbstractRequest extends \Omnipay\Common\Message\AbstractReq
protected $liveEndpoint = 'https://api.netbanx.com/hosted/v1';
protected $testEndpoint = 'https://api.test.netbanx.com/hosted/v1';

/**
* @param $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setKeyId($value)
{
return $this->setParameter('keyId', $value);
}

/**
* @return mixed
*/
public function getKeyId()
{
return $this->getParameter('keyId');
}

/**
* @param $value
*
* @return \Omnipay\Common\Message\AbstractRequest
*/
public function setKeyPassword($value)
{
return $this->setParameter('keyPassword', $value);
}

/**
* @return mixed
*/
public function getKeyPassword()
{
return $this->getParameter('keyPassword');
}

/**
* @param $action
* @param null $data
* @param string $method
*
* @return \Guzzle\Http\Message\Response
*/
public function sendRequest($action, $data = null, $method = RequestInterface::POST)
{
// don't throw exceptions for 4xx errors, need the data for error messages
Expand Down Expand Up @@ -60,11 +83,17 @@ function ($event) {
return $this->httpClient->createRequest($method, $url, $headers, $data)->send();
}

/**
* @return string
*/
public function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
}

/**
* @return array
*/
protected function getBaseData()
{
$data = array();
Expand Down
15 changes: 15 additions & 0 deletions src/Message/HostedAbstractResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

abstract class HostedAbstractResponse extends \Omnipay\Common\Message\AbstractResponse
{
/**
* @return string
*/
public function getRedirectMethod()
{
return 'GET';
}

/**
* @return bool
*/
public function isSuccessful()
{
$successful = (isset($this->data['transaction']['status'])
Expand All @@ -17,6 +23,9 @@ public function isSuccessful()
return !$this->isRedirect() && !isset($this->data['error']) && $successful;
}

/**
* @return string|null
*/
public function getMessage()
{
$message = null;
Expand All @@ -36,6 +45,9 @@ public function getMessage()
return $message;
}

/**
* @return string|null
*/
public function getCode()
{
$code = null;
Expand All @@ -51,6 +63,9 @@ public function getCode()
return $code;
}

/**
* @return string|null
*/
public function getTransactionReference()
{
return isset($this->data['id']) ? $this->data['id'] : null;
Expand Down
3 changes: 3 additions & 0 deletions src/Message/HostedAuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
class HostedAuthorizeRequest extends HostedPurchaseRequest
{

/**
* @return array|mixed
*/
public function getData()
{
$data = parent::getData();
Expand Down
8 changes: 8 additions & 0 deletions src/Message/HostedCaptureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class HostedCaptureRequest extends HostedAbstractRequest
{
/**
* @return array
*/
public function getData()
{
$this->validate('amount', 'transactionReference', 'transactionId');
Expand All @@ -16,6 +19,11 @@ public function getData()
return $data;
}

/**
* @param mixed $data
*
* @return HostedCaptureResponse
*/
public function sendData($data)
{
$httpResponse = $this->sendRequest($this->getEndpointAction(), null, 'POST');
Expand Down
9 changes: 9 additions & 0 deletions src/Message/HostedCaptureResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@

class HostedCaptureResponse extends HostedAbstractResponse
{
/**
* @return bool
*/
public function isSuccessful()
{
$successfulTransaction = (isset($this->data['authType']) && $this->data['authType'] == 'settlement');

return !$this->isRedirect() && !isset($this->data['error']) && $successfulTransaction;
}

/**
* @return bool
*/
public function isRedirect()
{
return false;
}

/**
* @return null
*/
public function getMessage()
{
$message = null;
Expand Down
11 changes: 11 additions & 0 deletions src/Message/HostedCompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class HostedCompletePurchaseRequest extends HostedAbstractRequest
{
/**
* @return array
*/
public function getData()
{
$this->validate('transactionReference');
Expand All @@ -15,6 +18,11 @@ public function getData()
return $data;
}

/**
* @param mixed $data
*
* @return HostedPurchaseResponse
*/
public function sendData($data)
{
$httpResponse = $this->sendRequest($this->getEndpointAction(), null, 'GET');
Expand All @@ -23,6 +31,9 @@ public function sendData($data)
return $this->response = new HostedPurchaseResponse($this, $responseData);
}

/**
* @return string
*/
public function getEndpointAction()
{
return "/orders/".$this->getTransactionReference();
Expand Down
11 changes: 11 additions & 0 deletions src/Message/HostedPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class HostedPurchaseRequest extends HostedAbstractRequest
{
/**
* @return array
*/
public function getData()
{
$this->validate('amount', 'returnUrl', 'cancelUrl');
Expand Down Expand Up @@ -94,6 +97,11 @@ public function getData()
return $data;
}

/**
* @param mixed $data
*
* @return HostedPurchaseResponse
*/
public function sendData($data)
{
$httpResponse = $this->sendRequest($this->getEndpointAction(), $data, 'POST');
Expand All @@ -102,6 +110,9 @@ public function sendData($data)
return $this->response = new HostedPurchaseResponse($this, $responseData);
}

/**
* @return string
*/
public function getEndpointAction()
{
return '/orders';
Expand Down
9 changes: 9 additions & 0 deletions src/Message/HostedPurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class HostedPurchaseResponse extends HostedAbstractResponse implements RedirectResponseInterface
{
/**
* @return bool
*/
public function isRedirect()
{
$hasHostedLink = false;
Expand All @@ -23,6 +26,9 @@ public function isRedirect()
return $hasHostedLink && !$hasTransaction;
}

/**
* @return string|null
*/
public function getRedirectUrl()
{
if (isset($this->data['link'])) {
Expand All @@ -34,6 +40,9 @@ public function getRedirectUrl()
}
}

/**
* @return null
*/
public function getRedirectData()
{
return null;
Expand Down
Loading