Des modules ajoutés et mise en page du CSS
This commit is contained in:
330
local/modules/PayPal/Form/ConfigurationForm.php
Executable file
330
local/modules/PayPal/Form/ConfigurationForm.php
Executable file
@@ -0,0 +1,330 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace PayPal\Form;
|
||||
|
||||
use PayPal\PayPal;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Form\BaseForm;
|
||||
|
||||
/**
|
||||
* Class ConfigurePaypal
|
||||
* @package Paypal\Form
|
||||
* @author Thelia <info@thelia.net>
|
||||
*/
|
||||
class ConfigurationForm extends BaseForm
|
||||
{
|
||||
const FORM_NAME = 'paypal_form_configure';
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
$this->formBuilder
|
||||
->add(
|
||||
'login',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [ new NotBlank() ],
|
||||
'label' => $this->translator->trans('login', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans('Your Paypal login', [], PayPal::DOMAIN_NAME)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'password',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [ new NotBlank() ],
|
||||
'label' => $this->translator->trans('password', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans('Your Paypal password', [], PayPal::DOMAIN_NAME)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'merchant_id',
|
||||
'text',
|
||||
[
|
||||
'label' => $this->translator->trans('Merchant ID', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans('The Paypal <a target="_blank" href="%url">identity merchant account</a>', ['%url' => 'https://www.paypal.com/businessprofile/settings/'], PayPal::DOMAIN_NAME)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'sandbox',
|
||||
'checkbox',
|
||||
[
|
||||
'value' => 1,
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Activate sandbox mode', [], PayPal::DOMAIN_NAME),
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'sandbox_login',
|
||||
'text',
|
||||
[
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('login', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans('Your Paypal sandbox login', [], PayPal::DOMAIN_NAME)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'sandbox_password',
|
||||
'text',
|
||||
[
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('password', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans('Your Paypal sandbox password', [], PayPal::DOMAIN_NAME)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'sandbox_merchant_id',
|
||||
'text',
|
||||
[
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Merchant ID', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans('The Paypal <a target="_blank" href="%url">identity merchant account</a>', ['%url' => 'https://www.paypal.com/businessprofile/settings/'], PayPal::DOMAIN_NAME)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'allowed_ip_list',
|
||||
'textarea',
|
||||
[
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Allowed IPs in test mode', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->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',
|
||||
[ '%ip' => $this->getRequest()->getClientIp() ],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
],
|
||||
'attr' => [
|
||||
'rows' => 3
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'minimum_amount',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new GreaterThanOrEqual(array('value' => 0))
|
||||
],
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Minimum order total', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'Minimum order total in the default currency for which this payment method is available. Enter 0 for no minimum',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'maximum_amount',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new GreaterThanOrEqual(array('value' => 0))
|
||||
],
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Maximum order total', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'Maximum order total in the default currency for which this payment method is available. Enter 0 for no maximum',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'cart_item_count',
|
||||
'text',
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new GreaterThanOrEqual(array('value' => 0))
|
||||
],
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Maximum items in cart', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'Maximum number of items in the customer cart for which this payment method is available.',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'method_paypal',
|
||||
'checkbox',
|
||||
[
|
||||
'value' => 1,
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Activate payment with PayPal account', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'If checked, the order can be paid by PayPal account.',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'method_paypal_with_in_context',
|
||||
'checkbox',
|
||||
[
|
||||
'value' => 1,
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Use InContext mode for classic PayPal payment', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'If checked, a PayPal popup will be used to execute the payment.',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'method_express_checkout',
|
||||
'checkbox',
|
||||
[
|
||||
'value' => 1,
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Activate Express Checkout payment with PayPal', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'If checked, the order can be paid directly from cart.',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'method_credit_card',
|
||||
'checkbox',
|
||||
[
|
||||
'value' => 1,
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Activate payment with credit card', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'If checked, the order can be paid by credit card.',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'method_planified_payment',
|
||||
'checkbox',
|
||||
[
|
||||
'value' => 1,
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Activate payment with planified payment', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'If checked, the order can be paid by planified payement.',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'send_confirmation_message_only_if_paid',
|
||||
'checkbox',
|
||||
[
|
||||
'value' => 1,
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Send order confirmation on payment success', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'If checked, the order confirmation message is sent to the customer only when the payment is successful. The order notification is always sent to the shop administrator',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'send_payment_confirmation_message',
|
||||
'checkbox',
|
||||
[
|
||||
'value' => 1,
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Send a payment confirmation e-mail', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'If checked, a payment confirmation e-mail is sent to the customer.',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
'send_recursive_message',
|
||||
'checkbox',
|
||||
[
|
||||
'value' => 1,
|
||||
'required' => false,
|
||||
'label' => $this->translator->trans('Send a recursive payment confirmation e-mail', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => [
|
||||
'help' => $this->translator->trans(
|
||||
'If checked, a payment confirmation e-mail is sent to the customer after each PayPal transaction.',
|
||||
[],
|
||||
PayPal::DOMAIN_NAME
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of your form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return self::FORM_NAME;
|
||||
}
|
||||
}
|
||||
56
local/modules/PayPal/Form/PayPalFormFields.php
Normal file
56
local/modules/PayPal/Form/PayPalFormFields.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace PayPal\Form;
|
||||
|
||||
/**
|
||||
* Class PayPalFormFields
|
||||
* @package PayPal\Form
|
||||
*/
|
||||
class PayPalFormFields
|
||||
{
|
||||
const FIELD_PAYMENT_MODULE = 'payment-module';
|
||||
|
||||
// \Thelia\Form\OrderPayment
|
||||
const FIELD_PAYPAL_METHOD = 'paypal_method';
|
||||
const FIELD_PAYPAL_PLANIFIED_PAYMENT = 'paypal_planified_payment';
|
||||
|
||||
// \Form\Type\PayPalCreditCardType
|
||||
const FIELD_CARD_TYPE = 'card_type';
|
||||
const FIELD_CARD_NUMBER = 'card_number';
|
||||
const FIELD_CARD_EXPIRE_MONTH = 'card_expire_month';
|
||||
const FIELD_CARD_EXPIRE_YEAR = 'card_expire_year';
|
||||
const FIELD_CARD_CVV = 'card_cvv';
|
||||
|
||||
// \Form\PayPalPlanifiedPaymentForm
|
||||
const FIELD_PP_ID = 'id';
|
||||
const FIELD_PP_LOCALE = 'locale';
|
||||
const FIELD_PP_TITLE = 'title';
|
||||
const FIELD_PP_DESCRIPTION = 'description';
|
||||
const FIELD_PP_FREQUENCY = 'frequency';
|
||||
const FIELD_PP_FREQUENCY_INTERVAL = 'frequency_interval';
|
||||
const FIELD_PP_CYCLE = 'cycle';
|
||||
const FIELD_PP_MIN_AMOUNT = 'min_amount';
|
||||
const FIELD_PP_MAX_AMOUNT = 'max_amount';
|
||||
const FIELD_PP_POSITION = 'position';
|
||||
}
|
||||
191
local/modules/PayPal/Form/PayPalPlanifiedPaymentCreateForm.php
Normal file
191
local/modules/PayPal/Form/PayPalPlanifiedPaymentCreateForm.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace PayPal\Form;
|
||||
|
||||
use PayPal\PayPal;
|
||||
use PayPal\Service\PayPalAgreementService;
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThan;
|
||||
use Symfony\Component\Validator\Constraints\GreaterThanOrEqual;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Form\BaseForm;
|
||||
|
||||
class PayPalPlanifiedPaymentCreateForm extends BaseForm
|
||||
{
|
||||
const FORM_NAME = 'paypal_planified_payment_create_form';
|
||||
|
||||
/**
|
||||
* @return null
|
||||
*/
|
||||
protected function buildForm()
|
||||
{
|
||||
/** @var \Thelia\Model\Lang $lang */
|
||||
$lang = $this->getRequest()->getSession()->get('thelia.current.lang');
|
||||
|
||||
$this->formBuilder
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_LOCALE,
|
||||
HiddenType::class,
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank()
|
||||
],
|
||||
'required' => true,
|
||||
'data' => $lang->getLocale(),
|
||||
'label' => $this->trans('The locale of the planified payment'),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_PP_LOCALE]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_TITLE,
|
||||
TextType::class,
|
||||
[
|
||||
'constraints' => [
|
||||
new NotBlank()
|
||||
],
|
||||
'required' => true,
|
||||
'label' => $this->trans('The title of the planified payment'),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_PP_TITLE]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_DESCRIPTION,
|
||||
TextType::class,
|
||||
[
|
||||
'required' => false,
|
||||
'label' => $this->trans('The description of the planified payment'),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_PP_DESCRIPTION]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_FREQUENCY_INTERVAL,
|
||||
'integer',
|
||||
[
|
||||
'label' => $this->trans('Frequency interval'),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_PP_FREQUENCY_INTERVAL],
|
||||
'required' => true,
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new GreaterThan(['value' => 0])
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_FREQUENCY,
|
||||
'choice',
|
||||
[
|
||||
'choices' => PayPalAgreementService::getAllowedPaymentFrequency(),
|
||||
'label' => $this->trans('Frequency'),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_PP_FREQUENCY],
|
||||
'required' => true,
|
||||
'constraints' => [
|
||||
new NotBlank()
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_CYCLE,
|
||||
'integer',
|
||||
[
|
||||
'label' => $this->trans('Cycle'),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_PP_CYCLE],
|
||||
'required' => true,
|
||||
'constraints' => [
|
||||
new NotBlank(),
|
||||
new GreaterThan(['value' => 0])
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_MIN_AMOUNT,
|
||||
'number',
|
||||
[
|
||||
'label' => $this->trans('Min amount'),
|
||||
'label_attr' => [
|
||||
'for' => PayPalFormFields::FIELD_PP_MIN_AMOUNT,
|
||||
'help' => $this->trans("Let value to 0 if you don't want a minimum")
|
||||
],
|
||||
'required' => false,
|
||||
'constraints' => [
|
||||
new GreaterThanOrEqual(['value' => 0])
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_MAX_AMOUNT,
|
||||
'number',
|
||||
[
|
||||
'label' => $this->trans('Max amount'),
|
||||
'label_attr' => [
|
||||
'for' => PayPalFormFields::FIELD_PP_MAX_AMOUNT,
|
||||
'help' => $this->trans("Let value to 0 if you don't want a maximum")
|
||||
],
|
||||
'required' => false,
|
||||
'constraints' => [
|
||||
new GreaterThanOrEqual(['value' => 0])
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_POSITION,
|
||||
'integer',
|
||||
[
|
||||
'label' => $this->trans('Position'),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_PP_POSITION],
|
||||
'required' => false
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of your form. This name must be unique
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return self::FORM_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates the given message.
|
||||
*
|
||||
* @param string $id The message id (may also be an object that can be cast to string)
|
||||
* @param array $parameters An array of parameters for the message
|
||||
* @param string|null $domain The domain for the message or null to use the default
|
||||
*
|
||||
* @throws \InvalidArgumentException If the locale contains invalid characters
|
||||
*
|
||||
* @return string The translated string
|
||||
*/
|
||||
protected function trans($id, array $parameters = [], $domain = null)
|
||||
{
|
||||
return Translator::getInstance()->trans(
|
||||
$id,
|
||||
$parameters,
|
||||
$domain === null ? PayPal::DOMAIN_NAME : $domain
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace PayPal\Form;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
|
||||
use Symfony\Component\Validator\Constraints\NotBlank;
|
||||
|
||||
class PayPalPlanifiedPaymentUpdateForm extends PayPalPlanifiedPaymentCreateForm
|
||||
{
|
||||
const FORM_NAME = 'paypal_planified_payment_update_form';
|
||||
|
||||
protected function buildForm()
|
||||
{
|
||||
parent::buildForm();
|
||||
|
||||
$this->formBuilder
|
||||
->add(
|
||||
PayPalFormFields::FIELD_PP_ID,
|
||||
HiddenType::class,
|
||||
[
|
||||
'required' => true,
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_PP_ID],
|
||||
'constraints' => [
|
||||
new NotBlank()
|
||||
]
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return self::FORM_NAME;
|
||||
}
|
||||
}
|
||||
265
local/modules/PayPal/Form/Type/PayPalCreditCardType.php
Normal file
265
local/modules/PayPal/Form/Type/PayPalCreditCardType.php
Normal file
@@ -0,0 +1,265 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace PayPal\Form\Type;
|
||||
|
||||
use PayPal\Form\PayPalFormFields;
|
||||
use PayPal\PayPal;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Constraints\Callback;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Thelia\Core\Form\Type\AbstractTheliaType;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
|
||||
/**
|
||||
* Class PayPalCreditCardType
|
||||
* @package PayPal\Form\Type
|
||||
*/
|
||||
class PayPalCreditCardType extends AbstractTheliaType
|
||||
{
|
||||
const TYPE_NAME = 'paypal_credit_card_type';
|
||||
|
||||
/**
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add(
|
||||
PayPalFormFields::FIELD_CARD_TYPE,
|
||||
'choice',
|
||||
[
|
||||
'choices' => $this->getTypes(),
|
||||
'label' => Translator::getInstance()->trans('Card type', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_TYPE],
|
||||
'required' => false,
|
||||
'constraints' => [
|
||||
new Callback(
|
||||
[
|
||||
'methods' => [
|
||||
[$this, 'verifyCardType']
|
||||
],
|
||||
]
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_CARD_NUMBER,
|
||||
'text',
|
||||
[
|
||||
'label' => Translator::getInstance()->trans('Card number', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_NUMBER],
|
||||
'required' => false,
|
||||
'constraints' => [
|
||||
new Callback(
|
||||
[
|
||||
'methods' => [
|
||||
[$this, 'verifyCardNumber']
|
||||
],
|
||||
]
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_CARD_EXPIRE_MONTH,
|
||||
'choice',
|
||||
[
|
||||
'choices' => $this->getMonths(),
|
||||
'label' => Translator::getInstance()->trans('Expire month', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_EXPIRE_MONTH],
|
||||
'required' => false,
|
||||
'constraints' => [
|
||||
new Callback(
|
||||
[
|
||||
'methods' => [
|
||||
[$this, 'verifyCardExpireMonth']
|
||||
],
|
||||
]
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_CARD_EXPIRE_YEAR,
|
||||
'choice',
|
||||
[
|
||||
'choices' => $this->getYears(),
|
||||
'label' => Translator::getInstance()->trans('Expire year', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_EXPIRE_YEAR],
|
||||
'required' => false,
|
||||
'constraints' => [
|
||||
new Callback(
|
||||
[
|
||||
'methods' => [
|
||||
[$this, 'verifyCardExpireYear']
|
||||
],
|
||||
]
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
->add(
|
||||
PayPalFormFields::FIELD_CARD_CVV,
|
||||
'text',
|
||||
[
|
||||
'label' => Translator::getInstance()->trans('CVV', [], PayPal::DOMAIN_NAME),
|
||||
'label_attr' => ['for' => PayPalFormFields::FIELD_CARD_CVV],
|
||||
'required' => false,
|
||||
'constraints' => [
|
||||
new Callback(
|
||||
[
|
||||
'methods' => [
|
||||
[$this, 'verifyCardCVV']
|
||||
],
|
||||
]
|
||||
)
|
||||
]
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
public function verifyCardType($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$this->checkNotBlank($value, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
public function verifyCardNumber($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$this->checkNotBlank($value, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
public function verifyCardExpireMonth($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$this->checkNotBlank($value, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
public function verifyCardExpireYear($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$this->checkNotBlank($value, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
public function verifyCardCVV($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$this->checkNotBlank($value, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param ExecutionContextInterface $context
|
||||
*/
|
||||
protected function checkNotBlank($value, ExecutionContextInterface $context)
|
||||
{
|
||||
$data = $context->getRoot()->getData();
|
||||
if (isset($data[PayPalFormFields::FIELD_PAYMENT_MODULE]) && PayPal::getModuleId() === $data[PayPalFormFields::FIELD_PAYMENT_MODULE]) {
|
||||
if (isset($data[PayPalFormFields::FIELD_PAYPAL_METHOD]) && PayPal::PAYPAL_METHOD_CREDIT_CARD === $data[PayPalFormFields::FIELD_PAYPAL_METHOD]) {
|
||||
if (false === $value || (empty($value) && '0' != $value)) {
|
||||
$context->addViolation(
|
||||
Translator::getInstance()->trans('This value should not be blank', [], PayPal::DOMAIN_NAME)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return self::TYPE_NAME;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getTypes()
|
||||
{
|
||||
return [
|
||||
PayPal::CREDIT_CARD_TYPE_VISA => 'Visa',
|
||||
PayPal::CREDIT_CARD_TYPE_MASTERCARD => 'MasterCard',
|
||||
PayPal::CREDIT_CARD_TYPE_DISCOVER => 'Discover',
|
||||
PayPal::CREDIT_CARD_TYPE_AMEX => 'Amex'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getMonths()
|
||||
{
|
||||
return [
|
||||
1 => '01',
|
||||
2 => '02',
|
||||
3 => '03',
|
||||
4 => '04',
|
||||
5 => '05',
|
||||
6 => '06',
|
||||
7 => '07',
|
||||
8 => '08',
|
||||
9 => '09',
|
||||
10 => '10',
|
||||
11 => '11',
|
||||
12 => '12'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function getYears()
|
||||
{
|
||||
$actualYear = date("Y");
|
||||
|
||||
$years = [];
|
||||
$years[(int)$actualYear] = $actualYear;
|
||||
for ($i = 1; $i <= 10; $i++) {
|
||||
$years[(int)($actualYear + $i)] = $actualYear + $i;
|
||||
}
|
||||
return $years;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user