/** * 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; }
/** * Transform joomla order to PaynetEasy order * * @param stdClass $joomlaAddress Joomla address * @param string $redirectUrl Url for final payment processing * * @return PaymentTransaction PaynetEasy order */ protected function getPaynetTransaction(stdClass $joomlaAddress, $redirectUrl = null) { $queryConfig = new QueryConfig(); $paynetAddress = new BillingAddress(); $paynetTransaction = new PaymentTransaction(); $paynetPayment = new Payment(); $paynetCustomer = new Customer(); $countryCode = ShopFunctions::getCountryByID($joomlaAddress->virtuemart_country_id, 'country_2_code'); $currencyCode = ShopFunctions::getCurrencyByID($joomlaAddress->order_currency, 'currency_code_3'); $paynetAddress->setCountry($countryCode)->setCity($joomlaAddress->city)->setFirstLine($joomlaAddress->address_1)->setZipCode($joomlaAddress->zip)->setPhone($joomlaAddress->phone_1 ?: '(000) 00-00-00'); if (isset($joomlaAddress->virtuemart_state_id)) { $stateCode = ShopFunctions::getStateByID($joomlaAddress->virtuemart_state_id, 'state_2_code'); $paynetAddress->setState($stateCode); } $paynetCustomer->setEmail($joomlaAddress->email)->setFirstName($joomlaAddress->first_name)->setLastName($joomlaAddress->last_name)->setIpAddress($joomlaAddress->ip_address); $paynetPayment->setClientId($joomlaAddress->order_number)->setDescription($this->getPaynetOrderDescription($joomlaAddress))->setAmount($joomlaAddress->order_total)->setCurrency($currencyCode)->setCustomer($paynetCustomer)->setBillingAddress($paynetAddress); if (isset($joomlaAddress->paynet_order_id)) { $paynetPayment->setPaynetId($joomlaAddress->paynet_order_id); } if (isset($joomlaAddress->payment_status)) { $paynetPayment->setStatus($joomlaAddress->payment_status); } $queryConfig->setEndPoint($this->getConfig('end_point'))->setLogin($this->getConfig('login'))->setSigningKey($this->getConfig('signing_key'))->setGatewayMode($this->getConfig('gateway_mode'))->setGatewayUrlSandbox($this->getConfig('sandbox_gateway'))->setGatewayUrlProduction($this->getConfig('production_gateway')); if (Validator::validateByRule($redirectUrl, Validator::URL, false)) { $queryConfig->setRedirectUrl($redirectUrl)->setCallbackUrl($redirectUrl); } $paynetTransaction->setPayment($paynetPayment)->setQueryConfig($queryConfig); if (isset($joomlaAddress->transaction_status)) { $paynetTransaction->setStatus($joomlaAddress->transaction_status); } return $paynetTransaction; }