From 7688dfd764996ed5283042577276b860b000581d Mon Sep 17 00:00:00 2001 From: Agbonghama Collins Date: Sun, 6 Mar 2016 06:59:56 +0100 Subject: [PATCH] added docblock comments to code --- src/Gateway.php | 99 ++++++++++++++++++++++++ src/Message/CompletePurchaseRequest.php | 14 ++++ src/Message/CompletePurchaseResponse.php | 10 +++ src/Message/NotificationRequest.php | 12 +++ src/Message/PurchaseRequest.php | 5 ++ src/Message/PurchaseResponse.php | 20 +++++ src/Message/TokenPurchaseRequest.php | 24 +++++- src/Message/TokenPurchaseResponse.php | 24 ++++++ src/TokenGateway.php | 24 ++++++ 9 files changed, 230 insertions(+), 2 deletions(-) diff --git a/src/Gateway.php b/src/Gateway.php index b308d27..a3cd2bd 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -25,61 +25,160 @@ public function getDefaultParameters() ); } + /** + * Getter: get cart items. + * + * @return array + */ public function getCart() { return $this->getParameter('cart'); } + /** + * Array of cart items. + * + * format: + * $gateway->setCart(array( + * array( + * 'type' => 'product', + * 'name' => 'Product 1', + * 'description' => 'Description of product 1', + * 'quantity' => 2, + * 'price' => 22, + * 'tangible' => 'N', + * 'product_id' => 12345, + * 'recurrence' => '1 Week', + * 'duration' => '1 Year', + * 'startup_fee' => '5', + * ), + * array( + * 'type' => 'product', + * 'name' => 'Product 2', + * 'quantity' => 1, + * 'price' => 10, + * 'tangible' => 'N' + * 'product_id' => 45678, + * 'recurrence' => '2 Week', + * 'duration' => '1 Year', + * 'startup_fee' => '3', + * ) + * )); + * + * @param array $value + * + * @return $this + */ public function setCart($value) { return $this->setParameter('cart', $value); } + /** + * Getter: demo mode. + * + * @return string + */ public function getDemoMode() { return $this->getParameter('demoMode'); } + /** + * Setter: demo mode. + * + * @param $value + * + * @return $this + */ public function setDemoMode($value) { return $this->setParameter('demoMode', $value); } + /** + * Getter: checkout language. + * + * @return string + */ public function getLanguage() { return $this->getParameter('language'); } + /** + * Setter: checkout language. + * + * @param $value + * + * @return $this + */ public function setLanguage($value) { return $this->setParameter('language', $value); } + /** + * Getter: coupon. + * + * @return string + */ public function getCoupon() { return $this->getParameter('coupon'); } + /** + * Setter: coupon. + * + * @param $value + * + * @return $this + */ public function setCoupon($value) { return $this->setParameter('coupon', $value); } + /** + * Getter: 2Checkout account number. + * + * @return string + */ public function getAccountNumber() { return $this->getParameter('accountNumber'); } + /** + * Setter: 2Checkout account number. + * + * @param $value + * + * @return $this + */ public function setAccountNumber($value) { return $this->setParameter('accountNumber', $value); } + /** + * Getter: 2Checkout secret word. + * + * @return string + */ public function getSecretWord() { return $this->getParameter('secretWord'); } + /** + * Setter: 2Checkout secret word. + * + * @param $value + * + * @return $this + */ public function setSecretWord($value) { return $this->setParameter('secretWord', $value); diff --git a/src/Message/CompletePurchaseRequest.php b/src/Message/CompletePurchaseRequest.php index 6344677..72c7cc7 100644 --- a/src/Message/CompletePurchaseRequest.php +++ b/src/Message/CompletePurchaseRequest.php @@ -9,6 +9,13 @@ */ class CompletePurchaseRequest extends PurchaseRequest { + /** + * {@inheritdoc} + * + * @return mixed + * + * @throws InvalidResponseException + */ public function getData() { // if 2co didn't send a POST body parameters, use sent GET string parameters instead. @@ -36,6 +43,13 @@ public function getData() return $this->httpRequest->$request_type->all(); } + /** + * {@inheritdoc} + * + * @param mixed $data + * + * @return CompletePurchaseResponse + */ public function sendData($data) { return $this->response = new CompletePurchaseResponse($this, $data); diff --git a/src/Message/CompletePurchaseResponse.php b/src/Message/CompletePurchaseResponse.php index 3a1c53b..e04acb0 100644 --- a/src/Message/CompletePurchaseResponse.php +++ b/src/Message/CompletePurchaseResponse.php @@ -14,11 +14,21 @@ public function isSuccessful() return true; } + /** + * Transaction ference returned by 2checkout or null on payment failure. + * + * @return mixed|null + */ public function getTransactionReference() { return isset($this->data['order_number']) ? $this->data['order_number'] : null; } + /** + * Transaction ID. + * + * @return mixed|null + */ public function getTransactionId() { return isset($this->data['merchant_order_id']) ? $this->data['merchant_order_id'] : null; diff --git a/src/Message/NotificationRequest.php b/src/Message/NotificationRequest.php index 79827c3..eef8820 100644 --- a/src/Message/NotificationRequest.php +++ b/src/Message/NotificationRequest.php @@ -4,6 +4,11 @@ class NotificationRequest extends AbstractRequest { + /** + * {@inheritdoc} + * + * @return array + */ public function getData() { $data = $this->httpRequest->request->all(); @@ -13,6 +18,13 @@ public function getData() return $data; } + /** + * {@inheritdoc} + * + * @param mixed $data + * + * @return NotificationResponse + */ public function sendData($data) { return new NotificationResponse($this, $data); diff --git a/src/Message/PurchaseRequest.php b/src/Message/PurchaseRequest.php index 0e8c703..92d8351 100644 --- a/src/Message/PurchaseRequest.php +++ b/src/Message/PurchaseRequest.php @@ -83,6 +83,11 @@ public function getData() return $data; } + /** + * @param mixed $data + * + * @return PurchaseResponse + */ public function sendData($data) { return $this->response = new PurchaseResponse($this, $data); diff --git a/src/Message/PurchaseResponse.php b/src/Message/PurchaseResponse.php index b76a94d..e95022e 100644 --- a/src/Message/PurchaseResponse.php +++ b/src/Message/PurchaseResponse.php @@ -13,6 +13,11 @@ class PurchaseResponse extends AbstractResponse implements RedirectResponseInter protected $liveEndpoint = 'https://www.2checkout.com/checkout/purchase'; protected $testEndpoint = 'https://sandbox.2checkout.com/checkout/purchase'; + /** + * Get appropriate 2checkout endpoints. + * + * @return string + */ public function getEndPoint() { if ($this->data['sandbox']) { @@ -22,16 +27,25 @@ public function getEndPoint() } } + /** + * @return bool + */ public function isSuccessful() { return false; } + /** + * @return bool + */ public function isRedirect() { return true; } + /** + * @return string + */ public function getRedirectUrl() { $endpoint = $this->getEndPoint(); @@ -45,11 +59,17 @@ public function getRedirectUrl() return str_replace('&', '&', $url); } + /** + * @return string + */ public function getRedirectMethod() { return 'GET'; } + /** + * No redirect data. + */ public function getRedirectData() { return; diff --git a/src/Message/TokenPurchaseRequest.php b/src/Message/TokenPurchaseRequest.php index 2616603..b4dcc0b 100644 --- a/src/Message/TokenPurchaseRequest.php +++ b/src/Message/TokenPurchaseRequest.php @@ -14,12 +14,23 @@ class TokenPurchaseRequest extends AbstractRequest protected $liveEndpoint = 'https://www.2checkout.com/checkout/api/1/'; protected $testEndpoint = 'https://sandbox.2checkout.com/checkout/api/1/'; + /** + * Build endpoint. + * + * @return string + */ public function getEndpoint() { $endpoint = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; return $endpoint.$this->getAccountNumber().'/rs/authService'; } + + /** + * HTTP request headers. + * + * @return array + */ public function getRequestHeaders() { return array( @@ -28,6 +39,11 @@ public function getRequestHeaders() ); } + /** + * @return array + * + * @throws \Omnipay\Common\Exception\InvalidRequestException + */ public function getData() { $this->validate('accountNumber', 'privateKey', 'token', 'amount', 'transactionId'); @@ -50,13 +66,17 @@ public function getData() $data['billingAddr']['email'] = $this->getCard()->getEmail(); $data['billingAddr']['country'] = $this->getCard()->getCountry(); $data['billingAddr']['phoneNumber'] = $this->getCard()->getPhone(); - // add this if PR (https://github.com/thephpleague/omnipay-common/pull/71) is merged - //$data['billingAddr']['phoneExt'] = $this->getCard()->getPhoneExtension(); + $data['billingAddr']['phoneExt'] = $this->getCard()->getPhoneExtension(); } return $data; } + /** + * @param mixed $data + * + * @return TokenPurchaseResponse + */ public function sendData($data) { try { diff --git a/src/Message/TokenPurchaseResponse.php b/src/Message/TokenPurchaseResponse.php index fc90c06..0e662a1 100644 --- a/src/Message/TokenPurchaseResponse.php +++ b/src/Message/TokenPurchaseResponse.php @@ -10,6 +10,11 @@ */ class TokenPurchaseResponse extends AbstractResponse implements ResponseInterface { + /** + * {@inheritdoc} + * + * @return bool + */ public function isSuccessful() { $responseCode = $this->data['response']['responseCode']; @@ -17,26 +22,45 @@ public function isSuccessful() return isset($responseCode) ? $responseCode == 'APPROVED' : false; } + /** + * {@inheritdoc} + * + * @return bool + */ public function isRedirect() { return false; } + /** + * {@inheritdoc} + * + * @return int|null + */ public function getCode() { return isset($this->data['exception']) ? $this->data['exception']['errorCode'] : null; } + /** + * {@inheritdoc} + */ public function getMessage() { return isset($this->data['exception']) ? $this->data['exception']['errorMsg'] : null; } + /** + * {@inheritdoc} + */ public function getTransactionReference() { return isset($this->data['response']['orderNumber']) ? $this->data['response']['orderNumber'] : null; } + /** + * {@inheritdoc} + */ public function getTransactionId() { return isset($this->data['response']['merchantOrderId']) ? $this->data['response']['merchantOrderId'] : null; diff --git a/src/TokenGateway.php b/src/TokenGateway.php index dcb0e4c..5220fcb 100644 --- a/src/TokenGateway.php +++ b/src/TokenGateway.php @@ -23,21 +23,45 @@ public function getDefaultParameters() ); } + /** + * Getter: 2Checkout account number. + * + * @return string + */ public function getAccountNumber() { return $this->getParameter('accountNumber'); } + /** + * Setter: 2Checkout account number. + * + * @param string $value + * + * @return $this + */ public function setAccountNumber($value) { return $this->setParameter('accountNumber', $value); } + /** + * Getter: 2Checkout private key. + * + * @return string + */ public function getPrivateKey() { return $this->getParameter('privateKey'); } + /** + * Setter: 2Checkout private key. + * + * @param $value + * + * @return $this + */ public function setPrivateKey($value) { return $this->setParameter('privateKey', $value);