Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 2ffa954

Browse files
author
Sasha Gerrand
committed
Add booking example for adult and infant
Associating an infant passenger with the relevant adult passenger can be complicated, so providing a worked example of how to do this could be useful.
1 parent 907d4a8 commit 2ffa954

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
from datetime import date
2+
3+
from duffel_api import Duffel
4+
5+
6+
if __name__ == "__main__":
7+
print("Duffel Flights API - book with adult and infant example")
8+
client = Duffel()
9+
departure_date = date.today().replace(date.today().year + 1)
10+
slices = [
11+
{
12+
"origin": "LHR",
13+
"destination": "STN",
14+
"departure_date": departure_date.strftime("%Y-%m-%d"),
15+
},
16+
]
17+
offer_request = (
18+
client.offer_requests.create()
19+
.passengers(
20+
[{"type": "adult"}, {"age": 1}, {"age": (date.today().year - 2003)}]
21+
)
22+
.slices(slices)
23+
.execute()
24+
)
25+
26+
print("Created offer request: %s" % (offer_request.id))
27+
28+
offers = client.offers.list(offer_request.id)
29+
offers_list = list(enumerate(offers))
30+
31+
print("Got %d offers" % len(offers_list))
32+
33+
selected_offer = offers_list[0][1]
34+
35+
print("Selected offer %s to book" % (selected_offer.id))
36+
37+
priced_offer = client.offers.get(selected_offer.id)
38+
39+
print(
40+
"The final price for offer %s is %s (%s)"
41+
% (priced_offer.id, priced_offer.total_amount, priced_offer.total_currency)
42+
)
43+
44+
payments = [
45+
{
46+
"currency": selected_offer.total_currency,
47+
"amount": priced_offer.total_amount,
48+
"type": "balance",
49+
}
50+
]
51+
passengers = [
52+
{
53+
"born_on": "1976-01-21",
54+
"email": "[email protected]",
55+
"family_name": "Corde",
56+
"gender": "f",
57+
"given_name": "Conelia",
58+
"id": offer_request.passengers[0].id,
59+
"infant_passenger_id": offer_request.passengers[1].id,
60+
"phone_number": "+442080160508",
61+
"title": "ms",
62+
},
63+
{
64+
"born_on": date.today().replace(date.today().year - 1).strftime("%Y-%m-%d"),
65+
"email": "[email protected]",
66+
"family_name": "Corde",
67+
"gender": "f",
68+
"given_name": "Baby",
69+
"id": offer_request.passengers[1].id,
70+
"phone_number": "+442080160508",
71+
"title": "miss",
72+
},
73+
{
74+
"born_on": "2003-10-24",
75+
"email": "[email protected]",
76+
"family_name": "Corde",
77+
"gender": "m",
78+
"given_name": "Constantine",
79+
"id": offer_request.passengers[2].id,
80+
"phone_number": "+442080160508",
81+
"title": "mr",
82+
},
83+
]
84+
85+
order = (
86+
client.orders.create()
87+
.payments(payments)
88+
.passengers(passengers)
89+
.selected_offers([selected_offer.id])
90+
.execute()
91+
)
92+
93+
print(
94+
"Created order %s with booking reference %s"
95+
% (order.id, order.booking_reference)
96+
)
97+
98+
order_cancellation = client.order_cancellations.create(order.id)
99+
100+
print(
101+
"Requested refund quote for order %s – %s (%s) is available"
102+
% (
103+
order.id,
104+
order_cancellation.refund_amount,
105+
order_cancellation.refund_currency,
106+
)
107+
)
108+
109+
client.order_cancellations.confirm(order_cancellation.id)
110+
111+
print("Confirmed refund quote for order %s" % (order.id))

0 commit comments

Comments
 (0)