/** * End the current session and clear local session * @return void */ public function endSession() { $session = CheckfrontModule::session(); if ($sessionID = $session->getID()) { CheckfrontModule::api()->post(new CheckfrontAPIRequest('session/end', array('session_id' => $sessionID))); } $session->clear(null); }
/** * */ public function testListPackages() { $this->loadConfig(); /** @var CheckfrontAPIPackagesResponse $response */ $response = CheckfrontModule::api()->listPackages(); $packages = $response->getPackages(); $info = $packages->map('ItemID', 'Title'); $this->assertContains('Package A', $info); }
/** * Creates form with: * - Package Selector dropdown * - Start Date field * - End Date field * - 'Type' field (public/private) which indicates endpoint to book package. * - 'generate' action. * * @param array $controller * @param array $nameOverride - use this instead of default self.FormName * @param $fields * @param $actions * @param null $validator */ public function __construct($controller, $nameOverride, $fields, $actions, $validator = null) { /** @var SS_HTTPRequest $request */ $request = $controller->getRequest(); $fields = $fields ?: new FieldList(); $actions = $actions ?: new FieldList(); // list skus available via the API or get empty array if fails if ($apiResponse = CheckfrontModule::api()->listPackages()) { $fields->push($this->makePackageSelectorField($apiResponse, $request)); // add private endpoint, user type and payment type fields $fields->merge(array($this->makeDateField(self::OrganiserStartDate, ''), $this->makeDateField(self::OrganiserEndDate, ''), $this->makeDateField(self::IndividualStartDate, ''), $this->makeDateField(self::IndividualEndDate, ''), $this->makeLinkTypeField(), $this->makePaymentTypeField())); $actions->merge(new FieldList(array(new FormAction(static::SubmitButtonName, $this->getFieldLabel(static::SubmitButtonName))))); } // all fields are mandatory $validator = new RequiredFields(array_keys($fields->toArray())); parent::__construct($controller, $nameOverride ?: self::FormName, $fields, $actions, $validator); }
/** * Renders the CheckfrontLinkGenerator template with filled in * - Package * - Posted array info * - AccessKey encoded so can copy/paste * - Link to copy paste to email * * @param SS_HTTPRequest $request * * @return HTMLText */ protected function generateLinks(SS_HTTPRequest $request) { $postVars = $request->postVars(); $packageID = $postVars[CheckfrontLinkGeneratorForm::PackageIDFieldName]; $packageResponse = CheckfrontModule::api()->fetchPackage($packageID); if (!($package = $packageResponse->getPackage())) { throw new CheckfrontException(_t('Package.NoSuchPackageMessage', "Package {id}not found", array('id' => $packageID)), CheckfrontException::TypeError); } /* if (!$organiserEvent = $packageResponse->getEvent($postVars[CheckfrontLinkGeneratorForm::OrganiserEventFieldName])) { throw new CheckfrontException(_t('Package.NoSuchEventMessage', "{type}event not found", array('type' => 'Organiser '))); } if (!$individualEvent = $packageResponse->getEvent($postVars[CheckfrontLinkGeneratorForm::IndividualEventFieldName])) { throw new CheckfrontException(_t('Package.NoSuchEventMessage', "{type}event not found", array('type' => 'Individual '))); } */ $accessKey = CheckfrontModule::crypto()->generate_key(); $organiserLink = $this->makeLink($accessKey, $postVars[CheckfrontLinkGeneratorForm::PackageIDFieldName], $postVars[CheckfrontLinkGeneratorForm::OrganiserStartDate], $postVars[CheckfrontLinkGeneratorForm::OrganiserEndDate], $postVars[CheckfrontLinkGeneratorForm::LinkTypeFieldName], CheckfrontModule::UserTypeOrganiser, $postVars[CheckfrontLinkGeneratorForm::PaymentTypeFieldName]); $individualLink = $this->makeLink($accessKey, $postVars[CheckfrontLinkGeneratorForm::PackageIDFieldName], $postVars[CheckfrontLinkGeneratorForm::IndividualStartDate], $postVars[CheckfrontLinkGeneratorForm::IndividualEndDate], $postVars[CheckfrontLinkGeneratorForm::LinkTypeFieldName], CheckfrontModule::UserTypeIndividual, $postVars[CheckfrontLinkGeneratorForm::PaymentTypeFieldName]); $form = $this->buildLinkGeneratorForm(); return $this->renderWith(array('CheckfrontLinkGenerator', 'Page'), array('ShowOutput' => true, 'Package' => $package, 'Posted' => new ArrayData($postVars), 'OrganiserLink' => $organiserLink, 'IndividualLink' => $individualLink, 'AccessKey' => $accessKey, 'CheckfrontForm' => $form)); }
public static function factory($controller, CheckfrontAPIPackageResponse $packageResponse, array $info, array $data) { list($packageID, $startDate, $endDate, $linkType, $userType, $paymentType) = $info; // now build the form $fields = new FieldList(); // add a hidden accessKey field if set $accessKey = isset($data[CheckfrontForm::AccessKeyFieldName]) ? $data[CheckfrontForm::AccessKeyFieldName] : null; $fields->push(new HiddenField(CheckfrontForm::AccessKeyFieldName, '', $accessKey)); if ($userType === CheckfrontModule::UserTypeOrganiser) { // if organiser then add hidden start and end date fields for the actual booking $fields->merge(array(new HiddenField(CheckfrontForm::StartDateFieldName, '', $startDate), new HiddenField(CheckfrontForm::EndDateFieldName, '', $endDate))); } else { // if not organiser then let user specify their start and end dates $fields->merge(array(CheckfrontForm::make_date_field(CheckfrontForm::StartDateFieldName, 'Start Date', $startDate, $startDate, $endDate), CheckfrontForm::make_date_field(CheckfrontForm::EndDateFieldName, 'End Date', $endDate, $startDate, $endDate))); } // add the package items to the field list which will make the form as fields /** @var CheckfrontModel $item */ foreach ($packageResponse->getPackageItems() as $item) { if ($controller->shouldShowItem($item, $userType, $linkType)) { $fields->merge($item->fieldsForForm('form')); } } $fields->merge(new FieldList(array(new HiddenField(CheckfrontAccessKeyForm::AccessKeyFieldName, '', $accessKey)))); $actions = new FieldList(); $required = array(); // add the standard 'booking' fields (name etc) if ($response = CheckfrontModule::api()->fetchBookingForm()) { if ($response->isValid()) { // now add the booking fields to the fieldlist for the form $bookingFields = $response->getFormFields($required); $fields->merge($bookingFields); } $actions->push(new FormAction(static::SubmitButtonName, _t(__CLASS__ . ".SubmitButtonText"))); } $validator = new RequiredFields($required); $form = new CheckfrontPackageBookingForm($controller, static::FormName, $fields, $actions, $validator); return $form; }
public function __construct($dataRecord = null) { $this->api = CheckfrontModule::api(); parent::__construct($dataRecord); }