Пример #1
0
 function add_recurrent()
 {
     $do_api_invoice = new Invoice();
     $do_api_rec_invoice = new RecurrentInvoice();
     if (!$do_api_invoice->isInvoiceOwner($this->idinvoice, $this->iduser)) {
         $this->setMessage("711", "Invoice does not belong to you");
         return false;
     } elseif (!in_array($this->recurrencetype, $do_api_rec_invoice->frequencyComboArray)) {
         $this->setMessage("731", "Invalid Invoice Recurrent Type");
         return false;
     } elseif (!preg_match("/^[0-9]*\$/", $this->recurrence, $parts) || $this->recurrence == 0) {
         $this->setMessage("732", "Invalid Invoice Recurrent Value");
         return false;
     } elseif ($this->callback_url != '' && !preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $this->callback_url)) {
         $this->setMessage("722", "Invalid Call Back URL");
         return false;
     } elseif ($this->next_url != '' && !preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $this->next_url)) {
         $this->setMessage("723", "Invalid Next URL");
         return false;
     } elseif ($do_api_rec_invoice->checkIfInvoiceIsInRecurrent($this->idinvoice)) {
         $this->setMessage("733", "Invoice is already set to recurrent idinvoice :" . $this->idinvoice);
         return false;
     } else {
         //add Recurrent Here
         if ($this->callback_url != '' || $this->next_url != '') {
             $add_call_back_url = true;
         }
         if ($add_call_back_url) {
             $do_api_inv_call_back = new InvoiceCallback();
             $callback = $do_api_inv_call_back->addCallBackUrl($this->idinvoice, $this->callback_url, $this->next_url);
         }
         $do_api_invoice->getId($this->idinvoice);
         $do_api_rec_invoice->addRecurrentInvoice($this->idinvoice, $this->recurrence, $this->recurrencetype, $do_api_invoice->datecreated, $this->iduser);
         if ($callback !== true) {
             $this->setValues(array("msg" => "Invoice has been set as recurrent for-Call back URL exists for idinvoice : " . $this->idinvoice, "stat" => "ok", "code" => "730", "callback_url" => $callback));
         } else {
             $this->setValues(array("msg" => "Invoice has been set as recurrent for " . $this->idinvoice, "stat" => "ok", "code" => "730"));
         }
         return true;
     }
 }
Пример #2
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);
 }
Пример #3
0
         }
         //Email for admin
         $doemail_template_adm = new EmailTemplate("ofuz_inv_payment_confirmation_adm");
         $doemail_template_adm->setSenderName('Admin');
         $doemail_template_adm->setSenderEmail($admin_email);
         $emailer2 = new Radria_Emailer();
         $emailer2->setEmailTemplate($doemail_template_adm);
         $emailer2->mergeArray($email_data);
         $emailer2->addTo($admin_email);
         print_r($emailer);
         //$emailer->send();
         $do_user = new User();
         $date = date('Y-m-d');
         $do_user->query("update user set plan='paid' where iduser="******"Y-m-d"), $iduser);
         echo "Paid";
     } else {
         $do_user = new User();
         $do_user->query("update user set status='suspend'  where iduser="******"Not paid declined";
     }
     $do_pay_log->free();
     $do_payment_inv->free();
     $do_invoice1->free();
     $do_invoice->free();
     $do_user->free();
     $do_recurrentInvoice->free();
     $payment->free();
     $read_qry2->free();
 }