/** * everytime a new registration is created * consult with the fee table and create relevant charges * this could be a registration fee * * should we apply the "first time" fee for a newly registered camper * * (non-PHPdoc) * * @see \PhalconRest\API\Entity::afterSave() */ public function afterSave($object, $id) { // only apply system wide fees on insert if ($this->saveMode == 'update') { return; } // pull system fees based around registraton $regFees = \PhalconRest\Models\Fees::find(array("basis = 'Registration'")); $attendee = \PhalconRest\Models\Attendees::findFirst($object->attendee_id); if ($attendee) { // create a charge fee for each one found foreach ($regFees as $fee) { $charge = new \PhalconRest\Models\Charges(); $charge->registration_id = $id; $charge->name = $fee->name; $charge->amount = $fee->amount; $charge->account_id = $attendee->account_id; if ($charge->create() == false) { throw new ValidationException("Internal error creating a registration", array('code' => '34534657', 'dev' => 'Error while processing RegistrationEntity->afterSave(). Could not create Charge record.'), $charge->getMessages()); } } } else { throw new ValidationException("Internal error creating a registration", array('code' => '4562456786', 'dev' => 'Error while processing RegistratinoEntity->afterSave(). Could not find a valid attendee record.'), $charge->getMessages()); } }
/** * for a given request, will toggle fees on/off depeneding on the request status * will take care not to duplicate fees that are already applied * * @param \PhalconRest\Models\Request $request */ private function toggleFees(\PhalconRest\Models\Requests $request) { // are we on or off? if ($request->submit_status == self::CONFIRMED) { $fees = $this->getFees($request); foreach ($fees as $fee) { $charge = new \PhalconRest\Models\Charges(); $charge->registration_id = $request->registration_id; $charge->request_id = $request->id; $charge->name = $fee['name']; $charge->amount = $fee['amount']; $attendee = $request->Registrations->Attendees; $charge->account_id = $attendee->account_id; if (!$charge->create()) { throw new ValidationException("Internal error saving a request", array('code' => '45623457456987986', 'dev' => 'Error while processing RequestEntity->toggleFee(). Could not create Charge record.'), $charge->getMessages()); } } } else { // remove fees foreach (\PhalconRest\Models\Charges::find("request_id={$request->id}") as $charge) { if (!$charge->delete()) { throw new ValidationException("Internal error clearing out charges", array('code' => '234546678345', 'dev' => 'Error while attempting to delete a charge for a request that is no longer CONFIRMED.'), $charge->getMessages()); } } } }