/
cron_processcc_recurrent_invoice.php
131 lines (121 loc) · 7.91 KB
/
cron_processcc_recurrent_invoice.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
<?php
/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/
// Copyright 2008 - 2010 all rights reserved, SQLFusion LLC, info@sqlfusion.com
/** Ofuz Open Source version is released under the GNU Affero General Public License, please read the full license at: http://www.gnu.org/licenses/agpl-3.0.html **/
/**
* Process the CC on Authnet for the recurrent invoices
* on due date
* Recurrent Invoices which are paid monthly online are porcessed via this script
* Will retrieve the encrypted CC info and will process the invoice payment if its the due date.
* @see class/RecurrentInvoice.class.php
* @see class/RecurrentInvoiceCC.class.php
*/
include_once('config.php');
include_once('class/Authnet.class.php');
set_time_limit(3600);
$do_recurrent = new RecurrentInvoice();
$do_invoice = new Invoice();
$do_inv_line = new InvoiceLine();
$do_contact = new Contact();
$do_recurrent_cc = new RecurrentInvoiceCC();
$do_recurrent->getRecInvoiceForCCProcess();
if($do_recurrent->getNumRows()){
while($do_recurrent->next()){
$do_user_detail = new User();
$do_invoice = new Invoice();
$do_invoice->getId($do_recurrent->idinvoice);
$do_invoice->sessionPersistent("do_invoice", "index.php", OFUZ_TTL);
$do_user_detail->getId($_SESSION['do_invoice']->iduser);
$user_settings = $do_user_detail->getChildUserSettings();
if($user_settings->getNumRows()){// Get the setting data for the user who has created the invoice
while($user_settings->next()){
$payment_mode = false;
if($user_settings->setting_name == 'invoice_logo' && $user_settings->setting_value != ''){
$_SESSION['do_invoice']->inv_logo = $user_settings->setting_value ;
}
if($user_settings->setting_name == 'authnet_login' && $user_settings->setting_value != ''){
$_SESSION['do_invoice']->authnet_login = $user_settings->setting_value ;
}
if($user_settings->setting_name == 'authnet_merchant_id' && $user_settings->setting_value != ''){
$_SESSION['do_invoice']->authnet_merchant_id = $user_settings->setting_value ;
}
if($user_settings->setting_name == 'paypal_business_email' && $user_settings->setting_value != ''){
$_SESSION['do_invoice']->paypal_business_email = $user_settings->setting_value ;
}
if($user_settings->setting_name == 'payment_selection' && $user_settings->setting_value != ''){
$_SESSION['do_invoice']->payment_selection = $user_settings->setting_value;
}
/* if(empty($payment_mode)){
if((!empty($_SESSION['do_invoice']->authnet_login)) && (!empty($_SESSION['do_invoice']->authnet_merchant_id))){
$payment_mode = true;
}
}*/
if($user_settings->setting_name == 'currency' && $user_settings->setting_value != ''){
$currency = explode("-",$user_settings->setting_value) ;
$_SESSION['do_invoice']->currency_iso_code = $currency[0];
$_SESSION['do_invoice']->currency_sign = $currency[1];
$_SESSION['do_invoice']->setCurrencyDisplay() ;
$_SESSION['do_invoice']->getCurrencyPostion() ;
}
}
}// User setting data ends here
if(isset($_SESSION['do_invoice']->payment_selection)){
if($_SESSION['do_invoice']->payment_selection == 'authorized.net'){
if((!empty($_SESSION['do_invoice']->authnet_login)) && (!empty($_SESSION['do_invoice']->authnet_merchant_id))){
$payment_mode = true;
}
}
} else {
if((!empty($_SESSION['do_invoice']->authnet_login)) && (!empty($_SESSION['do_invoice']->authnet_merchant_id))){
$payment_mode = true;
}
}
if($payment_mode == true){
$do_user_detail->free();
$arr_user_info = $do_contact->getContactInfo_For_Invoice($do_recurrent->idcontact);
$inv_info_arr = array();
$inv_info_arr['description'] = $_SESSION['do_invoice']->description;
$inv_info_arr['inv_num'] = $_SESSION['do_invoice']->num;
$cc_number = $do_recurrent_cc->CCDecrypt($do_recurrent->cc_num);
$payment_type = $do_recurrent->cc_type;
$expire_year = $do_recurrent->cc_exp_year;
$expire_month = $do_recurrent->cc_exp_mon;
/* @param true = test mode
@param false = non test mode i.e live
*/
$payment = new Authnet(false, $arr_user_info,$_SESSION['do_invoice']->authnet_login,$_SESSION['do_invoice']->authnet_merchant_id,$inv_info_arr);
$cc_msg = $payment->validateCreditCard($cc_number, $payment_type,"",$expire_year, $expire_month,false);
//echo '<br />'.$cc_msg;
if($cc_msg == ""){
$invoice = uniqid('ofuz_', true);
$expiration = $expire_month.$expire_year;
$payment->transaction($cc_number, $expiration, $do_recurrent->net_total, "", $do_recurrent->idinvoice);
$payment->process();
if ($payment -> isApproved()){
$transactionID = $payment->getTransactionID();
echo '<br />Payment Processed for invoice ID::: '.$do_recurrent->idinvoice.' Transaction ID ::: '.$transactionID.'<br />';
$do_pay_log = new PaymentLog();
$do_pay_log->addPaymentLog($transactionID,"AuthNet",$do_recurrent->idinvoice,$do_recurrent->net_total);
$idpayment_log = $do_pay_log->getPrimaryKeyValue();
$do_payment_inv = new PaymentInvoice();
$do_payment_inv->addPaymentInvoice($idpayment_log,$_SESSION['do_invoice']->idinvoice,$do_recurrent->net_total);
$_SESSION['do_invoice']->updatePayment($do_recurrent->net_total);
$_SESSION['do_invoice']->sendPaymentApprovedEmail($do_recurrent->net_total,"Authorized.net",$transactionID);
$do_inv_callback = new InvoiceCallback();
$do_inv_callback->processCallBack($_SESSION['do_invoice']->idinvoice,$_SESSION['do_invoice']->num,$do_recurrent->net_total,$_SESSION['do_invoice']->iduser,"AuthNet",$transactionID);
$do_inv_callback->free();
}elseif($payment -> isDeclined()){
$reason = $payment -> getResponseText();
$do_inv_callback = new InvoiceCallback();
$do_inv_callback->processCallBack($_SESSION['do_invoice']->idinvoice,$_SESSION['do_invoice']->num,$do_recurrent->net_total,$_SESSION['do_invoice']->iduser,"fail","AuthNet","",$reason);
}else{
$reason = $payment -> getResponseText();
$do_inv_callback = new InvoiceCallback();
$do_inv_callback->processCallBack($_SESSION['do_invoice']->idinvoice,$_SESSION['do_invoice']->num,$do_recurrent->net_total,$_SESSION['do_invoice']->iduser,"fail","AuthNet","",$reason);
}
}
}
}
$do_invoice->free();
}
?>