/** * Get PaynetEasy address object by Prestashop cart object. * * @param Cart $prestashop_cart Prestashop cart. * * @return BillingAddress PaynetEasy payment transaction */ protected function getPaynetAddress(Cart $prestashop_cart) { $paynet_address = new BillingAddress(); $prestashop_address = new Address(intval($prestashop_cart->id_address_invoice)); $prestashop_country = new Country(intval($prestashop_address->id_country)); // In Prestashop to many countries has states. // PaynetEasy API requires state code only for some countries. if (RegionFinder::hasStates($prestashop_country->iso_code) && Country::containsStates($prestashop_address->id_country)) { $prestashop_state = new State($prestashop_address->id_state); $paynet_address->setState($prestashop_state->iso_code); } if (Validate::isPhoneNumber($prestashop_address->phone)) { $paynet_address->setPhone($prestashop_address->phone); } if (Validate::isPhoneNumber($prestashop_address->phone_mobile)) { $paynet_address->setCellPhone($prestashop_address->phone_mobile); } $paynet_address->setCountry($prestashop_country->iso_code)->setCity($prestashop_address->city)->setFirstLine($prestashop_address->address1)->setZipCode($prestashop_address->postcode); return $paynet_address; }
/** * Add customer data to PaynetEasy payment * * @param PaymentTransaction $paynetTransaction PaynetEasy payment transaction * @param jshopOrder $joomlaOrder Joomshopping order */ protected function addBillingAdressData(PaymentTransaction $paynetTransaction, jshopOrder $joomlaOrder) { $country = JTable::getInstance('country', 'jshop'); $country->load($joomlaOrder->d_country); $paynetTransaction->getPayment()->getBillingAddress()->setCountry($country->country_code_2)->setCity($joomlaOrder->city)->setFirstLine($joomlaOrder->street)->setZipCode($joomlaOrder->zip)->setPhone($joomlaOrder->phone); if (RegionFinder::hasStateByName($joomlaOrder->state)) { $paynetTransaction->getPayment()->getBillingAddress()->setState(RegionFinder::getStateCode($joomlaOrder->state)); } }
/** * Validates value by given rule. * Rule can be one of Validator constants or regExp. * * @param string $value Value for validation * @param string $rule Rule for validation * @param boolean $failOnError Throw exception on invalid value or not * * @return boolean Validation result * * @throws ValidationException Value does not match rule (if $failOnError == true) */ public static function validateByRule($value, $rule, $failOnError = true) { $valid = false; switch ($rule) { case self::EMAIL: $valid = filter_var($value, FILTER_VALIDATE_EMAIL); break; case self::IP: $valid = filter_var($value, FILTER_VALIDATE_IP); break; case self::URL: $valid = filter_var($value, FILTER_VALIDATE_URL); break; case self::MONTH: $valid = in_array($value, range(1, 12)); break; case self::COUNTRY: $valid = RegionFinder::hasCountryByCode($value); break; case self::STATE: $valid = RegionFinder::hasStateByCode($value); break; default: if (isset(static::$ruleRegExps[$rule])) { $valid = static::validateByRegExp($value, static::$ruleRegExps[$rule], $failOnError); } else { $valid = static::validateByRegExp($value, $rule, $failOnError); } } if ($valid !== false) { return true; } elseif ($failOnError === true) { throw new ValidationException("Value '{$value}' does not match rule '{$rule}'"); } else { return false; } }