Skip to content

Commit c656d04

Browse files
Vault Card Autosave
Added on option to save cards automatically without requesting approval from the user.
1 parent b7c7707 commit c656d04

File tree

7 files changed

+52
-8
lines changed

7 files changed

+52
-8
lines changed

Gateway/Config/Config.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class Config extends BaseConfig {
5959
const KEY_EMBEDDED_CSS = 'embedded_css';
6060
const KEY_CUSTOM_CSS = 'custom_css';
6161
const KEY_CSS_FILE = 'css_file';
62-
const KEY_VAULT_TITLE = 'checkout_com_cc_vault/title';
6362
const KEY_ORDER_COMMENTS_OVERRIDE = 'order_comments_override';
6463
const KEY_ORDER_CREATION = 'order_creation';
6564

@@ -97,6 +96,17 @@ public function getVaultTitle() {
9796
return (string) $scopeConfig->getValue('payment/checkout_com_cc_vault/title');
9897
}
9998

99+
/**
100+
* Returns the vault card autosave state.
101+
*
102+
* @return bool
103+
*/
104+
public function isCardAutosave() {
105+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
106+
$scopeConfig = $objectManager->create('Magento\Framework\App\Config\ScopeConfigInterface');
107+
return (bool) $scopeConfig->getValue('payment/checkout_com_cc_vault/autosave');
108+
}
109+
100110
/**
101111
* Returns the payment mode.
102112
*

Gateway/Request/VaultRequest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Magento\Payment\Gateway\Request\BuilderInterface;
1414
use Magento\Customer\Model\Session as CustomerSession;
15+
use Magento\Framework\App\Config\ScopeConfigInterface;
1516

1617
class VaultRequest implements BuilderInterface {
1718

@@ -31,12 +32,18 @@ class VaultRequest implements BuilderInterface {
3132
*/
3233
protected $customerSession;
3334

35+
/**
36+
* @var ScopeConfigInterface
37+
*/
38+
protected $scopeConfig;
39+
3440
/**
3541
* VaultRequest constructor.
3642
* @param CustomerSession $customerSession
3743
*/
38-
public function __construct(CustomerSession $customerSession) {
44+
public function __construct(CustomerSession $customerSession, ScopeConfigInterface $scopeConfig) {
3945
$this->customerSession = $customerSession;
46+
$this->scopeConfig = $scopeConfig;
4047
}
4148

4249
/**
@@ -54,10 +61,16 @@ public function getVaultSaveInfo() {
5461
// Get the checkout session data
5562
$checkoutSessionData = $this->customerSession->getData('checkoutSessionData');
5663

64+
// Get the auto save card config
65+
$isAutoSave = $scopeConfig->getValue('payment/checkout_com_cc_vault/autosave');
66+
5767
// Check if save card is requested
5868
if (isset($checkoutSessionData['saveShopperCard'])) {
5969
return filter_var($checkoutSessionData['saveShopperCard'], FILTER_VALIDATE_BOOLEAN);
6070
}
71+
else if ($isAutoSave) {
72+
return true;
73+
}
6174

6275
return false;
6376
}

Model/Ui/ConfigProvider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function getConfig() {
9797
'custom_css' => $this->config->getCustomCss(),
9898
'vault_title' => $this->config->getVaultTitle(),
9999
'order_creation' => $this->config->getOrderCreation(),
100+
'card_autosave' => $this->config->isCardAutosave(),
100101
],
101102
],
102103
];

etc/adminhtml/system.xml

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,31 @@
128128
</depends>
129129
</field>
130130

131-
<field id="useccv" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
131+
<field id="checkout_com_cc_vault_autosave" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
132+
<label>Save cards automatically</label>
133+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
134+
<config_path>payment/checkout_com_cc_vault/autosave</config_path>
135+
<depends>
136+
<field id="checkout_com_cc_vault_active">1</field>
137+
</depends>
138+
<comment>
139+
If set to "No", customers will be asked during checkout if the card used for payment should be stored. If set to "Yes", the card will be saved automatically without requesting agreement.
140+
</comment>
141+
</field>
142+
143+
<field id="useccv" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
132144
<label>CVV Verification</label>
133145
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
134146
<config_path>payment/checkout_com/useccv</config_path>
135147
</field>
136148

137-
<field id="verify_3dsecure" translate="label" sortOrder="40" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
149+
<field id="verify_3dsecure" translate="label" sortOrder="50" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
138150
<label>3D Secure Verification</label>
139151
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
140152
<config_path>payment/checkout_com/verify_3dsecure</config_path>
141153
</field>
142154

143-
<field id="attemptN3D" translate="label comment" sortOrder="50" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
155+
<field id="attemptN3D" translate="label comment" sortOrder="60" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
144156
<label>Attempt Non 3D Secure</label>
145157
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
146158
<config_path>payment/checkout_com/attemptN3D</config_path>
@@ -152,13 +164,13 @@
152164
</comment>
153165
</field>
154166

155-
<field id="auto_capture" translate="label" sortOrder="60" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
167+
<field id="auto_capture" translate="label" sortOrder="70" type="select" showInDefault="1" showInWebsite="1" showInStore="0">
156168
<label>Auto Capture</label>
157169
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
158170
<config_path>payment/checkout_com/auto_capture</config_path>
159171
</field>
160172

161-
<field id="auto_capture_time" translate="label comment" sortOrder="70" type="text" showInDefault="1" showInWebsite="1" showInStore="0">
173+
<field id="auto_capture_time" translate="label comment" sortOrder="80" type="text" showInDefault="1" showInWebsite="1" showInStore="0">
162174
<label>Auto Capture Time</label>
163175
<config_path>payment/checkout_com/auto_capture_time</config_path>
164176
<validate>validate-required validate-digits validate-zero-or-greater</validate>

etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<checkout_com_cc_vault>
6565
<model>CheckoutComCreditCardVaultFacade</model>
6666
<title>Stored Cards (Checkout.com)</title>
67+
<autosave>1</autosave>
6768
</checkout_com_cc_vault>
6869
</payment>
6970
</default>

view/frontend/web/js/view/payment/method-renderer/hosted.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ define(
7575
return CheckoutCom.getPaymentConfig()['quote_currency'];
7676
},
7777

78+
/**
79+
* @returns {bool}
80+
*/
81+
isCardAutosave: function() {
82+
return CheckoutCom.getPaymentConfig()['card_autosave'];
83+
},
84+
7885
/**
7986
* @returns {string}
8087
*/

view/frontend/web/template/payment/hosted.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
<!--/ko-->
5454
</div>
5555

56-
<!-- ko if: (isVaultEnabled())-->
56+
<!-- ko if: ((isVaultEnabled()) && !isCardAutosave()) -->
5757
<div class="field choice">
5858
<input type="checkbox" name="vault[is_enabled]" class="checkbox" data-bind="attr: {'id': getCode() + '_enable_vault'}, checked: vaultEnabler.isActivePaymentTokenEnabler" />
5959
<label class="label" data-bind="attr: {'for': getCode() + '_enable_vault'}">

0 commit comments

Comments
 (0)