-
Notifications
You must be signed in to change notification settings - Fork 0
/
profile.server.php
627 lines (555 loc) · 29.3 KB
/
profile.server.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
<?php
/*******************************************************************************
* profile.server.php
* 配置管理系统后台文件
* profile background management script
* Function Desc
provide profile management script
* 功能描述
提供配置管理脚本
* Function Desc
init 初始化页面元素
* Revision 0.0057 2009/03/28 15:47:00 last modified by donnie
* Desc: page created
********************************************************************************/
require_once ("db_connect.php");
require_once ("profile.common.php");
require_once ("include/astercrm.class.php");
require_once ("include/paypal.class.php");
require_once ('include/xajaxGrid.inc.php');
/**
* initialize page elements
*
*/
function init($get=''){
global $config,$locate;
$objResponse = new xajaxResponse();
if($get != ''){
$get = rtrim($get,',');
$get = preg_split('/,/',$get);
foreach($get as $item_tmp){
$item = preg_split('/:/',$item_tmp);
$get_item[$item[0]] = $item[1];
}
}
$rechargeEable = true;
if($_SESSION['curuser']['usertype'] == 'reseller'){
$paymentinfoHtml = paymentInfoHtml();
$objResponse->addAssign("paymentInfo","innerHTML",$paymentinfoHtml);
if( $config['epayment']['epayment_status'] != 'enable' || $config['epayment']['paypal_payment_url'] == '' || $config['epayment']['paypal_account'] == '' || $config['epayment']['pdt_identity_token'] == '' || $config['epayment']['asterbilling_url'] == '' || $config['epayment']['amount'] == '' || $config['epayment']['currency_code'] == ''){
$rechargeEable = false;
}else{
$identity_token = $config['epayment']['pdt_identity_token'];
$receiver_email = $config['epayment']['paypal_account'];
$currency_code = $config['epayment']['currency_code'];
}
}elseif($_SESSION['curuser']['usertype'] == 'groupadmin'){
$reseller_row = astercrm::getRecordByID($_SESSION['curuser']['resellerid'],'resellergroup');
if($reseller_row['epayment_status'] != 'enable'){
$rechargeEable = false;
}else{
$identity_token = $reseller_row['epayment_identity_token'];
$receiver_email = $reseller_row['epayment_account'];
$currency_code = $config['epayment']['currency_code'];
}
}
$objResponse->addAssign("divNav","innerHTML",common::generateManageNav($skin,$_SESSION['curuser']['country'],$_SESSION['curuser']['language']));
$objResponse->addAssign("divCopyright","innerHTML",common::generateCopyright($skin));
$infoHtml = InfomationHtml();
$objResponse->addAssign("info","innerHTML",$infoHtml);
if($rechargeEable){
$rechargeInfoHtml =
'<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0" width="600">
<tr>
<td width="26%" height="39" class="td font" align="center">'.$locate->Translate('Recharge By Paypal').'
</td>
<td width="74%" class="td font" align="center"> </td>
</tr>
<tr><td height="10" class="td"></td>
<td class="td font" align="center"> </td>
</tr>
</table>
<table border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#F0F0F0" id="menu" width="600">
<tr bgcolor="#F7F7F7">
<td align="center" valign="top"><b>';
if($get_item["action"] == 'success'){
if($get_item['tx'] != ''){
$txn_res = astercrm::getRecordByField('epayment_txn_id',$get_item['tx'],'credithistory');
// check that txn_id has not been previously processed
if($txn_res['id'] > 0){
$rechargeInfoHtml .= $locate->Translate('payment_success');
}else{
if( $identity_token != ''){
$p = new paypal_class;
$p->verify_url = $config['epayment']['paypal_verify_url'];
if($config['epayment']['pdt_log']){
$return = $p->paypal_pdt_return($get_item['tx'],$identity_token,true);
}else{
$return = $p->paypal_pdt_return($get_item['tx'],$identity_token);
}
if($return['flag'] == 'SUCCESS'){
$errorFlag = 0;
// check that receiver_email is your Primary PayPal email
if($return['pdt']['receiver_email'] != $receiver_email){
$rechargeInfoHtml .= $locate->Translate('payment_receiver_error').'</br>';
$errorFlag += 1;
}
// check that payment_amount/payment_currency are correct
if($return['pdt']['mc_currency'] != $currency_code){
$rechargeInfoHtml .= $locate->Translate('payment_currency_error').'</br>';
$errorFlag += 1;
}
if($return['pdt']['payment_status'] == "Completed"){
if($errorFlag > 0){
$rechargeInfoHtml .= $locate->Translate('payment_order_error')."</br>".$locate->Translate('payment_may_completed');
}else{
// process Order 不再用pdt处理订单,等待ipn处理
//$process_res = processOrder($return['pdt']);
sleep(1);
$infoHtml = InfomationHtml();
$objResponse->addAssign("info","innerHTML",$infoHtml);
$rechargeInfoHtml .= $locate->Translate('payment_success');
}
}else{
$rechargeInfoHtml .= $locate->Translate('payment_failed');
}
}else{ //PDT return failed
$rechargeInfoHtml .= $locate->Translate('payment_return_failed');
}
}
}
}else{
$rechargeInfoHtml = rechargeHtml();
$objResponse->addAssign("rechargeInfo","innerHTML",$rechargeInfoHtml);
return $objResponse;
}
}elseif($get_item["action"] == 'cancel'){
$rechargeInfoHtml .= $locate->Translate('payment_canceled');
}else{
$rechargeInfoHtml = rechargeHtml();
$objResponse->addAssign("rechargeInfo","innerHTML",$rechargeInfoHtml);
return $objResponse;
}
$rechargeInfoHtml.= '</b> <a href="profile.php" >'.$locate->Translate('Return').'</a></td></tr></table>';
$objResponse->addAssign("rechargeInfo","innerHTML",$rechargeInfoHtml);
}
return $objResponse;
}
function InfomationHtml(){
global $locate;
if($_SESSION['curuser']['usertype'] == 'reseller'){
$reseller_row = astercrm::getRecordByID($_SESSION['curuser']['resellerid'],'resellergroup');
$balance = $reseller_row['creditlimit'] - $reseller_row['curcredit'];
$html = '<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0" width="600">
<tr>
<td width="25%" height="39" class="td font" align="left">
'.$locate->Translate('Reseller Infomation').'
</td>
<td width="75%" class="td font" align="center"> </td>
</tr>
<tr><td height="10" class="td"></td>
<td class="td font" align="center"> </td>
</tr>
</table>
<table border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#F0F0F0" id="menu" width="600">
<tr bgcolor="#F7F7F7">
<td width="20%" align="right" valign="top" >'.$locate->Translate('Reseller name').': </td>
<td width="30%" align="center" valign="top" ><b>'.$reseller_row['resellername'].'</b></div></td>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Accountcode').': </div></td>
<td width="30%" align="center" valign="top" >'.$reseller_row['accountcode'].'</td>
</tr>
<tr>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Limittype').': </td>
<td width="30%" align="center" valign="top" ><b>'.$reseller_row['limittype'].'</b></td>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Allowcallback').': </td>
<td width="30%" align="center" valign="top" ><b>'.$reseller_row['allowcallback'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td width="20%" align="right" valign="top" >'.$locate->Translate('Callshop cost').': </td>
<td width="30%" align="center" valign="top" ><b>'.$reseller_row['credit_group'].'</b></td>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Clid cost').': </td>
<td width="30%" align="center" valign="top" ><b>'.$reseller_row['credit_clid'].'</b></td>
</tr>
<tr>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Total cost').': </td>
<td width="30%" align="center" valign="top" ><b>'.$reseller_row['credit_reseller'].'</b></td>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Current cost').': </td>
<td width="30%" align="center" valign="top" ><b>'.$reseller_row['curcredit'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td width="20%" align="right" valign="top" >'.$locate->Translate('Credit limit').': </td>
<td width="30%" align="center" valign="top" ><b>'.$reseller_row['creditlimit'].'</b></td>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Balance').': </td>
<td width="30%" align="center" valign="top" ><b>'.$balance.'</b></td>
</tr>
</table>';
}elseif($_SESSION['curuser']['usertype'] == 'groupadmin'){
$group_row = astercrm::getRecordByID($_SESSION['curuser']['groupid'],'accountgroup');
$balance = $group_row['creditlimit'] - $group_row['curcredit'];
$html = '<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0" width="600">
<tr>
<td width="25%" height="39" class="td font" align="left">
'.$locate->Translate('Group Infomation').'
</td>
<td width="75%" class="td font" align="center"> </td>
</tr>
<tr><td height="10" class="td"></td>
<td class="td font" align="center"> </td>
</tr>
</table>
<table border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#F0F0F0" id="menu" width="600">
<tr bgcolor="#F7F7F7">
<td width="20%" align="right" valign="top" >'.$locate->Translate('Group name').': </td>
<td width="30%" align="center" valign="top" ><b>'.$group_row['groupname'].'</b></div></td>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Accountcode').': </div></td>
<td width="30%" align="center" valign="top" >'.$group_row['accountcode'].'</td>
</tr>
<tr>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Limittype').': </td>
<td width="30%" align="center" valign="top" ><b>'.$group_row['limittype'].'</b></td>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Allowcallback').': </td>
<td width="30%" align="center" valign="top" ><b>'.$group_row['allowcallback'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td width="20%" align="right" valign="top" >'.$locate->Translate('Credit limit').': </td>
<td width="30%" align="center" valign="top" ><b>'.$group_row['creditlimit'].'</b></td>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Clid cost').': </td>
<td width="30%" align="center" valign="top" ><b>'.$group_row['credit_clid'].'</b></td>
</tr>
<tr>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Total cost').': </td>
<td width="30%" align="center" valign="top" ><b>'.$group_row['credit_group'].'</b></td>
<td width="20%" align="right" valign="top" >'.$locate->Translate('Current cost').': </td>
<td width="30%" align="center" valign="top" ><b>'.$group_row['curcredit'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td width="20%" align="right" valign="top" >'.$locate->Translate('Balance').': </td>
<td width="30%" align="center" valign="top" ><b>'.$balance.'</b></td>
<td></td>
<td></td>
</tr>
</table>';
}
return $html;
}
function paymentInfoHtml(){
global $locate,$config;
$reseller_row = astercrm::getRecordByID($_SESSION['curuser']['resellerid'],'resellergroup');
$html = '<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0" width="600">
<tr>
<td width="46%" height="39" class="td font" align="left">'.
$locate->Translate('Online Payment Receiving Infomation').'
</td>
<td width="54%" class="td font" align="center"> </td>
</tr>
<tr><td height="10" class="td"></td>
<td class="td font" align="center"> </td>
</tr>
</table>
<table border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#F0F0F0" id="menu" width="600">
<tr bgcolor="#F7F7F7">
<td width="25%" align="right" valign="top" >'.$locate->Translate('Online payment').': </td>
<td width="75%" align="center" valign="top" ><b>'.$reseller_row['epayment_status'].'</b></td>
</tr>
<tr>
<td width="25%" align="right" valign="top" >'.$locate->Translate('Paypal account').': </td>
<td width="75%" align="center" valign="top" ><b>'.$reseller_row['epayment_account'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td width="25%" align="right" valign="top" >'.$locate->Translate('Paypal payment url').': </td>
<td width="75%" align="center" valign="top" ><b>'.$config['epayment']['paypal_payment_url'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td width="25%" align="right" valign="top" >'.$locate->Translate('Paypal verify url').': </td>
<td width="75%" align="center" valign="top" ><b>'.$config['epayment']['paypal_verify_url'].'</b></td>
</tr>
<tr>
<td align="right" valign="top" >'.$locate->Translate('Paypal identity token').': </td>
<td align="center" valign="top" ><b>'.$reseller_row['epayment_identity_token'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td align="right" valign="top" >'.$locate->Translate('Item name').': </td>
<td align="center" valign="top" ><b>'.$reseller_row['epayment_item_name'].'</b></td>
</tr>
<tr>
<td align="right" valign="top" >'.$locate->Translate('Available amount').': </td>
<td align="center" valign="top" ><b>'.$reseller_row['epayment_amount_package'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td align="right" valign="top" >'.$locate->Translate('Currency code').': </td>
<td align="center" valign="top" ><b>'.$config['epayment']['currency_code'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td align="right" valign="top" >'.$locate->Translate('Notify email').': </td>
<td align="center" valign="top" ><b>'.$reseller_row['epayment_notify_mail'].'</b></td>
</tr>
<tr bgcolor="#F7F7F7">
<td align="right" valign="top" >'.$locate->Translate('Callshop pay fee').': </td>
<td align="center" valign="top" ><b>'.$locate->Translate($reseller_row['callshop_pay_fee']).'</b></td>
</tr>
<tr>
<td align="right" valign="top" colspan="2"><input type="button" id="epayment_edit" name="epayment_edit" value="'.$locate->Translate('Edit').'" onclick="xajax_resellerPaymentInfoEdit();"> </td>
</tr>
</table>';
return $html;
}
function rechargeHtml(){
global $config,$locate;
$html = '<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0" width="600">
<tr>
<td width="26%" height="39" class="td font" align="left">
'.$locate->Translate('Recharge By Paypal').'
</td>
<td width="74%" class="td font" align="center"> </td>
</tr>
<tr><td height="10" class="td"></td>
<td class="td font" align="center"> </td>
</tr>
</table>
<table border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#F0F0F0" id="menu" width="600">';
if($_SESSION['curuser']['usertype'] == 'reseller'){
$html .='<tr bgcolor="#F7F7F7">
<td align="center" valign="top" ><span id="recharge_item_name" name="recharge_item_name">'.$config['epayment']['item_name'].'</span>: <span id="recharge_currency_code" id="recharge_currency_code">'.$config['epayment']['currency_code'].'</span> <select id="amount" name="amount">';
$amountP = preg_split('/,/',$config['epayment']['amount']);
}elseif($_SESSION['curuser']['usertype'] == 'groupadmin'){
$reseller_row = astercrm::getRecordByID($_SESSION['curuser']['resellerid'],'resellergroup');
$html .='<tr bgcolor="#F7F7F7">
<td align="center" valign="top" ><span id="recharge_item_name" name="recharge_item_name">'.$reseller_row['epayment_item_name'].'</span>: <span id="recharge_currency_code" id="recharge_currency_code">'.$config['epayment']['currency_code'].'</span> <select id="amount" name="amount">';
$amountP = preg_split('/,/',$reseller_row['epayment_amount_package']);
}
foreach ($amountP as $amount ){
if(is_numeric($amount)) {
$amount = round($amount,2);
$option .= '<option value="'.$amount.'">'.$amount.'</option>';
}
}
$html .= $option.'</select> <input type="button" value="'.$locate->Translate('Recharge By Paypal').'" onclick="rechargeByPaypal();"></td>
</tr>
</table>';
return $html;
}
function rechargeByPaypal($amount){
global $config,$locate;
$objResponse = new xajaxResponse();
if(!is_numeric($amount)) {
$objResponse->addAlert($locate->Translate('Please select amount'));
return $objResponse;
}
$paypal_charge = array();
if($_SESSION['curuser']['usertype'] == 'reseller'){
if( $config['epayment']['epayment_status'] != 'enable' || $config['epayment']['paypal_payment_url'] == '' || $config['epayment']['paypal_account'] == '' || $config['epayment']['pdt_identity_token'] == '' || $config['epayment']['asterbilling_url'] == '' || $config['epayment']['paypal_verify_url'] == '' || $config['epayment']['currency_code'] == ''){
$objResponse->addAlert($locate->Translate('The system does not support online payment'));
return $objResponse;
}else{
$p = new paypal_class;
$p->paypal_url = $config['epayment']['paypal_payment_url'];
$p->add_field('business',$config['epayment']['paypal_account']);
$this_url = $_SERVER['HTTP_REFERER'];
$this_url = preg_split('/\?/',$this_url);
$this_url = $this_url['0'];
$p->add_field('return',$this_url.'?action=success');
$p->add_field('cancel_return',$this_url.'?action=cancel');
$p->add_field('notify_url',$config['epayment']['asterbilling_url']."/epaymentreturn.php");
$p->add_field('item_name',$config['epayment']['item_name']);
$p->add_field('item_number',$_SESSION['curuser']['resellerid']);
$p->add_field('amount',$amount);
$p->add_field('mc_currency',$config['epayment']['currency_code']);
$p->add_field('currency_code',$config['epayment']['currency_code']);
//custum field userid:usertype:resellerid:gruopid
$p->add_field('custom',$_SESSION['curuser']['userid'].':reseller:'.$_SESSION['curuser']['resellerid'].':'.$_SESSION['curuser']['groupid']);
}
}elseif($_SESSION['curuser']['usertype'] == 'groupadmin'){
$reseller_row = astercrm::getRecordByID($_SESSION['curuser']['resellerid'],'resellergroup');
if($reseller_row['epayment_status'] != 'enable'){
$objResponse->addAlert($locate->Translate('The reseller does not support online payment'));
return $objResponse;
}else{
$p = new paypal_class;
$p->paypal_url = $config['epayment']['paypal_payment_url'];;
$p->add_field('business',$reseller_row['epayment_account']);
$this_url = $_SERVER['HTTP_REFERER'];
$this_url = preg_split('/\?/',$this_url);
$this_url = $this_url['0'];
$p->add_field('return',$this_url.'?action=success');
$p->add_field('cancel_return',$this_url.'?action=cancel');
$p->add_field('notify_url',$config['epayment']['asterbilling_url']."/epaymentreturn.php");
$p->add_field('item_name',$reseller_row['epayment_item_name']);
$p->add_field('item_number',$_SESSION['curuser']['groupid']);
$p->add_field('amount',$amount);
$p->add_field('mc_currency',$config['epayment']['currency_code']);
$p->add_field('currency_code',$config['epayment']['currency_code']);
//custum field userid:usertype:resellerid:gruopid
$p->add_field('custom',$_SESSION['curuser']['userid'].':groupadmin:'.$_SESSION['curuser']['resellerid'].':'.$_SESSION['curuser']['groupid']);
}
}
$paymentHtml .= '<table border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#F0F0F0" width="600">
<tr>
<td width="26%" height="39" class="td font" align="center">
'.$locate->Translate('Recharge By Paypal').'
</td>
<td width="74%" class="td font" align="center"> </td>
</tr>
<tr><td height="10" class="td"></td>
<td class="td font" align="center"> </td>
</tr>
</table>
<table border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#F0F0F0" id="menu" width="600">
<tr bgcolor="#F7F7F7">
<td align="center" valign="top"><b>'.$locate->Translate('Please wait your credit order is processing').'...</b>';
$paymentHtml .= $p->submit_paypal_post();
$paymentHtml .= '</td></tr></table>';
$objResponse->addAssign("rechargeInfo","innerHTML",$paymentHtml);
$objResponse->addScript("document.getElementById('paymentForm').submit()");
return $objResponse;
}
function processOrder($pdt){
global $db,$config,$locate;
$reseller_row = astercrm::getRecordByID($_SESSION['curuser']['resellerid'],'resellergroup');
if($_SESSION['curuser']['usertype'] == 'reseller'){
$srcCredit = $reseller_row['curcredit'];
if($config['epayment']['callshop_pay_fee']){
$creditBeforeFee = $srcCredit - $pdt['mc_gross'];
$updateCurCredit = $srcCredit - $pdt['mc_gross'] + $pdt['mc_fee'];
}else{
$updateCurCredit = $srcCredit - $pdt['mc_gross'];
}
$sql = "UPDATE resellergroup SET curcredit = $updateCurCredit WHERE id = '".$_SESSION['curuser']['resellerid']."'";
$mailto = $config['epayment']['notify_mail'];
$mailTitle = $locate->Translate('Reseller').': '.$_SESSION['curuser']['username'].' '.$locate->Translate('Paymented').' '.$config['epayment']['currency_code'].$pdt['mc_gross'].' '.$locate->Translate('for').' '.$config['epayment']['item_name'].','.$locate->Translate('Please check it').' -pdt';
}elseif($_SESSION['curuser']['usertype'] == 'groupadmin'){
$group_row = astercrm::getRecordByID($_SESSION['curuser']['groupid'],'accountgroup');
$srcCredit = $group_row['curcredit'];
if($reseller_row['callshop_pay_fee'] == 'no'){
$updateCurCredit = $srcCredit - $pdt['mc_gross'];
}else{
$creditBeforeFee = $srcCredit - $pdt['mc_gross'];
$updateCurCredit = $srcCredit - $pdt['mc_gross'] + $pdt['mc_fee'];
}
$sql = "UPDATE accountgroup SET curcredit = $updateCurCredit WHERE id='".$_SESSION['curuser']['groupid']."'";
$mailto = $reseller_row['epayment_notify_mail'];
$mailTitle = $locate->Translate('Callshop').': '.$_SESSION['curuser']['username'].' '.$locate->Translate('Paymented').' '.$config['epayment']['currency_code'].$pdt['mc_gross'].' '.$locate->Translate('for').' '.$reseller_row['epayment_item_name'].','.$locate->Translate('Please check it').' -pdt';
}
$res = $db->query($sql);
if($res){
$credithistory_sql = "INSERT INTO credithistory SET modifytime=now(), resellerid='".$_SESSION['curuser']['resellerid']."',groupid='".$_SESSION['curuser']['groupid']."',srccredit='".$srcCredit."',modifystatus='reduce',modifyamount='".$pdt['mc_gross']."',comment='Recharge By Paypal',operator='".$_SESSION['curuser']['userid']."',epayment_txn_id='".$pdt['txn_id']."'";
$credithistory_res=$db->query($credithistory_sql);
if(($_SESSION['curuser']['usertype'] == 'groupadmin' && $reseller_row['callshop_pay_fee'] == 'yes') || ($_SESSION['curuser']['usertype'] == 'reseller' && $config['epayment']['callshop_pay_fee'])){
$credithistory_sql = "INSERT INTO credithistory SET modifytime=now() + 1, resellerid='".$_SESSION['curuser']['resellerid']."',groupid='".$_SESSION['curuser']['groupid']."',srccredit='".$creditBeforeFee."',modifystatus='add',modifyamount='".$pdt['mc_fee']."',comment='Fees By Paypal',operator='".$_SESSION['curuser']['userid']."',epayment_txn_id='".$pdt['txn_id']."'";
$credithistory_res=$db->query($credithistory_sql);
}
}
$subject = 'Instant Payment Notification - Recieved Payment';
$to = $mailto; // your email
$body = "An instant payment notification was successfully recieved\n";
$body .= "from ".$pdt['payer_email'].", send by asterbilling on ".date('m/d/Y');
$body .= " at ".date('g:i A')."\n\n";
$body .= $mailTitle."\n\nDetails:\n";
foreach ($pdt as $key => $value) {
if($key != '' && $key != 'custom') $body .= "\n$key: $value";
}
mail($to, $subject, $body);
return $res;
}
function resellerPaymentInfoEdit(){
global $db,$config,$locate;
$objResponse = new xajaxResponse();
if($_SESSION['curuser']['usertype'] == 'reseller'){
$reseller_row = astercrm::getRecordByID($_SESSION['curuser']['resellerid'],'resellergroup');
$html = Table::Top( $locate->Translate("Edit Payment Receiving Infomation"),"formDiv");
if($reseller_row['epayment_status'] == 'enable'){
$enable = 'checked';
}else{
$diable = 'checked';
}
if($reseller_row['callshop_pay_fee'] == 'yes'){
$yesVal = 'checked';
}else{
$noVal = 'checked';
}
$html .= '
<!-- No edit the next line -->
<form method="post" name="f" id="f">
<table border="1" width="100%" class="adminlist">
<tr>
<td nowrap align="left">'.$locate->Translate("Paypal payment url").'</td>
<td align="left">'.$config['epayment']['paypal_payment_url'].'</td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Paypal verify url").'</td>
<td align="left">'.$config['epayment']['paypal_verify_url'].'</td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Online payment").'</td>
<td align="left"><input type="radio" id="epayment_status" name="epayment_status" value="enable" '.$enable.'>'.$locate->Translate("Enable").'<input type="radio" id="epayment_status" name="epayment_status" value="disable" '.$diable.'>'.$locate->Translate("Disable").'</td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Paypal account").'</td>
<td align="left"><input type="text" id="epayment_account" name="epayment_account" size="35" value="'.$reseller_row['epayment_account'].'"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Paypal identity token").'</td>
<td align="left"><input type="text" id="epayment_identity_token" name="epayment_identity_token" size="35" value="'.$reseller_row['epayment_identity_token'].'"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Item name").'</td>
<td align="left"><input type="text" id="epayment_item_name" name="epayment_item_name" size="35" value="'.$reseller_row['epayment_item_name'].'"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Available amount").'</td>
<td align="left"><input type="text" id="epayment_amount_package" name="epayment_amount_package" size="35" maxlength="30" value="'.$reseller_row['epayment_amount_package'].'"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Notify email").'</td>
<td align="left"><input type="text" id="epayment_notify_mail" name="epayment_notify_mail" size="35" value="'.$reseller_row['epayment_notify_mail'].'"></td>
</tr>
<tr>
<td nowrap align="left">'.$locate->Translate("Callshop pay fee").'</td>
<td align="left"><input type="radio" id="callshop_pay_fee" name="callshop_pay_fee" value="yes" '.$yesVal.'>'.$locate->Translate("Yes").'<input type="radio" id="callshop_pay_fee" name="callshop_pay_fee" value="no" '.$noVal.'>'.$locate->Translate("No").'</td>
</tr>
<tr>
<td colspan="2" align="center"><button id="submitButton" onClick=\'xajax_resellerPaymentInfoUpdate(xajax.getFormValues("f"));return false;\'>'.$locate->Translate("Continue").'</button></td>
</tr>
</table></form>';
$html .= Table::Footer();
$objResponse->addAssign("formDiv", "style.visibility", "visible");
$objResponse->addAssign("formDiv", "innerHTML", $html);
}
return $objResponse->getXML();
}
function resellerPaymentInfoUpdate($f){
global $db,$config,$locate;
$objResponse = new xajaxResponse();
if($_SESSION['curuser']['usertype'] == 'reseller'){
if($f['epayment_status'] == 'enable'){
if($config['epayment']['paypal_payment_url'] == '' || $config['epayment']['paypal_verify_url'] == '' || $config['epayment']['currency_code'] == '' || $config['epayment']['asterbilling_url'] == ''){
$objResponse->addAlert($locate->Translate('The system does not support online payment'));
return $objResponse;
}
if($f['epayment_account'] == '' || $f['epayment_identity_token'] == '' || $f['epayment_item_name'] == '' || $f['epayment_amount_package'] == '' || $f['epayment_notify_mail'] == ''){
$objResponse->addAlert($locate->Translate('All item can not be blank if enabaled online payment'));
return $objResponse;
}
}
$amounts = explode(',',$f['epayment_amount_package']);
foreach($amounts as $value){
if(is_numeric($value)){
$amount .= round($value,2).',';
}
}
$amount = rtrim($amount,',');
$sql = "UPDATE resellergroup SET epayment_status='".$f['epayment_status']."',epayment_account='".$f['epayment_account']."',epayment_item_name='".$f['epayment_item_name']."',epayment_identity_token='".$f['epayment_identity_token']."',epayment_amount_package='".$amount."',epayment_notify_mail='".$f['epayment_notify_mail']."',callshop_pay_fee='".$f['callshop_pay_fee']."' WHERE id='".$_SESSION['curuser']['resellerid']."'";
$res = $db->query($sql);
$objResponse->addAssign("formDiv", "style.visibility", "hidden");
$objResponse->addAssign("formDiv", "innerHTML", '');
if($res == 1){
$objResponse->addAlert($locate->Translate('Payment Receiving Infomation has been updated'));
$paymentinfoHtml = paymentInfoHtml();
$objResponse->addAssign("paymentInfo","innerHTML",$paymentinfoHtml);
}else{
$objResponse->addAlert($locate->Translate('Payment Receiving Infomation update failed'));
}
}
return $objResponse->getXML();
}
$xajax->processRequests();
?>