Skip to content

Commit

Permalink
INGA-118: Add "Soft Descriptor" field (#27191)
Browse files Browse the repository at this point in the history
 - rename ingenico js component
 - add field and use it in create payment request
  • Loading branch information
aivus authored Mar 10, 2020
1 parent 06ef2f4 commit 2ac6825
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 15 deletions.
29 changes: 29 additions & 0 deletions Entity/IngenicoSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class IngenicoSettings extends Transport
public const PAYMENT_ACTION = 'payment_action';
public const TOKENIZATION_ENABLED = 'tokenization_enabled';
public const DIRECT_DEBIT_TEXT = 'direct_debit_text';
public const SOFT_DESCRIPTOR = 'soft_descriptor';

/**
* @var ParameterBag
Expand Down Expand Up @@ -129,6 +130,13 @@ class IngenicoSettings extends Transport
*/
private $directDebitText;

/**
* @var string
*
* @ORM\Column(name="ingenico_soft_descriptor", type="string", length=255, nullable=true)
*/
private $softDescriptor;

public function __construct()
{
$this->labels = new ArrayCollection();
Expand All @@ -152,6 +160,7 @@ public function getSettingsBag()
self::PAYMENT_ACTION => $this->getPaymentAction(),
self::TOKENIZATION_ENABLED => $this->isTokenizationEnabled(),
self::DIRECT_DEBIT_TEXT => $this->getDirectDebitText(),
self::SOFT_DESCRIPTOR => $this->getSoftDescriptor(),
]);
}

Expand Down Expand Up @@ -385,4 +394,24 @@ public function setDirectDebitText(?string $directDebitText): IngenicoSettings

return $this;
}

/**
* @return string|null
*/
public function getSoftDescriptor()
{
return $this->softDescriptor;
}


/**
* @param string|null $softDescriptor
* @return IngenicoSettings
*/
public function setSoftDescriptor(?string $softDescriptor): IngenicoSettings
{
$this->softDescriptor = $softDescriptor;

return $this;
}
}
4 changes: 4 additions & 0 deletions Form/Type/IngenicoSettingsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ public function buildForm(FormBuilderInterface $builder, array $options)
->add('directDebitText', TextType::class, [
'tooltip' => 'ingenico.settings.directDebitText.tooltip',
'required' => false,
])
->add('softDescriptor', TextType::class, [
'tooltip' => 'ingenico.settings.softDescriptor.tooltip',
'required' => false,
]);
}

Expand Down
39 changes: 39 additions & 0 deletions Ingenico/Option/Payment/Order/References/Descriptor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\References;

use Ingenico\Connect\OroCommerce\Ingenico\Option\LengthNormalizerTrait;
use Ingenico\Connect\OroCommerce\Ingenico\Option\OptionInterface;
use Ingenico\Connect\OroCommerce\Ingenico\Option\OptionsResolver;

/**
* Option for descriptor field
*
* @codingStandardsIgnoreStart
* @see https://epayments-api.developer-ingenico.com/s2sapi/v1/en_US/java/payments/create.html?paymentPlatform=ALL#payments-create-payload
* @codingStandardsIgnoreEnd
*/
class Descriptor implements OptionInterface
{
use LengthNormalizerTrait;

public const NAME = '[order][references][descriptor]';

/**
* From the doc:
* Note that we advise you to use 22 characters as the max length as beyond this our experience is that issuers
* will start to truncate.
*/
private const MAX_LENGTH = 22;

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver
->setDefined(self::NAME)
->setAllowedTypes(self::NAME, ['string', 'null'])
->setNormalizer(self::NAME, $this->getLengthNormalizer(self::MAX_LENGTH));
}
}
4 changes: 3 additions & 1 deletion Ingenico/Request/Payments/CreatePaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Customer\PersonalInformation\Surname;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\EncryptedCustomerInput;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\AmountOfMoney;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\References\Descriptor;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\References\MerchantOrderId;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\References\MerchantReference;
use Ingenico\Connect\OroCommerce\Ingenico\Request\RequestInterface;
Expand Down Expand Up @@ -54,7 +55,8 @@ public function configureOptions(OptionsResolver $resolver): void
->addOption(new FirstName())
->addOption(new Surname())
->addOption(new MerchantReference())
->addOption(new MerchantOrderId());
->addOption(new MerchantOrderId())
->addOption(new Descriptor());
}

