Skip to content

Commit

Permalink
Merge pull request #3 from klarna/feature/KLARNAPII-1757-SAP-Klarna-S…
Browse files Browse the repository at this point in the history
…ign-In-Web-SDK

SIWK (KLARNAPII-1757) and Configuration Updates (KLARNAPII-1844)
  • Loading branch information
marcosjgutierrez authored Oct 23, 2024
2 parents 718d204 + 959d7d0 commit 4474603
Show file tree
Hide file tree
Showing 98 changed files with 6,802 additions and 2,607 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# Learn more about .gitignore:
# https://www.atlassian.com/git/tutorials/saving-changes/gitignore

# B2B storefront extension
custom/yb2bacceleratorstorefront

# Generated files
Generated*.java

# Node artifact files
node_modules/
dist/
Expand Down
Binary file not shown.
185 changes: 185 additions & 0 deletions docs/KlarnaConfigMigrationScript.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import de.hybris.platform.acceleratorservices.config.SiteConfigService;
import de.hybris.platform.store.services.BaseStoreService;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.servicelayer.search.FlexibleSearchService;
import de.hybris.platform.servicelayer.exceptions.ModelNotFoundException;
import com.klarna.payment.constants.KlarnapaymentConstants;
import de.hybris.platform.store.BaseStoreModel;
import com.klarna.model.KlarnaConfigModel;
import com.klarna.model.KlarnaCredentialModel;
import com.klarna.model.KlarnaKECConfigModel;
import com.klarna.model.KlarnaKPConfigModel;
import com.klarna.model.KlarnaMarketCountryModel;
import com.klarna.model.KlarnaMarketRegionModel;
import com.klarna.osm.model.KlarnaKOSMConfigModel;
import com.klarna.osm.model.KlarnaOSMConfigModel;
import com.klarna.payment.model.KlarnaExpCheckoutConfigModel;
import com.klarna.payment.model.KlarnaPayConfigModel;
import com.klarna.payment.enums.KPEndpointMode;
import com.klarna.payment.enums.KlarnaEnv;
import com.klarna.payment.enums.KlarnaOSMPlacement;
import com.klarna.payment.enums.KlarnaKECPlacement;

// Base Store Id, Country Code and Region Code are mandatory parameters
String baseStoreId = "apparel-uk";
String marketCountryIsoCode = "GB";
String marketRegionCode = "EU";

BaseStoreService baseStoreService = spring.getBean("baseStoreService");
ModelService modelService = spring.getBean("modelService");
FlexibleSearchService flexibleSearchService = spring.getBean("flexibleSearchService");

println "Starting Klarna config migration..";
// Base Store Validation
if (StringUtils.isEmpty(baseStoreId))
{
return "Error! Please provide Base Store Id.";
}

BaseStoreModel baseStore = baseStoreService.getBaseStoreForUid(baseStoreId);
if (baseStore == null)
{
return "Error! No valid Base Store with Id: "+ baseStoreId;
}
println "Found Base Store with Id : "+baseStoreId;

// Country Validation
if (StringUtils.isEmpty(marketCountryIsoCode))
{
return "Error! Please provide Country ISO Code.";
}
KlarnaMarketCountryModel marketCountry = new KlarnaMarketCountryModel();
marketCountry.setIsoCode(marketCountryIsoCode);
try {
marketCountry = flexibleSearchService.getModelByExample(marketCountry);
}
catch(ModelNotFoundException e) {
return "Market Country doesnt't exist for the configured Country ISO Code: " + marketCountryIsoCode;
}
println "Market Country exists for ISO Code : "+marketCountryIsoCode;

// Check if valid market region is configured
if (StringUtils.isEmpty(marketRegionCode))
{
return "Error! Market Region not configured for the Base Store: " + baseStoreId;
}
KlarnaMarketRegionModel marketRegion = new KlarnaMarketRegionModel();
marketRegion.setCode(marketRegionCode);
try {
marketRegion = flexibleSearchService.getModelByExample(marketRegion);
}
catch(ModelNotFoundException e) {
return "Market Region doesnt't exist for the configured Region Code: " + marketRegionCode;
}
println "Market Region exists for Code : "+marketRegionCode;

