Skip to content

Added coupons, membership and flights methods to quickstart #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 73 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,74 @@
# passkit-python-quickstart
Python Quickstart to create, distribute, analyse and manage your Digital Coupons / Membership / Boarding Passes for Apple Wallet and Google Pay
PassKit Python Quickstart
=======================

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Version](https://badge.fury.io/py/passkit-python-grpc-sdk.svg)](https://pypi.org/project/passkit-python-grpc-sdk/)

### Overview

This quickstart aims to help get Python developers up and running with the PassKit SDK as quickly as possible.

### Prerequisites

You will need the following:

- A PassKit account (signup for free at https://app.passkit.com)
- Your PassKit SDK Credentials (available from the https://app.passkit.com/app/account/developer-tools)
- Python 3.7 or above from https://www.oracle.com/java/technologies/downloads/ (https://docs.oracle.com/en/java/javase/18/install/overview-jdk-installation.html - guide on how to download)
- Gradle Build Tool from https://gradle.org/install/ with guide on how to install
- Apple wallet certificate id (for flights only, https://app.passkit.com/app/account/certificates)
![ScreenShot](images/certificate.png)

### Configuration

1. Download or clone this quickstart repository, create a folder `certs` in the resources folder of the repository and add the following three PassKit credential files:
- certificate.pem
- ca-chain.pem
- key.pem

You can disregard the key-java.pem credentials file as it is not compatible with Python.
2. Use `pip install passkit-python-grpc-sdk` to download the latest sdk from python.

### Membership Cards
In the membership folder the methods there are:
- create-program.py - takes a new program name and creates a new program
- create-tier.py - takes the programId of the program just created in the above program, creates a new template (based of default template), creates a tier, and links this tier to the program
- enrol-member.py - takes programId and tierId created by the above methods, and memberDetails, creates a new member record, and sends a welcome email to deliver membership card url
- update-member.py - takes memberId and memberDetails, and updates existing member record
- check-in-member.py - takes memberId and location details and checks in the selected member
- check-out-member.py - takes memberId and location details and checks out the selected member
- earn-points.py - takes a programId of an existing program and memberId of existing member to add points to chosen member
- burn-points.py - takes a programId of an existing program and memberId of existing member to use points from a chosen member
- delete-member.py - takes programId, tierId, memberId and memberDetails, deletes an existing member record

### Coupons
In the coupons folder the methods are:
- create-campaign.py - takes a new campaign name and creates a new campaign
- create-offer.py - takes a campaignId of the campaign you just created and creates a new template (based of default template), creates an offer, and links this offer to the campaign
- create-coupon.py - takes campaignId and offerId created by the above methods, and couponDetails, creates a new coupon record, and sends a welcome email to deliver coupon card url
- list-coupons.py - takes campaignId and returns list of coupon records under that campaign
- update-coupon.py - takes a campaignId of an existing campaign and couponId of existing coupon to update that coupon
- redeem-coupon.py - takes a campaignId of an existing campaign and couponId of existing coupon to redeem that coupon
- void-coupon.py - takes the couponId, offerId and campaignId to void an existing coupon

### Boarding Passes
#### Issue A Boarding Pass.
In the flights folder the methods are:
- create-template.py - creates the pass template for flights and boarding passes
- create-carrier.py - takes a new carrier code and creates a new carrier
- create-airport.py - takes a new airport code and creates a new airport.
- create-flight.py - takes templateId , from previous method, to use as base template and uses a carrier code, created from previous method, and creates a new flight
- create-flight-designator.py - creates flight designator using flight code
- create-boarding-pass.py - takes templateId, from previous method, and customer details creates a new boarding pass, and sends a welcome email to deliver boarding pass url
- delete-flight.py - takes an existing flight number as well as other details and deletes the flight associated with it
- delete-flight-designator.py - takes an existing flight designation and deletes the flight designator associated with it
- delete-airports.py - takes an existing airport code and deletes the airport associated with it
- delete-carrier.py - takes an existing carrier code and deletes the carrier associated with it


## Documentation
* [PassKit Membership Official Documentation](https://docs.passkit.io/protocols/member)
* [PassKit Coupons Official Documentation](https://docs.passkit.io/protocols/coupon)
* [PassKit Boarding Passes Official Documentation](https://docs.passkit.io/protocols/boarding)
* [PassKit Events Official Documentation](https://docs.passkit.io/protocols/event-tickets/)

... coming soon
26 changes: 26 additions & 0 deletions coupons/create-campaign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import grpc
import io.single_use_coupons.campaign_pb2 as campaign_pb2
import io.single_use_coupons.a_rpc_pb2_grpc as a_rpc_pb2_grpc


def create_campaign():
# Create channel credentials
credentials = grpc.ssl_channel_credentials(
root_certificates='certs/certificate.pem', private_key_file='certs/key.pem', certificate_chain_file='certs/ca-chain.pem')

# Create a secure channel
channel = grpc.secure_channel(
'grpc.pub1.passkit.io' + ':' + '443', credentials)

# Create a stub
couponsStub = a_rpc_pb2_grpc.SingleUseCouponsStub(channel)

# Create campaign
campaign = campaign_pb2.CouponCampaign()
campaign.Name = "Quickstart Campaign"
campaign.Status = [1, 4]
response = couponsStub.createCouponCampaign(campaign)
print(response)


create_campaign()
34 changes: 34 additions & 0 deletions coupons/create-coupon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import grpc
import io.single_use_coupons.coupon_pb2 as coupon_pb2
import io.single_use_coupons.a_rpc_pb2_grpc as a_rpc_pb2_grpc
import io.common.personal_pb2 as personal_pb2


def create_coupon():
# Create channel credentials
credentials = grpc.ssl_channel_credentials(
root_certificates='certs/certificate.pem', private_key_file='certs/key.pem', certificate_chain_file='certs/ca-chain.pem')

# Create a secure channel
channel = grpc.secure_channel(
'grpc.pub1.passkit.io' + ':' + '443', credentials)

# Create a stub
couponsStub = a_rpc_pb2_grpc.SingleUseCouponsStub(channel)

# Create coupon
coupon = coupon_pb2.Coupon()
coupon.OfferId = "" # Get offerId from createOffer call or dashboard
coupon.CampaignId = "" # Get campaignId from createCampaign call or dashboard
coupon.Sku = ""

person = personal_pb2.Person()
person.DisplayName = "Loyal Larry"
person.EmailAddress = ""

coupon.Person = person
response = couponsStub.createCoupon(coupon)
print(response)


create_coupon()
75 changes: 75 additions & 0 deletions coupons/create-offer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import grpc
import io.single_use_coupons.offer_pb2 as offer_pb2
import io.single_use_coupons.a_rpc_pb2_grpc as a_rpc_pb2_grpc
import io.core.a_rpc_templates_pb2_grpc as a_rpc_templates_pb2_grpc
import io.common.template_pb2 as template_pb2
import google.protobuf.timestamp_pb2 as timestamp_pb2
import datetime


def create_offer():
# Create channel credentials
credentials = grpc.ssl_channel_credentials(
root_certificates='certs/certificate.pem', private_key_file='certs/key.pem', certificate_chain_file='certs/ca-chain.pem')

# Create a secure channel
channel = grpc.secure_channel(
'grpc.pub1.passkit.io' + ':' + '443', credentials)

# Create a stub
couponsStub = a_rpc_pb2_grpc.SingleUseCouponsStub(channel)

# Create templates stub
templatesStub = a_rpc_templates_pb2_grpc.TemplatesStub(channel)

# Create template
templateRequest = template_pb2.DefaultTemplateRequest()
templateRequest.Protocol = "SINGLE_USE_COUPON"
templateRequest.Revision = 1

template = templatesStub.getDefaultTemplate(templateRequest)

template.Name = "Quickstart Base Offer"
template.Description = "Quickstart Base Offer Pass"
template.Timezone = "Europe/London"

templateId = templatesStub.createTemplate(template)

# Create offer
offer = offer_pb2.CouponOffer()
offer.Id = "Base Offer"
offer.OfferTitle = "Base Offer Title"
offer.OfferShortTitle = "Base Offer"
offer.OfferDetails = "Base Offer Details"
offer.OfferFinePrint = "Base Offer fine print"
offer.BeforeRedeemPassTemplateId(templateId.Id)

issueStartDate = datetime.datetime.strptime(
"10/9/2023", "%d/%m/%Y").timestamp()
issueEndDate = datetime.datetime.strptime(
"10/11/2023", "%d/%m/%Y").timestamp()
redemptionStartDate = datetime.datetime.strptime(
"10/9/2023", "%d/%m/%Y").timestamp()
redemptionEndDate = datetime.datetime.strptime(
"10/11/2023", "%d/%m/%Y").timestamp()

redemptionSettings = offer_pb2.RedemptionSettings()
redemptionSettings.RedemptionStartDate = timestamp_pb2.Timestamp(
redemptionStartDate)
redemptionSettings.RedemptionEndDate = timestamp_pb2.Timestamp(
redemptionEndDate)

couponExpirySettings = offer_pb2.CouponExpirySettings
couponExpirySettings.CouponExpiryType = "AUTO_EXPIRE_REDEMPTION_END_DATE"

offer.IssueStartDate = timestamp_pb2.Timestamp(issueStartDate)
offer.IssueEndDate = timestamp_pb2.Timestamp(issueEndDate)
offer.RedemptionSettings = redemptionSettings
offer.CouponExpirySettings = couponExpirySettings
offer.CampaignId = "" # Get from campaignId from createCampaign call or dashboard
offer.IanaTimezone = "Europe/London"
response = couponsStub.createCouponOffer(offer)
print(response)


create_offer()
26 changes: 26 additions & 0 deletions coupons/list-coupons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import grpc
import io.single_use_coupons.coupon_pb2 as coupon_pb2
import io.single_use_coupons.a_rpc_pb2_grpc as a_rpc_pb2_grpc


def list_coupons():
# Create channel credentials
credentials = grpc.ssl_channel_credentials(
root_certificates='certs/certificate.pem', private_key_file='certs/key.pem', certificate_chain_file='certs/ca-chain.pem')

# Create a secure channel
channel = grpc.secure_channel(
'grpc.pub1.passkit.io' + ':' + '443', credentials)

# Create a stub
couponsStub = a_rpc_pb2_grpc.SingleUseCouponsStub(channel)

# List coupons by campaignId
listCouponRequest = coupon_pb2.ListRequest()
listCouponRequest.CouponCampaignId = "" # Campaign Id of coupons to list

response = couponsStub.listCouponsByCouponCampaign(listCouponRequest)
print(response)


list_coupons()
28 changes: 28 additions & 0 deletions coupons/redeem-coupon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import grpc
import io.single_use_coupons.coupon_pb2 as coupon_pb2
import io.single_use_coupons.a_rpc_pb2_grpc as a_rpc_pb2_grpc


def redeem_coupon():
# Create channel credentials
credentials = grpc.ssl_channel_credentials(
root_certificates='certs/certificate.pem', private_key_file='certs/key.pem', certificate_chain_file='certs/ca-chain.pem')

# Create a secure channel
channel = grpc.secure_channel(
'grpc.pub1.passkit.io' + ':' + '443', credentials)

# Create a stub
couponsStub = a_rpc_pb2_grpc.SingleUseCouponsStub(channel)

# Redeem coupon
coupon = coupon_pb2.Coupon()
coupon.Id = "" # Id of coupon to void
coupon.CampaignId = "" # Get campaignId from createCampaign call or dashboard
coupon.Status = 1

response = couponsStub.redeemCoupon(coupon)
print(response)


redeem_coupon()
34 changes: 34 additions & 0 deletions coupons/update-coupon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import grpc
import io.single_use_coupons.coupon_pb2 as coupon_pb2
import io.single_use_coupons.a_rpc_pb2_grpc as a_rpc_pb2_grpc
import io.common.personal_pb2 as personal_pb2


def update_coupon():
# Create channel credentials
credentials = grpc.ssl_channel_credentials(
root_certificates='certs/certificate.pem', private_key_file='certs/key.pem', certificate_chain_file='certs/ca-chain.pem')

# Create a secure channel
channel = grpc.secure_channel(
'grpc.pub1.passkit.io' + ':' + '443', credentials)

# Create a stub
couponsStub = a_rpc_pb2_grpc.SingleUseCouponsStub(channel)

# Update coupon
coupon = coupon_pb2.Coupon()
coupon.Id = "" # Id of coupon to update
coupon.OfferId = "" # Get offerId from createOffer call or dashboard
coupon.CampaignId = "" # Get campaignId from createCampaign call or dashboard

person = personal_pb2.Person()
person.DisplayName = "Loyal Larry"
person.EmailAddress = ""

coupon.Person = person
response = couponsStub.updateCoupon(coupon)
print(response)


update_coupon()
28 changes: 28 additions & 0 deletions coupons/void-coupon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import grpc
import io.single_use_coupons.coupon_pb2 as coupon_pb2
import io.single_use_coupons.a_rpc_pb2_grpc as a_rpc_pb2_grpc


def void_coupon():
# Create channel credentials
credentials = grpc.ssl_channel_credentials(
root_certificates='certs/certificate.pem', private_key_file='certs/key.pem', certificate_chain_file='certs/ca-chain.pem')

# Create a secure channel
channel = grpc.secure_channel(
'grpc.pub1.passkit.io' + ':' + '443', credentials)

# Create a stub
couponsStub = a_rpc_pb2_grpc.SingleUseCouponsStub(channel)

# Void coupon
coupon = coupon_pb2.Coupon()
coupon.Id = "" # Id of coupon to void
coupon.OfferId = "" # Get offerId from createOffer call or dashboard
coupon.CampaignId = "" # Get campaignId from createCampaign call or dashboard

response = couponsStub.update(coupon)
print(response)


void_coupon()
31 changes: 31 additions & 0 deletions flights/create-airport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import grpc
import io.flights.airport_pb2 as airport_pb2
import io.flights.a_rpc_pb2_grpc as a_rpc_pb2_grpc


def create_airport():
# Create channel credentials
credentials = grpc.ssl_channel_credentials(
root_certificates='certs/certificate.pem', private_key_file='certs/key.pem', certificate_chain_file='certs/ca-chain.pem')

# Create a secure channel
channel = grpc.secure_channel(
'grpc.pub1.passkit.io' + ':' + '443', credentials)

# Create a stub
flightsStub = a_rpc_pb2_grpc.FlightsStub(channel)

# Create airport
airport = airport_pb2.Port()
airport.AirportName = "ABC Airport"
airport.CityName = "London"
airport.IataAirportCode = "" # Your airport IATA code
airport.IcaoAirportCode = "" # Your airport ICAO code
airport.CountryCode = "IE"
airport.Timezone("Europe/London")

response = flightsStub.createPort(airport)
print(response)


create_airport()
Loading