public function postAction(Request $request) { $form = new ConfigurationForm($request); try { $configForm = $this->validateForm($form); $data = $configForm->getData(); $paylineConfig = new PaylineConfig(); $paylineConfig->merge($data); // 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/Payline'; } else { // If we have to close the page, go back to the module back-office page. $route = '/admin/modules'; } return RedirectResponse::create(URL::getInstance()->absoluteUrl($route)); } catch (FormValidationException $e) { $error = $this->createStandardFormValidationErrorMessage($e); } catch (\Exception $e) { $error = $e->getMessage(); } $this->setupFormErrorContext('Payline Configuration', $error, $form, $e); return $this->render('module-configure', ['module_code' => 'Payline']); }
/** * @see : 3.1.1 PAYLINE-GUIDE-Descriptif des appels webservices. * @param Order $order * @return RedirectResponse * @throws \Exception */ public function doWebPayment(Order $order) { /** @var Customer $subscriber */ $customer = $order->getCustomer(); $array['version'] = self::VERSION; $array['returnURL'] = $this->frontRouter->generate('order.placed', ['order_id' => $order->getId()], true); $array['cancelURL'] = $this->frontRouter->generate('order.failed', ['order_id' => $order->getId(), 'message' => 'payline'], true); $array['notificationURL'] = $this->paylineRouter->generate('payline_notify', ['orderId' => $order->getId()], true); $amount = (double) $order->getTotalAmount() * 100; $currency = CurrencyNumericCodeQuery::create()->findPk($order->getCurrency()->getCode())->getNumericCode(); $array['payment']['amount'] = $amount; $array['payment']['currency'] = $currency; $array['payment']['action'] = '100'; $array['payment']['mode'] = 'CPT'; $array['payment']['contractNumber'] = $this->config->getContractNumber(); $array['order']['ref'] = $order->getRef(); $array['order']['amount'] = $amount; $array['order']['currency'] = $currency; $array['order']['date'] = $order->getUpdatedAt()->format('d/m/Y H:m'); $array['buyer']['lastName'] = $customer->getLastName(); $array['buyer']['firstName'] = $customer->getFirstName(); $array['buyer']['email'] = $customer->getEmail(); $array['securityMode'] = 'SSL'; $response = $this->payline->doWebPayment($array); $code = $response['result']['code']; if ($code !== '00000') { $message = isset($response['result']['longMessage']) ? $response['result']['longMessage'] : 'Error undefined'; $this->logger->error($message); throw new \Exception($message); } return new RedirectResponse($response['redirectURL']); }
/** * * This method is call on Payment loop. * * If you return true, the payment method will de display * If you return false, the payment method will not be display * * @return boolean */ public function isValidPayment() { $paylineConfig = new PaylineConfig(); if (!$paylineConfig->checkRequireConfig()) { $logger = new PaylineLogger(); $logger->getLogger()->addError('Payline payment module is not properly configured. Please check module configuration in your back-office.'); return false; } $maximum = $paylineConfig->getMaximumAmount(); $minimum = $paylineConfig->getMinimumAmount(); $orderAmount = $this->getCurrentOrderTotalAmount(); if ($orderAmount === 0) { return false; } return ($minimum <= 0 || $orderAmount >= $minimum) && ($maximum <= 0 || $orderAmount <= $maximum); }
/** * * in this function you add all the fields you need for your Form. * Form this you have to call add method on $this->formBuilder attribute : */ protected function buildForm() { $paylineConfig = new PaylineConfig(); $this->formBuilder->add('merchantId', 'text', ['constraints' => [new NotBlank()], 'label' => $this->trans('Merchant id :'), 'data' => $paylineConfig->getMerchantId()])->add('merchantAccesskey', 'text', ['constraints' => [new NotBlank()], 'label' => $this->trans('Merchant access key :'), 'data' => $paylineConfig->getMerchantAccesskey()])->add('contractNumber', 'text', ['constraints' => [new NotBlank()], 'label' => $this->trans('Contract number :'), 'data' => $paylineConfig->getContractNumber()])->add('env', 'choice', ['constraints' => [new NotBlank()], 'label' => $this->trans('Environment :'), 'choices' => [PaylineConfig::ENV_DEV => $this->trans('Development'), PaylineConfig::ENV_HOMO => $this->trans('Approval'), PaylineConfig::ENV_PROD => $this->trans('Production')], 'expanded' => false, 'multiple' => false, 'data' => $paylineConfig->getEnv()])->add('minimumAmount', 'money', ['constraints' => [new NotBlank(), new GreaterThanOrEqual(['value' => 0])], 'label' => $this->trans('Minimum order total'), 'data' => $paylineConfig->getMinimumAmount(), 'label_attr' => ['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('maximumAmount', 'money', ['constraints' => [new NotBlank(), new GreaterThanOrEqual(['value' => 0])], 'label' => $this->trans('Maximum order total'), 'data' => $paylineConfig->getMaximumAmount(), 'label_attr' => ['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')]]); }