/**
Expand Down
1 change: 1 addition & 0 deletions Method/Config/Factory/IngenicoConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function createConfig(IngenicoSettings $settings): IngenicoConfig
$params[IngenicoConfig::FIELD_PAYMENT_METHOD_IDENTIFIER] =
$this->identifierGenerator->generateIdentifier($channel);
$params[IngenicoConfig::FIELD_DIRECT_DEBIT_TEXT_KEY] = (string)$settings->getDirectDebitText();
$params[IngenicoConfig::FIELD_SOFT_DESCRIPTOR_KEY] = (string)$settings->getSoftDescriptor();

return new IngenicoConfig($params);
}
Expand Down
24 changes: 16 additions & 8 deletions Method/Config/IngenicoConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
*/
class IngenicoConfig extends AbstractParameterBagPaymentConfig
{
const FIELD_API_ENDPOINT_KEY = 'api_endpoint';
const FIELD_API_KEY_ID_KEY = 'api_key_id';
const FIELD_API_SECRET_KEY = 'api_secret';
const FIELD_MERCHANT_ID_KEY = 'merchant_id';
const FIELD_ENABLED_PRODUCTS_KEY = 'enabled_products';
const FIELD_PAYMENT_ACTION_KEY = 'payment_action';
const FIELD_TOKENIZAION_ENABLED_KEY = 'tokenization_enabled';
const FIELD_DIRECT_DEBIT_TEXT_KEY = 'direct_debit_text';
public const FIELD_API_ENDPOINT_KEY = 'api_endpoint';
public const FIELD_API_KEY_ID_KEY = 'api_key_id';
public const FIELD_API_SECRET_KEY = 'api_secret';
public const FIELD_MERCHANT_ID_KEY = 'merchant_id';
public const FIELD_ENABLED_PRODUCTS_KEY = 'enabled_products';
public const FIELD_PAYMENT_ACTION_KEY = 'payment_action';
public const FIELD_TOKENIZAION_ENABLED_KEY = 'tokenization_enabled';
public const FIELD_DIRECT_DEBIT_TEXT_KEY = 'direct_debit_text';
public const FIELD_SOFT_DESCRIPTOR_KEY = 'soft_descriptor';

/**
* {@inheritdoc}
Expand Down Expand Up @@ -90,4 +91,11 @@ public function getDirectDebitText(): ?string
{
return $this->get(self::FIELD_DIRECT_DEBIT_TEXT_KEY);
}
/**
* @return string|null
*/
public function getSoftDescriptor(): ?string
{
return $this->get(self::FIELD_SOFT_DESCRIPTOR_KEY);
}
}
2 changes: 2 additions & 0 deletions Method/Handler/AbstractPaymentProductHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Capture;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\EncryptedCustomerInput;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\AmountOfMoney;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\References\Descriptor;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\References\MerchantOrderId;
use Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\References\MerchantReference;
use Ingenico\Connect\OroCommerce\Ingenico\Provider\CheckoutInformationProvider;
Expand Down Expand Up @@ -148,6 +149,7 @@ protected function requestCreatePayment(
EncryptedCustomerInput::NAME => $customerEncryptedDetails,
AmountOfMoney\Amount::NAME => $this->normalizeAmount($paymentTransaction),
AmountOfMoney\CurrencyCode::NAME => $paymentTransaction->getCurrency(),
Descriptor::NAME => $config->getSoftDescriptor(),
MerchantReference::NAME => $this->generateMerchantReference($paymentTransaction),
MerchantOrderId::NAME => $paymentTransaction->getEntityIdentifier(),
];
Expand Down
3 changes: 2 additions & 1 deletion Migrations/Schema/IngenicoBundleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IngenicoBundleInstaller implements Installation
*/
public function getMigrationVersion()
{
return 'v1_3';
return 'v1_4';
}

