Skip to content

Commit

Permalink
merged
Browse files Browse the repository at this point in the history
  • Loading branch information
cave committed Sep 28, 2021
2 parents 709a9d8 + 24428a5 commit 2cb1285
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ The result will be a redirect to the gateway or bank.
```php
use Omnipay\Omnipay;

<<<<<<< HEAD
$gateway = Omnipay::create('APS');
=======
$gateway = Omnipay::create('Amazon Payment Service');
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455

// Send purchase request (don't get so excited... params below are just fake :))
$response = $gateway->purchase([
Expand Down
6 changes: 6 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ public function getDefaultParameters(): array
{
return [
'testMode' => FALSE,
<<<<<<< HEAD
'currency' => 'AED',
'language' => 'en',
=======
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
];
}

Expand Down Expand Up @@ -91,6 +94,7 @@ public function refund(array $options = [])
return $this->createRequest(RefundRequest::class, $options);
}

<<<<<<< HEAD
public function setAccessCode($code)
{
return $this->setParameter('access_code', $code);
Expand Down Expand Up @@ -152,6 +156,8 @@ public function setFortId($fort_id)
return $this;
}

=======
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
/**
* @param string $requestPhrase
*
Expand Down
21 changes: 21 additions & 0 deletions src/Message/Request/APSAbstractRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,23 @@ public function sendData($data): ResponseInterface
'POST',
$this->getEndpoint(),
[
<<<<<<< HEAD
=======
'Accept' => 'application/json',
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
'Content-type' => 'application/json',
],
json_encode($data)
);

<<<<<<< HEAD
if ($httpResponse->getStatusCode() != 200)
{
throw new \Exception($httpResponse->getReasonPhrase(), $httpResponse->getStatusCode());
}

=======
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
$json = $httpResponse->getBody()->getContents();

$data = !empty($json) ? json_decode($json, true) : [];
Expand Down Expand Up @@ -70,6 +77,7 @@ protected function getEndpoint(): string
*/
private function _createSignature(array $data): string
{
<<<<<<< HEAD
unset($data['testMode']);
unset($data['Mode']);

Expand All @@ -83,12 +91,22 @@ private function _createSignature(array $data): string
{
if (empty($value)) continue;

=======
$shaType = $this->hasParameter('sha_type') ? $this->hasParameter('sha_type') : self::DEFAULT_SHA_TYPE;

if ( ! $this->hasParameter('request_phrase'))
throw new RequestPhraseException('Request phrase is missing.');

foreach ($data as $key => $value)
{
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
$shaString .= "$key=$value";
}

// "Glue" phrase to the both sides of the payload
$shaString = $this->getParameter('request_phrase') . $shaString . $this->getParameter('request_phrase');

<<<<<<< HEAD
return hash_hmac($shaType, $shaString, $this->getParameter('request_phrase'));
}

Expand Down Expand Up @@ -160,5 +178,8 @@ public function setFortId($fort_id)
protected function _is_json_response($string) {
json_decode($string);
return json_last_error() === JSON_ERROR_NONE;
=======
return hash($shaType, $shaString);
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
}
}
10 changes: 10 additions & 0 deletions src/Message/Request/AbstractCheckoutRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

abstract class AbstractCheckoutRequest extends APSAbstractRequest
{
<<<<<<< HEAD
protected $test_endpoint = 'https://sbcheckout.payfort.com/FortAPI/paymentPage';

protected $live_endpoint = 'https://checkout.payfort.com/FortAPI/paymentPage';

public function validateData()
{
$this->validate('access_code', 'merchant_identifier', 'merchant_reference', 'amount', 'currency', 'language', 'customer_email');
=======
private $test_endpoint = 'https://sbcheckout.payfort.com/FortAPI/paymentPage';

private $live_endpoint = 'https://checkout.payfort.com/FortAPI/paymentPage';

public function validateData()
{
$this->validate('access_code', 'merchant_identifier', 'merchant_reference', 'amount', 'currency', 'language', 'customer_email', 'signature');
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
}
}
4 changes: 4 additions & 0 deletions src/Message/Request/AuthorizationRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function getData(): array
$this->validateData();

return [
<<<<<<< HEAD
'command' => self::COMMAND,
'testMode' => $this->getParameter('testMode'),
'access_code' => $this->getParameter('access_code'),
Expand All @@ -24,6 +25,9 @@ public function getData(): array
'language' => $this->getParameter('language'),
'customer_email' => $this->getParameter('customer_email'),
'order_description' => $this->getParameter('order_description'),
=======
'command' => self::COMMAND,
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
];
}

Expand Down
13 changes: 13 additions & 0 deletions src/Message/Request/CaptureRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ class CaptureRequest extends APSAbstractRequest
{
const COMMAND = 'CAPTURE';

<<<<<<< HEAD
protected $test_endpoint = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';

protected $live_endpoint = 'https://paymentservices.payfort.com/FortAPI/paymentApi';
=======
private $test_endpoint = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';

private $live_endpoint = 'https://paymentservices.payfort.com/FortAPI/paymentApi';
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455

/**
* @return mixed
* @throws InvalidRequestException
*/
public function getData(): array
{
<<<<<<< HEAD
$this->validate('access_code', 'merchant_identifier', 'merchant_reference', 'amount', 'currency', 'language');

return [
Expand All @@ -30,6 +37,12 @@ public function getData(): array
'language' => $this->getParameter('language'),
'order_description' => $this->getParameter('order_description'),
'fort_id' => $this->getParameter('fort_id'),
=======
$this->validate('access_code', 'merchant_identifier', 'merchant_reference', 'amount', 'currency', 'language', 'signature');

return [
'command' => self::COMMAND,
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
];
}

Expand Down
10 changes: 10 additions & 0 deletions src/Message/Request/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function getData(): array

return [
'command' => self::COMMAND,
<<<<<<< HEAD
'testMode' => $this->getParameter('testMode'),
'access_code' => $this->getParameter('access_code'),
'merchant_identifier' => $this->getParameter('merchant_identifier'),
Expand All @@ -24,17 +25,26 @@ public function getData(): array
'language' => $this->getParameter('language'),
'customer_email' => $this->getParameter('customer_email'),
'order_description' => $this->getParameter('order_description'),
=======
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
];
}

/**
* @param array $data
<<<<<<< HEAD
=======
*
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
* @return PurchaseResponse
* @throws \Omnipay\Common\Exception\InvalidResponseException
*/
protected function createResponse(array $data): PurchaseResponse
{
return new PurchaseResponse($this, $data);
}
<<<<<<< HEAD

=======
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
}
13 changes: 13 additions & 0 deletions src/Message/Request/RefundRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ class RefundRequest extends APSAbstractRequest
{
const COMMAND = 'REFUND';

<<<<<<< HEAD
protected $test_endpoint = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';

protected $live_endpoint = 'https://paymentservices.payfort.com/FortAPI/paymentApi';
=======
private $test_endpoint = 'https://sbpaymentservices.payfort.com/FortAPI/paymentApi';

private $live_endpoint = 'https://paymentservices.payfort.com/FortAPI/paymentApi';
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455

/**
* @return mixed
Expand All @@ -18,6 +24,7 @@ class RefundRequest extends APSAbstractRequest
*/
public function getData(): array
{
<<<<<<< HEAD
$this->validate('access_code', 'merchant_identifier', 'merchant_reference', 'amount', 'currency', 'language');

return [
Expand All @@ -31,6 +38,12 @@ public function getData(): array
'language' => $this->getParameter('language'),
'order_description' => $this->getParameter('order_description'),
'fort_id' => $this->getParameter('fort_id'),
=======
$this->validate('access_code', 'merchant_identifier', 'merchant_reference', 'amount', 'currency', 'language', 'signature');

return [
'command' => self::COMMAND,
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
];
}

Expand Down
4 changes: 4 additions & 0 deletions tests/GatewayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ protected function setUp()
'currency' => 'AED',
'language' => 'en',
'customer_email' => '[email protected]',
<<<<<<< HEAD
=======
'signature' => '7cad05f0212ed933c9a5d5dffa31661acf2c827a',
>>>>>>> 24428a5b7399bc46a68f08187fb62fe42a45d455
'order_description' => 'iPhone 6-S',
];
}
Expand Down

0 comments on commit 2cb1285

Please sign in to comment.