Skip to content

Commit

Permalink
Refactor bas64_url* functions to static
Browse files Browse the repository at this point in the history
  • Loading branch information
hakito committed Aug 8, 2020
1 parent 7c5b460 commit b4f2234
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Model/Table/PayPalPaymentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,23 +181,23 @@ public function encryptRedirectUrl($text, $id)
$credentials = self::getCredentials();
$compressed = gzcompress($text, 9);
$key = $credentials['ClientSecret'] . $id;
return $this->base64_url_encode(Security::encrypt($compressed, $key)) ;
return self::base64_url_encode(Security::encrypt($compressed, $key)) ;
}

public function decryptRedirectUrl($encryptedText, $id)
{
$credentials = self::getCredentials();
$key = $credentials['ClientSecret'] . $id;
$compressed = Security::decrypt($this->base64_url_decode($encryptedText), $key);
$compressed = Security::decrypt(self::base64_url_decode($encryptedText), $key);
return gzuncompress($compressed);
}

public function base64_url_encode($input)
public static function base64_url_encode($input)
{
return strtr(base64_encode($input) , '+/=', '-_,');
}

public function base64_url_decode($input)
public static function base64_url_decode($input)
{
return base64_decode(strtr($input, '-_,', '+/='));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Model/Table/PayPalPaymentsTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public function testBase64UrlEncode()
$plus = chr(0x3e << 2);
$slash = chr(0x3f);
$value = "$plus\x0$slash\o\x3Fo";
$actual = $this->PayPalPayments->base64_url_encode($value);
$actual = PayPalPaymentsTable::base64_url_encode($value);
$this->assertEquals('-AA_XG8_bw,,', $actual);
}

Expand All @@ -329,7 +329,7 @@ public function testBase64UrlDecode()
$plus = chr(0x3e << 2);
$slash = chr(0x3f);
$value = "$plus\x0$slash\o\x3Fo";
$actual = $this->PayPalPayments->base64_url_decode('-AA_XG8_bw,,');
$actual = PayPalPaymentsTable::base64_url_decode('-AA_XG8_bw,,');
$this->assertEquals($value, $actual);
}
}

0 comments on commit b4f2234

Please sign in to comment.