Skip to content

Commit

Permalink
Add debug & useUnixTimeNonce features
Browse files Browse the repository at this point in the history
  • Loading branch information
yidas committed Oct 26, 2021
1 parent 1d2dc1b commit f626b6c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/linePay/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* LINE Pay Client
*
* @author Nick Tsai <myintaer@gmail.com>
* @version 3.6.0
* @version 3.7.0
*/
class Client
{
Expand Down Expand Up @@ -71,6 +71,13 @@ class Client
*/
protected $channelSecret;

/**
* Saved whether to use milliseconds unixTime as LINE Pay X-LINE-Authorization-Nonce
*
* @var boolean
*/
protected $useUnixTimeNonce;

/**
* Constructor
*
Expand All @@ -88,6 +95,8 @@ function __construct($optParams)
$merchantDeviceType = isset($optParams['merchantDeviceType']) ? $optParams['merchantDeviceType'] : null;
$merchantDeviceProfileId = isset($optParams['merchantDeviceProfileId']) ? $optParams['merchantDeviceProfileId'] : null;
$isSandbox = isset($optParams['isSandbox']) ? $optParams['isSandbox'] : false;
$debug = isset($optParams['debug']) ? $optParams['debug'] : false;
$this->useUnixTimeNonce = isset($optParams['useUnixTimeNonce']) ? $optParams['useUnixTimeNonce'] : false;

// Check
if (!$channelId || !$channelSecret) {
Expand Down Expand Up @@ -119,6 +128,7 @@ function __construct($optParams)
// 'timeout' => 6.0,
'headers' => $headers,
'http_errors' => false,
'debug' => $debug,
]);

return $this;
Expand Down Expand Up @@ -188,7 +198,7 @@ public function requestHandler($version, $method, $uri, $queryParams=null, $body
case 'v3':
default:
// V3 API Authentication
$authNonce = date('c') . uniqid('-'); // ISO 8601 date + UUID 1
$authNonce = ($this->useUnixTimeNonce) ? round(microtime(true) * 1000) : date('c') . uniqid('-'); // ISO 8601 date + UUID 1
$authParams = ($method=='GET' && $queryParams) ? $queryString : (($bodyParams) ? $body : null);
$headers['X-LINE-Authorization'] = self::getAuthSignature($this->channelSecret, $uri, $authParams, $authNonce);
$headers['X-LINE-Authorization-Nonce'] = $authNonce;
Expand Down

0 comments on commit f626b6c

Please sign in to comment.