public function verifyCountryList($value, ExecutionContextInterface $context) { $jsonType = new JsonType(); if (!$jsonType->isValid($value)) { $context->addViolation(Translator::getInstance()->trans("Country list is not valid JSON")); } $countryList = json_decode($value, true); foreach ($countryList as $countryItem) { if (is_array($countryItem)) { $country = CountryQuery::create()->findPk($countryItem[0]); if (null === $country) { $context->addViolation(Translator::getInstance()->trans("Country ID %id not found", ['%id' => $countryItem[0]])); } if ($countryItem[1] == "0") { continue; } $state = StateQuery::create()->findPk($countryItem[1]); if (null === $state) { $context->addViolation(Translator::getInstance()->trans("State ID %id not found", ['%id' => $countryItem[1]])); } } else { $context->addViolation(Translator::getInstance()->trans("Wrong country definition")); } } }
/** * Create the form parameter list for the given order * * @param Order $order * @param string $payment_config single or multiple payment - see vads_payment_config parameter description * * @throws \InvalidArgumentException if an unsupported currency is used in order * @return array the payzen form parameters */ protected function getPayzenParameters(Order $order, $payment_config) { $payzenApi = new PayzenMultiApi(); // Total order amount $amount = $order->getTotalAmount(); /** @var PayzenCurrency $currency */ // Currency conversion to numeric ISO 1427 code if (null === ($currency = $payzenApi->findCurrencyByAlphaCode($order->getCurrency()->getCode()))) { throw new \InvalidArgumentException(Translator::getInstance()->trans("Unsupported order currency: '%code'", array('%code' => $order->getCurrency()->getCode()), Payzen::MODULE_DOMAIN)); } $customer = $order->getCustomer(); // Get customer lang code and locale if (null !== ($langObj = LangQuery::create()->findPk($customer->getLang()))) { $customer_lang = $langObj->getCode(); $locale = $langObj->getLocale(); } else { $customer_lang = PayzenConfigQuery::read('default_language'); $locale = LangQuery::create()->findOneByByDefault(true)->getLocale(); } $address = $customer->getDefaultAddress(); // Customer phone (first non empty) $phone = $address->getPhone(); if (empty($phone)) { $phone = $address->getCellphone(); } // Transaction ID $transaction_id = $this->getTransactionId(); $order->setTransactionRef($transaction_id)->save(); $payzen_params = array('vads_version' => 'V2', 'vads_contrib' => 'Thelia version ' . ConfigQuery::read('thelia_version'), 'vads_action_mode' => 'INTERACTIVE', 'vads_payment_config' => $this->getPaymentConfigValue($payment_config, $amount, $currency), 'vads_page_action' => 'PAYMENT', 'vads_return_mode' => 'POST', 'vads_shop_name' => ConfigQuery::read("store_name", ''), 'vads_url_success' => $this->getPaymentSuccessPageUrl($order->getId()), 'vads_url_refused' => $this->getPaymentFailurePageUrl($order->getId(), Translator::getInstance()->trans("Your payement has been refused"), [], Payzen::MODULE_DOMAIN), 'vads_url_referral' => $this->getPaymentFailurePageUrl($order->getId(), Translator::getInstance()->trans("Authorization request was rejected"), [], Payzen::MODULE_DOMAIN), 'vads_url_cancel' => $this->getPaymentFailurePageUrl($order->getId(), Translator::getInstance()->trans("You canceled the payement"), [], Payzen::MODULE_DOMAIN), 'vads_url_error' => $this->getPaymentFailurePageUrl($order->getId(), Translator::getInstance()->trans("An internal error occured"), [], Payzen::MODULE_DOMAIN), 'vads_site_id' => PayzenConfigQuery::read('site_id'), 'vads_key_test' => PayzenConfigQuery::read('test_certificate'), 'vads_key_prod' => PayzenConfigQuery::read('production_certificate'), 'vads_ctx_mode' => PayzenConfigQuery::read('mode'), 'vads_platform_url' => PayzenConfigQuery::read('platform_url'), 'vads_default_language' => PayzenConfigQuery::read('default_language'), 'vads_available_languages' => PayzenConfigQuery::read('available_languages'), 'vads_capture_delay' => PayzenConfigQuery::read('banking_delay'), 'vads_validation_mode' => PayzenConfigQuery::read('validation_mode'), 'vads_payment_cards' => PayzenConfigQuery::read('allowed_cards'), 'vads_redirect_enabled' => PayzenConfigQuery::read('redirect_enabled'), 'vads_redirect_success_timeout' => PayzenConfigQuery::read('success_timeout'), 'vads_redirect_success_message' => PayzenConfigQuery::read('success_message'), 'vads_redirect_error_timeout' => PayzenConfigQuery::read('failure_timeout'), 'vads_redirect_error_message' => PayzenConfigQuery::read('failure_message'), 'vads_language' => $customer_lang, 'vads_order_id' => $order->getId(), 'vads_currency' => $currency->num, 'vads_amount' => $currency->convertAmountToInteger($amount), 'vads_trans_id' => $transaction_id, 'vads_trans_date' => gmdate("YmdHis"), 'vads_threeds_mpi' => $amount >= PayzenConfigQuery::read('three_ds_minimum_order_amount', 0) ? 2 : 0, 'vads_cust_email' => $customer->getEmail(), 'vads_cust_id' => $customer->getId(), 'vads_cust_title' => $customer->getCustomerTitle()->setLocale($locale)->getLong(), 'vads_cust_last_name' => $customer->getLastname(), 'vads_cust_first_name' => $customer->getFirstname(), 'vads_cust_address' => trim($address->getAddress1() . ' ' . $address->getAddress2() . ' ' . $address->getAddress3()), 'vads_cust_city' => $address->getCity(), 'vads_cust_zip' => $address->getZipcode(), 'vads_cust_country' => CountryQuery::create()->findPk($address->getCountryId())->getIsoalpha2(), 'vads_cust_phone' => $phone); foreach ($payzen_params as $payzen_parameter_name => $value) { $payzenApi->set($payzen_parameter_name, $value); } return $payzenApi->getRequestFields(); }
private function setCountriesVisibility(MigrateCountryEvent $event) { $oldCountry = CountryQuery::create()->findPk($event->getCountry()); if (null !== $oldCountry) { $oldCountry->setVisible(0)->save(); } $newCountry = CountryQuery::create()->findPk($event->getNewCountry()); if (null !== $newCountry) { $newCountry->setVisible(1)->save(); } }
public function go($order_id) { /* * vars used for setExpressCheckout * $order Order The order object, which is used to get products and prices * $config ConfigInterface Object that contains configuration * $api PaypalApiCredentials Class used by the library to store and use 3T login(username, password, signature) * $redirect_api PaypalApiManager Instance of PaypalApiManager, only used to get checkout url ( and redirect to paypal ) * $sandbox bool true if sandbox is enabled * $products array(array) 2D array that stores products in usable NVP format. * $i int counter * $logger PaypalApiLogManager used to log transactions with paypal */ $order = OrderQuery::create()->findPk($order_id); $config = new PaypalConfig(); $config->pushValues(); $api = new PaypalApiCredentials($config); $redirect_api = new PaypalApiManager($config); $sandbox = $api->getConfig()->getSandbox(); $products = array(array()); $i = 0; $logger = new PaypalApiLogManager(); /* * Store products into 2d array $products */ $products_amount = 0; foreach ($order->getOrderProducts() as $product) { if ($product !== null) { $amount = floatval($product->getWasInPromo() ? $product->getPromoPrice() : $product->getPrice()); foreach ($product->getOrderProductTaxes() as $tax) { $amount += $product->getWasInPromo() ? $tax->getPromoAmount() : $tax->getAmount(); } $products_amount += $amount * $product->getQuantity(); $products[0]["NAME" . $i] = urlencode($product->getTitle()); $products[0]["AMT" . $i] = urlencode(round($amount, 2)); $products[0]["QTY" . $i] = urlencode($product->getQuantity()); $i++; } } /* * Compute difference between prodcts total and cart amount * -> get Coupons. */ $delta = round($products_amount - $order->getTotalAmount($useless, false), 2); if ($delta > 0) { $products[0]["NAME" . $i] = Translator::getInstance()->trans("Discount"); $products[0]["AMT" . $i] = -$delta; $products[0]["QTY" . $i] = 1; } /* * Create setExpressCheckout request */ $setExpressCheckout = new PaypalNvpOperationsSetExpressCheckout($api, round($order->getTotalAmount(), 2), $order->getCurrency()->getCode(), Paypal::getPaypalURL('paiement', $order_id), Paypal::getPaypalURL('cancel', $order_id), 0, array("L_PAYMENTREQUEST" => $products, "PAYMENTREQUEST" => array(array("SHIPPINGAMT" => round($order->getPostage(), 2), "ITEMAMT" => round($order->getTotalAmount($useless, false), 2))))); /* * Try to get customer's delivery address */ $address = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId()); if ($address !== null) { /* * If address is found, set address in setExpressCheckout request */ $setExpressCheckout->setCustomerDeliveryAddress($address->getLastname(), $address->getAddress1(), $address->getAddress2(), $address->getCity(), "", $address->getZipcode(), CountryQuery::create()->findPk($address->getCountryId())->getIsoalpha2()); /* * $sender PaypalNvpMessageSender Instance of the class that sends requests * $response string NVP response of paypal for setExpressCheckout request * $req array array cast of NVP response */ $sender = new PaypalNvpMessageSender($setExpressCheckout, $sandbox); $response = $sender->send(); $logger->logTransaction($response); $response = PaypalApiManager::nvpToArray($response); /* * if setExpressCheckout is correct, store values in the session & redirect to paypal checkout page * else print error. ( return $this->render ... ) */ if (isset($response['ACK']) && $response['ACK'] === "Success" && isset($response['TOKEN']) && !empty($response['TOKEN'])) { $sess = $this->getRequest()->getSession(); $sess->set("Paypal.token", $response['TOKEN']); return new RedirectResponse($redirect_api->getExpressCheckoutUrl($response['TOKEN'])); } } return $this->render("gotopaypalfail", array(), 500); }
public function export() { if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('SoColissimo'), AccessManager::UPDATE))) { return $response; } $csv = new CSV(self::CSV_SEPARATOR); try { $form = new ExportOrder($this->getRequest()); $vform = $this->validateForm($form); // Check status_id $status_id = $vform->get("new_status_id")->getData(); if (!preg_match("#^nochange|processing|sent\$#", $status_id)) { throw new Exception("Bad value for new_status_id field"); } $status = OrderStatusQuery::create()->filterByCode(array(OrderStatus::CODE_PAID, OrderStatus::CODE_PROCESSING, OrderStatus::CODE_SENT), Criteria::IN)->find()->toArray("code"); $query = OrderQuery::create()->filterByDeliveryModuleId(SoColissimo::getModCode())->filterByStatusId(array($status[OrderStatus::CODE_PAID]['Id'], $status[OrderStatus::CODE_PROCESSING]['Id']), Criteria::IN)->find(); // check form && exec csv /** @var \Thelia\Model\Order $order */ foreach ($query as $order) { $value = $vform->get('order_' . $order->getId())->getData(); // If checkbox is checked if ($value) { /** * Retrieve user with the order */ $customer = $order->getCustomer(); /** * Retrieve address with the order */ $address = OrderAddressQuery::create()->findPk($order->getDeliveryOrderAddressId()); if ($address === null) { throw new Exception("Could not find the order's invoice address"); } /** * Retrieve country with the address */ $country = CountryQuery::create()->findPk($address->getCountryId()); if ($country === null) { throw new Exception("Could not find the order's country"); } /** * Retrieve Title */ $title = CustomerTitleI18nQuery::create()->filterById($customer->getTitleId())->findOneByLocale($this->getSession()->getAdminEditionLang()->getLocale()); /** * Get user's phone & cellphone * First get invoice address phone, * If empty, try to get default address' phone. * If still empty, set default value */ $phone = $address->getPhone(); if (empty($phone)) { $phone = $customer->getDefaultAddress()->getPhone(); if (empty($phone)) { $phone = self::DEFAULT_PHONE; } } /** * Cellp */ $cellphone = $customer->getDefaultAddress()->getCellphone(); if (empty($cellphone)) { $cellphone = self::DEFAULT_CELLPHONE; } /** * Compute package weight */ $weight = 0; /** @var \Thelia\Model\OrderProduct $product */ foreach ($order->getOrderProducts() as $product) { $weight += (double) $product->getWeight(); } /** * Get relay ID */ $relay_id = OrderAddressSocolissimoQuery::create()->findPk($order->getDeliveryOrderAddressId()); if ($relay_id === null) { throw new Exception("Invalid order " . $order->getRef() . ", no relay id found"); } /** * Get store's name */ $store_name = ConfigQuery::read("store_name"); /** * Write CSV line */ $csv->addLine(CSVLine::create(array($address->getFirstname(), $address->getLastname(), $address->getCompany(), $address->getAddress1(), $address->getAddress2(), $address->getAddress3(), $address->getZipcode(), $address->getCity(), $country->getIsoalpha2(), $phone, $cellphone, $order->getRef(), $title->getShort(), $relay_id->getCode() == 0 ? '' : $relay_id->getCode(), $customer->getEmail(), $weight, $store_name, $relay_id->getType()))); /** * Then update order's status if necessary */ if ($status_id == "processing") { $event = new OrderEvent($order); $event->setStatus($status[OrderStatus::CODE_PROCESSING]['Id']); $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); } elseif ($status_id == "sent") { $event = new OrderEvent($order); $event->setStatus($status[OrderStatus::CODE_SENT]['Id']); $this->dispatch(TheliaEvents::ORDER_UPDATE_STATUS, $event); } } } } catch (\Exception $e) { return Response::create($e->getMessage(), 500); } return Response::create(utf8_decode($csv->parse()), 200, array("Content-Encoding" => "ISO-8889-1", "Content-Type" => "application/csv-tab-delimited-table", "Content-disposition" => "filename=export.csv")); }