Skip to content

Latest commit

 

History

History
116 lines (90 loc) · 6.64 KB

README.md

File metadata and controls

116 lines (90 loc) · 6.64 KB

Payments

(bookings.payments)

Overview

Available Operations

create

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.

Example Usage

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();

Standalone function

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();

Parameters

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.

Response

Promise<operations.CreateBookingPaymentResponse>

Errors

Error Type Status Code Content Type
errors.APIError 4XX, 5XX */*