// Create Klarna Common Configuration
KlarnaConfigModel klarnaConfigModel = modelService.create(KlarnaConfigModel._TYPECODE);
klarnaConfigModel.setCode("Klarna_Config_" + baseStoreId);
klarnaConfigModel.setActive(true);
klarnaConfigModel.setBaseStores(new ArrayList<BaseStoreModel>(Arrays.asList(baseStore)));

// Create Credential configuration
KlarnaCredentialModel klarnaCredentialModel = modelService.create(KlarnaCredentialModel._TYPECODE);
klarnaCredentialModel.setCode("Klarna_Credential_"+baseStoreId+"_"+marketRegionCode);
klarnaCredentialModel.setMarketRegion(marketRegion);
klarnaCredentialModel.setMarketCountries(new ArrayList<KlarnaMarketCountryModel>(Arrays.asList(marketCountry)));

KlarnaPayConfigModel klarnaPayConfigOld = baseStore.getKlarnaPayConfig();
KlarnaKPConfigModel klarnaKPConfigModel = null;
if (klarnaPayConfigOld == null)
{
println "Klarna Payment Configuration doesn't exist for Base Store: " + baseStoreId;
}
else
{
// Create Klarna Payment Configuration
klarnaKPConfigModel = modelService.create(KlarnaKPConfigModel._TYPECODE);
klarnaKPConfigModel.setCode("Klarna_Payment_Config_"+baseStoreId);
klarnaKPConfigModel.setActive(klarnaPayConfigOld.getActive());
klarnaKPConfigModel.setAutoCapture(klarnaPayConfigOld.getAutoCapture());
klarnaKPConfigModel.setMerchantEmail(klarnaPayConfigOld.getMerchantEmail());
klarnaKPConfigModel.setMerchantReference2(klarnaPayConfigOld.getMerchantReference2());
klarnaKPConfigModel.setSendEMD(klarnaPayConfigOld.getAttachementRequired());
modelService.save(klarnaKPConfigModel);
println "Created new Klarna Payment Configuration with Code: " + klarnaKPConfigModel.getCode();
klarnaConfigModel.setKpConfig(klarnaKPConfigModel);
if(KPEndpointMode.LIVE.equals(klarnaPayConfigOld.getEndpointMode())) {
klarnaConfigModel.setEnvironment(KlarnaEnv.PRODUCTION);
}
else {
klarnaConfigModel.setEnvironment(KlarnaEnv.PLAYGROUND);
}
klarnaCredentialModel.setApiUserName(klarnaPayConfigOld.getMerchantID());
klarnaCredentialModel.setApiPassword(klarnaPayConfigOld.getSharedSecret());
klarnaCredentialModel.setVcnEnabled(klarnaPayConfigOld.getIsVCNEnabled());
klarnaCredentialModel.setVcnKey(klarnaPayConfigOld.getVcnKeyID());
}

KlarnaOSMConfigModel klarnaOSMConfigModelOld = baseStore.getKlarnaOsmConfig();
KlarnaKOSMConfigModel klarnaKOSMConfigModel = null;
if (klarnaOSMConfigModelOld == null)
{
println "Klarna OSM Configuration doesn't exist for Base Store: " + baseStoreId;
}
else
{
// Create Klarna OSM Configuration
klarnaKOSMConfigModel = modelService.create(KlarnaKOSMConfigModel._TYPECODE);
klarnaKOSMConfigModel.setCode("Klarna_OSM_Config_"+baseStoreId);
List<KlarnaOSMPlacement> osmPlacements = new ArrayList<KlarnaOSMPlacement>();
if(Boolean.TRUE.equals(klarnaOSMConfigModelOld.getCartEnabled())) {
osmPlacements.add(KlarnaOSMPlacement.CART_PAGE);
klarnaKOSMConfigModel.setActive(Boolean.TRUE);
klarnaKOSMConfigModel.setTheme(klarnaOSMConfigModelOld.getCartTheme());
}
if(Boolean.TRUE.equals(klarnaOSMConfigModelOld.getPdpEnabled())) {
osmPlacements.add(KlarnaOSMPlacement.PRODUCT_DETAILS_PAGE);
klarnaKOSMConfigModel.setActive(Boolean.TRUE);
klarnaKOSMConfigModel.setTheme(klarnaOSMConfigModelOld.getPdpTheme());
}
klarnaKOSMConfigModel.setPlacements(osmPlacements);
klarnaKOSMConfigModel.setCustomStyle(klarnaOSMConfigModelOld.getCustomStyle());
modelService.save(klarnaKOSMConfigModel);
println "Created new Klarna OSM Configuration with Code: " + klarnaKOSMConfigModel.getCode();
klarnaConfigModel.setOsmConfig(klarnaKOSMConfigModel);
klarnaCredentialModel.setClientId(klarnaOSMConfigModelOld.getUci());
}

