Ejemplo n.º 1
0
 /**
  * Event Method for Authnet Payment Process
  * test with credit card 4111111111111111
  * American Express Card Test : 378282246310005
  * @param $evtcl -- Object
  */
 function eventProcessAuthNetPayment(Eventcontroler $evtcl)
 {
     $flag = true;
     if ($evtcl->tot_amt > $_SESSION['do_invoice']->amt_due) {
         $_SESSION['in_page_message'] = _("The Total Amount entered is greater than the invoice amount. Please re-enter.");
         $flag = false;
     }
     if ($flag) {
         // $this->Authnet_message = "";
         include_once 'class/Authnet.class.php';
         $payment_type = $evtcl->payment_type;
         $cc_number = $evtcl->cc;
         $cvv = trim($evtcl->cvv);
         $expire_year = $evtcl->expire_year;
         $expire_month = $evtcl->expire_month;
         $expiration = $evtcl->expire_month . $evtcl->expire_year;
         if ($evtcl->tot_amt > 0) {
             $total = $evtcl->tot_amt;
         } else {
             $total = $_SESSION['do_invoice']->amt_due;
         }
         $idinvoice = $_SESSION['do_invoice']->idinvoice;
         $idcontact = $_SESSION['do_invoice']->idcontact;
         $goto = $evtcl->goto;
         $do_contact = new Contact();
         $arr_user_info = $do_contact->getContactInfo_For_Invoice($idcontact);
         $auth_login = $_SESSION['do_invoice']->authnet_login;
         $inv_info_arr = array();
         $inv_info_arr['description'] = $_SESSION['do_invoice']->description;
         $inv_info_arr['inv_num'] = $_SESSION['do_invoice']->num;
         $auth_merchant_id = $_SESSION['do_invoice']->authnet_merchant_id;
         /* @param true = test mode
         			@param false = non test mode i.e live  
         			*/
         $payment = new Authnet(false, $arr_user_info, $auth_login, $auth_merchant_id, $inv_info_arr);
         $cc_msg = $payment->validateCreditCard($cc_number, $payment_type, $cvv, $expire_year, $expire_month);
         if ($cc_msg == "") {
             $invoice = uniqid('ofuz_', true);
             $payment->transaction($cc_number, $expiration, $total, $cvv, $invoice);
             $payment->process();
             if ($payment->isApproved()) {
                 $reason = $payment->getResponseText();
                 // Display a printable receipt
                 $_SESSION['in_page_message'] = _("This transaction has been approved. Thank you for your payment");
                 $transactionID = $payment->getTransactionID();
                 $do_pay_log = new PaymentLog();
                 $do_pay_log->addPaymentLog($transactionID, "AuthNet", $_SESSION['do_invoice']->idinvoice, $total);
                 $idpayment_log = $do_pay_log->getPrimaryKeyValue();
                 $do_payment_inv = new PaymentInvoice();
                 $do_payment_inv->addPaymentInvoice($idpayment_log, $_SESSION['do_invoice']->idinvoice, $total);
                 $this->updatePayment($total);
                 $this->sendPaymentApprovedEmail($total, "Authorized.net", $transactionID);
                 // Sending to customer
                 $this->sendPaymentApprovedEmail($total, "Authorized.net", $transactionID, true);
                 // Sending to user
                 /*
                 	Lets check if the invoice has an call back URL and process that
                 */
                 $do_inv_callback = new InvoiceCallback();
                 $do_User = $_SESSION['do_invoice']->getParentUser();
                 $do_inv_callback->processCallBack($this->idinvoice, $this->num, $total, $do_User->iduser, "ok", "AuthNet", $transactionID);
                 /*
                 Check if there is a next URL if so then set goto variable to that URL. Userful if we want the user to go to someother page
                 Than in the goto page. This is triggered only when full payment is done.
                 */
                 $next_url = $do_inv_callback->isNextUrl($this->idinvoice);
                 //if($next_url !== false){
                 //     $due_amt = $this->getDueAmount($this->idinvoice);
                 //     if($due_amt == '0.00'){
                 $goto = $next_url;
                 //     }
                 //}
                 $_SESSION['autologin_paid'] = True;
                 // Add the CC info in the RecurrentInvoiceCC
                 if ($evtcl->is_rec != 0 && $evtcl->is_cc == 0) {
                     $RecurrentInvoiceCC = new RecurrentInvoiceCC();
                     $RecurrentInvoiceCC->add_cc_info($cc_number, $expire_year, $expire_month, $evtcl->payment_type, $evtcl->is_rec);
                 }
             } else {
                 if ($payment->isDeclined()) {
                     $reason = $payment->getResponseText();
                     $do_inv_callback = new InvoiceCallback();
                     $do_inv_callback->processCallBack($this->idinvoice, $this->num, $total, $_SESSION['do_User']->iduser, "fail", "AuthNet", "", $reason);
                     $goto = $evtcl->error_page;
                     // As for another form of payment
                     $_SESSION['in_page_message'] = _("The transaction has been declined.'{$reason}'");
                 } else {
                     $reason = $payment->getResponseText();
                     //$reason .= $payment->getResponseCode();
                     $do_inv_callback = new InvoiceCallback();
                     $do_inv_callback->processCallBack($this->idinvoice, $this->num, $total, $_SESSION['do_User']->iduser, "fail", "AuthNet", "", $reason);
                     $goto = $evtcl->error_page;
                     // Ask the merchant to call us
                     $_SESSION['in_page_message'] = _("The transaction failed.'{$reason}'");
                 }
             }
         } else {
             $_SESSION['in_page_message'] = $cc_msg;
         }
     }
     $evtcl->setDisplayNext(new Display($goto));
 }
