/** * Returns a new ChildPayzenConfigQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return ChildPayzenConfigQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof \Payzen\Model\PayzenConfigQuery) { return $criteria; } $query = new \Payzen\Model\PayzenConfigQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * @return mixed an HTTP response, or */ public function configure() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, 'Payzen', AccessManager::UPDATE))) { return $response; } // Initialize the potential error message, and the potential exception $error_msg = $ex = null; // Create the Form from the request $configurationForm = new ConfigurationForm($this->getRequest()); try { // Check the form against constraints violations $form = $this->validateForm($configurationForm, "POST"); // Get the form field values $data = $form->getData(); foreach ($data as $name => $value) { if (is_array($value)) { $value = implode(';', $value); } PayzenConfigQuery::set($name, $value); } // Log configuration modification $this->adminLogAppend("payzen.configuration.message", AccessManager::UPDATE, sprintf("Payzen configuration updated")); // Redirect to the success URL, if ($this->getRequest()->get('save_mode') == 'stay') { // If we have to stay on the same page, redisplay the configuration page/ $route = '/admin/module/Payzen'; } else { // If we have to close the page, go back to the module back-office page. $route = '/admin/modules'; } $this->redirect(URL::getInstance()->absoluteUrl($route)); // An exit is performed after redirect.+ } catch (FormValidationException $ex) { // Form cannot be validated. Create the error message using // the BaseAdminController helper method. $error_msg = $this->createStandardFormValidationErrorMessage($ex); } catch (\Exception $ex) { // Any other error $error_msg = $ex->getMessage(); } // At this point, the form has errors, and should be redisplayed. We don not redirect, // just redisplay the same template. // Setup the Form error context, to make error information available in the template. $this->setupFormErrorContext($this->getTranslator()->trans("Payzen configuration", [], Payzen::MODULE_DOMAIN), $error_msg, $configurationForm, $ex); // Do not redirect at this point, or the error context will be lost. // Just redisplay the current template. return $this->render('module-configure', array('module_code' => 'Payzen')); }
/** * Process a Payzen platform request */ public function processPayzenRequest() { // The response code to the server $gateway_response_code = 'ko'; $payzenResponse = new PayzenResponse($_POST, PayzenConfigQuery::read('mode'), PayzenConfigQuery::read('test_certificate'), PayzenConfigQuery::read('production_certificate')); $request = $this->getRequest(); $order_id = intval($request->get('vads_order_id')); $this->getLog()->addInfo($this->getTranslator()->trans("Payzen platform request received for order ID %id.", array('%id' => $order_id), Payzen::MODULE_DOMAIN)); if (null !== ($order = $this->getOrder($order_id))) { // Check the authenticity of the request if ($payzenResponse->isAuthentified()) { // Check payment status if ($payzenResponse->isAcceptedPayment()) { // Payment was accepted. if ($order->isPaid()) { $this->getLog()->addInfo($this->getTranslator()->trans("Order ID %id is already paid.", array('%id' => $order_id), Payzen::MODULE_DOMAIN)); $gateway_response_code = 'payment_ok_already_done'; } else { $this->getLog()->addInfo($this->getTranslator()->trans("Order ID %id payment was successful.", array('%id' => $order_id), Payzen::MODULE_DOMAIN)); // Payment OK ! $this->confirmPayment($order_id); $gateway_response_code = 'payment_ok'; } } else { if ($payzenResponse->isCancelledPayment()) { // Payment was canceled. $this->cancelPayment($order_id); } else { // Payment was not accepted. $this->getLog()->addError($this->getTranslator()->trans("Order ID %id payment failed.", array('%id' => $order_id), Payzen::MODULE_DOMAIN)); if ($order->isPaid()) { $gateway_response_code = 'payment_ko_already_done'; } else { $gateway_response_code = 'payment_ko'; } } } } else { $this->getLog()->addError($this->getTranslator()->trans("Response could not be authentified.")); $gateway_response_code = 'auth_fail'; } } else { $gateway_response_code = 'order_not_found'; } $this->getLog()->info($this->getTranslator()->trans("Payzen platform request for order ID %id processing teminated.", array('%id' => $order_id), Payzen::MODULE_DOMAIN)); return Response::create($payzenResponse->getOutputForGateway($gateway_response_code)); }
protected function buildForm() { $api = new PayzenApi(); // Available languages, translated. $available_languages = array(); foreach ($api->getSupportedLanguages() as $code => $label) { $available_languages[$code] = $this->trans($label); } $available_languages_combo = array_merge(array("" => $this->trans("Please select...")), $available_languages); asort($available_languages); foreach ($api->getSupportedCardTypes() as $code => $label) { $available_cards[$code] = $this->trans($label); } asort($available_cards); // If the Multi plugin is not enabled, all multi_fields are hidden /** @var Module $multiModule */ $multiEnabled = null !== ($multiModule = ModuleQuery::create()->findOneByCode('PayzenMulti')) && $multiModule->getActivate() != 0; $this->formBuilder->add('site_id', 'text', array('constraints' => array(new NotBlank()), 'required' => true, 'label' => $this->trans('Site ID'), 'data' => PayzenConfigQuery::read('site_id', '12345678'), 'label_attr' => array('for' => 'site_id', 'help' => $this->trans('Site ID provided by the payment gateway'))))->add('test_certificate', 'text', array('constraints' => array(new NotBlank()), 'required' => true, 'label' => $this->trans('Test certificate'), 'data' => PayzenConfigQuery::read('test_certificate', '1111111111111111'), 'label_attr' => array('for' => 'test_certificate', 'help' => $this->trans('The test certificate provided by the payment gateway'))))->add('production_certificate', 'text', array('constraints' => array(new NotBlank()), 'required' => true, 'label' => $this->trans('Production certificate'), 'data' => PayzenConfigQuery::read('production_certificate', '1111111111111111'), 'label_attr' => array('for' => 'production_certificate', 'help' => $this->trans('The production certificate provided by the payment gateway'))))->add('platform_url', 'text', array('constraints' => array(new NotBlank()), 'required' => true, 'label' => $this->trans('Payment page URL'), 'data' => PayzenConfigQuery::read('platform_url', 'https://secure.payzen.eu/vads-payment/'), 'label_attr' => array('for' => 'platform_url', 'help' => $this->trans('URL the client will be redirected to'))))->add('mode', 'choice', array('constraints' => array(new NotBlank()), 'required' => true, 'choices' => array('TEST' => $this->trans('Test'), 'PROD' => $this->trans('Production')), 'label' => $this->trans('Operation Mode'), 'data' => PayzenConfigQuery::read('mode', 'TEST'), 'label_attr' => array('for' => 'mode', 'help' => $this->trans('Test or production mode'))))->add('allowed_ip_list', 'textarea', array('required' => false, 'label' => $this->trans('Allowed IPs in test mode'), 'data' => PayzenConfigQuery::read('allowed_ip_list', ''), 'label_attr' => array('for' => 'platform_url', 'help' => $this->trans('List of IP addresses allowed to use this payment on the front-office when in test mode (your current IP is %ip). One address per line', array('%ip' => $this->getRequest()->getClientIp())), 'rows' => 3)))->add('default_language', 'choice', array('constraints' => array(new NotBlank()), 'required' => true, 'choices' => $available_languages_combo, 'label' => $this->trans('Default language'), 'data' => PayzenConfigQuery::read('default_language', ''), 'label_attr' => array('for' => 'default_language', 'help' => $this->trans('The default language of the payment page'))))->add('available_languages', 'choice', array('required' => false, 'choices' => $available_languages, 'multiple' => true, 'label' => $this->trans('Available languages'), 'data' => explode(';', PayzenConfigQuery::read('available_languages', '')), 'label_attr' => array('for' => 'available_languages', 'help' => $this->trans('Languages available on the payment page. Select nothing to use gateway config.'), 'size' => 10)))->add('banking_delay', 'number', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 0))), 'required' => true, 'label' => $this->trans('Banking delay'), 'data' => PayzenConfigQuery::read('banking_delay', '0'), 'label_attr' => array('for' => 'banking_delay', 'help' => $this->trans('Delay before banking (in days)'))))->add('validation_mode', 'choice', array('required' => false, 'choices' => array('' => $this->trans('Default'), '0' => $this->trans('Automatic'), '1' => $this->trans('Manual')), 'label' => $this->trans('Payment validation'), 'data' => PayzenConfigQuery::read('validation_mode', ''), 'label_attr' => array('for' => 'validation_mode', 'help' => $this->trans('If manual is selected, you will have to confirm payments manually in your bank back-office'))))->add('allowed_cards', 'choice', array('required' => false, 'choices' => $available_cards, 'multiple' => true, 'label' => $this->trans('Available payment cards'), 'data' => explode(';', PayzenConfigQuery::read('allowed_cards', '')), 'label_attr' => array('for' => 'allowed_cards', 'help' => $this->trans('Select nothing to use gateway configuration.'), 'size' => 7)))->add('redirect_enabled', 'choice', array('required' => true, 'choices' => array('False' => $this->trans('Disabled'), 'True' => $this->trans('Enabled')), 'label' => $this->trans('Automatic redirection after payment'), 'data' => PayzenConfigQuery::read('redirect_enabled', 'True'), 'label_attr' => array('for' => 'redirect_enabled', 'help' => $this->trans('Redirect the customer to the shop at the end of the payment process'))))->add('success_timeout', 'number', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 0))), 'required' => true, 'label' => $this->trans('Success timeout'), 'data' => PayzenConfigQuery::read('success_timeout', '5'), 'label_attr' => array('for' => 'success_timeout', 'help' => $this->trans('Time in seconds before the client is redirected after a successful payment'))))->add('success_message', 'text', array('required' => false, 'label' => $this->trans('Success message'), 'data' => PayzenConfigQuery::read('success_message', '5'), 'label_attr' => array('for' => 'success_timeout', 'help' => $this->trans('Message displayed after a successful payment before redirecting'))))->add('failure_timeout', 'number', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 0))), 'required' => true, 'label' => $this->trans('Failure timeout'), 'data' => PayzenConfigQuery::read('failure_timeout', '5'), 'label_attr' => array('for' => 'failure_timeout', 'help' => $this->trans('Time in seconds before the client is redirected after a failed payment'))))->add('failure_message', 'text', array('required' => false, 'label' => $this->trans('Failure message'), 'data' => PayzenConfigQuery::read('failure_message', '5'), 'label_attr' => array('for' => 'failure_message', 'help' => $this->trans('Message displayed after a failed payment before redirecting'))))->add('minimum_amount', 'money', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 0))), 'required' => true, 'label' => $this->trans('Minimum order total'), 'data' => PayzenConfigQuery::read('minimum_amount', '0'), 'label_attr' => array('for' => 'minimum_amount', 'help' => $this->trans('Minimum order total in the default currency for which this payment method is available. Enter 0 for no minimum'))))->add('maximum_amount', 'money', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 0))), 'required' => true, 'label' => $this->trans('Maximum order total'), 'data' => PayzenConfigQuery::read('maximum_amount', '0'), 'label_attr' => array('for' => 'maximum_amount', 'help' => $this->trans('Maximum order total in the default currency for which this payment method is available. Enter 0 for no maximum'))))->add('three_ds_minimum_order_amount', 'money', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 0))), 'required' => true, 'label' => $this->trans('3D Secure minimum order amount'), 'data' => PayzenConfigQuery::read('three_ds_minimum_order_amount', '0'), 'label_attr' => array('for' => 'three_ds_minimum_order_amount', 'help' => $this->trans('Minimum order total in the default currency to request a 3D Secure authentication'))))->add('multi_minimum_amount', $multiEnabled ? 'money' : 'hidden', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 0))), 'required' => true, 'label' => $this->trans('Minimum order total for multiple times'), 'data' => PayzenConfigQuery::read('minimum_amount', '0'), 'label_attr' => array('for' => 'minimum_amount', 'help' => $this->trans('Minimum order total in the default currency for which multiple times payment method is available. Enter 0 for no minimum'))))->add('multi_maximum_amount', $multiEnabled ? 'money' : 'hidden', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 0))), 'required' => true, 'label' => $this->trans('Maximum order total for multiple times'), 'data' => PayzenConfigQuery::read('maximum_amount', '0'), 'label_attr' => array('for' => 'maximum_amount', 'help' => $this->trans('Maximum order total in the default currency for which multiple times payment method is available. Enter 0 for no maximum'))))->add('multi_first_payment', $multiEnabled ? 'number' : 'hidden', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 0)), new LessThanOrEqual(array('value' => 100))), 'required' => false, 'label' => $this->trans('Amount of first payment '), 'data' => PayzenConfigQuery::read('multi_first_payment', 25), 'label_attr' => array('for' => 'multi_first_payment', 'help' => $this->trans('Amount of the first payment, as a percent of the order total. If zero or empty, all payments will be equals.'))))->add('multi_number_of_payments', $multiEnabled ? 'number' : 'hidden', array('constraints' => array(new NotBlank(), new GreaterThanOrEqual(array('value' => 1))), 'required' => true, 'label' => $this->trans('Number of payments'), 'data' => PayzenConfigQuery::read('multi_number_of_payments', 4), 'label_attr' => array('for' => 'multi_number_of_payments', 'help' => $this->trans('The total number of payments'))))->add('multi_payments_interval', $multiEnabled ? 'number' : 'hidden', array('constraints' => array(new NotBlank()), 'required' => true, 'label' => $this->trans('Days between two payments'), 'data' => PayzenConfigQuery::read('multi_payments_interval', 30), 'label_attr' => array('for' => 'multi_payments_interval', 'help' => $this->trans('The interval in days between payments')))); }
/** * Performs an INSERT on the database, given a PayzenConfig or Criteria object. * * @param mixed $criteria Criteria or PayzenConfig object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(PayzenConfigTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from PayzenConfig object } // Set the correct dbName $query = PayzenConfigQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = $query->doInsert($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
/** * 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(); }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see PayzenConfig::setDeleted() * @see PayzenConfig::isDeleted() */ public function delete(ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getServiceContainer()->getWriteConnection(PayzenConfigTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildPayzenConfigQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }