Ejemplo n.º 1
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);
 }
     if ($_SESSION['do_invoice']->payment_selection == 'stripe.com') {
         if (!empty($_SESSION['do_invoice']->stripe_api_key) && !empty($_SESSION['do_invoice']->stripe_publish_key)) {
             $payment_mode = true;
         }
     }
 } else {
     if (!empty($_SESSION['do_invoice']->stripe_api_key) && !empty($_SESSION['do_invoice']->stripe_publish_key)) {
         $payment_mode = true;
     }
 }
 if ($payment_mode == true) {
     echo $_SESSION['do_invoice']->idcontact;
     $stripe_customer_id = $_SESSION['do_invoice']->getStripeCustomerId($_SESSION['do_invoice']->iduser, $_SESSION['do_invoice']->idcontact);
     if (!empty($stripe_customer_id)) {
         $total = $do_recurrent->net_total * 100;
         $payment = new StripeGateWay(false, $_SESSION['do_invoice']->stripe_api_key);
         $result = $payment->ChargeExsistingCustomer($stripe_customer_id, $total);
         if ($result['success'] == '1') {
             $total = $total / 100;
             $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->sendPaymentApprovedEmail($total,"Stripe.com",$transactionID);// Sending to customer
             //$this->sendPaymentApprovedEmail($total,"Stripe.com",$transactionID,true); // Sending to user
             $inv_qry = new sqlQuery($conx);
             $date_paid = date("Y-m-d");
             $status = 'Paid';
             $invoice_note = 'Thanks for the business';
             $sub_total = $total;
Ejemplo n.º 3
0
 $sql_get_ccdetails = "SELECT token  from cc_details where iduser = '******'";
 $read_qry2->query($sql_get_ccdetails);
 if ($read_qry2->getNumrows() > 0) {
     $read_qry2->fetch();
     $user_tokenid = $read_qry2->getData('token');
 } else {
     $user_tokenid = '';
 }
 if (!empty($user_tokenid)) {
     $name = $read_qry->getData('name');
     $email = $read_qry->getData('email');
     $description = $name;
     $srtipecustomer_id = $user_tokenid;
     //Amount need to conver to cents
     $total_amount = $membership_amount * 100;
     $payment = new StripeGateWay(false, $stripe_api_key);
     if (!empty($srtipecustomer_id)) {
         $result = $payment->ChargeExsistingCustomer($srtipecustomer_id, $total_amount);
     }
     if ($result['success'] == '1') {
         //set the amout back to $ value
         $re_membership_amount = $total_amount / 100;
         //Add the customer id in to stripe details class
         if (isset($result['customer_id'])) {
             $do_invoice->saveStripeCustomerId($adm_iduser, $read_qry->getData('idcontact'), $result['customer_id']);
         }
         $do_pay_log = new PaymentLog();
         $do_pay_log->addPaymentLog($result['response']['id'], "Stripe", $idinvoice, $total);
         $idpayment_log = $do_pay_log->getPrimaryKeyValue();
         $do_payment_inv = new PaymentInvoice();
         $do_payment_inv->addPaymentInvoice($idpayment_log, $idinvoice, $total);