Skip to content

Commit 5908029

Browse files
authored
Merge pull request #7 from BitBagCommerce/key-version-editable
key version editable
2 parents 65794c6 + 47a356c commit 5908029

16 files changed

+104
-12
lines changed

spec/Action/CaptureActionSpec.php

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ function it_executes(
5555
$mercanetBnpParibasBridge->getSecretKey()->willReturn('123');
5656
$mercanetBnpParibasBridge->getEnvironment()->willReturn(Mercanet::TEST);
5757
$mercanetBnpParibasBridge->getMerchantId()->willReturn('123');
58+
$mercanetBnpParibasBridge->getKeyVersion()->willReturn('3');
5859
$mercanetBnpParibasBridge->createMercanet('123')->willReturn($mercanet);
5960
$payment->getOrder()->willReturn($order);
6061
$payment->getCurrencyCode()->willReturn('EUR');

src/Action/CaptureAction.php

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ public function execute($request)
108108

109109
$environment = $this->mercanetBnpParibasBridge->getEnvironment();
110110
$merchantId = $this->mercanetBnpParibasBridge->getMerchantId();
111+
$keyVersion = $this->mercanetBnpParibasBridge->getKeyVersion();
111112

112113
$automaticResponseUrl = $notifyToken->getTargetUrl();
113114
$currencyCode = $payment->getCurrencyCode();
@@ -121,6 +122,7 @@ public function execute($request)
121122
$simplePayment = new SimplePayment(
122123
$mercanet,
123124
$merchantId,
125+
$keyVersion,
124126
$environment,
125127
$amount,
126128
$targetUrl,

src/Bridge/MercanetBnpParibasBridge.php

+21
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ final class MercanetBnpParibasBridge implements MercanetBnpParibasBridgeInterfac
3333
*/
3434
private $merchantId;
3535

36+
/**
37+
* @var string
38+
*/
39+
private $keyVersion;
40+
3641
/**
3742
* @var string
3843
*/
@@ -112,6 +117,22 @@ public function setMerchantId($merchantId)
112117
$this->merchantId = $merchantId;
113118
}
114119

120+
/**
121+
* @return string
122+
*/
123+
public function getKeyVersion()
124+
{
125+
return $this->keyVersion;
126+
}
127+
128+
/**
129+
* @param string $keyVersion
130+
*/
131+
public function setKeyVersion($keyVersion)
132+
{
133+
$this->keyVersion = $keyVersion;
134+
}
135+
115136
/**
116137
* @return string
117138
*/

src/Bridge/MercanetBnpParibasBridgeInterface.php

+10
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ public function getMerchantId();
5454
*/
5555
public function setMerchantId($merchantId);
5656

57+
/**
58+
* @return string
59+
*/
60+
public function getKeyVersion();
61+
62+
/**
63+
* @param string $keyVersion
64+
*/
65+
public function setKeyVersion($keyVersion);
66+
5767
/**
5868
* @return string
5969
*/

src/Form/Type/MercanetBnpParibasGatewayConfigurationType.php

+9
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)
5656
])
5757
],
5858
])
59+
->add('key_version', TextType::class, [
60+
'label' => 'bitbag.mercanet_bnp_paribas.key_version',
61+
'constraints' => [
62+
new NotBlank([
63+
'message' => 'bitbag.mercanet_bnp_paribas.key_version.not_blank',
64+
'groups' => ['sylius']
65+
])
66+
],
67+
])
5968
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
6069
$data = $event->getData();
6170
$data['payum.http_client'] = '@bitbag.mercanet_bnp_paribas.bridge.mercanet_bnp_paribas_bridge';

src/Legacy/SimplePayment.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ final class SimplePayment
3333
*/
3434
private $merchantId;
3535

