Skip to main content

Cancel VietJet Journey

Overview

This flow demonstrates how to cancel a journey on VietJet booking.

Important: VJ chỉ hủy từng chặng (journey), không hủy toàn bộ booking.

API Endpoint

POST /api/v1/services/booking/v1/huy-hanh-trinh

Request Body

Preview Mode (Calculate cancellation fee)

{
"ve_id": 293,
"index_chang_bay_huy": 0,
"tong_tien": 0,
"xac_nhan": ""
}

Confirm Mode (Execute cancellation)

{
"ve_id": 293,
"index_chang_bay_huy": 0,
"tong_tien": 1464300,
"xac_nhan": "y"
}

Parameters

ParameterTypeRequiredDescription
ve_idnumberYesBooking ID
index_chang_bay_huynumberYesJourney index to cancel (0-based)
tong_tiennumberYesCancellation fee (0 for preview)
xac_nhanstringYes"" = preview, "y" = confirm

Flow Steps

1. Get Booking Details

  • Retrieves booking information
  • Check total journeys available
  • API: GET /api/v1/services/booking/v1/thong-tin-ve/{ve_id}

2. Preview Cancellation Fee

  • Calculate cancellation fee
  • Request with xac_nhan=""
  • API: POST /huy-hanh-trinh (preview mode)

3. Confirm Cancellation

  • Execute cancellation with fee from preview
  • Request with xac_nhan="y"
  • API: POST /huy-hanh-trinh (confirm mode)

VJ API Details

Preview (Quotation)

PUT /quotations?httpMethod=PUT&requestURI=reservations/{key}/journeys/{journeyKey}

Confirm (Execute)

PUT /reservations/{key}/journeys/{journeyKey}

Journey object với reservationStatus.cancelled = true

Response

Preview Response

{
"status": "success",
"message": "Phí hủy hành trình",
"data": {
"tong_tien": 756000,
"phi_thay_doi": 756000
},
"code": 200
}

Confirm Response

{
"status": "success",
"message": "Huỷ hành trình thành công",
"data": true
}

Example Usage

Using Makefile

# Cancel journey index 0 for booking ID 293
make cancel-vj-journey ID=293 INDEX=0

# Cancel with PNR
make cancel-vj-journey PNR=A3SFNZ INDEX=0

# Cancel first journey (default index 0)
make cancel-vj-journey ID=293

Using Node.js

# Cancel journey index 1
node index.js cancel-vj-journey 293 1

# Cancel with PNR
node index.js cancel-vj-journey A3SFNZ 0

Using in Code

const cancelVJJourney = require('./flows/cancel-vj-journey');

// Cancel first journey (index 0)
await cancelVJJourney(CONFIG, STATE, reporter, 0);

// Cancel second journey (index 1)
await cancelVJJourney(CONFIG, STATE, reporter, 1);

Notes

VJ Cancel Journey Limitations:

  • ✅ Hủy từng chặng (individual journeys)
  • ❌ KHÔNG hủy toàn bộ booking
  • ✅ Support preview mode (calculate fee first)
  • ✅ Re-preview before confirm (prevent balance mismatch)

Multi-Journey Booking Example:

Booking: SGN → HAN → SGN (2 journeys)
- Journey 0: SGN → HAN (index_chang_bay_huy = 0)
- Journey 1: HAN → SGN (index_chang_bay_huy = 1)

Cancel journey 0 → Còn lại journey 1

Cancellation Fee:

  • Fee tính từ VJ quotations API
  • Can be 0 VNĐ (free) or có phí
  • Always re-preview to get fresh pricing

Error Handling

Common Errors:

Journey không tồn tại:

{
"status": "error",
"message": "Chặng bay muốn hủy không tồn tại (index 2)"
}

Booking đã hủy:

{
"status": "error",
"message": "Vé đã huỷ không thể hủy hành trình!"
}

Testing

To test this flow:

cd st-booking-examples
make cancel-vj-journey ID=293 INDEX=0