KlarnaExpCheckoutConfigModel klarnaExpCheckoutConfigModelOld = baseStore.getKlarnaExpCheckoutConfig();
KlarnaKECConfigModel klarnaKECConfigModel = null;
if (klarnaExpCheckoutConfigModelOld == null)
{
println "Klarna Express Checkout Configuration doesn't exist for Base Store: " + baseStoreId;
}
else
{
// Create Klarna OSM Configuration
klarnaKECConfigModel = modelService.create(KlarnaKECConfigModel._TYPECODE);
klarnaKECConfigModel.setCode("Klarna_KEC_Config_"+baseStoreId);
klarnaKECConfigModel.setActive(klarnaExpCheckoutConfigModelOld.getActive());
klarnaKECConfigModel.setButtonShape(klarnaExpCheckoutConfigModelOld.getButtonShape());
klarnaKECConfigModel.setButtonTheme(klarnaExpCheckoutConfigModelOld.getButtonTheme());
List<KlarnaKECPlacement> kecPlacements = new ArrayList<KlarnaKECPlacement>();
kecPlacements.add(KlarnaKECPlacement.CART_PAGE);
kecPlacements.add(KlarnaKECPlacement.PRODUCT_DETAILS_PAGE);
kecPlacements.add(KlarnaKECPlacement.MINI_CART_POPUP);
klarnaKECConfigModel.setPlacements(kecPlacements);
modelService.save(klarnaKECConfigModel);
println "Created new KEC Configuration with Code: " + klarnaKECConfigModel.getCode();
klarnaConfigModel.setKecConfig(klarnaKECConfigModel);
if(klarnaCredentialModel.getClientId() == null) {
klarnaCredentialModel.setClientId(klarnaExpCheckoutConfigModelOld.getClientKey());
}
}

modelService.save(klarnaCredentialModel);
println "Created new credential with Code: " + klarnaCredentialModel.getCode();

klarnaConfigModel.setCredentials(new ArrayList<KlarnaCredentialModel>(Arrays.asList(klarnaCredentialModel)));
modelService.save(klarnaConfigModel);
println "Created new Klarna configuration with Code: " + klarnaConfigModel.getCode();
return "Success";

23 changes: 22 additions & 1 deletion hybris/config/local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,28 @@ mail.use.tls=true

klarnacheckout.merchant.url.confirmation.apparel-de=https://klarnawin-apparel-de.tryzens-analytics.com/klarna/order/confirmation
klarnacheckout.merchant.url.notification.apparel-de=https://klarnawin-apparel-de.tryzens-analytics.com/klarna/payment/checkout/pending-update
klarnacheckout.merchant.url.authorization.apparel-de=https://klarnawin-apparel-de.tryzens-analytics.com/klarna/payment/auth-callback

klarnacheckout.merchant.url.confirmation.apparel-uk=https://klarnawin-apparel-uk.tryzens-analytics.com/klarna/order/confirmation
klarnacheckout.merchant.url.notification.apparel-uk=https://klarnawin-apparel-uk.tryzens-analytics.com/klarna/payment/checkout/pending-update
klarnacheckout.merchant.url.authorization.apparel-uk=https://klarnawin-apparel-uk.tryzens-analytics.com/klarna/payment/auth-callback

klarnacheckout.merchant.url.confirmation.electronics=https://klarnawin-electronics.tryzens-analytics.com/electronics/en/klarna/order/confirmation
klarnacheckout.merchant.url.notification.electronics=https://klarnawin-electronics.tryzens-analytics.com/electronics/en/klarna/payment/checkout/pending-update
klarnacheckout.merchant.url.authorization.electronics=https://klarnawin-electronics.tryzens-analytics.com/electronics/en/klarna/payment/auth-callback


