Skip to content

Commit 99488f4

Browse files
committed
hasher
1 parent 957ee09 commit 99488f4

File tree

2 files changed

+45
-17
lines changed

2 files changed

+45
-17
lines changed

src/Hasher.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace Omnipay\Gomypay;
4+
5+
class Hasher
6+
{
7+
/**
8+
* @var string
9+
*/
10+
private $customerId;
11+
/**
12+
* @var string
13+
*/
14+
private $strCheck;
15+
16+
public function __construct($customerId, $strCheck)
17+
{
18+
$this->customerId = $customerId;
19+
$this->strCheck = $strCheck;
20+
}
21+
22+
public function make(array $data)
23+
{
24+
$amount = 0;
25+
if (array_key_exists('PayAmount', $data)) {
26+
$amount = $data['PayAmount'];
27+
} elseif (array_key_exists('e_money', $data)) {
28+
$amount = $data['e_money'];
29+
} elseif (array_key_exists('Amount', $data)) {
30+
$amount = $data['Amount'];
31+
}
32+
33+
return md5(implode('', [
34+
$data['result'],
35+
$data['e_orderno'],
36+
$this->customerId,
37+
$amount,
38+
$data['OrderID'],
39+
$this->strCheck,
40+
]));
41+
}
42+
}

src/Traits/HasGomypay.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Omnipay\Gomypay\Traits;
44

5+
use Omnipay\Gomypay\Hasher;
6+
57
trait HasGomypay
68
{
79
public function getCustomerId()
@@ -47,22 +49,6 @@ public function setStr_Check($value)
4749

4850
public function makeHash(array $data)
4951
{
50-
$amount = 0;
51-
if (array_key_exists('PayAmount', $data)) {
52-
$amount = $data['PayAmount'];
53-
} elseif (array_key_exists('e_money', $data)) {
54-
$amount = $data['e_money'];
55-
} elseif (array_key_exists('Amount', $data)) {
56-
$amount = $data['Amount'];
57-
}
58-
59-
return md5(implode('', [
60-
$data['result'],
61-
$data['e_orderno'],
62-
$this->getCustomerId(),
63-
$amount,
64-
$data['OrderID'],
65-
$this->getStrCheck(),
66-
]));
52+
return (new Hasher($this->getCustomerId(), $this->getStrCheck()))->make($data);
6753
}
6854
}

0 commit comments

Comments
 (0)