Skip to content

Commit

Permalink
feat: adds php8.0 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
rommelfreddy authored and eiriarte-mendez committed Jun 10, 2021
1 parent 13027b9 commit 0d79010
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['7.0', '7.2', '7.4']
php-versions: ['7.0', '7.2', '7.4', '8.0']

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.17@dev",
"donatj/mock-webserver": "dev-master",
"phpunit/phpunit": "^6.5||^7.5||^8.5"
"phpunit/phpunit": "^6.5||^7.5||^8.5||^9.0"
},
"minimum-stability": "dev",
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion src/RequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ private function callMethod($name, $arguments)
*/
private function getMethod($name, $arguments)
{
if (method_exists($this->responseModel, $name)) {
if ($this->responseModel && method_exists($this->responseModel, $name)) {
if (count($arguments) > 0) {
return $this->responseModel->$name(current($arguments));
} else {
Expand Down
30 changes: 13 additions & 17 deletions src/Service/DeviceFingerprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,18 @@ public static function createDeviceIdentToken($identifier)
*/
public function getDeviceIdentSnippet($deviceIdentToken)
{
$snippet = sprintf(
'<script language="JavaScript">var di = %s;</script>',
json_encode([
't' => $deviceIdentToken,
'v' => $this->deviceIdentSId,
'l' => 'Checkout',
])
);

$snippet .= sprintf(
'<script type=\"text/javascript\" src=\"//d.ratepay.com/%1$s/di.js\"></script>
<noscript><link rel=\"stylesheet\" type=\"text/css\" href=\"//d.ratepay.com/di.css?t=%2$t&v=%1$s&l=Checkout\"></noscript>',
$this->deviceIdentSId,
$deviceIdentToken
);

return $snippet;
$params = [
't' => $deviceIdentToken,
'v' => $this->deviceIdentSId,
'l' => 'Checkout',
];
ob_start(); ?>
<script type="text/javascript">var di=<?php echo json_encode($params); ?>;</script>
<script type="text/javascript" src="//d.ratepay.com/<?php echo $this->deviceIdentSId; ?>/di.js"></script>
<noscript>
<link rel="stylesheet" type="text/css" href="//d.ratepay.com/di.css?<?php echo http_build_query($params); ?>" />
</noscript>
<?php
return ob_get_clean();
}
}
2 changes: 1 addition & 1 deletion src/Service/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public static function changeAmountToFloat($amount)
*/
public static function existsAndNotEmpty($object, $method)
{
if (method_exists($object, $method)) {
if ($object && method_exists($object, $method)) {
$var = $object->$method();
if (!empty($var)) {
return true;
Expand Down
11 changes: 7 additions & 4 deletions tests/Unit/Service/DeviceFingerprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function microtime()
use PHPUnit\Framework\TestCase;
use RatePAY\Service\DeviceFingerprint;

/**
* @requires PHPUnit 7.5
*/
class DeviceFingerprintTest extends TestCase
{
public function testCreateDeviceIdentToken()
Expand All @@ -33,16 +36,16 @@ public function testCreateDeviceIdentToken()
$this->assertEquals($expectedHash, $hash);
}


public function testGetDeviceIdentSnippet()
{
$deviceFingerprint = new DeviceFingerprint('hello-world-123');

$snippet = $deviceFingerprint->getDeviceIdentSnippet('secure-token-123');

$expectedSnippet = '<script language="JavaScript">var di = {"t":"secure-token-123","v":"hello-world-123","l":"Checkout"};</script><script type=\"text/javascript\" src=\"//d.ratepay.com/hello-world-123/di.js\"></script>
<noscript><link rel=\"stylesheet\" type=\"text/css\" href=\"//d.ratepay.com/di.css?t=&v=hello-world-123&l=Checkout\"></noscript>';

$this->assertEquals($expectedSnippet, $snippet);
$this->assertStringContainsString('//d.ratepay.com/di.css?t=secure-token-123&v=hello-world-123&l=Checkout', $snippet);
$this->assertStringContainsString('{"t":"secure-token-123","v":"hello-world-123","l":"Checkout"}', $snippet);
$this->assertStringContainsString('//d.ratepay.com/hello-world-123/di.js', $snippet);
}
}
}

0 comments on commit 0d79010

Please sign in to comment.