/**
Expand Down Expand Up @@ -52,6 +52,7 @@ protected function updateOroIntegrationTransportTable(Schema $schema)
$table->addColumn('ingenico_enabled_products', 'array', ['notnull' => false, 'comment' => '(DC2Type:array)']);
$table->addColumn('ingenico_payment_action', 'string', ['notnull' => false, 'length' => 255]);
$table->addColumn('ingenico_direct_debit_text', 'string', ['length' => 255, 'notnull' => false]);
$table->addColumn('ingenico_soft_descriptor', 'string', ['length' => 255, 'notnull' => false]);
$table->addColumn('ingenico_tokenization_enabled', 'boolean', ['notnull' => false, 'default' => '0',]);
}

Expand Down
19 changes: 19 additions & 0 deletions Migrations/Schema/v1_4/AddSoftDescriptorField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Ingenico\Connect\OroCommerce\Migrations\Schema\v1_4;

use Doctrine\DBAL\Schema\Schema;
use Oro\Bundle\MigrationBundle\Migration\Migration;
use Oro\Bundle\MigrationBundle\Migration\QueryBag;

class AddSoftDescriptorField implements Migration
{
/**
* {@inheritdoc}
*/
public function up(Schema $schema, QueryBag $queries)
{
$table = $schema->getTable('oro_integration_transport');
$table->addColumn('ingenico_soft_descriptor', 'string', ['length' => 255, 'notnull' => false]);
}
}
5 changes: 5 additions & 0 deletions Resources/config/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Ingenico\Connect\OroCommerce\Entity\IngenicoSettings:
# Max length according to the API
# See Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\DirectDebitPayment\DirectDebitText
max: 50
softDescriptor:
- Length:
# Recommended length according to the API
# See Ingenico\Connect\OroCommerce\Ingenico\Option\Payment\Order\References\Descriptor
max: 22

Oro\Bundle\IntegrationBundle\Entity\Channel:
constraints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ define(function(require) {
const errorHintTemplate = require('tpl-loader!ingenico/templates/error-hint.html');
require('jquery.validate');

const IngenicoCreditCardComponent = BaseComponent.extend({
const IngenicoPaymentComponent = BaseComponent.extend({
options: {
paymentMethod: null,
paymentDetails: {},
Expand Down Expand Up @@ -1068,9 +1068,9 @@ define(function(require) {
this.$el.off('.' + this.cid);
mediator.off('checkout:payment:before-transit', this.beforeTransit.bind(this));

IngenicoCreditCardComponent.__super__.dispose.call(this);
IngenicoPaymentComponent.__super__.dispose.call(this);
}
});

return IngenicoCreditCardComponent;
return IngenicoPaymentComponent;
});
4 changes: 4 additions & 0 deletions Resources/translations/messages.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ ingenico:
label: 'Direct Debit Text'
tooltip: 'Description of the transaction that will appear on the customer bank statement to aid the customer in recognizing the transaction.'

softDescriptor:
label: 'Soft Descriptor'
tooltip: 'Descriptive text that is used towards to customer, either during an online checkout at a third party and/or on the statement of the customer.'

payment:
direct_debit:
mark_paid: 'Mark as Paid'
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/layouts/blank/config/jsmodules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ aliases:
dynamic-imports:
ingenico:
- ingenico/js/app/stub/connect-sdk-client-mock
- ingenico/js/app/components/ingenico-credit-card-component
- ingenico/js/app/components/ingenico-payment-component
- ingenico/js/app/components/ingenico-payment-method-component
- ingenico/js/validator/sepa-iban
- ingenico/js/validator/ingenico-error-mapping/not-blank
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% block _payment_methods_ingenico_widget %}
{% set componentOptions = view.options|merge({paymentMethod: name}) %}
<div class="{{ class_prefix }}-form__payment-methods ingenico-payment-form"
data-page-component-module="ingenico/js/app/components/ingenico-credit-card-component"
data-page-component-module="ingenico/js/app/components/ingenico-payment-component"
data-page-component-options="{{ componentOptions|json_encode }}"
>
<input type="hidden" class="current-payment-product" name="{{ name ~ '-current-payment-product' }}">
Expand Down

0 comments on commit 2ac6825

Please sign in to comment.