Skip to content

Commit

Permalink
check key exists
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Feb 26, 2024
1 parent 71582f7 commit 3b7eb01
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Message/MyCash/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CompletePurchaseRequest extends AbstractRequest
public function getData()
{
$data = $this->httpRequest->request->all();
$validate = $data['Validate'];
$validate = array_key_exists('Validate', $data) ? $data['Validate'] : '';

if ($this->makeHash($data) !== $validate) {
throw new InvalidRequestException('Incorrect hash');
Expand Down
14 changes: 8 additions & 6 deletions src/Traits/MyCash/HasMyCash.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public function setMerTradeID($value)
private function makeHash(array $data)
{
$hasher = new Hasher($this->getHashKey(), $this->getValidateKey());
$lookup = ['RtnCode' => 'RtnCode', 'TradeID' => 'MerTradeID', 'UserID' => 'MerUserID', 'Money' => 'Amount'];
$result = [];
foreach ($lookup as $from => $to) {
if (array_key_exists($to, $data)) {
$result[$from] = $data[$to];
}
}

return $hasher->make([
'RtnCode' => $data['RtnCode'],
'TradeID' => $data['MerTradeID'],
'UserID' => $data['MerUserID'],
'Money' => $data['Amount'],
]);
return $hasher->make($result);
}
}

0 comments on commit 3b7eb01

Please sign in to comment.