Skip to content

Commit

Permalink
Support v2 Details API method
Browse files Browse the repository at this point in the history
  • Loading branch information
yidas committed Dec 21, 2020
1 parent 4be1317 commit d551217
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/linePay/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Client
'ordersCapture' => '/v2/payments/orders/{orderId}/capture',
'ordersRefund' => '/v2/payments/orders/{orderId}/refund',
'authorizations' => '/v2/payments/authorizations',
'detailsV2' => '/v2/payments',
];

/**
Expand Down Expand Up @@ -213,11 +214,14 @@ protected function requestHandler($version, $method, $uri, $queryParams=null, $b
* Get payment details
*
* @param array $queryParams
* @param string $version API version
* @return yidas\linePay\Response
*/
public function details($queryParams)
{
return $this->requestHandler('v3', 'GET', self::$apiUris['details'], $queryParams, null, [
public function details($queryParams, $version="v3")
{
$version = ($version == "v2") ? $version : "v3";
$apiUrl = ($version == "v2") ? self::$apiUris['detailsV2'] : self::$apiUris['details'];
return $this->requestHandler($version, 'GET', $apiUrl, $queryParams, null, [
'connect_timeout' => 5,
'timeout' => 20,
]);
Expand Down
8 changes: 5 additions & 3 deletions tool/details.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

$input = $_POST;
$input['isSandbox'] = (isset($input['isSandbox'])) ? true : false;
// Custom merchant only for security
// Merchant config option
if (isset($input['merchant'])) {
die("<script>alert('Custom merchant input only!');history.back();</script>");
$merchant = Merchant::getMerchant($input['merchant']);
$input['channelId'] = $merchant['channelId'];
$input['channelSecret'] = $merchant['channelSecret'];
}

// Create LINE Pay client
Expand All @@ -19,7 +21,7 @@
// Use Order Check API to confirm the transaction
$response = $linePay->details([
'transactionId' => $input['transactionId'],
]);
], "v2");

// Log
saveLog('Payment Details API', $response);
Expand Down
2 changes: 1 addition & 1 deletion tool/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function formSubmit(form) {
</div>
<hr>
<div class="form-group">
<label>Search Transaction <font color="#cccccc"><i>(Effective with Custom merchant & Sandbox setting)</i></font></label>
<label>Search Transaction</label>
<div class="input-group">
<input type="text" class="form-control" name="transactionId" placeholder="Input transactionId to search">
<div class="input-group-append">
Expand Down
2 changes: 1 addition & 1 deletion tool/refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

// Online Refund API
$refundParams = ($_GET['amount']!="") ? ['refundAmount' => (integer) $_GET['amount']] : null;
$refundParams = (isset($_GET['amount']) && $_GET['amount']!="") ? ['refundAmount' => (integer) $_GET['amount']] : null;
$response = $linePay->refund($order['transactionId'], $refundParams);

// Log
Expand Down

0 comments on commit d551217

Please sign in to comment.