Ejemplo n.º 1
0
 function send()
 {
     $Message = new mContact();
     $Message->__post();
     if ($Message->validate()) {
         $Customer = new mCustomer();
         $Customer->email = $Message->email;
         if ($Customer->load()) {
             $Message->customer = $Customer->id();
         }
         //Save and send
         $Message->save();
         $Email = new mailer();
         $Email->sendContactForm($Message);
         $Email->sendAdminContactConfirm($Message);
         $this->display('sent');
     } else {
         data('send-error', 'The form is not complete');
         $this->display('form');
     }
 }
Ejemplo n.º 2
0
 function charge()
 {
     if (count($this->order->items()) == 0) {
         redirect(getUrl('basket'));
     }
     $this->order->__fromMemory();
     $Customer = new mCustomer();
     $Customer->email = $_SESSION['mCustomer']['email'];
     $Customer->lastname = $_SESSION['mCustomer']['lastname'];
     $Customer->postcode_1 = $_SESSION['mCustomer']['postcode_1'];
     $Customer->postcode_2 = $_SESSION['mCustomer']['postcode_2'];
     $Customer->load();
     $Customer->__fromMemory();
     data('Order', $this->order);
     data('Customer', $Customer);
     if (isset($_POST['stripeToken'])) {
         $API = new stripelib();
         $Metadata = array();
         foreach ($this->order->_data as $K => $V) {
             $Metadata['Order: ' . $K] = $V;
         }
         foreach ($Customer->_data as $K => $V) {
             $Metadata['Customer: ' . $K] = $V;
         }
         $Result = $API->charge($_POST['stripeToken'], $this->order->getTotal(false), 'Order: ' . $this->order->nice_id, $Metadata);
         if ($Result === true) {
             $this->order->payment_method = 'STRIPE';
             $this->order->last_4 = substr($_POST['number'], -4, 4);
             $Customer->save($this->order);
             //Success!
             data('Finished', true);
             $this->display('success');
             //Send the user an email
             $Mailer = new Mailer();
             $Mailer->sendCheckoutComplete($Customer, $this->order);
             //Update availabe numbers
             foreach ($this->order->items() as $Item) {
                 list($Type, $ID) = explode(':', $Item->source());
                 if ($Type == 'shop') {
                     $Product = new mStoreItem($ID);
                     $Product->available -= $Item->quantity();
                     $Product->save();
                 }
             }
             //clear basket and unset
             $this->order->clear();
             $Customer->__clearMemory();
             return;
         } else {
             $Error = $Result->getMessage();
             //Some kind of error, genericly display and register on error handler of some sort
             data('StripeError', $Error);
             $this->display('charge');
             //print_r($Result);
             return;
         }
     } else {
         //Not tried to charge
         $this->display('charge');
     }
 }