36+
/**
37+
* @var string
38+
*/
39+
private $keyVersion;
40+
3641
/**
3742
* @var string
3843
*/
@@ -56,6 +61,7 @@ final class SimplePayment
5661
/**
5762
* @param Mercanet $mercanet
5863
* @param $merchantId
64+
* @param $keyVersion
5965
* @param $environment
6066
* @param $amount
6167
* @param $targetUrl
@@ -66,6 +72,7 @@ final class SimplePayment
6672
public function __construct(
6773
Mercanet $mercanet,
6874
$merchantId,
75+
$keyVersion,
6976
$environment,
7077
$amount,
7178
$targetUrl,
@@ -79,6 +86,7 @@ public function __construct(
7986
$this->mercanet = $mercanet;
8087
$this->environment = $environment;
8188
$this->merchantId = $merchantId;
89+
$this->keyVersion = $keyVersion;
8290
$this->amount = $amount;
8391
$this->currency = $currency;
8492
$this->targetUrl = $targetUrl;
@@ -90,7 +98,7 @@ public function execute()
9098

9199
$this->mercanet->setMerchantId($this->merchantId);
92100
$this->mercanet->setInterfaceVersion(Mercanet::INTERFACE_VERSION);
93-
$this->mercanet->setKeyVersion('3');
101+
$this->mercanet->setKeyVersion($this->keyVersion);
94102
$this->mercanet->setAmount($this->amount);
95103
$this->mercanet->setCurrency($this->currency);
96104
$this->mercanet->setOrderChannel("INTERNET");

src/MercanetBnpParibasGatewayFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ protected function populateConfig(ArrayObject $config)
3939
'environment' => '',
4040
'secure_key' => '',
4141
'merchant_id' => '',
42+
'key_version' => '',
4243
];
4344

4445
$config->defaults($config['payum.default_options']);
45-
$config['payum.required_options'] = ['secret_key', 'environment', 'merchant_id'];
46+
$config['payum.required_options'] = ['secret_key', 'environment', 'merchant_id', 'key_version'];
4647

4748
$config['payum.api'] = function (ArrayObject $config) {
4849
$config->validateNotEmpty($config['payum.required_options']);
@@ -52,6 +53,7 @@ protected function populateConfig(ArrayObject $config)
5253

5354
$mercanetBnpParibasBridge->setSecretKey($config['secret_key']);
5455
$mercanetBnpParibasBridge->setMerchantId($config['merchant_id']);
56+
$mercanetBnpParibasBridge->setKeyVersion($config['key_version']);
5557
$mercanetBnpParibasBridge->setEnvironment($config['environment']);
5658

5759
return $mercanetBnpParibasBridge;

src/Resources/translations/messages.en.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ bitbag:
33
environment: Environment
44
secure_key: Secure key
55
merchant_id: Merchant ID
6+
key_version: Key version
67
gateway_label: Mercanet BNP Paribas
78
production: Production
89
test: Test
9-
simulation: Simulation
10+
simulation: Simulation

src/Resources/translations/messages.fr.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ bitbag:
33
environment: Environnement
44
secure_key: Clé de sécurité
55
merchant_id: ID marchand
6+
key_version: Key version
67
gateway_label: Mercanet BNP Paribas
78
production: Production
89
test: Tester
9-
simulation: Simulation
10+
simulation: Simulation

src/Resources/translations/validators.en.yml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ bitbag:
22
mercanet_bnp_paribas:
33
merchant_id:
44
not_blank: Please enter the Merchant ID.
5+
key_version:
6+
not_blank: Please enter the Key version.
57
secure_key:
68
not_blank: Please enter the Security Code.
79
channel:

src/Resources/translations/validators.fr.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ bitbag:
22
mercanet_bnp_paribas:
33
merchant_id:
44
not_blank: Entrez l'identifiant du marchand.
5+
key_version:
6+
not_blank: Please enter the Key version.
57
secure_key:
68
not_blank: Veuillez entrer le code de sécurité.
79
channel:
8-
currency: La seule devise autorisée est EUR.
10+
currency: La seule devise autorisée est EUR.

tests/Behat/Context/Setup/MercanetBnpParibasContext.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public function theStoreHasAPaymentMethodWithACodeAndMercanetBnpParibasCheckoutG
8181
$paymentMethod->getGatewayConfig()->setConfig([
8282
'environment' => Mercanet::TEST,
8383
'merchant_id' => 'TEST',
84+
'key_version' => 'TEST',
8485
'secret_key' => 'TEST',
8586
'payum.http_client' => '@bitbag.mercanet_bnp_paribas.bridge.mercanet_bnp_paribas_bridge',
8687
]);
@@ -125,4 +126,4 @@ private function createPaymentMethod(
125126

126127
return $paymentMethod;
127128
}
128-
}
129+
}

tests/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function iConfigureItWithTestMercanetBnpParibasCredentials()
4747
{
4848
$this->createPage->setMercanetBnpParibasPluginGatewaySecretKey('test');
4949
$this->createPage->setMercanetBnpParibasPluginGatewayMerchantId('test');
50+
$this->createPage->setMercanetBnpParibasPluginGatewayKeyVersion('test');
5051
$this->createPage->setMercanetBnpParibasPluginGatewayEnvironment('Test');
5152
}
5253

@@ -65,4 +66,12 @@ public function iShouldBeNotifiedThatTheMerchantIdIsInvalid()
6566
{
6667
Assert::true($this->createPage->findValidationMessage('Please enter the Merchant ID.'));
6768
}
68-
}
69+
70+
/**
71+
* @Then I should be notified that the Key version is invalid
72+
*/
73+
public function iShouldBeNotifiedThatTheKeyVersionIsInvalid()
74+
{
75+
Assert::true($this->createPage->findValidationMessage('Please enter the Key version.'));
76+
}
77+
}

