-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathredeem-coupon.py
39 lines (28 loc) · 1.17 KB
/
redeem-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
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
def redeem_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)
# Redeem coupon
coupon = coupon_pb2.Coupon()
coupon.id = "" # Id of coupon to void
coupon.campaignId = "" # Get campaignId from createCampaign call or dashboard
response = couponsStub.redeemCoupon(coupon)
print(response)
redeem_coupon()