function __construct($id, $type) { parent::__construct($id); $this->payment = RegistrationPayment::load(array('order_id' => $id, 'payment_type' => $type)); if (!$this->payment) { error_exit("No such payment for this registration"); } }
function process() { global $lr_session; $this->title = 'Registration ' . $this->registration->formatted_order_id() . ' » Add Payment'; $this->smarty->assign('reg', $this->registration); $this->smarty->assign('event', $this->event); // TODO: should be get_user() for consistency. $this->smarty->assign('registrant', $this->registration->user()); $edit = $_POST['edit']; $payment = new RegistrationPayment(); $payment->set('order_id', $this->registration->order_id); $payment->set('entered_by', $lr_session->user->user_id); $fields = array('payment_type', 'payment_amount', 'payment_method', 'paid_by', 'date_paid'); foreach ($fields as $field) { $payment->set($field, $edit[$field]); } $dataInvalid = $payment->validate(); if ($dataInvalid) { info_exit($dataInvalid . '<br>Please use your back button to return to the form, fix these errors, and try again.'); } switch ($edit['step']) { default: case 'confirm': $this->smarty->assign('payment', $payment); $this->template_name = 'pages/registration/addpayment.tpl'; break; case 'submit': if (!$payment->save()) { error_exit("Internal error: couldn't save payment"); } switch ($payment->payment_type) { case 'Deposit': $this->registration->set('payment', 'Deposit Paid'); break; case 'Full': case 'Remaining Balance': $this->registration->set('payment', 'Paid'); break; } if (!$this->registration->save()) { error_exit("Internal error: couldn't save changes to registration"); } local_redirect(url("registration/view/" . $this->registration->order_id)); break; } return true; }
function get_payments() { if (!$this->_payments) { $this->_payments = RegistrationPayment::load_many(array('order_id' => $this->order_id, '_order' => 'date_paid')); } return $this->_payments; }
/** * Checks information received from PayPal to ensure it's correct data. * If correct, stores updated transaction details. * * @param int $order_id Registration # of event being paid * @param float $mc_gross Amount paid by user during the PayPal checkout * @param int $paid_by User ID of player who made the payment */ function validatePayment($order_id, $mc_gross, $paid_by) { // is the item number a valid registration? $registration = Registration::load(array('order_id' => $order_id)); if (!$registration) { $status = array('status' => false, 'message' => 'Invalid Registration ID'); return $status; } // has registration been already paid? //if ($registration->payment_type == 'Paid') { // $status = array('status' => false, 'message' =>'Registration '.$order_id.' already paid in full'); // return $status; //} // is the registration attached to the correct Event $event = Event::load(array('registration_id' => $registration->registration_id)); if (!$event) { $status = array('status' => false, 'message' => 'Invalid Event ID'); return $status; } // does the price paid and registration cost match? if ($mc_gross != $event->cost) { $status = array('status' => false, 'message' => 'Amount Paid does not match Registration Cost'); return $status; } // Payment is valid, and should be saved $payment = new RegistrationPayment(); $payment->set('order_id', $registration->order_id); // TODO: PDT returns from PayPal are logged under the Paypal account. // Would be nice to find a better way to do this instead of a Paypal user account $payment->set('entered_by', 999); // assign requrired values to the RegistrationPayment from the talkback results $payment->set('payment_type', 'Full'); $payment->set('payment_amount', $mc_gross); $payment->set('payment_method', 'PayPal'); $payment->set('paid_by', $paid_by); $payment->set('date_paid', date("Y-m-d")); // Save the payment if it's not already stored in the database // It's possible that the IPN payment beats the user PDT return. // Still need to ensure user is informed correctly, while not displaying any errors. if ($registration->payment_type != 'Paid') { if (!$payment->save()) { $status = array('status' => false, message => "Couldn't save payment to database"); return $status; } // update registration in question $registration->set('payment', 'Paid'); if (!$registration->save()) { $status = array('status' => false, message => "Internal error: couldn't save changes to registration"); } } // if successful, return the $payment to handle/display to user return array('status' => true, 'message' => $payment); }