-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps_jahanpay.php
114 lines (93 loc) · 3.38 KB
/
ps_jahanpay.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
class ps_jahanpay extends ps_payment_gateway {
public $api;
public function send( $callback, $price, $username, $email, $order_id ) {
$client = new ps_main_jahanpay();
$txt = urlencode( 'خرید از سایت با استفاده از افزونه پست شاپ' );
$res = $client->call( 'requestpayment', array( $this->api, $price, $callback, $order_id, $txt ) );
$this->insert_payment( $username, $price, $order_id, $email );
echo $this->info_alert( 'در حال اتصال به درگاه ...' );
$this->redirect( "http://www.jahanpay.com/pay_invoice/{$res}" );
}
public function verify( $price, $post_id, $order_id, $course_id = 0 ) {
if ( isset( $_GET['order_id'] ) && isset( $_GET["au"] ) ):
// $orderId = (int) $_GET["order_id"];
$Refnumber = $_GET["au"];
$client = new ps_main_jahanpay();
$result = $client->call( 'verification', array( $this->api, $price, $_GET["au"] ) );
if ( $result == 1 ) {
$this->success_payment( $Refnumber, $order_id, $price, $post_id, $course_id );
} else {
echo $this->danger_alert( 'خطا در پردازش عملیات پرداخت ، نتیجه پرداخت : ' . $result );
}
$this->end_payment();
endif;
}
}
class ps_main_jahanpay {
private $apiUrl = 'http://jahanpay.com/index.php/api', $timeOut = 30; //second
protected $api = '';
public function requestpayment( $api = 0, $amount = 0, $callback = '', $order_id = 0, $description = '', $bank = 'auto' ) {
$data = array(
'method' => 'requestpayment',
'api' => $api,
'amount' => $amount,
'order_id' => $order_id,
'description' => $description,
'bank' => $bank,
'callback' => $callback,
);
return $this->checkCUrl() ? $this->sendCurl( $data ) : $this->sendContent( $data );
}
public function verification( $api = 0, $amount = 0, $au = '' ) {
$data = array(
'method' => 'verification',
'api' => $api,
'amount' => $amount,
'au' => $au,
);
return $this->checkCUrl() ? $this->sendCurl( $data ) : $this->sendContent( $data );
}
public function call( $method = '', array $arr = array() ) {
if ( $method == 'requestpayment' ) {
$_ = array();
for ( $i = 0; $i < 6; $i ++ ) {
$_[ $i ] = isset( $arr[ $i ] ) ? $arr[ $i ] : null;
}
return $this->requestpayment( $_[0], $_[1], $_[2], $_[3], $_[4], $_[5] );
} else {
$_ = array();
for ( $i = 0; $i < 3; $i ++ ) {
$_[ $i ] = isset( $arr[ $i ] ) ? $arr[ $i ] : null;
}
return $this->verification( $_[0], $_[1], $_[2] );
}
}
private function checkCUrl() {
if ( function_exists( 'curl_init' ) and extension_loaded( 'curl' ) ) {
return true;
}
return false;
}
private function sendCurl( array $postdata = array() ) {
$data = array();
foreach ( $postdata as $key => $val ) {
$data[] = "{$key}=" . urlencode( $val );
}
$do = curl_init();
curl_setopt( $do, CURLOPT_URL, $this->apiUrl . '?' . join( '&', $data ) );
curl_setopt( $do, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $do, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $do, CURLOPT_CONNECTTIMEOUT, $this->timeOut );
$response = curl_exec( $do );
curl_close( $do );
return $response;
}
private function sendContent( array $postdata = array() ) {
$data = array();
foreach ( $postdata as $key => $val ) {
$data[] = "{$key}=" . urlencode( $val );
}
return file_get_contents( $this->apiUrl . '?' . join( '&', $data ) );
}
}