tests/Behat/Mocker/MercanetBnpParibasMocker.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function completedPayment(callable $action)
5353
->andReturn(true);
5454

5555
$openMercanetBnpParibasWrapper
56-
->shouldReceive('setSecretKey', 'setEnvironment', 'setMerchantId')
56+
->shouldReceive('setSecretKey', 'setEnvironment', 'setMerchantId', 'setKeyVersion')
5757
;
5858

5959
$openMercanetBnpParibasWrapper
@@ -66,6 +66,11 @@ public function completedPayment(callable $action)
6666
->andReturn('test')
6767
;
6868

69+
$openMercanetBnpParibasWrapper
70+
->shouldReceive('getKeyVersion')
71+
->andReturn('test')
72+
;
73+
6974
$openMercanetBnpParibasWrapper
7075
->shouldReceive('getEnvironment')
7176
->andReturn(Mercanet::TEST)
@@ -97,7 +102,7 @@ public function canceledPayment(callable $action)
97102
->andReturn(true);
98103

99104
$openMercanetBnpParibasWrapper
100-
->shouldReceive('setSecretKey', 'setEnvironment', 'setMerchantId')
105+
->shouldReceive('setSecretKey', 'setEnvironment', 'setMerchantId', 'setKeyVersion')
101106
;
102107

103108
$openMercanetBnpParibasWrapper
@@ -110,6 +115,11 @@ public function canceledPayment(callable $action)
110115
->andReturn('test')
111116
;
112117

118+
$openMercanetBnpParibasWrapper
119+
->shouldReceive('getKeyVersion')
120+
->andReturn('test')
121+
;
122+
113123
$openMercanetBnpParibasWrapper
114124
->shouldReceive('getEnvironment')
115125
->andReturn(Mercanet::TEST)
@@ -119,4 +129,4 @@ public function canceledPayment(callable $action)
119129

120130
$this->mocker->unmockAll();
121131
}
122-
}
132+
}

tests/Behat/Page/Admin/PaymentMethod/CreatePage.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ public function setMercanetBnpParibasPluginGatewayMerchantId($merchantId)
3434
$this->getDocument()->fillField('Merchant ID', $merchantId);
3535
}
3636

37+
/**
38+
* {@inheritdoc}
39+
*/
40+
public function setMercanetBnpParibasPluginGatewayKeyVersion($keyVersion)
41+
{
42+
$this->getDocument()->fillField('Key version', $keyVersion);
43+
}
44+
3745
/**
3846
* {@inheritdoc}
3947
*/
@@ -58,4 +66,4 @@ public function findValidationMessage($message)
5866

5967
return false;
6068
}
61-
}
69+
}

tests/Behat/Page/Admin/PaymentMethod/CreatePageInterface.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public function setMercanetBnpParibasPluginGatewaySecretKey($secretKey);
2727
*/
2828
public function setMercanetBnpParibasPluginGatewayMerchantId($merchantId);
2929

30+
/**
31+
* @param string $keyVersion
32+
*/
33+
public function setMercanetBnpParibasPluginGatewayKeyVersion($keyVersion);
34+
3035
/**
3136
* @param string $environment
3237
*/
@@ -38,4 +43,4 @@ public function setMercanetBnpParibasPluginGatewayEnvironment($environment);
3843
* @return bool
3944
*/
4045
public function findValidationMessage($message);
41-
}
46+
}

0 commit comments

Comments
 (0)