-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpro-vip-zarinpal.php
155 lines (126 loc) · 6.1 KB
/
pro-vip-zarinpal.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
* Plugin Name: Zarinpal Gateway For Pro-VIP
* Plugin URI: -
* Description: This plugin lets you use Zarinpal gateway in pro-vip wp plugin.
* Version: 1.0
* Author: Amini7
* Author URI: masoudamini.ir
* License: GPL2
* License URI: http://www.gnu.org/licenses/gpl-2.0.html.
*/
defined('ABSPATH') or exit;
if (!function_exists('init_Zarinpal_gateway_pv_class')) {
add_action('plugins_loaded', 'init_Zarinpal_gateway_pv_class');
function init_Zarinpal_gateway_pv_class()
{
add_filter('pro_vip_currencies_list', 'currencies_check');
function currencies_check($list)
{
if (!in_array('IRT', $list)) {
$list['IRT'] = [
'name' => 'تومان ایران',
'symbol' => 'تومان',
];
}
if (!in_array('IRR', $list)) {
$list['IRR'] = [
'name' => 'ریال ایران',
'symbol' => 'ریال',
];
}
return $list;
}
if (class_exists('Pro_VIP_Payment_Gateway') && !class_exists('Pro_VIP_Zarinpal_Gateway')) {
class Pro_VIP_Zarinpal_Gateway extends Pro_VIP_Payment_Gateway
{
public $id = 'Zarinpal',
$settings = [],
$frontendLabel = 'زرینپال',
$adminLabel = 'زرینپال';
public function __construct()
{
parent::__construct();
}
public function beforePayment(Pro_VIP_Payment $payment)
{
$MerchantID = $this->settings['api_key']; //Required
$Amount = intval($payment->price); // Required
$orderId = $payment->paymentId; // Required
$Description = 'پرداخت فاکتور به شماره ی'.$orderId; // Required
$CallbackURL = add_query_arg('order', $orderId, $this->getReturnUrl()); // $this->getReturnUrl();
//$currency = $order->get_order_currency();
if (pvGetOption('currency') === 'IRR') {
$amount /= 10;
}
$client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']);
$res = $client->PaymentRequest([
'MerchantID' => $MerchantID,
'Amount' => $Amount,
'Description' => $Description,
'Email' => '',
'Mobile' => '',
'CallbackURL' => $CallbackURL,
]);
$Result = $res->Status;
if ($Result == 100) {
$payment->key = $orderId;
$payment->user = get_current_user_id();
$payment->save();
$payment_url = 'https://www.zarinpal.com/pg/StartPay/';
header("Location: $payment_url".$res->Authority);
} else {
pvAddNotice('خطا در هنگام اتصال به زرینپال.');
return;
}
}
public function afterPayment()
{
if (isset($_GET['order'])) {
$orderId = $_GET['order'];
} else {
$orderId = 0;
}
if ($orderId) {
$payment = new Pro_VIP_Payment($orderId);
$MerchantID = $this->settings['api_key']; //Required
$Amount = intval($payment->price); // - ریال به مبلغ Required
$Authority = $_GET['Authority'];
$getStatus = $_GET['Status'];
if (pvGetOption('currency') === 'IRR') {
$amount /= 10;
}
if ($getStatus == 'OK') {
$client = new SoapClient('https://www.zarinpal.com/pg/services/WebGate/wsdl', ['encoding' => 'UTF-8']);
$result = $client->PaymentVerification([
'MerchantID' => $MerchantID,
'Authority' => $Authority,
'Amount' => $Amount,
]);
$Result = $res->Status;
if ($Result == 100) {
pvAddNotice('پرداخت شما با موفقیت انجام شد. کد پیگیری: '.$orderId, 'success');
$payment->status = 'publish';
$payment->save();
$this->paymentComplete($payment);
} else {
pvAddNotice('خطایی به هنگام پرداخت پیش آمده. کد خطا عبارت است از :'.$Result.' . برای آگاهی از دلیل خطا کد آن را به زرینپال ارائه نمایید.');
$this->paymentFailed($payment);
return false;
}
} else {
pvAddNotice('به نظر می رسد عملیات پرداخت توسط شما لغو گردیده، اگر چنین نیست مجددا اقدام به پرداخت فاکتور نمایید.');
$this->paymentFailed($payment);
return false;
}
}
}
public function adminSettings(PV_Framework_Form_Builder $form)
{
$form->textfield('api_key')->label('کلید API');
}
}
Pro_VIP_Payment_Gateway::registerGateway('Pro_VIP_Zarinpal_Gateway');
}
}
}