Giter VIP home page Giter VIP logo

passkit-csharp-grpc-sdk's Introduction

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

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:

  1. A PassKit account; sign up for free at https://app.passkit.com.
  2. 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 need ca-chain.pem, certificate.pem & key.pem).
  • modify the class level variables in exampmles/classes/MembersDemo.cs, examples/classes/CouponsDemo.cs and examples/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.

passkit-csharp-grpc-sdk's People

Contributors

pkosterman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.