예제 #1
0
 public function show($id = null)
 {
     $cart = $this->getCart($id);
     foreach ($cart->items() as $item) {
         if ($item->paid) {
             $item->destroy();
         } elseif (is_a($item, 'EventSignup') && $item->is_soldout()) {
             $item->destroy();
         } elseif (is_a($item, "EventService")) {
             if (!$item->event_signup->paid || !$item->service->available()) {
                 $item->destroy();
             }
         }
     }
     if (count($cart->items(true)) == 0) {
         $cart->destroy();
         Site::Flash("There is nothing to pay for in this cart.");
         Redirect("bookings");
     }
     $cart->check_discounts();
     $terms = Content::find_by_permalink("terms");
     $gateway = PaymentGateway::getActive();
     $this->assign('gateway', $gateway);
     $this->assign('baseURI', $this->getBaseURI());
     $this->assign('cart', $cart);
     $this->assign("terms", $terms);
     $this->title = "My Bookings :: Payment Options";
     $this->render("cart/show.tpl");
 }
예제 #2
0
 public function getPaymentTransaction($baseuri = null)
 {
     // Try and find a valid payment transaction for this cart
     $id = mysql_real_escape_string($this->id);
     $hash = mysql_real_escape_string($this->hash);
     $amount = round($this->cost(true, false) / 100, 2);
     $escapedAmount = mysql_real_escape_string($amount);
     $transaction = PaymentTransaction::find("paymenttransactions.cart_id = '{$id}' AND paymenttransactions.amount = '{$escapedAmount}' AND paymenttransactions.status IN ('ptsNew', 'ptsTaken') AND paymentgateways.enabled = 1");
     if (!$transaction) {
         $transaction = new PaymentTransaction();
         $transaction->amount = $amount;
         $transaction->hash = $this->hash;
         $transaction->cart = $this;
         $transaction->cart_id = $this->id;
         $transaction->paymentgateway = PaymentGateway::getActive();
         $transaction->paymentgateway_id = $transaction->paymentgateway->id;
         $transaction->baseuri = $baseuri;
         if (!$transaction->save()) {
             throw new Error500('Unable to create payment transaction');
         }
     }
     return $transaction;
 }
 public function pay($id = null)
 {
     $signup = self::load_signup($id);
     // Check signup here
     if (!$signup->paid and $signup->is_soldout()) {
         Site::Flash("error", "The ticket you have chosen has sold out");
         Redirect("bookings/{$signup->id}");
     }
     if ($signup->event->enddate < time()) {
         Site::Flash("error", "This event has now finished, it is not possible to pay for your booking");
         Redirect("bookings/{$signup->id}");
     }
     $services = $signup->check_services();
     $signup->event_services();
     $cart = Cart::create_from_signup($signup);
     if ($cart) {
         $cart->check_discounts();
         $this->assign("cart", $cart);
         $this->assign("signup", $signup);
         $this->assign("services", $services);
         $this->assign('eventpage', true);
         $terms = EventContent::find_by_permalink($signup->event, "terms");
         $this->assign("terms", $terms);
         $gateway = PaymentGateway::getActive();
         $this->assign('gateway', $gateway);
         $this->assign('baseURI', $this->getBaseURI());
         $this->title = "My Bookings :: {$signup->event->name} :: Pay";
         $this->render("event_signup/pay.tpl");
     } else {
         Site::Flash("error", "There is nothing to pay for in this booking");
         Redirect("bookings/{$signup->id}");
     }
 }