klarnacheckout.merchant.url.confirmation.apparel-mx=https://klarnawin-apparel-mx.tryzens-analytics.com/es/klarna/order/confirmation
klarnacheckout.merchant.url.notification.apparel-mx=https://klarnawin-apparel-mx.tryzens-analytics.com/es/klarna/payment/checkout/pending-update
klarnacheckout.merchant.url.authorization.apparel-mx=https://klarnawin-apparel-mx.tryzens-analytics.com/es/klarna/payment/auth-callback

klarnacheckout.merchant.url.confirmation.apparel-rom=https://klarnawin-apparel-rom.tryzens-analytics.com/en/klarna/order/confirmation
klarnacheckout.merchant.url.notification.apparel-rom=https://klarnawin-apparel-rom.tryzens-analytics.com/en/klarna/payment/checkout/pending-update
klarnacheckout.merchant.url.authorization.apparel-rom=https://klarnawin-apparel-rom.tryzens-analytics.com/en/klarna/payment/auth-callback

klarnacheckout.merchant.url.confirmation.apparel-swe=https://klarnawin-apparel-swe.tryzens-analytics.com/en/klarna/order/confirmation
klarnacheckout.merchant.url.notification.apparel-swe=https://klarnawin-apparel-swe.tryzens-analytics.com/en/klarna/payment/checkout/pending-update
klarnacheckout.merchant.url.authorization.apparel-swe=https://klarnawin-apparel-swe.tryzens-analytics.com/en/klarna/payment/auth-callback

klarnacheckout.merchant.url.confirmation.powertools=https://powertools.local:9002/yb2bacceleratorstorefront/powertools/en/SEK/klarna/order/confirmation
klarnacheckout.merchant.url.notification.powertools=https://powertools.local:9002/yb2bacceleratorstorefront/powertools/en/SEK/klarna/payment/checkout/pending-update
Expand All @@ -64,4 +71,18 @@ klarnacheckout.merchant.url.confirmation.powertools-swe=https://klarnawin-powert
klarnacheckout.merchant.url.notification.powertools-swe=https://klarnawin-powertools-swe.tryzens-analytics.com/yb2bacceleratorstorefront/en/klarna/payment/checkout/pending-update


tomcat.ssl.port=443
tomcat.ssl.port=443


klarna.market.country.apparel-uk=GB
klarna.market.region.apparel-uk=EU

klarna.market.country.apparel-de=DE
klarna.market.region.apparel-de=EU

klarna.market.country.apparel-mx=MX
klarna.market.region.apparel-mx=NA

klarna.market.country.electronics=US
klarna.market.region.electronics=NA

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ private KlarnaosmaddonWebConstants()
{
//empty to avoid instantiating this constant class
}

// implement here constants used by this extension
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package com.klarna.osm.interceptor;

import de.hybris.platform.addonsupport.interceptors.BeforeViewHandlerAdaptee;
import de.hybris.platform.servicelayer.config.ConfigurationService;
import de.hybris.platform.servicelayer.i18n.I18NService;

import javax.annotation.Resource;
Expand All @@ -11,62 +12,53 @@
import org.apache.log4j.Logger;
import org.springframework.ui.ModelMap;

import com.klarna.data.KlarnaOSMConfigData;
import com.klarna.osm.facade.KlarnaOSMConfigFacade;
import com.klarna.data.KlarnaConfigData;
import com.klarna.data.KlarnaKOSMConfigData;
import com.klarna.payment.constants.KlarnapaymentConstants;
import com.klarna.payment.facades.KlarnaConfigFacade;


