-
Notifications
You must be signed in to change notification settings - Fork 7
/
WalletOne.php
71 lines (61 loc) · 1.7 KB
/
WalletOne.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace bookin\walletone;
use yii\base\Component;
use yii\base\ErrorException;
use yii\helpers\Url;
class WalletOne extends Component
{
use TWalletOne;
const SIGNATURE_SHA1 = 'sha1';
const SIGNATURE_MD5 = 'md5';
const ERROR_SIGNATURE = 101;
const ERROR_UNKNOWN = 201;
const ERROR_HAVE_NOT_CURRENCY = 301;
protected static $CURRENCY_ID = [
'RUB'=>643,
'ZAR'=>710,
'USD'=>840,
'EUR'=>978,
'UAH'=>980,
'KZT'=>398,
'BYR'=>974,
'TJS'=>972
];
public function init(){
parent::init();
if(!$this->signatureMethod){
$this->signatureMethod = self::SIGNATURE_SHA1;
}
}
/**
* @param $post
* @return bool
* @throws ErrorException
* @throws WalletOneException
*/
public function checkPayment($post){
$success = $this->checkSignature($this->secretKey, $post, $this->signatureMethod);
if ($success){
if (strtoupper($post["WMI_ORDER_STATE"]) == "ACCEPTED")
{
return true;
}else{
throw new WalletOneException($_POST["WMI_ORDER_STATE"], self::ERROR_UNKNOWN);
}
}else{
throw new WalletOneException('Incorrect signature', self::ERROR_UNKNOWN);
}
}
/**
* @param $code - ISO 4217 currency code
* @return mixed
* @throws WalletOneException
*/
public static function CurrencyID($code){
if(isset(self::$CURRENCY_ID[$code])){
return self::$CURRENCY_ID[$code];
}else{
throw new WalletOneException('WalletOne do not support '.$code, self::ERROR_HAVE_NOT_CURRENCY);
}
}
}