SwedbankPaySDK 5.0.0

SwedbankPaySDK 5.0.0

Maintained by Swedbank Pay SDK for iOS.



  • By
  • Swedbank Pay

Swedbank Pay SDK for iOS

Swedbank Pay SDK for iOS

Tests Cocoapods Cocoapods platforms CLA assistant License Contributor Covenant

The Swedbank Pay iOS SDK facilitates the implementation of the Swedbank Pay API Platform in an iOS application.

Installation

The SDK has two components, SwedbankPaySDK and SwedbankPaySDKMerchantBackend. The first one is the core SDK, and the second one contains utilities for interfacing with a server implementing the Merchant Backend API.

If you are not using the Merchant Backend API for backend communication, you only need to use the SwedbankPaySDK component. Otherwise, you should add both components to your project.

Swift Package Manager

The SDK is available through the Swift Package Manager. This is the simplest way of adding the SDK to an Xcode project.

Follow the instructions here to add a SwiftPM dependency. Use https://github.com/SwedbankPay/swedbank-pay-sdk-ios.git as the repository URL. Select either only the SwedbankPaySDK library or both libraries depending on your use-case.

CocoaPods

The SDK is also available through CocoaPods. There are separate pods for the two components, named SwedbankPaySDK and SwedbankPaySDKMerchantBackend respectively.

Add the relevant dependencies in your Podfile:

pod 'SwedbankPaySDK', '~> 3.0'
pod 'SwedbankPaySDKMerchantBackend', '~> 3.0'

Usage

Please refer to the Developer Portal for usage instructions.

To explore a working app using the SDK, see the Example Project.

To import API-documentation to Xcode, to browse types and functions inside the Documentation window, double click one of the .doccarchives in the Documentation folder. Choose SwedbankPaySDK+MerchantDocumentation for the full set, and the other if you are not using the BackendMerchant.

Walkthrough / integration into an existing app

To start making payments you need four things:

  1. A SwedbankPaySDKConfiguration object that describes how to communicate with your backend. To get started quickly a default implementation is provided, called MerchantBackendConfiguration.
  2. A paymentOrder that describes what to purchase, the cost, currency and similar information.
  3. Give that paymentOrder to an instance of a SwedbankPaySDKController and present it in your view hierarchy.
  4. Implement the SwedbankPaySDKDelegate callbacks and wait for payment to succeed or fail.

Instead of just talking about it we have provided you with an example app, showing you in detail how integration can be done. Use that as a reference when building your own solution:

iOS Example app

1. SwedbankPaySDKConfiguration details

Using the MerchantBackendConfiguration you only need to provide the URL for your backend and header values for api key and an access token. Have a look at the configuration variable in PaymentViewModel.swift in the example app for a reference.

The SDK will then communicate with your backend, expecting the same API as our example backends. You don't have to provide all of the API, making payments only require /paymentorders, but you will want to support /tokens and /patch soon as well. To get started you can look at our backend example implementations which provides a complete set of functionality and describes in a very clear and easy manner how requests can be handled.

Using the Merchant example backend you can setup (for example) a Node.js backend and have it serve a client in debug-mode while integrating the app. Remember to supply your api-key and other values in the appconfig.json file in order for requests to work properly.

2. PaymentOrder details

In PaymentViewModel.swift there is a paymentOrder property that describes how we create it. PaymentOrders have default values for properties that can, so that you only need to supply values for what the customer intends to purchase, or for to access advanced functionality.

3. Presenting the payment menu

The last step is to just create an instance of the SwedbankPaySDKController and present it to the user. In the example app we add it as a sub view controller, but it could be managed in any other way, see PaymentViewController.swift for details.

4. SwedbankPaySDKDelegate

The delegate pattern is well known and widely used in the iOS community. Implement the delegate callbacks you are interested in to get notified of the state of the purchase. Typically you need to at least know when payments succeed, is canceled or fail, but there are a few more callbacks to your disposal. See the SwedbankPaySDKDelegate protocol, or the example app implementation for more details.

Integration conclusions

This is all you need to get started and accepting payments, the next step is to let your customers save their card details, or to create purchase tokens for subscriptions or tokens for charges at a later stage. Depending on your specific use case.

Continue reading the PaymentsOnly tokens walkthrough or Enterprise tokens walkthrough for a continued discussion on payment tokens. These features are also well documented in swedbank pay's developer portal under "optional features".

For more in-depth details of how to operate the SDK and to setup the necessary callbacks, please refer to the SwedbankPay SDK documentation.

Contributing

Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct and sign the contributor's license agreement.

License

The code within this repository is available as open source under the terms of the Apache 2.0 License and the contributor's license agreement.