Skip to content

Commit

Permalink
added docblock comments to code
Browse files Browse the repository at this point in the history
  • Loading branch information
w3guy committed Mar 6, 2016
1 parent 165118c commit 7688dfd
Show file tree
Hide file tree
Showing 9 changed files with 230 additions and 2 deletions.
99 changes: 99 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions src/Message/CompletePurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/Message/NotificationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

class NotificationRequest extends AbstractRequest
{
/**
* {@inheritdoc}
*
* @return array
*/
public function getData()
{
$data = $this->httpRequest->request->all();
Expand 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);
Expand Down
5 changes: 5 additions & 0 deletions src/Message/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions src/Message/PurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']) {
Expand All @@ -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();
Expand All @@ -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;
Expand Down
24 changes: 22 additions & 2 deletions src/Message/TokenPurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -28,6 +39,11 @@ public function getRequestHeaders()
);
}

/**
* @return array
*
* @throws \Omnipay\Common\Exception\InvalidRequestException
*/
public function getData()
{
$this->validate('accountNumber', 'privateKey', 'token', 'amount', 'transactionId');
Expand All @@ -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 {
Expand Down

0 comments on commit 7688dfd

Please sign in to comment.