The current generation of business apps takes advantage of unique external devices which expand mobile system capabilities. Sometimes you want to use less popular solutions which don’t have full support for Xamarin. In those situations, you will need to use third-party libraries and binding projects.

To learn more about binding projects be sure to read through general topic connected with Binding Objective-C Libraries from Advances Topics in Xamarin. The full article is available here: Binding Objective-C Libraries

Today we will show you how, to begin with, Payleven SDK in Xamarin iOS. Payleven offers you card payments the way you want. Their devices are contactless and are using Bluetooth technology. So far Payleven doesn’t provide support for Xamarin, so we must use their iOS Framework. Fortunatelly for us we got one of their devices and we can test them for you.

Payleven documentation is available here: Payleven mPOS SDK Reference

Just for your convenience, we split this article into two parts:
1. Creating sample iOS project & binding library
2. Making your first mobile payment with Payleven Framework

Creating sample iOS project & binding library

Step 1

Create a new solution and merge two projects:

  • PaylevenSample as Xamarin.iOS Empty Project
  • PaylevenLib as iOS Binding Project (Unified API)
Step 1.0 - Xamarin Payleven Sample iOS Project & Solution

Step 1.0 – Payleven Sample iOS Project & Solution

Step 1.1 - Xamarin Payleven new Binding Project

Step 1.1 – Payleven new Binding Project

Step 1.2 - Xamarin Payleven complete solution

Step 1.2 – Payleven complete solution

After creating a new solution with two projects inside add PaylevenLib as a reference in PaylevenSample.

Xamarin Payleven adding reference

Step 1.3 – Adding reference

Step 2

Prepare Payleven SDK files

Payleven SDK for iOS is available. Save it to your hard drive.

Xamarin Payleven - Github SDK

Step 2.0 Github SDK

Then extract files from Framework/directory that are necessary in our project:

  • AdyenToolkit with all header files from AdyenToolkit.framework
  • PaylevenSDK with all header files from PaylevenSDK.framework/Versions/A/
  • AdyenToolkit.bundle

Before we will add those files inside our project we need to rename two files:

  • AdyenToolkit file to libAdyenToolkit.a
  • PaylevenSDK to libPaylevenSDK.a

Files should look like on the image below:

Xamarin Payleven - All necessary files

Step 2.1 All necessary files

Step 3

Put Payleven SDK / AdyenToolkit into the binding project
Click on PaylevenLib project (main directory) and add an existing folder with your files. Then select all files without AdyenToolkit.bundle and OS system data.

Xamarin Payleven - Add files to project

Step 3.0 – Add files to project

Xamarin Payleven - Adding files dialog

Step 3.1 – Adding files dialogue

AdyenToolkit.bundle should be inside Resources folder, so select Resources folder and then click add existing folder and select correct one. After this your PaylevenLib project should look like:

Xamarin Payleven - All files inside project

Step 3.2 – All files inside the project

so check if:

  • All headers inside Header folder
  • Two files – libAdyenToolkit.a and libPaylevenSDK.a are present
  • In your resources folder, there is AdyenToolkit.bundle

Step 4

Set LinkWith attribute for binary files

After you added libAdyenToolkit.a and libPaylevenSDK.a your IDE created two files with extension .linkwith.cs.

Xamarin Payleven - Link with files

Step 4.0 – Link with files

Default file looks like:

using System;
using ObjCRuntime;

[assembly: LinkWith ("libdefault.a", SmartLink = true, ForceLoad = true)]

Those files contain information for linker that you need an update with link targets, frameworks and flags. They are specified in Payleven documentation:

CoreData.framework
CoreLocation.framework
ExternalAccessory.framework
SystemConfiguration.framework
libsqlite3.0.dylib

So, your updated files should look like:

[assembly: LinkWith ("libAdyenToolkit.a",
LinkTarget.Simulator | LinkTarget.Simulator64 | LinkTarget.ArmV7 | LinkTarget.Arm64, SmartLink = true, ForceLoad = true,
Frameworks = "CoreFoundation CoreText UIKit Foundation CoreLocation ExternalAccessory SystemConfiguration CoreGraphics",
LinkerFlags = "-lz -lsqlite3")]
[assembly: LinkWith ("libPaylevenSDK.a",
LinkTarget.Simulator | LinkTarget.Simulator64 | LinkTarget.ArmV7 | LinkTarget.Arm64, SmartLink = true, ForceLoad = true,
Frameworks = "CoreFoundation CoreText UIKit Foundation CoreData CoreLocation ExternalAccessory SystemConfiguration",
LinkerFlags = "-lz -lsqlite3")]

As you see there are targets that I will use in our project and some frameworks that are required for assemblies to work correctly.

Step 5

Update ApiDefinition.cs & StructsAndEnums.cs

The last step is to simply set up new definitions of interfaces that are defined in our assemblies.

Xamarin Payleven API definitions

Step 5.0 – API definitions

This step is the most time-consuming step. This is the list of interfaces that we need to declare to make payment in our sample app:

  • PLVPayleven
  • PLVPaymentTaskDelegate
  • PLVPaymentTask
  • PLVPaymentResultAdditionalData
  • PLVPaymentResult
  • PLVDevice
  • PLVPaymentRequest

Some of those interfaces require additional enumeration types which we declare in StructsAndEnums file. For example, PLVPaymentResult interface contains method State which returns one those types like Approved, Declined or Cancelled. What we need is a missing declaration of enumeration PLVPaymentResultState in our project.

Xamarin Payleven - Interface Declaration

Step 5.1 – Interface declaration

Xamarin Payleven - Enum Declaration

Step 5.2 – Enum declaration

Now check just to be sure if you are able to compile the project without any errors and we can move on. You can check out the full source code for the Payleven sample application shown above on my GitHub.

Get started with us

Avatar Hi, I’m Marcin, COO of Applandeo

Looking for a partner that will work with you to create a great product? Fill in the form below and we’ll walk you through the process. Our developers will do more than just write code, but will also work with you to find the best business solutions to your specific needs. Let’s build something great together.

Drop a message
Contact image