Ejemplo n.º 2
0
    if (!is_object($_SESSION['do_invoice'])) {
        $do_invoice = new Invoice();
        $do_invoice->sessionPersistent("do_invoice", "index.php", OFUZ_TTL);
    }
    $_SESSION['do_invoice']->getId($id);
    if ($status == "Completed") {
        $do_pay_log = new PaymentLog();
        $do_pay_log->addPaymentLog($ref_num, "Paypal", $_SESSION['do_invoice']->idinvoice, $amt_paid);
        $idpayment_log = $do_pay_log->getPrimaryKeyValue();
        $do_payment_inv = new PaymentInvoice();
        $do_payment_inv->addPaymentInvoice($idpayment_log, $_SESSION['do_invoice']->idinvoice, $amt_paid);
        $_SESSION['do_invoice']->updatePayment($amt_paid);
        // if(!$do_pay_log->isTransRefExists($ref_num,$_SESSION['do_invoice']->idinvoice,"Paypal")){
        // $do_pay_log->addPaymentLog($ref_num,"Paypal",$_SESSION['do_invoice']->idinvoice,$amt_paid);
        // $_SESSION['do_invoice']->updatePayment($amt_paid);
        $_SESSION['do_invoice']->sendPaymentApprovedEmail($amt_paid, "Paypal", $ref_num);
        $_SESSION['do_invoice']->sendPaymentApprovedEmail($amt_paid, "Paypal", $ref_num, true);
        // True for sending the ofuz user
        /*
           Lets check if the invoice has an call back URL and process that
        */
        $do_inv_callback = new InvoiceCallback();
        $do_inv_callback->processCallBack($_SESSION['do_invoice']->idinvoice, $_SESSION['do_invoice']->num, $amt_paid, $_SESSION['do_invoice']->iduser, "ok", "Paypal", $ref_num);
        //}
        $_SESSION['in_page_message'] = _("This transaction has been approved.");
    } else {
        $do_inv_callback = new InvoiceCallback();
        $do_inv_callback->processCallBack($_SESSION['do_invoice']->idinvoice, $_SESSION['do_invoice']->num, $amt_paid, $_SESSION['do_invoice']->iduser, "fail", "Paypal", "", $status);
        $_SESSION['in_page_message'] = _("The transaction has been declined.'{$status}'");
    }
}
Ejemplo n.º 3
0
 /**
  * Event Method for Stripe Payment Process
  * test with credit card 4242424242424242
  * @param object $evtcl 
  */
 function eventProcessStripePayment(Eventcontroler $evtcl)
 {
     $flag = true;
     if ($evtcl->tot_amt > $_SESSION['do_invoice']->amt_due) {
         $_SESSION['in_page_message'] = _("The Total Amount entered is greater than the invoice amount. Please re-enter.");
         $flag = false;
     }
     if ($flag) {
         include_once 'class/Stripe.class.php';
         include_once "stripe-lib/Stripe.php";
         $token = $evtcl->stripeToken;
         $name = $evtcl->name;
         //$email = $evtcl->email;
         $description = $name;
         $srtipecustomer_id = $evtcl->stripecustomer_id;
         if ($evtcl->tot_amt > 0) {
             $total = $evtcl->tot_amt;
         } else {
             $total = $_SESSION['do_invoice']->amt_due;
         }
         //Amount need to conver to cents
         $total = $total * 100;
         $idinvoice = $_SESSION['do_invoice']->idinvoice;
         $idcontact = $_SESSION['do_invoice']->idcontact;
         $goto = $evtcl->goto;
         $error_page = $evtcl->error_page;
         $updateStripecustomer = $evtcl->updateStripecustomer;
         $do_contact = new Contact();
         $arr_user_info = $do_contact->getContactInfo_For_Invoice($idcontact);
         $inv_info_arr = array();
         $inv_info_arr['description'] = $_SESSION['do_invoice']->description;
         $inv_info_arr['inv_num'] = $_SESSION['do_invoice']->num;
         $stripe_api_key = $evtcl->stripe_api_key;
         $payment = new StripeGateWay(false, $stripe_api_key);
         if (empty($srtipecustomer_id)) {
             $result = $payment->CreateCustomer($token, $name, $total, $email = "", $description);
         } else {
             if ($updateStripecustomer === 'Yes') {
                 $result = $payment->UpdateExistingCustomer($srtipecustomer_id, $token, $name, $total, $email = "", $description = "");
                 if ($result['update'] == 1) {
                     $payment = new StripeGateWay(false, $stripe_api_key);
                     $result = $payment->CreateCustomer($token, $name, $total, $email = "", $description);
                 }
             } else {
                 $result = $payment->ChargeExsistingCustomer($srtipecustomer_id, $total);
             }
         }
         if ($result['success'] == '1') {
             //set the amout back to $ value
             $total = $total / 100;
             //echo $result['customer_id'];die();
             //Add the customer id in to stripe details class
             if (isset($result['customer_id'])) {
                 $this->saveStripeCustomerId($_SESSION['do_invoice']->iduser, $_SESSION['do_invoice']->idcontact, $result['customer_id']);
             }
             // Display a printable receipt
             $_SESSION['in_page_message'] = _("This transaction has been approved. Thank you for your payment");
             $do_pay_log = new PaymentLog();
             $do_pay_log->addPaymentLog($result['response']['id'], "Stripe", $_SESSION['do_invoice']->idinvoice, $total);
             $idpayment_log = $do_pay_log->getPrimaryKeyValue();
             $do_payment_inv = new PaymentInvoice();
             $do_payment_inv->addPaymentInvoice($idpayment_log, $_SESSION['do_invoice']->idinvoice, $total);
             $this->updatePayment($total);
             //$this->sendPaymentApprovedEmail($total,"Stripe.com",$transactionID);// Sending to customer
             //$this->sendPaymentApprovedEmail($total,"Stripe.com",$transactionID,true); // Sending to user
             if (isset($_SESSION["upgrade"])) {
                 $do_user = new User();
                 $date = date('Y-m-d');
                 $do_user->query("update user set plan='paid', regdate = '{$date}' where iduser="******"Y-m-d"), $_SESSION['do_User']->iduser);
                 $do_ccdetails = new CcDetails();
                 $do_ccdetails->iduser = $_SESSION['do_User']->iduser;
                 $do_ccdetails->token = $result['customer_id'];
                 $do_ccdetails->type = 'Stripe';
                 $do_ccdetails->add();
                 $goto = 'index.php';
                 unset($_SESSION['upgrade']);
             } else {
                 /*
                   Lets check if the invoice has an call back URL and process that
                 */
                 $do_inv_callback = new InvoiceCallback();
                 $do_User = $_SESSION['do_invoice']->getParentUser();
                 $do_inv_callback->processCallBack($this->idinvoice, $this->num, $total, $do_User->iduser, "ok", "Stripe", $transactionID);
                 /*
                 Check if there is a next URL if so then set goto variable to that URL. Userful if we want the user to go to someother page
                 Than in the goto page. This is triggered only when full payment is done.
                 */
                 $next_url = $do_inv_callback->isNextUrl($this->idinvoice);
             }
             //$goto = $next_url;
             $_SESSION['autologin_paid'] = True;
         } else {
             $rr = json_decode($result, true);
             //echo'<pre>';print_r($rr);echo'</pre>';die();
             $r = $rr['error']['message'];
             $error_code = $rr['error']['code'];
             $error_type = $rr['error']['type'];
             if ($error_code == 'invalid_expiry_month' || $error_code == 'invalid_expiry_year' || $error_code == 'expired_card' || $error_code == 'missing') {
                 $goto = $error_page;
                 $_SESSION['updatecustomer'] = 'Yes';
             } elseif ($error_type == 'invalid_request_error') {
                 $goto = $error_page;
                 $_SESSION['updatecustomer'] = 'Yes';
             }
             $_SESSION['in_page_message'] = $r;
         }
     }
     $disp_next = new Display($goto);
     if (isset($_SESSION['upgrade'])) {
         $msg = "Thank You . Your payment has been apporved and now you are paid user.";
         $disp_next->addParam("message", $msg);
     }
     $evtcl->setDisplayNext($disp_next);
 }
