Skip to content

Commit 4acb77a

Browse files
Merge pull request #25 from klarna/release-26.1.0
Release 26.1.0
2 parents dea0cfa + de8516f commit 4acb77a

54 files changed

Lines changed: 2253 additions & 155 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# CHANGELOG
22

3+
## 26.1.0
4+
* Upgraded Onsite Messaging (OSM) to use Klarna Web SDK version 2.
5+
* Added Klarna Express Checkout (KEC) one-step payments for direct merchants.
6+
* Added metadata (integrator and originator) in every request sent to Klarna both in Web SDK initialization and also in API calls.
7+
* Updated interoperability data storage to use a custom object instead of session storage.
8+
* Enhanced OSM installment messaging to dynamically refresh on the checkout page when the purchase amount changes.
9+
310
## 25.5.0
411
* When Klarna payments are integrated through a PSP, the interoperability_data is required by the PSP for payment processing and order finalization. As part of this release, we have added interoperability_data to the session. This data includes the order amount and the order lines for which the payment was initiated. The PSP will be able to retrieve this information from the session for further processing.
512

cartridges/int_klarna_payments/cartridge/scripts/common/klarnaPaymentsHttpService.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ KlarnaPaymentsHttpService.prototype.call = function( serviceID, urlPath, httpVer
8484
service.addHeader( 'Accept', 'application/json' );
8585
service.addHeader( 'User-Agent', SERVICE_HEADER );
8686

87+
// Add X-Klarna-Integration-Metadata header
88+
var KlarnaConstants = require( '*/cartridge/scripts/util/klarnaPaymentsConstants' );
89+
if ( KlarnaConstants.integrator && KlarnaConstants.originators ) {
90+
var integrationMetadata = {
91+
integrator: KlarnaConstants.integrator,
92+
originators: KlarnaConstants.originators
93+
};
94+
service.addHeader( 'X-Klarna-Integration-Metadata', JSON.stringify( integrationMetadata ) );
95+
}
96+
8797
if ( !empty( klarnaIdempotencyKey ) && klarnaIdempotencyKey !== 'undefined' ) {
8898
service.addHeader( 'Klarna-Idempotency-Key', klarnaIdempotencyKey );
8999
}

cartridges/int_klarna_payments/cartridge/scripts/common/klarnaSignInHttpService.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ KlarnaSignInsHttpService.prototype.call = function( serviceID, urlPath, httpVerb
7070
service.addHeader( 'Content-Type', contentType ? contentType : 'application/json' );
7171
service.addHeader( 'Accept', 'application/json' );
7272
service.addHeader( 'User-Agent', SERVICE_HEADER );
73+
74+
// Add X-Klarna-Integration-Metadata header
75+
var KlarnaConstants = require( '*/cartridge/scripts/util/klarnaPaymentsConstants' );
76+
if ( KlarnaConstants.integrator && KlarnaConstants.originators ) {
77+
var integrationMetadata = {
78+
integrator: KlarnaConstants.integrator,
79+
originators: KlarnaConstants.originators
80+
};
81+
service.addHeader( 'X-Klarna-Integration-Metadata', JSON.stringify( integrationMetadata ) );
82+
}
7383
if ( !empty( httpVerb ) && this.isValidHttpVerb( httpVerb ) ) {
7484
service.setRequestMethod( httpVerb );
7585
}

cartridges/int_klarna_payments/cartridge/scripts/common/klarnaWebhookHttpService.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ KlarnaWebhookHttpService.prototype.call = function( serviceId, urlPath, httpVerb
5858
service.addHeader( 'Accept', 'application/json' );
5959
service.addHeader( 'User-Agent', SERVICE_HEADER );
6060

61+
// Add X-Klarna-Integration-Metadata header
62+
var KlarnaConstants = require( '*/cartridge/scripts/util/klarnaPaymentsConstants' );
63+
if ( KlarnaConstants.integrator && KlarnaConstants.originators ) {
64+
var integrationMetadata = {
65+
integrator: KlarnaConstants.integrator,
66+
originators: KlarnaConstants.originators
67+
};
68+
service.addHeader( 'X-Klarna-Integration-Metadata', JSON.stringify( integrationMetadata ) );
69+
}
70+
6171
if ( !empty( httpVerb ) && this.isValidHttpVerb( httpVerb ) ) {
6272
service.setRequestMethod( httpVerb );
6373
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
'use strict';
2+
3+
/**
4+
* Script to cleanup expired Klarna interoperability data from custom objects
5+
* This job should run daily to remove records older than 24 hours
6+
*/
7+
8+
var Status = require('dw/system/Status');
9+
var Logger = require('dw/system/Logger');
10+
11+
/**
12+
* Function called by job to clean up expired interoperability data
13+
* @param {Object} parameters Job parameters
14+
* @return {dw.system.Status} execution status
15+
*/
16+
exports.execute = function (parameters) {
17+
try {
18+
var siteID = dw.system.Site.getCurrent().getID();
19+
var KlarnaInteroperabilityDataManager = require('*/cartridge/scripts/common/klarnaInteroperabilityDataManager');
20+
21+
Logger.info('[' + siteID + '] Starting cleanup of expired Klarna interoperability data');
22+
23+
var count = KlarnaInteroperabilityDataManager.cleanupExpiredData();
24+
25+
if (count > 0) {
26+
Logger.info('[' + siteID + '] Successfully cleaned up ' + count + ' expired interoperability data records');
27+
} else {
28+
Logger.debug('[' + siteID + '] No expired interoperability data records found');
29+
}
30+
31+
return new Status(Status.OK);
32+
} catch (e) {
33+
Logger.error('Error cleaning up Klarna interoperability data: {0}', e.message + e.stack);
34+
return new Status(Status.ERROR);
35+
}
36+
};

cartridges/int_klarna_payments/cartridge/scripts/klarnaPaymentsCancelAuthorization.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function execute( args )
4040
function cancelAuthorization( klarnaAuthorizationToken, localeObject ) {
4141
if ( klarnaAuthorizationToken ) {
4242
var StringUtils = require( 'dw/util/StringUtils' );
43+
var Logger = require('dw/system/Logger');
4344
var klarnaPaymentsHttpService = new KlarnaPayments.httpService();
4445
var klarnaApiContext = new KlarnaPayments.apiContext();
4546
var requestUrl = StringUtils.format( klarnaApiContext.getFlowApiUrls().get( 'cancelAuthorization' ), klarnaAuthorizationToken );
@@ -50,7 +51,7 @@ function cancelAuthorization( klarnaAuthorizationToken, localeObject ) {
5051
session.privacy.KlarnaPaymentsFinalizeRequired = null;
5152
return response;
5253
} catch ( e ) {
53-
logger.error( 'Error in canceling Klarna Payments Authorization: {0}', e.message + e.stack );
54+
Logger.error( 'Error in canceling Klarna Payments Authorization: {0}', e.message + e.stack );
5455
}
5556
}
5657
return null;

cartridges/int_klarna_payments/cartridge/scripts/marketing/klarnaOSM.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,14 @@ var KlarnaOSM = {
291291
return !empty( currentSite.getCustomPreferenceValue( 'kec_enable' ) ) ? ( this.isKlarnaEnabled() && currentSite.getCustomPreferenceValue( 'kec_enable' ) ) :
292292
( currentSite.getCustomPreferenceValue( 'kpECEnabled' ) || false );
293293
},
294-
isKECSingleStepEnabled: function() {
295-
return ( this.isKlarnaEnabled() && currentSite.getCustomPreferenceValue( 'kec_enable' ) && currentSite.getCustomPreferenceValue( 'kpIntegrationViaPSP' ) ) || false;
294+
isKECSingleStepWithPSPIntegration: function() {
295+
var isPSPIntegrated = currentSite.getCustomPreferenceValue( 'kpIntegrationViaPSP' );
296+
return ( this.isKlarnaEnabled() && currentSite.getCustomPreferenceValue( 'kec_enable' ) && isPSPIntegrated ) || false;
297+
},
298+
isKECSingleStepForDirectMerchant: function() {
299+
var isPSPIntegrated = currentSite.getCustomPreferenceValue( 'kpIntegrationViaPSP' );
300+
var isSingleStepMode = currentSite.getCustomPreferenceValue( 'kec_useOneStepCheckout' );
301+
return ( this.isKlarnaEnabled() && currentSite.getCustomPreferenceValue( 'kec_enable' ) && isSingleStepMode && !isPSPIntegrated ) || false;
296302
},
297303
showExpressCheckoutButton: function() {
298304
var showECButton = currentSite.getCustomPreferenceValue( 'kec_placement' );
@@ -415,6 +421,20 @@ var KlarnaOSM = {
415421
} );
416422
}
417423
return showSignInButtonObj;
424+
},
425+
getKlarnaClientIDForSDK : function() {
426+
var osmClientId = this.isEnabled() ? this.getUCI() : null;
427+
var expressCheckoutClientId = this.isKlarnExpressCheckoutEnabled() && ( this.isKECSingleStepWithPSPIntegration() || this.isKECSingleStepForDirectMerchant() ) ? this.getKlarnExpressCheckoutClientKey() : null;
428+
var signInClientId = this.isKlarnaSignInEnabled() ? this.getKlarnaSignInClientId() : null;
429+
var clientId = {};
430+
if ( osmClientId === expressCheckoutClientId && osmClientId === signInClientId) {
431+
clientId.clientId = osmClientId;
432+
} else {
433+
clientId.osmClientId = osmClientId;
434+
clientId.expressCheckoutClientId = expressCheckoutClientId;
435+
clientId.signInClientId = signInClientId;
436+
}
437+
return clientId;
418438
}
419439
};
420440

cartridges/int_klarna_payments/cartridge/scripts/payments/model/request/singleStepKec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
function singleStepKECModel() {
99
this.amount = '';
1010
this.currency = '';
11+
this.shipping_config = {};
12+
this.collect_customer_profile = [];
1113
this.customer_interaction_config = {};
1214
this.supplementary_purchase_data = {};
1315
}

cartridges/int_klarna_payments/cartridge/scripts/payments/requestBuilder/singleStepKec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,30 @@
267267
return this;
268268
};
269269

270+
KlarnaSingleStepCheckoutRequestBuilder.prototype.buildShippingConfigs = function() {
271+
var localeObject = this.getLocaleObject();
272+
var supportedCountries = [];
273+
274+
if ( !empty( localeObject ) && !empty( localeObject.country ) ) {
275+
supportedCountries.push( localeObject.country );
276+
}
277+
278+
this.context.shipping_config = {
279+
mode: "EDITABLE",
280+
supported_countries: supportedCountries
281+
};
282+
return this;
283+
};
284+
285+
KlarnaSingleStepCheckoutRequestBuilder.prototype.collectCustomerProfile = function( basket ) {
286+
this.context.collect_customer_profile = [
287+
"profile:email",
288+
"profile:phone",
289+
"profile:billing_address"
290+
];
291+
return this;
292+
};
293+
270294
KlarnaSingleStepCheckoutRequestBuilder.prototype.build = function() {
271295
var basket = this.params.basket;
272296
var kpAttachmentsPreferenceValue = Site.getCurrent().getCustomPreferenceValue( 'kpEMD' ) || null;
@@ -282,6 +306,8 @@
282306
this.buildOrderLines( basket );
283307
this.buildTotalAmount( basket );
284308
this.buildReturnUrl( basket );
309+
this.buildShippingConfigs();
310+
this.collectCustomerProfile();
285311

286312
// Validate the built data using the context and line items
287313
this.validateBuildAmounts( basket );

cartridges/int_klarna_payments/cartridge/scripts/util/klarnaHelper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ function mapKlarnaExpressAddress( collectedAddress ) {
520520
addressData.address1 = collectedAddress.street_address || '';
521521
addressData.address2 = collectedAddress.street_address_2 || '';
522522
addressData.city = collectedAddress.city || '';
523-
addressData.postalCode = collectedAddress.postal_code || '';
523+
addressData.postalCode = collectedAddress.postal_code || collectedAddress.postalCode || '';
524524
addressData.stateCode = collectedAddress.region || '';
525525
addressData.countryCode = { value: collectedAddress.country || '' };
526526
addressData.phone = collectedAddress.phone || '';

0 commit comments

Comments
 (0)