Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

Commit

Permalink
Move Method Specific input into PaymentMethodInput
Browse files Browse the repository at this point in the history
  • Loading branch information
pmclain committed Jul 2, 2019
1 parent d57d076 commit 05632a8
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class BraintreeDataProvider implements AdditionalDataProviderInterface
{
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree';
private const PATH_ADDITIONAL_DATA = 'braintree';

/**
* @var ArrayManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class BraintreeVaultDataProvider implements AdditionalDataProviderInterface
{
private const PATH_ADDITIONAL_DATA = 'input/payment_method/additional_data/braintree_cc_vault';
private const PATH_ADDITIONAL_DATA = 'braintree_cc_vault';

/**
* @var ArrayManager
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/BraintreeGraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright © Magento, Inc. All rights reserved.
# See COPYING.txt for license details.

input PaymentMethodAdditionalDataInput {
input PaymentMethodInput {
braintree: BraintreeInput
braintree_cc_vault: BraintreeCcVaultInput
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,15 @@ public function execute(Quote $cart, array $paymentData): void
$paymentMethodCode = $paymentData['code'];

$poNumber = $paymentData['purchase_order_number'] ?? null;
$additionalData = isset($paymentData['additional_data'])
? $this->additionalDataProviderPool->getData($paymentMethodCode, $paymentData['additional_data'])
: [];
$additionalData = $this->additionalDataProviderPool->getData($paymentMethodCode, $paymentData);

$payment = $this->paymentFactory->create(
[
'data' =>
[
PaymentInterface::KEY_METHOD => $paymentMethodCode,
PaymentInterface::KEY_PO_NUMBER => $poNumber,
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData,
],
'data' => [
PaymentInterface::KEY_METHOD => $paymentMethodCode,
PaymentInterface::KEY_PO_NUMBER => $poNumber,
PaymentInterface::KEY_ADDITIONAL_DATA => $additionalData,
],
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected function setUp()
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
* @magentoApiDataFixture Magento/Graphql/Braintree/_files/payments.php
* @magentoApiDataFixture Magento/GraphQl/Braintree/_files/enable_braintree_payment.php
*/
public function testPlaceOrder()
{
Expand Down Expand Up @@ -121,7 +121,7 @@ public function testPlaceOrder()
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
* @magentoApiDataFixture Magento/Graphql/Braintree/_files/payments.php
* @magentoApiDataFixture Magento/GraphQl/Braintree/_files/enable_braintree_payment.php
*/
public function testPlaceOrderSaveInVault()
{
Expand Down Expand Up @@ -161,8 +161,8 @@ public function testPlaceOrderSaveInVault()
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
* @magentoApiDataFixture Magento/Graphql/Braintree/_files/payments.php
* @magentoApiDataFixture Magento/Graphql/Braintree/_files/token.php
* @magentoApiDataFixture Magento/GraphQl/Braintree/_files/enable_braintree_payment.php
* @magentoApiDataFixture Magento/GraphQl/Braintree/_files/token.php
*/
public function testPlaceOrderWithVault()
{
Expand Down Expand Up @@ -224,11 +224,9 @@ private function getSetPaymentBraintreeQuery(string $maskedQuoteId, bool $saveIn
cart_id:"{$maskedQuoteId}"
payment_method:{
code:"braintree"
additional_data:{
braintree:{
is_active_payment_token_enabler:{$saveInVault}
payment_method_nonce:"fake-valid-nonce"
}
braintree:{
is_active_payment_token_enabler:{$saveInVault}
payment_method_nonce:"fake-valid-nonce"
}
}
}) {
Expand Down Expand Up @@ -262,12 +260,10 @@ private function getSetPaymentBraintreeVaultQuery(
cart_id:"{$maskedQuoteId}"
payment_method:{
code:"braintree_cc_vault"
additional_data:{
braintree_cc_vault:{
is_active_payment_token_enabler:{$saveInVault}
payment_method_nonce:"{$nonce}"
public_hash:"{$publicHash}"
}
braintree_cc_vault:{
is_active_payment_token_enabler:{$saveInVault}
payment_method_nonce:"{$nonce}"
public_hash:"{$publicHash}"
}
}
}) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
*/
class SetPaymentMethodTest extends GraphQlAbstract
{
private const REQUIRED_CONSTS = [
'TESTS_BRAINTREE_MERCHANT_ID',
'TESTS_BRAINTREE_PUBLIC_KEY',
'TESTS_BRAINTREE_PRIVATE_KEY',
];

/**
* @var CustomerTokenServiceInterface
*/
Expand Down Expand Up @@ -56,12 +50,6 @@ class SetPaymentMethodTest extends GraphQlAbstract
*/
protected function setUp()
{
foreach (static::REQUIRED_CONSTS as $const) {
if (!defined($const)) {
$this->markTestSkipped('Braintree sandbox credentials must be defined in phpunit_graphql.xml.dist');
}
}

$objectManager = Bootstrap::getObjectManager();
$this->getMaskedQuoteIdByReservedOrderId = $objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
$this->customerTokenService = $objectManager->get(CustomerTokenServiceInterface::class);
Expand All @@ -79,7 +67,7 @@ protected function setUp()
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_billing_address.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_flatrate_shipping_method.php
* @magentoApiDataFixture Magento/Graphql/Braintree/_files/payments.php
* @magentoApiDataFixture Magento/GraphQl/Braintree/_files/enable_braintree_payment.php
*/
public function testPlaceOrder()
{
Expand Down Expand Up @@ -126,11 +114,9 @@ private function getSetPaymentBraintreeQuery(string $maskedQuoteId): string
cart_id:"{$maskedQuoteId}"
payment_method:{
code:"braintree"
additional_data:{
braintree:{
is_active_payment_token_enabler:false
payment_method_nonce:"fake-valid-nonce"
}
braintree:{
is_active_payment_token_enabler:false
payment_method_nonce:"fake-valid-nonce"
}
}
}) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\App\Config\Storage\Writer;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Braintree\Model\Ui\ConfigProvider;
use Magento\Framework\App\Config\ScopeConfigInterface;

$objectManager = Bootstrap::getObjectManager();

/** @var Writer $configWriter */
$configWriter = $objectManager->get(WriterInterface::class);
/** @var EncryptorInterface $encryptor */
$encryptor = $objectManager->get(EncryptorInterface::class);

/** @var $mutableScopeConfig */
$mutableScopeConfig = $objectManager->get(
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
);

$configWriter->save('payment/' . ConfigProvider::CODE . '/merchant_id', 'def_merchant_id');
$configWriter->save('payment/' . ConfigProvider::CODE . '/public_key', $encryptor->encrypt('def_public_key'));
$configWriter->save('payment/' . ConfigProvider::CODE . '/private_key', $encryptor->encrypt('def_private_key'));
$configWriter->save('payment/' . ConfigProvider::CODE . '/active', '1');
$configWriter->save('payment/' . ConfigProvider::CODE . '/environment', 'sandbox');
$configWriter->save('payment/' . ConfigProvider::CC_VAULT_CODE . '/active', '1');

$scopeConfig = $objectManager->get(ScopeConfigInterface::class);
$scopeConfig->clean();
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\App\Config\Storage\Writer;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\Encryption\EncryptorInterface;
use Magento\Braintree\Model\Ui\ConfigProvider;

$objectManager = Bootstrap::getObjectManager();

/** @var Writer $configWriter */
$configWriter = $objectManager->get(WriterInterface::class);
/** @var EncryptorInterface $encryptor */
$encryptor = $objectManager->get(EncryptorInterface::class);

/** @var $mutableScopeConfig */
$mutableScopeConfig = $objectManager->get(
\Magento\Framework\App\Config\MutableScopeConfigInterface::class
);

$configWriter->delete('payment/' . ConfigProvider::CODE . '/merchant_id');
$configWriter->delete('payment/' . ConfigProvider::CODE . '/public_key');
$configWriter->delete('payment/' . ConfigProvider::CODE . '/private_key');
$configWriter->delete('payment/' . ConfigProvider::CODE . '/active');
$configWriter->delete('payment/' . ConfigProvider::CODE . '/environment');
$configWriter->delete('payment/' . ConfigProvider::CC_VAULT_CODE . '/active');

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@
use Magento\Vault\Model\PaymentToken;
use Magento\Vault\Model\PaymentTokenRepository;

$requiredConst = [
'TESTS_BRAINTREE_MERCHANT_ID',
'TESTS_BRAINTREE_PUBLIC_KEY',
'TESTS_BRAINTREE_PRIVATE_KEY',
];
foreach ($requiredConst as $const) {
if (!defined($const)) {
return;
}
}

$objectManager = Bootstrap::getObjectManager();

$adapterFactory = $objectManager->get(\Magento\Braintree\Model\Adapter\BraintreeAdapterFactory::class);
Expand Down

0 comments on commit 05632a8

Please sign in to comment.