(bookings.payments)
- create - Pay for a Booking
A payment is an attempt to pay for the booking, which will confirm the booking for the user and enable them to get their tickets.
import { TrainTravelSDK } from "train-travel-sdk";
const trainTravelSDK = new TrainTravelSDK({
oAuth2: process.env["TRAINTRAVELSDK_O_AUTH2"] ?? "",
});
async function run() {
const result = await trainTravelSDK.bookings.payments.create({
bookingId: "1725ff48-ab45-4bb5-9d02-88745177dedb",
bookingPayment: {
amount: 49.99,
currency: "gbp",
source: {
name: "J. Doe",
number: "4242424242424242",
cvc: "123",
expMonth: 12,
expYear: 2025,
addressLine1: "123 Fake Street",
addressLine2: "4th Floor",
addressCity: "London",
addressCountry: "gb",
addressPostCode: "N12 9XX",
},
},
});
// Handle the result
console.log(result);
}
run();
The standalone function version of this method:
import { TrainTravelSDKCore } from "train-travel-sdk/core.js";
import { bookingsPaymentsCreate } from "train-travel-sdk/funcs/bookingsPaymentsCreate.js";
// Use `TrainTravelSDKCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const trainTravelSDK = new TrainTravelSDKCore({
oAuth2: process.env["TRAINTRAVELSDK_O_AUTH2"] ?? "",
});
async function run() {
const res = await bookingsPaymentsCreate(trainTravelSDK, {
bookingId: "1725ff48-ab45-4bb5-9d02-88745177dedb",
bookingPayment: {
amount: 49.99,
currency: "gbp",
source: {
name: "J. Doe",
number: "4242424242424242",
cvc: "123",
expMonth: 12,
expYear: 2025,
addressLine1: "123 Fake Street",
addressLine2: "4th Floor",
addressCity: "London",
addressCountry: "gb",
addressPostCode: "N12 9XX",
},
},
});
if (!res.ok) {
throw res.error;
}
const { value: result } = res;
// Handle the result
console.log(result);
}
run();
Parameter | Type | Required | Description |
---|---|---|---|
request |
operations.CreateBookingPaymentRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body , are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Promise<operations.CreateBookingPaymentResponse>
Error Type | Status Code | Content Type |
---|---|---|
errors.APIError | 4XX, 5XX | */* |