Ejemplo n.º 4
0
 function upgrade_plan_add_invoice()
 {
     $add_call_back_url = false;
     $do_contact_invoice = new Contact();
     $do_api_invoice = new Invoice();
     $do_api_invoice->addNew();
     $do_contact_invoice->setSqlViewName($_SESSION["do_User"]->iduser);
     //  set the sqlview name
     $do_api_invoice->idcontact = $this->idcontact;
     $do_api_invoice->iduser = $this->iduser;
     $do_api_invoice->status = $this->type;
     // could be status
     $do_api_invoice->num = $do_api_invoice->getUniqueInvoiceNum($this->iduser);
     $do_api_invoice->datecreated = date("Y-m-d");
     $do_api_invoice->due_date = $this->due_date;
     $do_api_invoice->invoice_address = $do_contact_invoice->ajaxGetInvoiceAddress($this->idcontact);
     $do_api_invoice->invoice_term = $this->invoice_term;
     $do_api_invoice->invoice_note = $this->invoice_note;
     $do_api_invoice->description = $this->description;
     $do_contact_invoice->getId($this->idcontact);
     $do_api_invoice->idcompany = $do_contact_invoice->idcompany;
     $do_api_invoice->amt_due = $this->amt_due;
     $do_api_invoice->sub_total = $this->sub_total;
     $do_api_invoice->net_total = $this->net_total;
     $do_api_invoice->discount = $this->discount;
     $do_api_invoice->add();
     $idinvoice = $do_api_invoice->getPrimaryKeyValue();
     /** 
      * Will Add an entry to the Invoice line table 
      * */
     if ($_SESSION["upgrade"]) {
         $do_invoice_line = new InvoiceLine();
         $do_invoice_line->idinvoice = $idinvoice;
         $do_invoice_line->item = 'User Plan Upgrade';
         $do_invoice_line->price = $this->amt_due;
         $do_invoice_line->qty = 1;
         $do_invoice_line->total = $this->amt_due;
         $do_invoice_line->description = $this->description;
         $do_invoice_line->add();
     }
     //add to table invoice call back for trail users
     $url = $this->url;
     $next_url = $this->next_url;
     $invoice_call_back = new InvoiceCallback();
     $invoice_call_back->addCallBackUrl($idinvoice, $url, $next_url);
     /*if($add_call_back_url){
           $do_api_inv_call_back = new InvoiceCallback();
           $callback = $do_api_inv_call_back->addCallBackUrl($idinvoice,$this->callback_url,$this->next_url);
       }*/
     $do_api_user_rel = new UserRelations();
     //$inv_url =  $GLOBALS['cfg_ofuz_site_https_base'].'inv/'.$do_api_user_rel->encrypt($idinvoice).'/'.$do_api_user_rel->encrypt($this->idcontact);
     $pay_url = $GLOBALS['cfg_ofuz_site_https_base'] . 'pay/' . $do_api_user_rel->encrypt($idinvoice) . '/' . $do_api_user_rel->encrypt($this->idcontact);
     //$inv_url =  'http://ofuz.localhost/inv/'.$do_api_user_rel->encrypt($idinvoice).'/'.$do_api_user_rel->encrypt($this->idcontact);
     //$pay_url =  'http://ofuz.localhost/pay/'.$do_api_user_rel->encrypt($idinvoice).'/'.$do_api_user_rel->encrypt($this->idcontact);
     return $pay_url;
 }
 $do_inv_add->getId($do_recurrent->idinvoice);
 $inv_line = $do_inv_add->getChildinvoiceline();
 while ($inv_line->next()) {
     $do_inv_line->addNew();
     $do_inv_line->idinvoice = $idinvoice;
     $do_inv_line->description = $inv_line->description;
     $do_inv_line->price = $inv_line->price;
     $do_inv_line->qty = $inv_line->qty;
     $do_inv_line->total = $inv_line->total;
     $do_inv_line->item = $inv_line->item;
     $do_inv_line->add();
 }
 $do_invoice->setInvoiceCalculations($idinvoice);
 // Call this method for other calculations
 //update callback
 $do_inv_callbak = new InvoiceCallback();
 $do_inv_callbak->updateCallBack($do_recurrent->idcontact, $idinvoice);
 // Process RegistrationInvoiceLog will update only if the invoice is from registration Part of Ofuz.com
 $do_RegistrationInvoiceLog = new RegistrationInvoiceLog();
 // @params old invoiceid,new invoice id and the iduser
 $do_RegistrationInvoiceLog->process_reg_invoice_log($do_recurrent->idinvoice, $idinvoice, $do_recurrent->iduser);
 // Update Recurrent
 $do_recurrent_update = new RecurrentInvoice();
 $next_date = $do_recurrent_update->getNextDate($do_recurrent->recurrence, $do_recurrent->recurrencetype, $do_recurrent->nextdate);
 $do_recurrent_update->getId($do_recurrent->idrecurrentinvoice);
 $do_recurrent_update->nextdate = $next_date;
 $do_recurrent_update->idinvoice = $idinvoice;
 $do_recurrent_update->update();
 $do_recurrent_update->free();
 //Sending Email to the customer
 //echo 'Calling method sendInvoiceByEmail()..........<br />';
                $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();
}