Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.2.0 #100

Merged
merged 9 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release

on:
# Manual run from Github UI (e.g. for when a merged PR labels have changed)
workflow_dispatch:
inputs:
pre-release:
required: false
type: boolean
default: false
description: "This release will be labeled as non-production ready"
# Publish the current version now, useful if the automated run failed
github-release:
required: false
type: boolean
default: false
description: "Publish Github release for the current version"
# Monitor pull request events

pull_request:
types:
- closed
branches:
- main

jobs:
release:
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Prepare the next main release
uses: Adyen/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
develop-branch: main
version-files: composer.json
release-title: Adyen Magento 2 Express Checkout Module
pre-release: ${{ inputs.pre-release || false }}
# For a manual Github release
github-release: ${{ inputs.github-release || false }}
separator: .pre.beta
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.1.0
19 changes: 19 additions & 0 deletions ViewModel/CheckoutConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Adyen\ExpressCheckout\ViewModel;

use Adyen\Payment\Model\Ui\AdyenGenericConfigProvider;
use Adyen\Payment\Helper\Data;
use Magento\Framework\DataObject;
use Magento\Framework\Event\ManagerInterface;
use Magento\Framework\Exception\NoSuchEntityException;
Expand All @@ -28,6 +29,11 @@ class CheckoutConfig implements ArgumentInterface
*/
private $adyenGenericConfigProvider;

/**
* @var Data
*/
private $adyenDataHelper;

/**
* @var SerializerInterface
*/
Expand All @@ -45,17 +51,20 @@ class CheckoutConfig implements ArgumentInterface

