Skip to content

klarna/klarna-mobile-sdk-flutter

Repository files navigation

Klarna Mobile SDK Flutter Plugin

Klarna's Flutter wrapper for the Klarna Mobile SDK

Build Status License Developed at Klarna

Looking for the native Klarna Mobile SDK? Check out the Klarna Mobile SDK repo instead.

Looking for the React-Native Klarna Mobile SDK? Check out the React Native Klarna Mobile SDK repo instead.

Integration

Requirements

  • iOS 9 or later.
  • Android 4.4 or later.

Supported Products

  • ✅ Klarna Post Purchase
  • ❌ Klarna Payments
  • ❌ Klarna Checkout

Post Purchase

As of now, credentials needed for Post Purchase is only available through Klarna Delivery Managers. If you want to test this integration, please contact your Delivery Manager to get required information regarding Post Purchase.

Klarna Mobile SDK Documentation

Overview of the SDK

Flutter Dependency

Add klarna_mobile_sdk_flutter as a dependency in your pubspec.yaml file according to the official documentation.

Usage

KlarnaPostPurchaseSDK

Construct
Parameters
Name Type Description
eventListener KlarnaPostPurchaseEventListener An interface implementation for PostPurchaseSDK event and error callbacks.
returnUrl String An app-defined URL scheme the component uses to return customers to your app.
environment named optional KlarnaEnvironment? Environment for Post Purchase SDK.
region named optional KlarnaRegion? Region for Post Purchase SDK.
resourceEndpoint named optional KlarnaResourceEndpoint? Resource cloud endpoint for Post Purchase SDK.
initialize()

Initializes new WebView and javascript Klarna Post Purchase Experience library.

Parameters
Name Type Description
locale String A string representing the user locale. For example: se-SE
purchaseCountry String A string representing the purchase country. For example: SE
design named optional String? A string representing the design ID.
authorizationRequest()

Called to kick off the oauth flow.

Parameters
Name Type Description
clientId String The client_id for your application.
scope String A space-delimited list of scopes that identify the resources that your application could access on the user's behalf. These values define the consent screen that Klarna displays to the user.
redirectUri String The “location” where the OAuth server redirects the user after the user completes the authorization flow. The value must exactly match one of the redirect_url values provided to Klarna in advance.
locale named optional String? A string representing the user locale.
state named optional String? A string value that your application uses to maintain state between your authorization request and the authorization server's response. The Authorization server returns the exact value that you send to the redirect_url as a URL parameter.
loginHint named optional String? If your application knows which user is trying to authenticate, it can use this parameter to provide a hint to the Klarna’s Authorization Server. The server uses the hint to simplify the login flow by prefilling the email field in the sign-in form. It’s recommended to use this as it will improve the customer experience.
responseType named optional String? The desired grant type. The value MUST be one of "code" for requesting an authorization code or "token" for requesting an access token (implicit grant). The default is "code"
renderOperation()

Load the Klarna widget for the operation.

Parameters
Name Type Description
operationToken String The operation token for the related order returned from the post purchase api.
locale named optional String? A string representing the user locale.
redirectUri named optional String The “location” where the OAuth server redirects the user after the user completes the authorization flow. The value must exactly match one of the redirect_url values provided to Klarna in advance.
destroy()

Destroys any object, including WebView attached to the client.

Development

Getting Started

After cloning the repository run the command below to setup the project.

flutter packages get

Flutter

  1. Open root directory from Android Studio or your preferred Dart supported IDE.

Plugin implementation will be located at lib and example app implementation will be located at example/lib directories.

Android

  1. Open example/android directory from Android Studio.

Plugin implementation will be located at klarna_mobile_sdk_flutter/java/com.klarna.mobile.sdk.flutter/.

iOS

  1. Execute pod install in example/ios
  2. Open the example/ios/Runner.xcworkspace file from XCode.

Plugin implementation will be located at Pods/Development Pods/klarna_mobile_sdk_flutter/../../example/ios/.symlinks/plugins/klarna_mobile_sdk_flutter/ios/Classes inside XCode.

Build Example App

  • Execute flutter build apk in example directory to build Android example app.
  • Execute flutter build ios --no-codesign in example directory to build iOS example app.

Support

If you are having any issues using the SDK in your project or if you think that something is wrong with the SDK itself, please create an issue on Github or report a bug by following the guidelines in the next section.

How can I contribute?

Thank you for reading this and taking the time to contribute to Klarna Mobile SDK! Below is a set of guidelines to help you contribute whether you want to report a bug, come with suggestions or modify code�.

Reporting Bugs

This section will guide you through submitting a bug report for Klarna Mobile SDK.

Before submitting a bug report, please check that the issue hasn't been reported before. If you find a Closed issue that seems to describe an issue that is similar to what you want to report, open a new issue and link to the original issue in the new one. When you have checked that the issue hasn't been reported before, please fill out the required template which will help us resolve the issue faster.

Submitting a Bug Report

Submitted bugs are tracked as GitHub issues. To report a bug, create an issue and use the template to provide information about the bug. Explain the problem thoroughly and include any additional information that you think might help the maintainers reproduce the issue. When creating the GitHub issue please make sure that you:

  • Use a clear and descriptive title for the issue.
  • Describe the exact steps which reproduce the problem with as many details as possible. It's generally better to provide too much than too little information.
  • Describe the behavior you observed after following the steps and explain precisely what the problem is with that behavior.
  • Explain which behavior you expected instead and why.
  • Provide screenshots and/or screen recordings that might help explain the issue you are facing. To screen record a phone connected to Android Studio or an emulator, follow the steps here. To screen record on iOS, follow the steps described here.
  • Include relevant logs in the bug report by putting it in a code block, a file attachment or in a gist and provide a link to that gist.
  • Tell how recently you started having the issue. When was the first time you experienced the issue and was it after updating the SDK version? Or has it always been a problem?
  • If the problem started happening recently, can you reproduce it in an older version of the SDK? What's the most recent version in which the problem doesn't happen?
  • Can you reliably reproduce the issue? If not, explain how often it occurs and under what conditions it usually happens. For example, in what environment you are running.

Include details about the device/emulator/simulator you are experiencing the issue on:

  • Which version of the SDK are you using?
  • Which OS is this a problem in, iOS, Android or both? What version(s)? Also, add the appropriate label to the issue.
  • Did you experience the issue in simulator/emulator or on real device(s)?

Contribution

Before contributing, please read through the Klarna Mobile SDK documentation.

Branching

Prefix the branch you are going to work on depending on what you are working on (bug fix or feature). Use the following prefixes when creating a new branch:

  • feature/ if the branch contains a new feature, for example: feature/my-shiny-feature.
  • bugfix/ if the branch contains a bug fix, for example: bugfix/my-bug-fix.
Pull Requests

When creating a PR, please include as much information as possible about the type of enhancement, whether if it's a bugfix, new functionality, or any other change. There's a template for you to fill out, which will make the review process for the maintainers faster. When creating a PR do it against the master branch. The PR should include:

  • A clear and descriptive title.
  • Description of the issue if you are fixing a bug together with a link to the relevant issue or background for introducing a new feature.