-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
361 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Omnipay\NewebPay\Message; | ||
|
||
use Omnipay\Common\Exception\InvalidRequestException; | ||
use Omnipay\Common\Exception\InvalidResponseException; | ||
use Omnipay\NewebPay\Encryptor; | ||
use Omnipay\NewebPay\Traits\HasDefaults; | ||
|
||
class FetchTransactionRequest extends AbstractRequest | ||
{ | ||
use HasDefaults; | ||
|
||
protected $liveEndpoint = 'https://core.newebpay.com/API/QueryTradeInfo'; | ||
|
||
protected $testEndpoint = 'https://ccore.newebpay.com/API/QueryTradeInfo'; | ||
|
||
public function getEndpoint() | ||
{ | ||
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; | ||
} | ||
|
||
/** | ||
* 資料來源. | ||
* 預設為空值。 | ||
* 1.若為複合式商店(MS5 開頭) ,此欄位為必填 | ||
* 2.複合式商店查詢請固定填入:Composite設定此參數會查詢 複合式商店旗下對應商店的訂單。 | ||
* 3.若沒有帶[Gateway]或是帶入其他參數值,則查詢一般商店代號。 | ||
* | ||
* @param string $value | ||
* @return static | ||
*/ | ||
public function setGateway($value) | ||
{ | ||
return $this->setParameter('Gateway', $value); | ||
} | ||
|
||
/** | ||
* @return ?string | ||
*/ | ||
public function getGateway() | ||
{ | ||
return $this->getParameter('Gateway'); | ||
} | ||
|
||
/** | ||
* @throws InvalidRequestException | ||
*/ | ||
public function getData() | ||
{ | ||
$encryptor = new Encryptor($this->getHashKey(), $this->getHashIv()); | ||
|
||
return array_filter([ | ||
'MerchantID' => $this->getMerchantID(), | ||
'Version' => $this->getVersion() ?: '1.3', | ||
'RespondType' => $this->getRespondType(), | ||
'CheckValue' => $encryptor->checkValue([ | ||
'Amt' => (int) $this->getAmount(), | ||
'MerchantID' => $this->getMerchantID(), | ||
'MerchantOrderNo' => $this->getTransactionId(), | ||
]), | ||
'TimeStamp' => $this->getTimeStamp(), | ||
'MerchantOrderNo' => $this->getTransactionId(), | ||
'Amt' => (int) $this->getAmount(), | ||
'Gateway' => $this->getGateway(), | ||
], static function ($value) { | ||
return $value !== null && $value !== ''; | ||
}); | ||
} | ||
|
||
/** | ||
* @throws InvalidResponseException | ||
*/ | ||
public function sendData($data) | ||
{ | ||
$response = $this->httpClient->request('POST', $this->getEndpoint(), [ | ||
'Content-Type' => 'application/x-www-form-urlencoded', | ||
], http_build_query($data)); | ||
$result = json_decode((string) $response->getBody(), true); | ||
|
||
$encryptor = new Encryptor($this->getHashKey(), $this->getHashIv()); | ||
|
||
if (! hash_equals($result['Result']['CheckCode'], $encryptor->checkCode([ | ||
'MerchantID' => $result['Result']['MerchantID'], | ||
'Amt' => $result['Result']['Amt'], | ||
'MerchantOrderNo' => $result['Result']['MerchantOrderNo'], | ||
'TradeNo' => $result['Result']['TradeNo'], | ||
]))) { | ||
throw new InvalidResponseException('Incorrect CheckCode'); | ||
} | ||
|
||
return $this->response = new FetchTransactionResponse($this, $result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Omnipay\NewebPay\Message; | ||
|
||
class FetchTransactionResponse extends AbstractResponse | ||
{ | ||
public function isSuccessful() | ||
{ | ||
return $this->getCode() === '00'; | ||
} | ||
|
||
public function getCode() | ||
{ | ||
return $this->data['Result']['RespondCode']; | ||
} | ||
|
||
public function getMessage() | ||
{ | ||
return $this->data['Result']['RespondMsg']; | ||
} | ||
|
||
public function getTransactionId() | ||
{ | ||
return $this->data['Result']['MerchantOrderNo']; | ||
} | ||
|
||
public function getTransactionReference() | ||
{ | ||
return $this->data['Result']['TradeNo']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.