php class Easypay private ch public function __construct this- ch curl

 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
<?php
class Easypay {
private $ch;
public function __construct() {
$this->ch = curl_init();
curl_setopt_array($this->ch, array(
CURLOPT_RETURNTRANSFER => true
));
}
public function setProxy($proxy, $timeout = false) {
//curl_setopt($this->ch, CURLOPT_HTTPPROXYTUNNEL, true);
if($timeout)
curl_setopt($this->ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($this->ch, CURLOPT_PROXY, $proxy);
return $this;
}
public function payMTS($phone, $sum, $cc, $exp, $cvv) {
$tmpcook = 'tmpcook/' . time() . '.cook';
$data = array();
curl_setopt_array($this->ch, array(
CURLOPT_URL => 'https://easypay.ua/partner/mts/payment',
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_COOKIEFILE => $tmpcook,
CURLOPT_COOKIEJAR => $tmpcook
));
curl_setopt($this->ch, CURLOPT_POST, true);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, array(
'isAccount' => 'false',
'account' => $phone,
'amount' => $sum,
'instrumentKey' => 'card',
'cardPan' => $cc,
'cardExpire' => $exp,
'cardCvv' => $cvv
));
$res = json_decode(curl_exec($this->ch), true);
$data['response'] = $res;
curl_setopt($this->ch, CURLOPT_POST, false);
$data['3ds'] = false;
if(isset($res['ForwardUrl'])) {
$data['3ds'] = true;
curl_setopt($this->ch, CURLOPT_URL, 'https://easypay.ua' . $res['ForwardUrl']);
$res = curl_exec($this->ch);
preg_match('/<form id="paymentForm" action="(.*?)"/i', $res, $data1);
$data['3ds_uri'] = $data1[1];
}
return $data;
}
}