-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from onlinesid/omnipay2
omnipay/common ~2.0 and omnipay/tests ~2.0
- Loading branch information
Showing
11 changed files
with
322 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -17,23 +17,31 @@ | |
"name": "Jeremy Shipman", | ||
"email": "[email protected]", | ||
"homepage": "http://jeremyshipman.com" | ||
}, | ||
{ | ||
"name": "Sid Bachtiar", | ||
"email": "[email protected]", | ||
"homepage": "http://onlinesid.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { "Omnipay\\Poli\\" : "src/" } | ||
"psr-4": { | ||
"Omnipay\\Poli\\" : "src/" | ||
} | ||
}, | ||
"require": { | ||
"omnipay/omnipay": "~1.1" | ||
"omnipay/common": "~2.0" | ||
}, | ||
"require-dev": { | ||
"guzzle/plugin-mock": "~3.1", | ||
"mockery/mockery": "~0.7", | ||
"phpunit/phpunit": "~3.7.16", | ||
"squizlabs/php_codesniffer": "~1.4" | ||
"phpunit/phpunit": "~3.7.0", | ||
"squizlabs/php_codesniffer": "~1.4", | ||
"omnipay/tests": "~2.0" | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0.x-dev" | ||
"dev-master": "2.0.x-dev" | ||
} | ||
} | ||
} |
This file contains 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 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 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,67 @@ | ||
<?php | ||
|
||
namespace Omnipay\Poli\Message; | ||
|
||
use Omnipay\Common\Message\AbstractRequest; | ||
|
||
class FetchCheckoutRequest extends AbstractRequest | ||
{ | ||
protected $endpoint = 'https://poliapi.apac.paywithpoli.com/api/v2/Transaction/GetTransaction'; | ||
|
||
public function getMerchantCode() | ||
{ | ||
return $this->getParameter('merchantCode'); | ||
} | ||
|
||
public function setMerchantCode($value) | ||
{ | ||
return $this->setParameter('merchantCode', $value); | ||
} | ||
|
||
public function getAuthenticationCode() | ||
{ | ||
return $this->getParameter('authenticationCode'); | ||
} | ||
|
||
public function setAuthenticationCode($value) | ||
{ | ||
return $this->setParameter('authenticationCode', $value); | ||
} | ||
|
||
public function getData() | ||
{ | ||
$this->validate( | ||
'merchantCode', | ||
'authenticationCode' | ||
); | ||
$data = array(); | ||
return $data; | ||
} | ||
|
||
public function send() | ||
{ | ||
$data = $this->getData(); | ||
return $this->sendData($data); | ||
} | ||
|
||
public function sendData($data) | ||
{ | ||
$token = $this->httpRequest->query->get('token'); | ||
$url = $this->endpoint.'?token='.urlencode($token); | ||
|
||
$merchantCode = $this->getMerchantCode(); | ||
$authenticationCode = $this->getAuthenticationCode(); | ||
$auth = base64_encode($merchantCode.":".$authenticationCode); //'S61xxxxx:AuthCode123'); | ||
|
||
$httpRequest = $this->httpClient->get( | ||
$url, | ||
array( | ||
'Content-Type'=>'application/json', | ||
'Authorization' => 'Basic '.$auth, | ||
) | ||
); | ||
$httpResponse = $httpRequest->send(); | ||
return $this->response = new FetchCheckoutResponse($this, $httpResponse->getBody(true)); | ||
|
||
} | ||
} |
This file contains 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,100 @@ | ||
<?php | ||
|
||
namespace Omnipay\Poli\Message; | ||
|
||
use Guzzle\Http\EntityBodyInterface; | ||
use Omnipay\Common\Message\AbstractResponse; | ||
use Omnipay\Common\Message\RequestInterface; | ||
use Omnipay\Common\Exception\InvalidResponseException; | ||
use Omnipay\Common\Message\RedirectResponseInterface; | ||
|
||
/** | ||
* Poli Checkout Response | ||
* | ||
*/ | ||
class FetchCheckoutResponse extends AbstractResponse implements RedirectResponseInterface | ||
{ | ||
/** | ||
* | ||
* @param RequestInterface $request | ||
* @param string $data | ||
* @throws InvalidResponseException | ||
*/ | ||
public function __construct(RequestInterface $request, $data) | ||
{ | ||
$this->request = $request; | ||
$this->data = json_decode($data, true); | ||
} | ||
|
||
/** | ||
* Is the result a success? | ||
* | ||
* @return bool | ||
*/ | ||
public function isSuccessful() | ||
{ | ||
return !$this->getCode(); | ||
} | ||
|
||
/** | ||
* Do we need to redirect? | ||
* | ||
* @return bool | ||
*/ | ||
public function isRedirect() | ||
{ | ||
return isset($this->data['NavigateURL']); | ||
} | ||
|
||
/** | ||
* Error message, e.g.: '' = no error | ||
* | ||
* @return string | ||
*/ | ||
public function getMessage() | ||
{ | ||
return $this->data['ErrorMessage']; | ||
} | ||
|
||
/** | ||
* Error code, e.g.: 0 or '' = no error | ||
* | ||
* @return int | ||
*/ | ||
public function getCode() | ||
{ | ||
return $this->data['ErrorCode']; | ||
} | ||
|
||
/** | ||
* Redirection URL | ||
* | ||
* @return string | ||
*/ | ||
public function getRedirectUrl() | ||
{ | ||
if ($this->isRedirect()) { | ||
return $this->data['NavigateURL']; | ||
} | ||
} | ||
|
||
/** | ||
* Redirection method | ||
* | ||
* @return string | ||
*/ | ||
public function getRedirectMethod() | ||
{ | ||
return 'GET'; | ||
} | ||
|
||
/** | ||
* Redirection data | ||
* | ||
* @return null | ||
*/ | ||
public function getRedirectData() | ||
{ | ||
return null; | ||
} | ||
} |
This file contains 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
Oops, something went wrong.