Skip to content

Commit

Permalink
hasher
Browse files Browse the repository at this point in the history
  • Loading branch information
recca0120 committed Oct 14, 2024
1 parent 957ee09 commit 99488f4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
42 changes: 42 additions & 0 deletions src/Hasher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Omnipay\Gomypay;

class Hasher
{
/**
* @var string
*/
private $customerId;
/**
* @var string
*/
private $strCheck;

public function __construct($customerId, $strCheck)
{
$this->customerId = $customerId;
$this->strCheck = $strCheck;
}

public function make(array $data)
{
$amount = 0;
if (array_key_exists('PayAmount', $data)) {
$amount = $data['PayAmount'];
} elseif (array_key_exists('e_money', $data)) {
$amount = $data['e_money'];
} elseif (array_key_exists('Amount', $data)) {
$amount = $data['Amount'];
}

return md5(implode('', [
$data['result'],
$data['e_orderno'],
$this->customerId,
$amount,
$data['OrderID'],
$this->strCheck,
]));
}
}
20 changes: 3 additions & 17 deletions src/Traits/HasGomypay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Omnipay\Gomypay\Traits;

use Omnipay\Gomypay\Hasher;

trait HasGomypay
{
public function getCustomerId()
Expand Down Expand Up @@ -47,22 +49,6 @@ public function setStr_Check($value)

public function makeHash(array $data)
{
$amount = 0;
if (array_key_exists('PayAmount', $data)) {
$amount = $data['PayAmount'];
} elseif (array_key_exists('e_money', $data)) {
$amount = $data['e_money'];
} elseif (array_key_exists('Amount', $data)) {
$amount = $data['Amount'];
}

return md5(implode('', [
$data['result'],
$data['e_orderno'],
$this->getCustomerId(),
$amount,
$data['OrderID'],
$this->getStrCheck(),
]));
return (new Hasher($this->getCustomerId(), $this->getStrCheck()))->make($data);
}
}

0 comments on commit 99488f4

Please sign in to comment.