Code Monkey home page Code Monkey logo

passkit-php-grpc-sdk's Introduction

PassKit PHP SDK

License: MIT Version

Use the PassKit PHP gRPC SDK to issue and manage Apple Wallet and Google Pay Passes from your PHP application.

For more information, please visit the documentation.

Table Of Contents

Requirements

  1. PHP 7.0 or higher.
  2. PECL.
  3. Composer.
  4. A PassKit account; sign up for free at https://app.passkit.com.
  5. Your SDK API credentials (Home >> Account >> Developer Tools >> Generate New SDK Credentials).

Installation

Instal & Enable the gRPC PHP extension

sudo pecl install grpc-1.42.0

After installing the gRPC extension, make sure the extension is enabled in your php.ini file, (e.g. /etc/php5/cli/php.ini, /etc/php5/apache2/php.ini, or /usr/local/etc/php/7.2/php.ini), depending on where your PHP installation is.

extension=grpc.so

For detailed steps visit the gRPC PHP quickstart.

Add bindings to composer

To install the bindings via Composer, add the following to composer.json:

{
  "repositories": [
    {
      "type": "git",
      "url": "https://github.com/passkit/passkit-php-grpc-sdk.git"
    }
  ],
  "require": {
    "passkit/passkit-php-grpc-sdk": "1.1.70"
  }
}

Then run composer install

Manual Installation

Clone the repo and include autoload.php:

require_once('/path/to/passkit-php-grpc-sdk/vendor/autoload.php');

Getting Started

Follow the installation procedure, and see general usage format & examples below.

Authorization

Simply request your SDK credentials from the PassKit Portal. You will receive an email with your credentials on your registered email address. Follow the instructions in the email to decrypt key.pem, and then copy the .pem files into your project (in this project & for the examples to work they should be in the certs directory).

You will need the credentials when you setup the SSL connection to the server.

Your credentials consist of 3 files:

  • ca-chain.pem: the PassKit CA chain.
  • certificate.pem: the certificate for your account.
  • key.pem: the key that belongs to your certificate.

Setting up the connection:

putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");

$ca_filename = "ca-chain.pem";
$key_filename = "key.pem";
$cert_filename = "certificate.pem";
$path = "../certs/";

$credentials = Grpc\ChannelCredentials::createSsl(
    file_get_contents($path . $ca_filename),
    file_get_contents($path . $key_filename),
    file_get_contents($path . $cert_filename)
);

$client = new Members\MembersClient('grpc.pub1.passkit.io:443', [
    'credentials' => $credentials
]);

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 credentials object.

General format:

<?php
require_once "../vendor/autoload.php";

putenv("GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA");

try {
    $ca_filename = "ca-chain.pem";
    $key_filename = "key.pem";
    $cert_filename = "certificate.pem";
    $path = "../certs/";

    $credentials = Grpc\ChannelCredentials::createSsl(
        file_get_contents($path . $ca_filename),
        file_get_contents($path . $key_filename),
        file_get_contents($path . $cert_filename)
    );

    $client = new Members\MembersClient('grpc.pub1.passkit.io:443', [
        'credentials' => $credentials
    ]);

    // Set the Member body
    $member = new Members\Member();
    $member->setProgramId("5fbCcr7f4NuBg9lvjJayvV");
    $member->setTierId("bronze");

    $person = new Io\Person();
    $person->setDisplayName("Patrick Kosterman");
    $dateOfBirth = new Io\Date();
    $dateOfBirth->setDay(22);
    $dateOfBirth->setMonth(6);
    $dateOfBirth->setYear(2020);
    $person->setDateOfBirth($dateOfBirth);
    $person->setEmailAddress("[email protected]");
    $member->setPerson($person);

    list($id, $status) = $client->enrolMember($member)->wait();
    if ($status->code !== 0) {
        throw new Exception(sprintf('Status Code: %s, Details: %s, Meta: %s', $status->code, $status->details, var_dump($status->metadata)));
    }

    echo "https://pub1.pskt.io/" . $id->getId();
} catch (Exception $e) {
    echo $e;
}
?>

Examples

The examples folder contains working samples for using the SDK.

To successfully run the program:

  • ensure your gPRC certificates are in the certs folder in this repo (you will need ca-chain.pem, certificate.pem & key.pem).
  • modify the variables with the values for your programs & campaigns.
  • run cd examples && php enrol-member.php.

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-php-grpc-sdk's People

Contributors

canderson1538 avatar pkosterman avatar pkpfr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

passkit-php-grpc-sdk's Issues

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.