-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
252 lines (187 loc) · 8.48 KB
/
main.go
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
package main
import (
"log"
"github.com/PassKit/passkit-golang-grpc-quickstart/examples/coupons"
event_tickets "github.com/PassKit/passkit-golang-grpc-quickstart/examples/event-tickets"
"github.com/PassKit/passkit-golang-grpc-quickstart/examples/flights"
"github.com/PassKit/passkit-golang-grpc-quickstart/examples/membership"
"github.com/PassKit/passkit-golang-grpc-quickstart/examples/shared"
)
/*
Prerequisites to run this file:
- store your certificate.pem in passkit-golang-members-quickstart/certs/ directory
- store your key.pem in passkit-golang-members-quickstart/certs/ directory
- store your ca-chain.pem in passkit-golang-members-quickstart/certs/ directory
- decrypt your key.pem with `cd ./certs openssl ec -in key.pem -out key.pem` from project root
*/
const (
// The address & port of the PassKit gRPC service.
gRPCHost = "grpc.pub1.passkit.io"
gRPCPort = "443"
// The location of your client certificates.
clientCertFile = "certs/certificate.pem" // [Required] Please store your certificate.pem at ./certs directory. Your client certificate you receive by email or on Settings > Developer Credential page (https://dev-app.passkit.io/login).
clientKeyFile = "certs/key.pem" // [Required] Please store your key.pem at ./certs directory. Your private key you receive by email or on Settings > Developer Credential page (https://dev-app.passkit.io/login). You need to decrypt the key before use. Check README.md for details.
clientCAFile = "certs/ca-chain.pem" // [Required] Please store your ca-chain.pem at ./certs directory. The certificate chain you receive by email or on Settings > Developer Credential page (https://dev-app.passkit.io/login).
emailAddressToReceiveSamplePassUrl = "[email protected]" // [Required] Please set your email address to receive digital card url by email.
)
// These variables will be used by EngageWithMembers methods.
var programId string
var tierId string
var memberId string
var campaignId string
var offerId string
var couponId string
var boardingPassId string
var templateId string
var productionId string
var venueId string
var ticketTypeId string
var ticketId string
var eventId string
func main() {
if emailAddressToReceiveSamplePassUrl == "" {
log.Fatal("Please set emailAddressToReceiveSamplePassUrl with your email address in coupons.go so that you can receive sample welcome email with digital card url.")
}
ConnectWithPasskitServer()
// Membership functions
IssueMembershipCard()
EngageWithMembers()
// Coupon functions
IssueCoupon()
EngageWithCoupons()
// Flight functions
IssueBoardingPass()
EngageWithBoardingPass()
// Event ticket functions
IssueEventTicket()
EngageWithEventTicket()
}
// In order to use PassKit SDK, you need to establish the connection to the PassKit server first.
func ConnectWithPasskitServer() {
shared.ConnectPasskitSdk(clientCertFile, clientKeyFile, clientCAFile, gRPCHost, gRPCPort)
}
// Each method has the minimum information needed to execute the method, if you
// would like to add more details please refer to
// https://docs.passkit.io/protocols/member/
// for fields that can be added.
// IssueMembershipCard shows the methods needed to issue a membership card
// In order to create a membership card for your member, you need to take following process:
// 1. Create a program
// 2. Create a tier
// 3. Enrol a member (enrolling a member will automatically issue a membership card to your member).
func IssueMembershipCard() {
newProgramId := membership.CreateProgram()
newTierId := membership.CreateTier(newProgramId)
newMemberId := membership.EnrolMember(newProgramId, newTierId, emailAddressToReceiveSamplePassUrl)
// These variables will be used by EngageWithMembers().
programId = newProgramId
tierId = newTierId
memberId = newMemberId
}
// EngageWithMembers show methods you can use to engage with loyalty members.
// When you execute EngageWithMembers method by itself, please establish connection with the server first by using
// ConnectWithPasskitServer
func EngageWithMembers() {
membership.GetSingleMember(memberId)
membership.ListMembers(programId)
membership.CountMembers(programId, tierId)
membership.SendWelcomeEmail(memberId)
membership.UpdateMember_EmailAddress(memberId, tierId, programId)
membership.AddPoints(programId, memberId)
membership.UsePoints(programId, memberId)
membership.DeleteMember(programId, tierId, memberId)
}
// Each method has the minimum information needed to execute the method, if
// you would like to add more details please refer to
// https://docs.passkit.io/protocols/coupon/
//for fields that can be added.
// IssueCoupon shows the methods needed to issue a coupon
// In order to create a coupon, you need to take following process:
// 1. Create a campaign
// 2. Create an offer
// 3. Enrol someone on a couppn (enrolling someone will automatically issue a coupon card to your customer).
func IssueCoupon() {
newCampaignId := coupons.CreateCampaign()
newOfferId := coupons.CreateOffer(newCampaignId)
newCouponId := coupons.CreateCoupon(newCampaignId, newOfferId, emailAddressToReceiveSamplePassUrl)
// These variables will be used by EngageWithCoupons().
campaignId = newCampaignId
offerId = newOfferId
couponId = newCouponId
}
// EngageWithCoupons show methods you can use to engage with coupons.
// When you execute EngageWithCoupons method by itself, please establish connection with the server first by using
// ConnectWithPasskitServer
func EngageWithCoupons() {
coupons.GetSingleCoupon(couponId)
coupons.ListCoupons(campaignId)
coupons.CountCoupons(campaignId, offerId)
coupons.UpdateCoupon(campaignId, couponId)
coupons.RedeemCoupon(campaignId, couponId)
coupons.VoidCoupon(campaignId, offerId, couponId)
coupons.DeleteCouponOffer(campaignId)
}
// Each method has the minimum information needed to execute the method, if you
// would like to add more details please refer to
// https://docs.passkit.io/protocols/boarding/
// for fields that can be added.
// IssueBoardingPass shows the methods needed to issue a boarding pass
// In order to create a boarding pass, you need to take following process:
// 1. Create a carrier
// 2. Create departure and arrival airport
// 3. Create boarding pass template
// 4. Create a flight
// 5. Create flight designator
// 6. Enrol someone on a boarding pass (enrolling someone will automatically issue a boarding pass to your customer).
func IssueBoardingPass() {
newTemplateId := flights.CreateTemplate()
flights.CreateCarrier()
flights.CreateAirports()
flights.CreateFlight(newTemplateId)
flights.CreateFlightDesignator(newTemplateId)
newBoardingPass := flights.CreateBoardingPass(newTemplateId, emailAddressToReceiveSamplePassUrl)
boardingPassId = newBoardingPass
templateId = newTemplateId
}
// EngageWithBoardingPass show methods you can use to engage with boarding passes.
// When you execute EngageWithBoardingPass method by itself, please establish connection with the server first by using
// ConnectWithPasskitServer
func EngageWithBoardingPass() {
flights.DeleteFlight()
flights.DeleteFlightDesignator()
// Delete arrival airport
flights.DeleteAirport("YY4")
// Delete departure airport
flights.DeleteAirport("ADP")
flights.DeleteCarrier()
}
// Each method has the minimum information needed to execute the method, if you
// would like to add more details please refer to
// https://docs.passkit.io/protocols/event-tickets/
// for fields that can be added.
// IssueEventTicket shows the methods needed to issue an event ticket
// In order to create an event ticket, you need to take following process:
// 1. Create a venue
// 2. Create a production
// 3. Create event ticket template
// 4. Create a event ticket type
// 5. Issue an event ticket
func IssueEventTicket() {
newTemplateId := event_tickets.CreateTemplate()
newProductionId := event_tickets.CreateProduction()
newVenueId := event_tickets.CreateVenue()
newTicketTypeId := event_tickets.CreateTicketType(newProductionId, newTemplateId)
newEventId := event_tickets.CreateEvent(newVenueId, newProductionId)
newTicketId := event_tickets.IssueEventTicket(newTicketTypeId, newProductionId, newEventId)
venueId = newVenueId
productionId = newProductionId
ticketTypeId = newTicketTypeId
ticketId = newTicketId
}
// EngageWithEventTicket show methods you can use to engage with event tickets.
// When you execute EngageWithEventTicket method by itself, please establish connection with the server first by using
// ConnectWithPasskitServer
func EngageWithEventTicket() {
event_tickets.ValidateTicket(ticketId)
event_tickets.RedeemTicket(ticketId)
}