/**
* @param AdyenGenericConfigProvider $adyenGenericConfigProvider
* @param Data $adyenDataHelper
* @param SerializerInterface $serializer
* @param StoreManagerInterface $storeManager
* @param ManagerInterface $eventManager
*/
public function __construct(
AdyenGenericConfigProvider $adyenGenericConfigProvider,
Data $adyenDataHelper,
SerializerInterface $serializer,
StoreManagerInterface $storeManager,
ManagerInterface $eventManager
) {
$this->adyenGenericConfigProvider = $adyenGenericConfigProvider;
$this->adyenDataHelper = $adyenDataHelper;
$this->serializer = $serializer;
$this->storeManager = $storeManager;
$this->eventManager = $eventManager;
Expand Down Expand Up @@ -95,4 +104,14 @@ private function getStoreCode(): string
{
return $this->storeManager->getStore()->getCode();
}

/**
* Return application info values
*
* @return array
*/
public function getAdyenData(): array
{
return $this->adyenDataHelper->buildRequestHeaders();
}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "adyen/adyen-magento2-expresscheckout",
"description": "Official Adyen Magento2 plugin to add express payment method shortcuts.",
"type": "magento2-module",
"version": "2.1.0",
"version": "2.2.0",
"license": "MIT",
"repositories": [
{
Expand All @@ -11,7 +11,7 @@
}
],
"require": {
"adyen/module-payment": "^9"
"adyen/module-payment": "^9.1.0"
},
"require-dev": {
"phpunit/phpunit": "*",
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Adyen_ExpressCheckout" setup_version="2.1.0">
<module name="Adyen_ExpressCheckout">
<sequence>
<module name="Adyen_Payment"/>
</sequence>
Expand Down
4 changes: 4 additions & 0 deletions view/frontend/templates/checkout-config.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

$checkoutConfig = __('window.checkoutConfig = %1;', $serializedCheckoutConfig);
?>
<?php $adyenData = $viewModel->getAdyenData();
$serializedAdyenData = json_encode($adyenData, JSON_HEX_TAG);
?>
<script>
<?=$checkoutConfig?>
window.customerData = window.checkoutConfig.customerData;
window.isCustomerLoggedIn = window.checkoutConfig.isCustomerLoggedIn;
window.adyenData = <?=$serializedAdyenData?>;
</script>
65 changes: 34 additions & 31 deletions view/frontend/web/js/actions/getExpressMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,47 @@ define([
getRequest: function (element) {
const existingRequest = this.request();

if (!existingRequest) {
const pdpForm = getPdpForm(element);
const formData = getFormData(pdpForm);
const cartMaskedId = getMaskedIdFromCart();
const adyenMaskedQuoteId = maskedIdModel().getMaskedId();
const payload = {
productCartParams: {
product: formData['product'],
qty: formData['qty'],
super_attribute: formData['super_attribute']
}
};
const url = getIsLoggedIn()
? 'rest/V1/adyen/express/init/mine'
: 'rest/V1/adyen/express/init/guest';
if (existingRequest) {
return existingRequest;
}

if (cartMaskedId) {
payload.guestMaskedId = cartMaskedId;
}
const pdpForm = getPdpForm(element);
const formData = getFormData(pdpForm);
const cartMaskedId = getMaskedIdFromCart();

if (adyenMaskedQuoteId) {
payload.adyenMaskedQuoteId = adyenMaskedQuoteId;
}
const previousQuoteId = localStorage.getItem("quoteId");
const adyenMaskedQuoteId = previousQuoteId != null ? previousQuoteId : maskedIdModel().getMaskedId();

const request = storage.post(
url,
JSON.stringify(payload)
).done(function (response) {
this.request(null);
return response;
}.bind(this));
const payload = {
productCartParams: {
product: formData['product'],
qty: formData['qty'],
super_attribute: formData['super_attribute']
}
};
const url = getIsLoggedIn()
? 'rest/V1/adyen/express/init/mine'
: 'rest/V1/adyen/express/init/guest';

this.request(request);
if (cartMaskedId) {
payload.guestMaskedId = cartMaskedId;
}

return request;
if (adyenMaskedQuoteId) {
payload.adyenMaskedQuoteId = adyenMaskedQuoteId;
}

return existingRequest;
const request = storage.post(
url,
JSON.stringify(payload)
).done(function (response) {
this.request(null);
return response;
}.bind(this));

this.request(request);

return request;
}
});
});
22 changes: 22 additions & 0 deletions view/frontend/web/js/applepay/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ define([
'Adyen_ExpressCheckout/js/helpers/redirectToSuccess',
'Adyen_ExpressCheckout/js/helpers/setExpressMethods',
'Adyen_ExpressCheckout/js/helpers/validatePdpForm',
'Adyen_ExpressCheckout/js/helpers/manageQuoteIdOnPageRefresh',
'Adyen_ExpressCheckout/js/model/config',
'Adyen_ExpressCheckout/js/model/countries',
'Adyen_ExpressCheckout/js/model/totals',
Expand Down Expand Up @@ -58,6 +59,7 @@ define([
redirectToSuccess,
setExpressMethods,
validatePdpForm,
manageQuoteIdOnPageRefresh,
configModel,
countriesModel,
totalsModel,
Expand All @@ -80,11 +82,14 @@ define([
configModel().setConfig(config);
countriesModel();

await manageQuoteIdOnPageRefresh();
this.isProductView = config.isProductView;

// If express methods is not set then set it.
if (this.isProductView) {
const response = await getExpressMethods().getRequest(element);

localStorage.setItem("quoteId", response.masked_quote_id);
const cart = customerData.get('cart');

virtualQuoteModel().setIsVirtual(true, response);
Expand Down Expand Up @@ -142,10 +147,26 @@ define([

initialiseApplePayComponent: async function (applePaymentMethod, element) {
const config = configModel().getConfig();
const adyenData = window.adyenData;

const adyenCheckoutComponent = await new AdyenCheckout({
locale: config.locale,
originKey: config.originkey,
environment: config.checkoutenv,
analytics: {
analyticsData: {
applicationInfo: {
merchantApplication: {
name: adyenData['merchant-application-name'],
version: adyenData['merchant-application-version']
},
externalPlatform: {
name: adyenData['external-platform-name'],
version: adyenData['external-platform-version']
}
}
}
},
risk: {
enabled: false
},
Expand Down Expand Up @@ -249,6 +270,7 @@ define([
: formatAmount(getCartSubtotal() * 100),
currency: currency
},
isExpress: true,
supportedNetworks: getSupportedNetworks(),
merchantCapabilities: ['supports3DS'],
requiredShippingContactFields: ['postalAddress', 'name', 'email', 'phone'],
Expand Down
22 changes: 22 additions & 0 deletions view/frontend/web/js/googlepay/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ define([
'Adyen_ExpressCheckout/js/helpers/setExpressMethods',
'Adyen_ExpressCheckout/js/helpers/validatePdpForm',
'Adyen_ExpressCheckout/js/helpers/getMaskedIdFromCart',
'Adyen_ExpressCheckout/js/helpers/manageQuoteIdOnPageRefresh',
'Adyen_ExpressCheckout/js/model/maskedId',
'Adyen_ExpressCheckout/js/model/config',
'Adyen_ExpressCheckout/js/model/countries',
Expand Down Expand Up @@ -74,6 +75,7 @@ define([
validatePdpForm,
getMaskedIdFromCart,
maskedIdModel,
manageQuoteIdOnPageRefresh,
configModel,
countriesModel,
totalsModel,
Expand Down Expand Up @@ -107,6 +109,7 @@ define([
configModel().setConfig(config);
countriesModel();

await manageQuoteIdOnPageRefresh();
this.isProductView = config.isProductView;

// If express methods is not set then set it.
Expand All @@ -133,6 +136,8 @@ define([

initializeOnPDP: async function (config, element) {
const response = await getExpressMethods().getRequest(element);

localStorage.setItem("quoteId", response.masked_quote_id);
const cart = customerData.get('cart');
virtualQuoteModel().setIsVirtual(true, response);

Expand Down Expand Up @@ -171,10 +176,26 @@ define([

initialiseGooglePayComponent: async function (googlePaymentMethod, element) {
const config = configModel().getConfig();
const adyenData = window.adyenData;

this.checkoutComponent = await new AdyenCheckout({
locale: config.locale,
clientKey: config.originkey,
environment: config.checkoutenv,
analytics: {
analyticsData: {
applicationInfo: {
merchantApplication: {
name: adyenData['merchant-application-name'],
version: adyenData['merchant-application-version']
},
externalPlatform: {
name: adyenData['external-platform-name'],
version: adyenData['external-platform-version']
}
}
}
},
paymentMethodsResponse: getPaymentMethod('googlepay', this.isProductView),
onAdditionalDetails: this.handleOnAdditionalDetails.bind(this),
risk: {
Expand Down Expand Up @@ -256,6 +277,7 @@ define([
format: 'FULL',
phoneNumberRequired: true
},
isExpress: true,
callbackIntents: !isVirtual ? ['SHIPPING_ADDRESS', 'SHIPPING_OPTION'] : ['OFFER'],
transactionInfo: {
totalPriceStatus: 'ESTIMATED',
Expand Down
12 changes: 12 additions & 0 deletions view/frontend/web/js/helpers/manageQuoteIdOnPageRefresh.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
define(function () {
'use strict';

return async function(){
const navigationEntries = performance.getEntriesByType('navigation');
const pageAccessedByReload = navigationEntries.length > 0 &&
navigationEntries[0].type === 'reload';
if(!pageAccessedByReload){
localStorage.removeItem("quoteId");
}
};
});
Loading