diff --git a/CHANGELOG.md b/CHANGELOG.md index 288fe1d..28646b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.1.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [3.3.0](https://github.com/unzerdev/magento2/compare/3.2.2..3.3.0) +### Added +* ApplePay V2 + ## [3.2.2](https://github.com/unzerdev/magento2/compare/3.2.1..3.2.2) ### Fixed * bank name not needed anymore for eps payment method diff --git a/Model/Config.php b/Model/Config.php index 51b7d27..1091a3b 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -55,6 +55,7 @@ class Config extends \Magento\Payment\Gateway\Config\Config public const METHOD_BANCONTACT = 'unzer_bancontact'; public const METHOD_PREPAYMENT = 'unzer_prepayment'; public const METHOD_APPLEPAY = 'unzer_applepay'; + public const METHOD_APPLEPAYV2 = 'unzer_applepayv2'; public const METHOD_GOOGLEPAY = 'unzer_googlepay'; public const METHOD_TWINT = 'unzer_twint'; diff --git a/Model/Config/Provider.php b/Model/Config/Provider.php index 9c0e9ed..dd6ce5b 100644 --- a/Model/Config/Provider.php +++ b/Model/Config/Provider.php @@ -44,6 +44,7 @@ class Provider implements ConfigProviderInterface Config::METHOD_BANCONTACT, Config::METHOD_PREPAYMENT, Config::METHOD_APPLEPAY, + Config::METHOD_APPLEPAYV2, Config::METHOD_GOOGLEPAY, Config::METHOD_TWINT, ]; diff --git a/Model/Method/ApplepayV2.php b/Model/Method/ApplepayV2.php new file mode 100644 index 0000000..4dacc70 --- /dev/null +++ b/Model/Method/ApplepayV2.php @@ -0,0 +1,27 @@ +_scopeConfig->getValue('payment/unzer/applepayv2/supported_networks'); + $supportedNetworks = explode(',', $supportedNetworks); + + return [ + 'supportedNetworks' => $supportedNetworks, + 'merchantCapabilities' => ['supports3DS'], + 'label' => $this->_scopeConfig->getValue('payment/unzer_applepayv2/display_name') //label + ]; + } +} diff --git a/Model/Source/ApplepayV2/SupportedNetworks.php b/Model/Source/ApplepayV2/SupportedNetworks.php new file mode 100644 index 0000000..9ee38a6 --- /dev/null +++ b/Model/Source/ApplepayV2/SupportedNetworks.php @@ -0,0 +1,57 @@ + $network, + 'label' => ucfirst($network), + ]; + } + return $options; + } +} diff --git a/Model/System/Config/Backend/ApplepayV2/Upload.php b/Model/System/Config/Backend/ApplepayV2/Upload.php new file mode 100644 index 0000000..dd84f9b --- /dev/null +++ b/Model/System/Config/Backend/ApplepayV2/Upload.php @@ -0,0 +1,80 @@ +_mediaDirectory = $this->_filesystem->getDirectoryWrite(DirectoryList::PUB); + + $path = $this->_mediaDirectory->getAbsolutePath($uploadDir); + + if (!$this->_mediaDirectory->isDirectory($path)) { + $this->_mediaDirectory->create($path); + } + + return $path; + } + + /** + * Save uploaded file before saving config value + * + * @return $this + * @throws LocalizedException + */ + public function beforeSave(): Upload + { + $value = $this->getValue(); + $file = $this->getFileData(); + + if (!empty($file)) { + $uploadDir = $this->getUploadDirPath('.well-known/'); + try { + $uploader = $this->_uploaderFactory->create(['fileId' => $file]); + $uploader->setAllowRenameFiles(false); + $uploader->addValidateCallback('size', $this, 'validateMaxSize'); + $uploader->setFilesDispersion(false); + + $domainAssocFileName = 'apple-developer-merchantid-domain-association'; + + $result = $uploader->save($uploadDir, $domainAssocFileName); + } catch (Exception $e) { + throw new LocalizedException(__('%1', $e->getMessage())); + } + if ($result !== false) { + if ($this->_addWhetherScopeInfo()) { + $domainAssocFileName = $this->_prependScopeInfo($domainAssocFileName); + } + $this->setValue($domainAssocFileName); + } + } else { + if (is_array($value) && !empty($value['delete'])) { + $this->setValue(''); + } elseif (is_array($value) && !empty($value['value'])) { + $this->setValue($value['value']); + } else { + $this->unsValue(); + } + } + + return $this; + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index ef98938..afbbc57 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -70,6 +70,7 @@ + diff --git a/etc/adminhtml/system/applepay.xml b/etc/adminhtml/system/applepay.xml index 039b995..a6d9359 100644 --- a/etc/adminhtml/system/applepay.xml +++ b/etc/adminhtml/system/applepay.xml @@ -3,6 +3,22 @@ + + + + +

Existing merchants:

+

We have updated our integration with Apple Pay, but since you already have it set up, you don't need to do anything just now.

+

However, when your Apple Pay certificates are about to expire, you can change to the new integration.

+

You can of course change to the new integration now, if you want, and then you don't have to worry about expiring certificates, changing integration, etc. in the future.

+
+

Existing and new both:

+

Before you activate Apple Pay, please make sure you have read our checklist.

+ + ]]> +
+
diff --git a/etc/adminhtml/system/applepayv2.xml b/etc/adminhtml/system/applepayv2.xml new file mode 100644 index 0000000..b23df83 --- /dev/null +++ b/etc/adminhtml/system/applepayv2.xml @@ -0,0 +1,48 @@ + + + + + + + Magento\Config\Model\Config\Source\Yesno + payment/unzer_applepayv2/active + + + + payment/unzer_applepayv2/title + + + + payment/unzer_applepayv2/order_payment_action + Unzer\PAPI\Model\System\Config\Source\PaymentAction + + + + payment/unzer_applepayv2/min_order_total + + + + payment/unzer_applepayv2/max_order_total + Insert 0 to disable limit. + + + + Unzer\PAPI\Model\Source\ApplepayV2\SupportedNetworks + + + + Unzer\PAPI\Model\System\Config\Backend\ApplepayV2\Upload + + + + payment/unzer_applepayv2/sort_order + + + diff --git a/etc/config.xml b/etc/config.xml index 6bbf5f3..a86ef5a 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -402,6 +402,22 @@ 0 Unzer\PAPI\Model\Method\Applepay + + 0 + order + authorize_capture + <![CDATA[Apple Pay]]> + 0 + 0 + 0 + 1 + 1 + 1 + 1 + 1 + 0 + Unzer\PAPI\Model\Method\ApplepayV2 + 0 order diff --git a/etc/di.xml b/etc/di.xml index 5357140..a6f51c0 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -1330,7 +1330,6 @@ UnzerCaptureCommandPool - @@ -1382,6 +1381,57 @@ + + + + Unzer\PAPI\Model\Config::METHOD_APPLEPAYV2 + + + + + + UnzerApplepayV2Config + + + + + + + UnzerApplepayV2ConfigValueHandler + Unzer\PAPI\Model\Config\CanCancelHandler + Unzer\PAPI\Model\Config\CanRefundHandler + Unzer\PAPI\Model\Config\CanRefundHandler + + Unzer\PAPI\Model\Config\CanVoidHandler + + + + + + + UnzerApplepayV2Config + + + + + + + UnzerApplepayV2ValidatorCountry + + + + + + + Unzer\PAPI\Model\Config::METHOD_APPLEPAYV2 + Magento\Payment\Block\Form + Magento\Payment\Block\Info + UnzerApplepayV2ValueHandlerPool + UnzerApplepayV2ValidatorPool + UnzerAuthorizeAndCaptureCommandPool + + + diff --git a/etc/events.xml b/etc/events.xml index be07425..897fec6 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -66,6 +66,9 @@ + + + diff --git a/etc/module.xml b/etc/module.xml index 876c1bf..8533da0 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,7 +1,7 @@ - + diff --git a/i18n/de_DE.csv b/i18n/de_DE.csv index e73d5de..2e18117 100644 --- a/i18n/de_DE.csv +++ b/i18n/de_DE.csv @@ -23,7 +23,8 @@ "UNZER_BANCONTACT","Bancontact" "UNZER_PREPAYMENT","Unzer Prepayment" "UNZER_ABOUT_US","Unzer ist eine innovative und modulare Plattform für den internationalen Zahlungsverkehr. Unternehmen aller Größen und Branchen vertrauen auf die datengetriebenen, sicheren und passgenauen Lösungen für mehr Wachstum – online, mobil oder am Point of Sale. Die einfach integrierbaren Module decken das gesamte Spektrum des Zahlungsmanagements ab: Von der Abwicklung verschiedener Zahlungsarten über automatisierte Analysen von Kundenverhalten und -bedürfnissen bis hin zum ganzheitlichen Risikomanagement.

