public function show($id = null)
 {
     $cart = $this->load_cart($id);
     if (!$cart->paid) {
         $cart->check_discounts();
         $manualGateway = null;
         $gateways = null;
         $allGateways = PaymentGateway::find_all('', 'paymentgateways.position ASC');
         foreach ($allGateways as $gateway) {
             $gateways[$gateway->id] = $gateway->name;
             if ($gateway->code == 'manual') {
                 $manualGateway = $gateway;
             }
         }
         $payment = new PaymentTransaction();
         $payment->cart_id = $cart->id;
         $payment->cart = $cart;
         $payment->paymentgateway = $manualGateway;
         $payment->paymentgateway_id = $manualGateway->id;
         $payment->externalid = (string) $cart;
         $payment->amount = Money($cart->cost());
         $payment->sender = $cart->user->email;
         $payment->status = 'ptsTaken';
         $payment->processResponse = array('notes' => '');
         if ($this->post) {
             $payment->paymentgateway_id = $this->postData('paymentgateway_id');
             $payment->externalid = $this->postData('externalid');
             $payment->sender = $this->postData('sender');
             $payment->amount = $this->postData('amount');
             $payment->processResponse = array('notes' => $this->postData('notes'));
             $payment->method = $gateways[$payment->paymentgateway_id];
             if ($payment->save()) {
                 Email::send_user_paymentconfirmation($payment);
                 $cart->mark_paid($payment, 'Manually Paid');
                 Email::send_payment_complete(array(), "", $cart);
                 Site::Flash('notice', 'The cart has been paid for');
                 Redirect("admin/carts/{$cart->id}");
             } else {
                 Site::InstantFlash('error', 'Invalid payment');
             }
             echo '<pre>';
             print_r($payment);
             die;
         }
         $this->assign('payment', $payment);
         $this->assign('gateways', $gateways);
     }
     $this->assign('cart', $cart);
     $this->title = "Cart :: {$cart->id}";
     $this->render('cart/show.tpl');
 }
Example #2
0
 protected static function getDiscountBreakdown($discount, $originalCost, $fullCart = false)
 {
     $description = "{$discount->code}: {$discount->description}";
     $amount = '-' . Money($discount->calculate_saving($originalCost, $fullCart));
     return array('discount' => true, 'id' => $discount->id, 'description' => $description, 'price' => '-£' . $amount, 'textid' => str_pad($discount->id, 5), 'textdescription' => str_pad('   ' . $description, 70), 'textprice' => str_pad('£' . $amount, 8, ' ', STR_PAD_LEFT));
 }