protected function validate(YousticeShopRegistration $registration) { if (Tools::strlen(trim($registration->getCompanyName())) == 0) { return 'company_name_required'; } if (Tools::strlen(trim($registration->getFirstName())) == 0) { return 'first_name_required'; } if (Tools::strlen(trim($registration->getLastName())) == 0) { return 'last_name_required'; } if (!filter_var($registration->getEmail(), FILTER_VALIDATE_EMAIL)) { return 'email_invalid'; } if (!filter_var($registration->getShopUrl(), FILTER_VALIDATE_URL)) { return 'shop_url_invalid'; } if (Tools::strlen($registration->getPassword()) < 6) { return 'password_less_than_6_characters'; } if ($registration->getPassword() !== $registration->getVerifyPasswordValue()) { return 'passwords_do_not_match'; } return true; }
public function register(YousticeShopRegistration $registration) { $referenceString = uniqid(); $request_data = array('orgName' => $registration->getCompanyName(), 'orgUrl' => $registration->getShopUrl(), 'orgLogo' => $registration->getShopLogo(), 'admin' => array('email' => $registration->getEmail(), 'firstName' => $registration->getFirstName(), 'lastName' => $registration->getLastName(), 'password' => $registration->getPassword(), 'primaryLang' => $registration->getAdminLang()), 'country' => $registration->getDefaultCountry(), 'subscription' => $registration->getSubscription(), 'acceptsTC' => true, 'acceptsPP' => true, 'couponCode' => $registration->getCouponCode(), 'shops' => array(array('ref' => $referenceString, 'name' => $registration->getShopName(), 'url' => $registration->getShopUrl(), 'sector' => 'RETAIL', 'currency' => $registration->getShopCurrency(), 'primaryLang' => $registration->getShopLang(), 'logo' => $registration->getShopLogo(), 'integrationInfo' => array('platform' => $this->shop_software_type, 'version' => $this->shop_software_version, 'pluginVersion' => $this->plugin_software_version)))); $url = $this->api_production_url . 'organizations/retailers/registration'; try { $this->post($url, $request_data); } catch (YousticeFailedRemoteConnectionException $e) { //shop was already registered if ($e->getCode() == 409) { throw new YousticeShopRegistrationShopAlreadyRegistered(); } throw $e; } $response = $this->responseToArray(); $shop_data = $response['shops'][0]; if ($shop_data['ref'] != $referenceString) { throw new YousticeFailedRemoteConnectionException('Post Request failed: ' . $url, -1); } return $shop_data['apiKey']; }