-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreate-coupon.py
47 lines (35 loc) · 1.43 KB
/
create-coupon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import grpc
import passkit_io.single_use_coupons.coupon_pb2 as coupon_pb2
import passkit_io.single_use_coupons.a_rpc_pb2_grpc as a_rpc_pb2_grpc
from passkit_io.common.personal_pb2 import Person
def create_coupon():
# Read the CA, certificate, and private key files
with open('../certs/ca-chain.pem', 'rb') as ca_file:
root_certificates = ca_file.read()
with open('../certs/certificate.pem', 'rb') as cert_file:
certificate_chain = cert_file.read()
with open('../certs/key.pem', 'rb') as key_file:
private_key = key_file.read()
# Create SSL credentials for gRPC
credentials = grpc.ssl_channel_credentials(
root_certificates=root_certificates,
private_key=private_key,
certificate_chain=certificate_chain
)
# Create a secure gRPC 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
person = Person()
person.displayName = "Percy PassKit"
person.surname = "PassKit"
person.forename = "Percy"
person.emailAddress = ""
coupon.person.CopyFrom(person)
response = couponsStub.createCoupon(coupon)
print(response)
create_coupon()