public class KlarnaOSMUiThemeResourceBeforeViewHandlerAdaptee implements BeforeViewHandlerAdaptee
{
private static final Logger LOG = Logger.getLogger(KlarnaOSMUiThemeResourceBeforeViewHandlerAdaptee.class);

KlarnaOSMConfigFacade klarnaOSMConfigFacade;
@Resource(name = "klarnaConfigFacade")
KlarnaConfigFacade klarnaConfigFacade;

@Resource(name = "i18NService")
private I18NService i18NService;

/**
* @return the klarnaOSMConfigFacade
*/
public KlarnaOSMConfigFacade getKlarnaOSMConfigFacade()
{
return klarnaOSMConfigFacade;
}

/**
* @param klarnaOSMConfigFacade
* the klarnaOSMConfigFacade to set
*/
public void setKlarnaOSMConfigFacade(final KlarnaOSMConfigFacade klarnaOSMConfigFacade)
{
this.klarnaOSMConfigFacade = klarnaOSMConfigFacade;
}
@Resource(name = "configurationService")
private ConfigurationService configurationService;

@Override
public String beforeView(final HttpServletRequest request, final HttpServletResponse response, final ModelMap model,
final String viewName)
{

if (LOG.isDebugEnabled())
{
LOG.debug("intercepting KlarnaUiThemeResourceBeforeViewHandlerAdaptee ...");
}
final KlarnaOSMConfigData configData = klarnaOSMConfigFacade.getKlarnaConfig();
if (configData != null)
{
model.addAttribute("isPdpEnabled", configData.getPdpEnabled());
model.addAttribute("isCartEnabled", configData.getCartEnabled());
model.addAttribute("isDataInlineEnabled", configData.getDataInlineEnabled());
model.addAttribute("scriptUrl", configData.getScriptUrl());
model.addAttribute("cartPlacementTagId", configData.getCartPlacementTagID());
model.addAttribute("productPlacementTagId", configData.getProductPlacementTagID());
model.addAttribute("osmCountry", configData.getCountry());
model.addAttribute("uci", configData.getUci());
model.addAttribute("locale", i18NService.getCurrentLocale());
model.addAttribute("cartTheme", configData.getCartTheme());
model.addAttribute("pdpTheme", configData.getPdpTheme());
model.addAttribute("customStyle", configData.getCustomStyle());
final KlarnaConfigData configData = klarnaConfigFacade.getKlarnaConfig();

if (configData != null && configData.getCredential() != null)
{
final KlarnaKOSMConfigData osmConfigData = configData.getOsmConfig();
if (osmConfigData != null)
{
model.addAttribute("scriptUrlKOSM",
configurationService.getConfiguration().getString(KlarnapaymentConstants.KLARNA_OSM_SCRIPTURL));
//model.addAttribute("cartPlacementTagId", configData.getCartPlacementTagID());
//model.addAttribute("productPlacementTagId", configData.getProductPlacementTagID());
model.addAttribute("osmConfigData", osmConfigData);
model.addAttribute("osmCountry", configData.getCredential().getMarketCountry()); //klarnaConfig.getCredential().getMarketCountry()
// when KlarnaConfigData is not null credential will also not be null
model.addAttribute("uci", configData.getCredential().getClientId());
model.addAttribute("locale", i18NService.getCurrentLocale());
model.addAttribute("osmTheme", osmConfigData.getTheme());
model.addAttribute("customStyleOSM", osmConfigData.getCustomStyle());
}
}

return viewName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@

<%@ attribute name="price" required="true" type="java.lang.Double" %>

<c:set var="datainline" value="false"/>
<c:if test="${isDataInlineEnabled}">
<c:set var="datainline" value="true"/>
</c:if>

<c:if test="${isCartEnabled}">
<c:if test="${osmConfigData.showInCartPage == true}">
<br>
<div class="kosm_prod">
<fmt:formatNumber var="priceValue" type="number" groupingUsed="false" maxFractionDigits="0" value="${price*100}" />
<klarna-placement id="osm-cart-strip" data-key="${cartPlacementTagId}" data-locale="${locale}-${osmCountry}" data-purchase-amount="${priceValue}" data-theme="${cartTheme}" ></klarna-placement>
<klarna-placement id="osm-cart-strip" data-key="credit-promotion-auto-size" data-locale="${locale}-${osmCountry}" data-purchase-amount="${priceValue}" data-theme="${osmTheme}" ></klarna-placement>
<div class="customStyle">
${customStyle}
${customStyleOSM}
</div>
</div>
</c:if>
Loading

0 comments on commit 4474603

Please sign in to comment.