Mehr Informationen finden Sie auf www.unzer.com" -"UNZER_APPLEPAY","Apple Pay" +"UNZER_APPLEPAY","(Deprecated) Apple Pay" +"UNZER_APPLEPAYV2","Apple Pay" "UNZER_GOOGLEPAY","Google Pay" "UNZER_TWINT","TWINT" diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 76ce65e..c8176fb 100644 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -23,7 +23,8 @@ "UNZER_BANCONTACT","Bancontact" "UNZER_PREPAYMENT","Unzer Prepayment" "UNZER_ABOUT_US","Unzer is an innovative and modular platform for international payment transactions. Companies of all sizes and from all sectors rely on the data-driven, secure and perfectly tailored solutions to help them drive growth – whether online, mobile or at the point of sale. The modules, which are easy to integrate, cover the entire spectrum of payment management: from processing of various payment types, through automated analytics of customer behaviour and requirements, all the way up to integrative risk management.

For more information please visit www.unzer.com" -"UNZER_APPLEPAY","Apple Pay" +"UNZER_APPLEPAY","(Deprecated) Apple Pay" +"UNZER_APPLEPAYV2","Apple Pay" "UNZER_GOOGLEPAY","Google Pay" "UNZER_TWINT","TWINT" diff --git a/view/frontend/layout/checkout_index_index.xml b/view/frontend/layout/checkout_index_index.xml index 2abc392..6afab30 100644 --- a/view/frontend/layout/checkout_index_index.xml +++ b/view/frontend/layout/checkout_index_index.xml @@ -95,6 +95,9 @@ true + + true + true diff --git a/view/frontend/web/js/view/payment/method-renderer.js b/view/frontend/web/js/view/payment/method-renderer.js index f5743ae..fd71ce6 100644 --- a/view/frontend/web/js/view/payment/method-renderer.js +++ b/view/frontend/web/js/view/payment/method-renderer.js @@ -97,6 +97,10 @@ define( type: 'unzer_applepay', component: 'Unzer_PAPI/js/view/payment/method-renderer/applepay' }, + { + type: 'unzer_applepayv2', + component: 'Unzer_PAPI/js/view/payment/method-renderer/applepayv2' + }, { type: 'unzer_googlepay', component: 'Unzer_PAPI/js/view/payment/method-renderer/googlepay' diff --git a/view/frontend/web/js/view/payment/method-renderer/applepayv2.js b/view/frontend/web/js/view/payment/method-renderer/applepayv2.js new file mode 100644 index 0000000..9fa841b --- /dev/null +++ b/view/frontend/web/js/view/payment/method-renderer/applepayv2.js @@ -0,0 +1,86 @@ +define( + [ + 'jquery', + 'Unzer_PAPI/js/view/payment/method-renderer/base', + 'Magento_Checkout/js/model/quote', + '//applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js' + ], + function ($, Component, quote) { + 'use strict'; + + return Component.extend({ + defaults: { + template: 'Unzer_PAPI/payment/applepayv2' + }, + + initialize: function () { + this._super(); + + return this; + }, + + initializeForm: function () { + const self = this; + if (!this.isApplePayAvailable()) { + this.handleError("This device does not support Apple Pay!"); + } + self.resourceProvider = this.sdk.ApplePay(); + }, + + isApplePayAvailable: function () { + return window.ApplePaySession && ApplePaySession.canMakePayments(); + }, + + startApplePaySession: function () { + let self = this; + window.checkoutConfig.quoteData.trigger_reload = new Date().getTime(); + + const supportedNetworks = window.checkoutConfig.payment.unzer_applepayv2.supportedNetworks.map((network) => network.toLowerCase()) + + const applePayPaymentRequest = { + countryCode: quote.billingAddress().countryId, + currencyCode: window.checkoutConfig.quoteData.quote_currency_code, + totalLabel: window.checkoutConfig.payment.unzer_applepayv2.label, //display_name + totalAmount: Number(window.checkoutConfig.quoteData.base_grand_total).toFixed(2), + supportedNetworks: supportedNetworks, + merchantCapabilities: window.checkoutConfig.payment.unzer_applepayv2.merchantCapabilities, + requiredShippingContactFields: [], + requiredBillingContactFields: [], + total: { + label: window.checkoutConfig.payment.unzer_applepayv2.label, + amount: Number(window.checkoutConfig.quoteData.base_grand_total).toFixed(2) + }, + }; + + const session = this.resourceProvider.initApplePaySession(applePayPaymentRequest, 6); + + session.onpaymentauthorized = function(event) { + const paymentData = event.payment.token.paymentData; + session.completePayment({status: window.ApplePaySession.STATUS_SUCCESS}); + self.paymentData = paymentData; + + self.placeOrder(); + }; + + session.onpaymentmethodselected = function(event) { + let update = { + newTotal: { + label: window.checkoutConfig.payment.unzer_applepayv2.label, + type: "final", + amount: Number(window.checkoutConfig.quoteData.base_grand_total).toFixed(2) + } + }; + + session.completePaymentMethodSelection(update); + }; + + session.begin(); + }, + + handleError: function (message) { + $('#unzer-applepay-error').html(message); + }, + }); + }, +); + diff --git a/view/frontend/web/template/payment/applepayv2.html b/view/frontend/web/template/payment/applepayv2.html new file mode 100644 index 0000000..6fe3045 --- /dev/null +++ b/view/frontend/web/template/payment/applepayv2.html @@ -0,0 +1,74 @@ +
+
+ + +
+
+
+ + + +
+
+
+
+ + +
+
+
+ + + +
+
+