passkit-csharp-grpc-sdk
Use the PassKit gRPC SDK to issue and manage Apple Wallet and Google Pay Passes from your C# applications.
For more information, please visit the documentation.
Table Of Contents
- Requirements
- Installation
- Getting Started
- PassKit Portal
- Known Issues & Unsupported Endpoints
- Getting Help
- Contributing
- Author & License
Supported Platforms
- .NET Core on Linux, Windows and Mac OS X.
- .NET Framework 4.5+ (Windows).
- Mono 4+ on Linux, Windows and Mac OS X.
Requirements
The SDK works with gRPC for C#.
When using gRPC C# under .NET Core you only need to install .NET Core.
In addition to that, you can also use gRPC C# with these runtimes / IDEs:
- Windows: .NET Framework 4.5+, Visual Studio 2013 or newer, Visual Studio Code.
- Linux: Mono 4+, Visual Studio Code.
- Mac OS X: Mono 4+, Visual Studio Code, Visual Studio for Mac.
Furthermore you will need:
- A PassKit account; sign up for free at https://app.passkit.com.
- Your SDK API credentials (Home >> Account >> Developer Tools >> Generate New SDK Credentials).
Installation
Manual Installation
Clone the repo, import the required SDK's from the lib
folder and add the following related packages:
<PackageReference Include="Google.Protobuf" Version="3.12.3" />
<PackageReference Include="Google.Api.CommonProtos" version="2.1.0" />
<PackageReference Include="Grpc.Core" Version="2.29.0"/>
See the sample code for what your csproj
file should look like.
Getting Started
Follow the installation procedure, and see general usage format & examples below.
Authorization
Simply download your SDK credentials from the PassKit Portal. You will need the credentials when you setup the SSL connection to the server.
Your credentials consist of 3 files:
ca-chain
: the PassKit CA chain.client-cert
: the certificate for your account.client-key
: the key that belongs to your certificate.
Setting up the connection:
var caCert = File.ReadAllText(@“ca-chain.pem");
var clientCert = File.ReadAllText(@"client.pem");
var clientKey = File.ReadAllText(@“client-key.pem");
var ssl = new SslCredentials(caCert, new KeyCertificatePair(clientCert, clientKey));
// Channel that holds the connection to the gRPC server.
// Channel can remain open and be reused, but should be shutdown cleanly on exit.
Channel channel = new Channel(“grpc.pub1.passkit.io”, 443, ssl);
General Instructions
The general format is shown below. Each API has its own client that you will need to initialise. Clients can re-use the connection channel.
General format:
using System;
using System.IO;
using Grpc.Core;
using PKMembers;
namespace Demo
{
class MemberDemo
{
public static void Main(string[] args)
{
// Create a client
var caCert = File.ReadAllText(@"ca-chain.pem");
var clientCert = File.ReadAllText(@"client.pem");
var clientKey = File.ReadAllText(@"client-key.pem");
var ssl = new SslCredentials(caCert, new KeyCertificatePair(clientCert, clientKey));
Channel channel = new Channel("grpc.pub1.passkit.io", 443, ssl);
var client = new Members.MembersClient(channel);
// Create a member object
var member = new Member {
ProgramId = "2hWUtzcwx43Q3xaZjSzutq",
TierId = "blue",
};
try {
// Call the API
var reply = client.enrolMember(member);
// Process the response
Console.WriteLine(reply);
} catch (Exception e) {
Console.WriteLine("Exception caught: {0}.", e.Message);
}
// Channel can remain open and be reused, but should be shutdown cleanly on exit
channel.ShutdownAsync().Wait();
}
}
}
Examples
The examples folder contains a working sample project for using the SDK.
To successfully run the program:
- ensure your gPRC certificates are in the
examples/certs
folder (you will needca-chain.pem
,certificate.pem
&key.pem
). - modify the class level variables in
exampmles/classes/MembersDemo.cs
,examples/classes/CouponsDemo.cs
andexamples/classes/FlightsDemo.cs
with the values for your programs & campaigns. - run
dotnet run
.
PassKit Portal
The https://app.passkit.com allows you to easily design loyalty cards, membership cards and coupons for both Apple Wallet and Google Pay.
Additionally, the PassKit portal facilitates management, distribution and simple analysis of your Mobile Wallet projects.
Best Practices:
- Use the web portal for initial account and project setup.
- Then use the SDKs / APIs to issue, update and delete your individual passes.
Known Issues & Unsupported Endpoints
The following methods are currently not implemented:
Members:
- Update Members by Segment: can be done by updating individual members and looping on client side
- Delete Members by Segment: can be done by deleting individual members and looping on client side
- Check In / Out Member
Coupons:
- GetAnalytics
Getting Help
Contributing
Send bug reports, feature requests and code contributions into this repository.
Author & License
PassKit Inc.: [email protected]
Distributed under MIT License. Details available in license file.