mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Payment] Add new field 'code' to PaymentMethod, PaymentMethodInterface extends CodeAwareInterface
[PaymentBundle] PaymentMethodType add AddCodeFormSubscriber to builder
This commit is contained in:
parent
26c7bb4d9d
commit
80aa11d548
24 changed files with 163 additions and 52 deletions
36
app/migrations/Version20151209104639.php
Normal file
36
app/migrations/Version20151209104639.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Sylius\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
class Version20151209104639 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE sylius_payment_method ADD code VARCHAR(255) NOT NULL');
|
||||
$this->addSql('CREATE UNIQUE INDEX UNIQ_A75B0B0D77153098 ON sylius_payment_method (code)');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
|
||||
|
||||
$this->addSql('DROP INDEX UNIQ_A75B0B0D77153098 ON sylius_payment_method');
|
||||
$this->addSql('ALTER TABLE sylius_payment_method DROP code');
|
||||
}
|
||||
}
|
||||
|
|
@ -7,9 +7,9 @@ Feature: Payment methods
|
|||
Background:
|
||||
Given store has default configuration
|
||||
And the following payment methods exist:
|
||||
| name | gateway | calculator | calculator_configuration |
|
||||
| Credit Card | stripe | fixed | amount: 10 |
|
||||
| PayPal | paypal | percent | percent: 5 |
|
||||
| code | name | gateway | calculator | calculator_configuration |
|
||||
| PM1 | Credit Card | stripe | fixed | amount: 10 |
|
||||
| PM2 | PayPal | paypal | percent | percent: 5 |
|
||||
And I am logged in as administrator
|
||||
|
||||
Scenario: Seeing index of all payment methods
|
||||
|
|
@ -31,34 +31,38 @@ Feature: Payment methods
|
|||
|
||||
Scenario: Submitting form without specifying the required values
|
||||
Given I am on the payment method creation page
|
||||
When I press "Create"
|
||||
Then I should still be on the payment method creation page
|
||||
And I should see "Please enter payment method name."
|
||||
When I press "Create"
|
||||
Then I should still be on the payment method creation page
|
||||
And I should see "Please enter payment method name."
|
||||
And I should see "Please enter payment method code."
|
||||
|
||||
Scenario: Creating new payment method with flexible rate
|
||||
Given I am on the payment method creation page
|
||||
When I fill in "Name" with "Google Checkout"
|
||||
And I fill in "Amount" with "10"
|
||||
And I press "Create"
|
||||
Then I should be on the payment method index page
|
||||
And I should see "Payment method has been successfully created."
|
||||
When I fill in "Code" with "PM3"
|
||||
And I fill in "Name" with "Google Checkout"
|
||||
And I fill in "Amount" with "10"
|
||||
And I press "Create"
|
||||
Then I should be on the payment method index page
|
||||
And I should see "Payment method has been successfully created."
|
||||
|
||||
Scenario: Describing the payment method
|
||||
Given I am on the payment method creation page
|
||||
When I fill in "Name" with "Google Checkout"
|
||||
And I fill in "Description" with "Flexible checkout by Google!"
|
||||
And I fill in "Amount" with "10"
|
||||
And I press "Create"
|
||||
Then I should be on the payment method index page
|
||||
And I should see "Payment method has been successfully created."
|
||||
When I fill in "Code" with "PM3"
|
||||
And I fill in "Name" with "Google Checkout"
|
||||
And I fill in "Description" with "Flexible checkout by Google!"
|
||||
And I fill in "Amount" with "10"
|
||||
And I press "Create"
|
||||
Then I should be on the payment method index page
|
||||
And I should see "Payment method has been successfully created."
|
||||
|
||||
Scenario: Created methods appear in the list
|
||||
Given I am on the payment method creation page
|
||||
When I fill in "Name" with "PayU"
|
||||
And I fill in "Amount" with "10"
|
||||
And I press "Create"
|
||||
Then I should be on the payment method index page
|
||||
And I should see payment method with name "PayU" in the list
|
||||
When I fill in "Code" with "PM3"
|
||||
And I fill in "Name" with "PayU"
|
||||
And I fill in "Amount" with "10"
|
||||
And I press "Create"
|
||||
Then I should be on the payment method index page
|
||||
And I should see payment method with name "PayU" in the list
|
||||
|
||||
Scenario: Accessing the editing form from the list
|
||||
Given I am on the payment method index page
|
||||
|
|
@ -128,3 +132,15 @@ Feature: Payment methods
|
|||
And I click "delete" from the confirmation modal
|
||||
Then I should still be on the payment method index page
|
||||
And I should not see payment method with name "PayPal" in that list
|
||||
|
||||
Scenario: Cannot update payment method code
|
||||
When I am editing payment method "PayPal"
|
||||
Then the code field should be disabled
|
||||
|
||||
Scenario: Try add payment method with existing code
|
||||
Given I am on the payment method creation page
|
||||
When I fill in "Code" with "PM1"
|
||||
And I fill in "Name" with "Master Card"
|
||||
And I press "Create"
|
||||
Then I should still be on the payment method creation page
|
||||
And I should see "The payment method with given code already exists."
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ Feature: Shipping methods
|
|||
Scenario: Try add shipping method with existing code
|
||||
Given I am on the shipping method creation page
|
||||
When I fill in "Name" with "MegaPackage"
|
||||
When I fill in "Code" with "SM1"
|
||||
And I fill in "Code" with "SM1"
|
||||
And I press "Create"
|
||||
Then I should still be on the shipping method creation page
|
||||
And I should see "The shipping method with given code already exists"
|
||||
|
|
|
|||
|
|
@ -20,10 +20,10 @@ Feature: Channel management
|
|||
| fr_FR |
|
||||
| de_DE |
|
||||
And the following payment methods exist:
|
||||
| name | gateway |
|
||||
| Credit Card (US) | stripe |
|
||||
| Credit Card (EU) | adyen |
|
||||
| PayPal | paypal |
|
||||
| code | name | gateway |
|
||||
| PM1 | Credit Card (US) | stripe |
|
||||
| PM2 | Credit Card (EU) | adyen |
|
||||
| PM3 | PayPal | paypal |
|
||||
And the following shipping methods exist:
|
||||
| code | zone | name |
|
||||
| SM1 | USA | FedEx |
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ Feature: Checkout finalization
|
|||
| code | zone | name |
|
||||
| SM1 | UK | DHL Express |
|
||||
And the following payment methods exist:
|
||||
| name | gateway | enabled | calculator | calculator_configuration |
|
||||
| Dummy | dummy | yes | fixed | amount: 0 |
|
||||
| code | name | gateway | enabled | calculator | calculator_configuration |
|
||||
| PM1 | Dummy | dummy | yes | fixed | amount: 0 |
|
||||
And all products are assigned to the default channel
|
||||
And the default channel has following configuration:
|
||||
| taxonomy | payment | shipping |
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ Feature: Checkout inventory
|
|||
| code | zone | name |
|
||||
| SM1 | UK | DHL Express |
|
||||
And the following payment methods exist:
|
||||
| name | gateway | enabled | calculator | calculator_configuration |
|
||||
| Credit Card | dummy | yes | fixed | amount: 0 |
|
||||
| code | name | gateway | enabled | calculator | calculator_configuration |
|
||||
| PM1 | Credit Card | dummy | yes | fixed | amount: 0 |
|
||||
And all products are assigned to the default channel
|
||||
And the default channel has following configuration:
|
||||
| taxonomy | payment | shipping |
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ Feature: Checkout Payment
|
|||
| code | zone | name |
|
||||
| SM1 | UK | DHL Express |
|
||||
And the following payment methods exist:
|
||||
| name | gateway | enabled | calculator | calculator_configuration |
|
||||
| Credit Card | stripe | yes | fixed | amount: 0 |
|
||||
| Credit Card PRO | stripe | yes | percent | percent: 0 |
|
||||
| PayPal | paypal | yes | fixed | amount: 50 |
|
||||
| PayPal PRO | paypal_pro | no | percent | percent: 10 |
|
||||
| code | name | gateway | enabled | calculator | calculator_configuration |
|
||||
| PM1 | Credit Card | stripe | yes | fixed | amount: 0 |
|
||||
| PM2 | Credit Card PRO | stripe | yes | percent | percent: 0 |
|
||||
| PM3 | PayPal | paypal | yes | fixed | amount: 50 |
|
||||
| PM4 | PayPal PRO | paypal_pro | no | percent | percent: 10 |
|
||||
And all products are assigned to the default channel
|
||||
And the default channel has following configuration:
|
||||
| taxonomy | payment | shipping |
|
||||
|
|
|
|||
|
|
@ -25,8 +25,8 @@ Feature: Checkout security
|
|||
| code | zone | name |
|
||||
| SM1 | UK | DHL Express |
|
||||
And the following payment methods exist:
|
||||
| name | gateway | enabled | calculator | calculator_configuration |
|
||||
| Dummy | dummy | yes | fixed | amount: 0 |
|
||||
| code | name | gateway | enabled | calculator | calculator_configuration |
|
||||
| PM1 | Dummy | dummy | yes | fixed | amount: 0 |
|
||||
And all products are assigned to the default channel
|
||||
And the default channel has following configuration:
|
||||
| taxonomy | payment | shipping |
|
||||
|
|
|
|||
|
|
@ -31,8 +31,8 @@ Feature: Checkout shipping
|
|||
| SM3 | USA | FedEx Premium | Flat rate | Amount: 10000 | yes |
|
||||
| SM4 | UK + Germany | UPS Ground | Flat rate | Amount: 20000 | no |
|
||||
And the following payment methods exist:
|
||||
| name | gateway | enabled | calculator | calculator_configuration |
|
||||
| Dummy | dummy | yes | fixed | amount: 0 |
|
||||
| code | name | gateway | enabled | calculator | calculator_configuration |
|
||||
| PM1 | Dummy | dummy | yes | fixed | amount: 0 |
|
||||
And all products are assigned to the default channel
|
||||
And the default channel has following configuration:
|
||||
| taxonomy | payment | shipping |
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ Feature: Checkout taxation
|
|||
| code | zone | name |
|
||||
| SM1 | UK | DHL Express |
|
||||
And the following payment methods exist:
|
||||
| name | gateway | enabled | calculator | calculator_configuration |
|
||||
| Dummy | dummy | yes | fixed | amount: 0 |
|
||||
| code | name | gateway | enabled | calculator | calculator_configuration |
|
||||
| PM1 | Dummy | dummy | yes | fixed | amount: 0 |
|
||||
And all products are assigned to the default channel
|
||||
And the default channel has following configuration:
|
||||
| taxonomy | payment | shipping |
|
||||
|
|
|
|||
|
|
@ -123,6 +123,7 @@ class CoreContext extends DefaultContext
|
|||
$paymentMethod = $this->getFactory('payment_method')->createNew();
|
||||
$paymentMethod->setName('Stripe');
|
||||
$paymentMethod->setGateway('stripe');
|
||||
$paymentMethod->setCode('PM100');
|
||||
$manager->persist($paymentMethod);
|
||||
|
||||
$currentOrderNumber = 1;
|
||||
|
|
|
|||
|
|
@ -27,12 +27,12 @@ class LoadPaymentMethodsData extends DataFixture
|
|||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$manager->persist($this->createPaymentMethod('Dummy', 'dummy', 'fixed', array('amount' => 0)));
|
||||
$manager->persist($this->createPaymentMethod('PaypalExpressCheckout', 'paypal_express_checkout', 'fixed', array('amount' => 1000)));
|
||||
$manager->persist($this->createPaymentMethod('Be2bill', 'be2bill_direct', 'fixed', array('amount' => 100)));
|
||||
$manager->persist($this->createPaymentMethod('Be2billOffsite', 'be2bill_offsite', 'percent', array('percent' => 7)));
|
||||
$manager->persist($this->createPaymentMethod('StripeCheckout', 'stripe_checkout', 'percent', array('percent' => 5)));
|
||||
$manager->persist($this->createPaymentMethod('Offline', 'offline', 'fixed', array('amount' => 500)));
|
||||
$manager->persist($this->createPaymentMethod('PM1', 'Dummy', 'dummy', 'fixed', array('amount' => 0)));
|
||||
$manager->persist($this->createPaymentMethod('PM2', 'PaypalExpressCheckout', 'paypal_express_checkout', 'fixed', array('amount' => 1000)));
|
||||
$manager->persist($this->createPaymentMethod('PM3', 'Be2bill', 'be2bill_direct', 'fixed', array('amount' => 100)));
|
||||
$manager->persist($this->createPaymentMethod('PM4', 'Be2billOffsite', 'be2bill_offsite', 'percent', array('percent' => 7)));
|
||||
$manager->persist($this->createPaymentMethod('PM5', 'StripeCheckout', 'stripe_checkout', 'percent', array('percent' => 5)));
|
||||
$manager->persist($this->createPaymentMethod('PM6', 'Offline', 'offline', 'fixed', array('amount' => 500)));
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
|
@ -46,8 +46,8 @@ class LoadPaymentMethodsData extends DataFixture
|
|||
}
|
||||
|
||||
/**
|
||||
* Create payment method.
|
||||
*
|
||||
* @param string $code
|
||||
* @param string $name
|
||||
* @param string $gateway
|
||||
* @param string $feeCalculator
|
||||
|
|
@ -56,7 +56,7 @@ class LoadPaymentMethodsData extends DataFixture
|
|||
*
|
||||
* @return PaymentMethodInterface
|
||||
*/
|
||||
protected function createPaymentMethod($name, $gateway, $feeCalculator, array $feeCalculatorConfiguration, $enabled = true)
|
||||
protected function createPaymentMethod($code, $name, $gateway, $feeCalculator, array $feeCalculatorConfiguration, $enabled = true)
|
||||
{
|
||||
/* @var $method PaymentMethodInterface */
|
||||
$method = $this->getPaymentMethodFactory()->createNew();
|
||||
|
|
@ -71,6 +71,7 @@ class LoadPaymentMethodsData extends DataFixture
|
|||
$method->setEnabled($enabled);
|
||||
$method->setFeeCalculator($feeCalculator);
|
||||
$method->setFeeCalculatorConfiguration($feeCalculatorConfiguration);
|
||||
$method->setCode($code);
|
||||
|
||||
$this->setReference('Sylius.PaymentMethod.'.$name, $method);
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class PaymentContext extends DefaultContext
|
|||
|
||||
/* @var $method PaymentMethodInterface */
|
||||
$method = $factory->createNew();
|
||||
$method->setCode(trim($data['code']));
|
||||
$method->setName(trim($data['name']));
|
||||
$method->setGateway(trim($data['gateway']));
|
||||
$method->setFeeCalculator($data['calculator']);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use Sylius\Component\Registry\ServiceRegistryInterface;
|
|||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
|
||||
|
||||
/**
|
||||
* Payment method form type.
|
||||
|
|
@ -70,6 +71,7 @@ class PaymentMethodType extends AbstractResourceType
|
|||
->add('feeCalculator', 'sylius_fee_calculator_choice', array(
|
||||
'label' => 'sylius.form.payment.fee_calculator',
|
||||
))
|
||||
->addEventSubscriber(new AddCodeFormSubscriber())
|
||||
->addEventSubscriber(new BuildPaymentMethodFeeCalculatorFormSubscriber($this->feeCalculatorRegistry, $builder->getFormFactory()))
|
||||
;
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<id name="id" column="id" type="integer">
|
||||
<generator strategy="AUTO" />
|
||||
</id>
|
||||
|
||||
<field name="code" column="code" type="string" unique="true"/>
|
||||
<field name="gateway" column="gateway" type="string" />
|
||||
<field name="environment" column="environment" type="string" nullable="true" />
|
||||
<field name="enabled" column="is_enabled" type="boolean" />
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ Sylius\Component\Payment\Model\PaymentMethod:
|
|||
expose: true
|
||||
type: integer
|
||||
xml_attribute: true
|
||||
code:
|
||||
expose: true
|
||||
type: string
|
||||
name:
|
||||
expose: true
|
||||
type: string
|
||||
|
|
|
|||
|
|
@ -17,6 +17,17 @@
|
|||
http://symfony.com/schema/dic/services/constraint-mapping-1.0.xsd">
|
||||
|
||||
<class name="Sylius\Component\Payment\Model\PaymentMethod">
|
||||
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity" >
|
||||
<option name="fields">code</option>
|
||||
<option name="message">sylius.payment_method.code.unique</option>
|
||||
<option name="groups">sylius</option>
|
||||
</constraint>
|
||||
<property name="code">
|
||||
<constraint name="NotBlank">
|
||||
<option name="message">sylius.payment_method.code.not_blank</option>
|
||||
<option name="groups">sylius</option>
|
||||
</constraint>
|
||||
</property>
|
||||
<property name="translations">
|
||||
<constraint name="Valid" />
|
||||
</property>
|
||||
|
|
|
|||
|
|
@ -31,3 +31,6 @@ sylius:
|
|||
max_range: Percent fee cannot be greater than {{ limit }}.
|
||||
min_range: Percent fee cannot be lower than {{ limit }}.
|
||||
not_blank: Please enter the fee percent.
|
||||
code:
|
||||
not_blank: 'Please enter payment method code.'
|
||||
unique: 'The payment method with given code already exists.'
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace spec\Sylius\Bundle\PaymentBundle\Form\Type;
|
|||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Bundle\ResourceBundle\Form\EventSubscriber\AddCodeFormSubscriber;
|
||||
use Sylius\Component\Payment\Calculator\FeeCalculatorInterface;
|
||||
use Sylius\Component\Registry\ServiceRegistryInterface;
|
||||
use Symfony\Component\Form\Form;
|
||||
|
|
@ -73,6 +74,11 @@ class PaymentMethodTypeSpec extends ObjectBehavior
|
|||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$builder
|
||||
->addEventSubscriber(Argument::type(AddCodeFormSubscriber::class))
|
||||
->willReturn($builder)
|
||||
;
|
||||
|
||||
$feeCalculatorRegistry->all()->willReturn(array('test' => $feeCalculatorTest))->shouldBeCalled();
|
||||
|
||||
$feeCalculatorTest->getType()->willReturn('test')->shouldBeCalled();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
<fieldset>
|
||||
{{ form_row(form.translations) }}
|
||||
{{ form_row(form.code) }}
|
||||
{{ form_row(form.gateway) }}
|
||||
{{ form_row(form.enabled) }}
|
||||
<div class="col-xs-12">
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th>{{ sylius_resource_sort('id', 'sylius.payment_method.id'|trans) }}</th>
|
||||
<th>{{ sylius_resource_sort('code', 'sylius.ui.code'|trans) }}</th>
|
||||
<th>{{ sylius_resource_sort('name', 'sylius.payment_method.name'|trans) }}</th>
|
||||
<th>{{ sylius_resource_sort('gateway', 'sylius.payment_method.gateway'|trans) }}</th>
|
||||
<th>{{ sylius_resource_sort('enabled', 'sylius.payment_method.enabled'|trans) }}</th>
|
||||
|
|
@ -19,6 +20,7 @@
|
|||
{% for payment_method in payment_methods %}
|
||||
<tr id="{{ payment_method.id }}">
|
||||
<td>{{ payment_method.id }}</td>
|
||||
<td>{{ payment_method.code }}</td>
|
||||
<td>
|
||||
<strong>{{ payment_method.name }}</strong>
|
||||
<p>{{ payment_method.description }}</p>
|
||||
|
|
|
|||
|
|
@ -24,6 +24,11 @@ class PaymentMethod extends AbstractTranslatable implements PaymentMethodInterfa
|
|||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $code;
|
||||
|
||||
/**
|
||||
* @var Boolean
|
||||
*/
|
||||
|
|
@ -92,6 +97,22 @@ class PaymentMethod extends AbstractTranslatable implements PaymentMethodInterfa
|
|||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setCode($code)
|
||||
{
|
||||
$this->code = $code;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
namespace Sylius\Component\Payment\Model;
|
||||
|
||||
use Sylius\Component\Resource\Model\CodeAwareInterface;
|
||||
use Sylius\Component\Resource\Model\TimestampableInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -18,7 +19,7 @@ use Sylius\Component\Resource\Model\TimestampableInterface;
|
|||
*
|
||||
* @author Paweł Jędrzejewski <pawel@sylius.org>
|
||||
*/
|
||||
interface PaymentMethodInterface extends TimestampableInterface, PaymentMethodTranslationInterface
|
||||
interface PaymentMethodInterface extends CodeAwareInterface, TimestampableInterface, PaymentMethodTranslationInterface
|
||||
{
|
||||
/**
|
||||
* @return Boolean
|
||||
|
|
|
|||
|
|
@ -39,6 +39,12 @@ class PaymentMethodSpec extends ObjectBehavior
|
|||
$this->getId()->shouldReturn(null);
|
||||
}
|
||||
|
||||
function its_code_is_mutable()
|
||||
{
|
||||
$this->setCode('PM1');
|
||||
$this->getCode()->shouldReturn('PM1');
|
||||
}
|
||||
|
||||
function it_is_unnamed_by_default()
|
||||
{
|
||||
$this->getName()->shouldReturn(null);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue