Last updated

KCO iOS migration guide


This document provides a guide for migrating to the new Klarna Checkout (KCO) iOS implementation, which is now integrated into the Klarna Mobile SDK.

Getting started

Klarna Checkout SDK was previously a standalone library, but is now part of the Klarna Mobile SDK.

The new KCO can be integrated in mobile projects in the following ways:

IntegrationOld ImplementationNew Implementation
Cocoapodspod 'KlarnaCheckoutSDK'pod 'KlarnaMobileSDK'
Swift Package Managerhttps://github.com/klarna/kco-mobile-sdkhttps://github.com/klarna/klarna-mobile-sdk-spm
Carthagebinary "https://raw.githubusercontent.com/klarna/kco-mobile-sdk/master/KlarnaCheckoutSDK.json"binary "https://raw.githubusercontent.com/klarna/klarna-mobile-sdk/master/KlarnaMobileSDK.json"

SDK Initialization Steps

Previously, initialization used the KCOKlarnaCheckout class. Now, use KlarnaCheckoutView.

Objective-C (Previous)

// Previous implementation
self.checkout = [[KCOKlarnaCheckout alloc] initWithViewController:self redirectURI:<YOUR-URL>];
checkout.snippet = @"\<div id='klarna-checkout-container'\>...\</script\>\<div\>";

Swift (New)

// New implementation
self.checkout = KlarnaCheckoutView(returnURL: <YOUR-URL>, eventHandler: <YOUR-KlarnaEventHandler>)
checkout.setSnippet("\<div id='klarna-checkout-container'\>...\</script\>\<div\>")

Full Screen Mode (Not available)

The fullscreen mode is no longer supported. Use the embedded mode instead.

Embedded Mode

Using a checkout view

Use KlarnaCheckoutView to embed the KCO view in your native checkout flow.

Swift (New)

// New implementation
self.checkout = KlarnaCheckoutView(returnURL: <YOUR-URL>, eventHandler: <YOUR-KlarnaEventHandler>)
checkout.setSnippet(<YOUR-SNIPPET>)
<YOUR-SUPERVIEW>.addSubview(checkout)

IMPORTANT WHEN EMBEDDING

You must now manage scrolling and view resizing yourself.

Objective-C (Previous)

// Previous implementation
viewController.internalScrollDisabled = YES;
viewController.sizingDelegate = self;
viewController.parentScrollView = self.scrollView;

Swift (New) - Resizing

// New implementation
func klarnaComponent(_ klarnaComponent: KlarnaComponent, resizedToHeight height: CGFloat) {
	// Handle the new height value to resize the native view
}

Event listeners

The new KCO implementation uses an eventHandler instead of notifications.

Objective-C (Previous)

// Previous implementation
- (void)handleNotification:(NSNotification *)notification { ... }

Swift (New)

// New implementation
func klarnaComponent(_ klarnaComponent: KlarnaComponent, dispatchedEvent event: KlarnaProductEvent) { ... }

func klarnaComponent(_ klarnaComponent: KlarnaComponent, encounteredError error: KlarnaError) { ... }

Suspend and resume

The suspend/resume methods remain mostly the same.

Swift (New)

// New implementation
self.checkout.suspend()
self.checkout.resume()

Handling External Payment Methods & Handling Validation Errors

Use the checkoutOptions property.

Swift (New)

// New implementation
self.checkout.checkoutOptions.merchantHandlesEPM = true
self.checkout.checkoutOptions.merchantHandlesValidationErrors = true