This repository was archived by the owner on Mar 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsilver_test.py
More file actions
352 lines (265 loc) · 10.3 KB
/
silver_test.py
File metadata and controls
352 lines (265 loc) · 10.3 KB
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
from silver import *
from silver.silverraw import silvershop, silvercom, silverbook, silvercore
import pyxb
from datetime import datetime
cert = "/Users/bloomberglondonrd1/.ssh/certificates/hacktrain.nokey.pem"
key = "/Users/bloomberglondonrd1/.ssh/certificates/hacktrain.key"
sc = SilverCore("HackTrain", "GB", "CH2", cert, key)
# =======================================================
# ===================== Fares query =====================
# =======================================================
p1 = Passenger(age=30)
tp1 = TravelPoint(
origin="GBQQU",
destination="GBQQM",
departure=datetime(2015, 11, 16, 12))
fq = FareSearch(
travel_points = [tp1],
fare_filter = FARE_FILTER.CHEAPEST,
passengers = [p1])
fares_result = sc.search_fare(fq)
print fares_result.requestStatus
print fares_result.requestStatus.success
fr = fares_result.results
for l in fr.legs.leg:
print l.originTravelPoint.value()
print l.originTravelPoint.type
print l.destinationTravelPoint.value()
print l.destinationTravelPoint.type
for p in fr.passengers.passenger:
print p.passengerSpecID
print p.age
for s in l.legSolutions.legSolution:
print s.legSolutionID
print s.overtakenJourney
print s.duration
for a in s.availableSeatPreferences.availableSeatPreference:
print a.marketingCarrier
print a.serviceClass
print a.supplierEquipmentType
print a.value()
for r in s.passengerInformationRequired.passengerInformation:
print r.type
print r.allPassengers
for t in s.travelSegments.travelSegment:
print t.sequence
print t.travelSegmentID
print t.originTravelPoint.type
print t.originTravelPoint.value()
print t.destinationTravelPoint.type
print t.destinationTravelPoint.value()
print t.arrivalDateTime
print t.designator
print t.operatingCarrier.value()
print t.supplierEquipmentType.value()
print t.duration
print t.crossBorderInfo
print t.equipmentType.code
print t.equipmentType.value()
print t.marketingServiceName
print t.marketingInformation.serviceCode
for p in fr.fareInformation.prices.pointToPointPrice:
print p.priceID
print p.totalPrice.currency
print p.totalPrice.value()
print p.holdExpiration
for l in p.legReferences.legSolutionIDRef:
print l
for t in p.ticketableFares.ticketableFare:
print t.totalPrice
print t.totalPrice.currency
print t.totalPrice.value()
print t.ticketingOptionsAvailable.TOD
print t.ticketingOptionsAvailable.ETK
print t.ticketingOptionsAvailable.PAH
print t.ticketingOptionsAvailable.EML
print t.ticketingOptionsAvailable.DEPARTURE_STATION_TOD
print t.ticketingOptionsAvailable.SMS
print t.fareOrigin.type
print t.fareOrigin.value()
print t.fareDestination.type
print t.fareDestination.value()
if t.fareDestinationTerminals:
for d in t.fareDestinationTerminals.fareDestinationTerminal:
print d.type
print d.value()
for r in t.passengerReferences.passengerReference:
print r.passengerIDRef
print r.passengerTypeCode
for c in r.fareCodes.fareCode:
print c.code
print c.serviceClass
print c.travelSegmentIDRef
print c.cabinClass
print c.rewardsEligible
print c.fareClass
print c.fareDisplayName
print c.openReturn
print c.reservable
print c.fareExpirationDateTime
for a in c.amenities.amenity:
print a.type
print a.value()
for f in c.fareApplicabilities.fareApplicability:
print f.outbound
print f.type
for r in t.prices.price:
print r.type
print r.currency
print r.value()
for o in t.optionalPrices.optionalPrice:
# TODO: Add consumption rules
print o.optionalPriceID
print o.category
print o.applicableTravelSegments.travelSegmentIDRef
print o.maximumBookableQuantity
for u in o.rules.rule:
print u.type
print u.priceType
print u.applicableOrderStatus
print u.refundToVoucher
for c in t.commissions.commission:
print c.type
print c.currency
print c.value()
for r in t.rules.rule:
print r.type
print r.description
print r.priceType
print r.applicableOrderStatus
if r.penalty:
print r.penalty.currency
print r.penalty.value()
# =======================================================
# ============= Booking From Fares Found ================
# =======================================================
p1 = Passenger(
id="PAX_SPEC_0",
age=30,
first_name="Jane",
last_name="Smith")
p1.add_contact(ContactInfo(CONTACT_TYPE.UNKNOWN, CONTACT_MEDIUM.PHONE, "123456789"))
p1.add_contact(ContactInfo(CONTACT_TYPE.BUSINESS, CONTACT_MEDIUM.PHONE, "123456789"))
p1.add_contact(ContactInfo(CONTACT_TYPE.BUSINESS, CONTACT_MEDIUM.EMAIL, "jsmith@email.com"))
passengers_chosen = [p1]
# Chose the legs for the journey
legs = [fares_result.results.legs.leg[0].legSolutions.legSolution[0]]
# Select fares chosen
fares = [fares_result.results.fareInformation.prices.pointToPointPrice[0]]
# Select passengers for the booking
passengers = [p1]
# Run booking request
booking_result = sc.create_booking_from_response(legs, fares, passengers)
print booking_result.toxml()
# =======================================================
# =============== Booking From Python ===================
# =======================================================
p1 = Passenger(
id="PAX_SPEC_0",
age=40,
first_name="Jane",
last_name="Smith")
p1.add_contact(ContactInfo(CONTACT_TYPE.UNKNOWN, CONTACT_MEDIUM.PHONE, "123456789"))
p1.add_contact(ContactInfo(CONTACT_TYPE.BUSINESS, CONTACT_MEDIUM.PHONE, "123456789"))
p1.add_contact(ContactInfo(CONTACT_TYPE.BUSINESS, CONTACT_MEDIUM.EMAIL, "jsmith@email.com"))
ts1 = TravelSegment(
id = "LS_1_1_TS_0",
sequence = 0,
origin = "GBRDG",
destination = "GBQQM",
departure = "2015-12-07T06:15:00",
arrival = "2015-12-07T09:38:00",
designator = "XC3040",
marketing_carrier = "CrossCountry",
operating_carrier = "CrossCountry",
equipment_type = "ICY",
equipment_type_str = "Inter-City")
leg1 = Leg(
id="LS_1_1",
travel_segments=[ts1])
fc1 = FareCode(
code="IXC-FOS-00700-STD-1",
service_class="FIRST",
travel_segment_id = "LS_1_1_TS_0",
cabin_class="First",
fare_display_name="Anytime Single (1st Class)")
# Creating passenger reference with one fare code (As there is 1 travel segment)
pr1 = PassengerReference(p1, PASSENGER_TYPE.A, [fc1])
# The FarePrice breakdown for the total ticketable fare cost
price1 = FarePrice(319.52, "TICKET", "USD")
tf1 = TicketableFare(
price= 319.52,
prices = [price1],
currency="GBP",
passenger_references=[pr1])
f1 = FareTotal(
id = "PRICE_P_1_23",
currency = "GBP",
price = 319.52,
expiration = "2015-10-27T15:50:33Z",
ticketable_fares = [tf1],
legs = [leg1])
fares = [f1]
passengers = [p1]
# Run booking request
booking_result = sc.create_booking(fares, passengers)
# View results
print booking_result.requestStatus.success # True
print booking_result.recordLocator # B-HACKTRAIN-IKS000262
print booking_result.lastHoldDateTime # 2015-11-15T15:49:09Z
# Store record locator to add payment, add ticket option, and confirm booking
# See the other examples for this
record_locator = booking_result.recordLocator
# =======================================================
# ==================== Add Payment ======================
# =======================================================
b = BillingAddress(
address1="9 Broad Court, Long Acre",
city="London",
zip_code="WC2B 5QN",
country="GB",
type=ADDRESS_TYPE.BUSINESS)
p = PaymentMethod(
record_locator=record_locator,
payment_form="CA",
payment_form_type=PAYMENT_TYPE.CREDIT_CARD,
card_number="5425232820001308",
card_type="CA",
card_holder_first_name="Jane",
card_holder_last_name="Smith",
expiration_year=2016,
expiration_month=12,
card_validation_number="123",
amount=198.20,
currency="GBP",
customer_ip_address="1.1.1.1",
billing_address=b)
payment_response = sc.add_payment(p)
print payment_response.requestStatus.success # True
print payment_response.paymentToken # Nl6qpzWfQiylKDaExw2W/g==
payment_token = payment_response.paymentToken
# =======================================================
# ==================== Add Delivery =====================
# =======================================================
to1 = TicketOption(
TICKET_DELIVERY_OPTION.VENDING_MACHINE,
"GBP",
0.00)
bu = BookingUpdate(
record_locator=record_locator,
ticket_option=to1)
booking_update = sc.update_booking(bu)
print booking_update.requestStatus.success # True
# =======================================================
# =================== Confirm Booking ===================
# =======================================================
b = BookingConfirmation(
record_locator=record_locator,
confirmation_type=CONFIRMATION_TYPE.CREDIT_CARD,
card_number="5425232820001308",
expiration_year=2016,
expiration_month=12,
card_holder_first_name="Jonathan",
card_holder_last_name="Harrah")
booking_confirm = sc.confirm_booking(b)
print booking_confirm.requestStatus.success # True