Press "Enter" to skip to content

Creating a Binding Library in Xamarin (Part. 2)

In the first part of this article, I covered how to create a binding library in Xamarin by creating one of the Pay.Card SDK.

In this article, I’ll be showing how to integrate and use this library in a Xamarin Forms project.

The result: 

To test you can use any credit card, or use this test credit card image I found on the internet.

Let’s start

After creating a new Xamarin Forms project, we need to import the Binding libraries (Android/iOS) into our solution.

Add the reference of the binding library for each platform project.

Xamarin.Forms

Create the interface for consuming our PayCard Service IPayCardRecognizerService.

iOS

First, we need to understand which are the methods/properties name by checking at the official documentation on how to use the SDK. Then translate that to C# code.

Added this ViewController and the Camera permission request in Info.plist.

Android

As on iOS, I translated the Java sample code to C#.

In the MainActivity class override the OnActivityResult method to call the OnActivityResult method of our service so that we can receive the activity result when the card is scanned.

Xamarin.Forms

Consume the service

You can check the full source here.

Happy Binding!