Skip to main content
POST
/
checkout
/
sessions
C#
using Gr4vy;
using Gr4vy.Models.Components;
using NodaTime;
using System;
using System.Collections.Generic;

var sdk = new Gr4vySDK(
    id: "example",
    server: SDKConfig.Server.Sandbox,
    bearerAuthSource: Auth.WithToken(privateKey),
    merchantAccountId: "default"
);

var res = await sdk.CheckoutSessions.CreateAsync(checkoutSessionCreate: new CheckoutSessionCreate() {
    CartItems = new List<CartItem>() {
        new CartItem() {
            Name = "GoPro HD",
            Quantity = 2,
            UnitAmount = 1299,
            DiscountAmount = 0,
            TaxAmount = 0,
            ExternalIdentifier = "goprohd",
            Sku = "GPHD1078",
            ProductUrl = "https://example.com/catalog/go-pro-hd",
            ImageUrl = "https://example.com/images/go-pro-hd.jpg",
            Categories = new List<string>() {
                "camera",
                "travel",
                "gear",
            },
            ProductType = "physical",
            SellerCountry = "GB",
        },
        new CartItem() {
            Name = "GoPro HD",
            Quantity = 2,
            UnitAmount = 1299,
            DiscountAmount = 0,
            TaxAmount = 0,
            ExternalIdentifier = "goprohd",
            Sku = "GPHD1078",
            ProductUrl = "https://example.com/catalog/go-pro-hd",
            ImageUrl = "https://example.com/images/go-pro-hd.jpg",
            Categories = new List<string>() {
                "camera",
                "travel",
                "gear",
            },
            ProductType = "physical",
            SellerCountry = "GB",
        },
        new CartItem() {
            Name = "GoPro HD",
            Quantity = 2,
            UnitAmount = 1299,
            DiscountAmount = 0,
            TaxAmount = 0,
            ExternalIdentifier = "goprohd",
            Sku = "GPHD1078",
            ProductUrl = "https://example.com/catalog/go-pro-hd",
            ImageUrl = "https://example.com/images/go-pro-hd.jpg",
            Categories = new List<string>() {
                "camera",
                "travel",
                "gear",
            },
            ProductType = "physical",
            SellerCountry = "US",
        },
    },
    Metadata = new Dictionary<string, string>() {
        { "cohort", "cohort-a" },
        { "order_id", "order-12345" },
    },
    Buyer = new GuestBuyer() {
        DisplayName = "John Doe",
        ExternalIdentifier = "buyer-12345",
        BillingDetails = new BillingDetails() {
            FirstName = "John",
            LastName = "Doe",
            EmailAddress = "john@example.com",
            PhoneNumber = "+1234567890",
            Address = new Address() {
                City = "San Jose",
                Country = "US",
                PostalCode = "94560",
                State = "California",
                StateCode = "US-CA",
                HouseNumberOrName = "10",
                Line1 = "Stafford Appartments",
                Line2 = "29th Street",
                Organization = "Gr4vy",
            },
            TaxId = new TaxId() {
                Value = "12345678931",
                Kind = "ar.cuit",
            },
        },
        ShippingDetails = new ShippingDetailsCreate() {
            FirstName = "John",
            LastName = "Doe",
            EmailAddress = "john@example.com",
            PhoneNumber = "+1234567890",
            Address = new Address() {
                City = "San Jose",
                Country = "US",
                PostalCode = "94560",
                State = "California",
                StateCode = "US-CA",
                HouseNumberOrName = "10",
                Line1 = "Stafford Appartments",
                Line2 = "29th Street",
                Organization = "Gr4vy",
            },
        },
    },
    Airline = new Airline() {
        BookingCode = "X36Q9C",
        IsCardholderTraveling = true,
        IssuedAddress = "123 Broadway, New York",
        IssuedAt = System.DateTime.Parse("2013-07-16T19:23:00.000+00:00"),
        IssuingCarrierCode = "649",
        IssuingCarrierName = "Air Transat A.T. Inc",
        IssuingIataDesignator = "TS",
        IssuingIcaoCode = "TSC",
        Legs = new List<AirlineLeg>() {
            new AirlineLeg() {
                ArrivalAirport = "LAX",
                ArrivalAt = System.DateTime.Parse("2013-07-16T19:23:00.000+00:00"),
                ArrivalCity = "Los Angeles",
                ArrivalCountry = "US",
                CarrierCode = "649",
                CarrierName = "Air Transat A.T. Inc",
                IataDesignator = "TS",
                IcaoCode = "TSC",
                CouponNumber = "15885566",
                DepartureAirport = "LHR",
                DepartureAt = System.DateTime.Parse("2013-07-16T19:23:00.000+00:00"),
                DepartureCity = "London",
                DepartureCountry = "GB",
                DepartureTaxAmount = 1200,
                FareAmount = 129900,
                FareBasisCode = "FY",
                FeeAmount = 1200,
                FlightClass = "E",
                FlightNumber = "101",
                RouteType = "round_trip",
                SeatClass = "F",
                StopOver = false,
                TaxAmount = 1200,
            },
            new AirlineLeg() {
                ArrivalAirport = "LAX",
                ArrivalAt = System.DateTime.Parse("2013-07-16T19:23:00.000+00:00"),
                ArrivalCity = "Los Angeles",
                ArrivalCountry = "US",
                CarrierCode = "649",
                CarrierName = "Air Transat A.T. Inc",
                IataDesignator = "TS",
                IcaoCode = "TSC",
                CouponNumber = "15885566",
                DepartureAirport = "LHR",
                DepartureAt = System.DateTime.Parse("2013-07-16T19:23:00.000+00:00"),
                DepartureCity = "London",
                DepartureCountry = "GB",
                DepartureTaxAmount = 1200,
                FareAmount = 129900,
                FareBasisCode = "FY",
                FeeAmount = 1200,
                FlightClass = "E",
                FlightNumber = "101",
                RouteType = "round_trip",
                SeatClass = "F",
                StopOver = false,
                TaxAmount = 1200,
            },
            new AirlineLeg() {
                ArrivalAirport = "LAX",
                ArrivalAt = System.DateTime.Parse("2013-07-16T19:23:00.000+00:00"),
                ArrivalCity = "Los Angeles",
                ArrivalCountry = "US",
                CarrierCode = "649",
                CarrierName = "Air Transat A.T. Inc",
                IataDesignator = "TS",
                IcaoCode = "TSC",
                CouponNumber = "15885566",
                DepartureAirport = "LHR",
                DepartureAt = System.DateTime.Parse("2013-07-16T19:23:00.000+00:00"),
                DepartureCity = "London",
                DepartureCountry = "GB",
                DepartureTaxAmount = 1200,
                FareAmount = 129900,
                FareBasisCode = "FY",
                FeeAmount = 1200,
                FlightClass = "E",
                FlightNumber = "101",
                RouteType = "round_trip",
                SeatClass = "F",
                StopOver = false,
                TaxAmount = 1200,
            },
        },
        PassengerNameRecord = "JOHN L",
        Passengers = new List<AirlinePassenger>() {
            new AirlinePassenger() {
                AgeGroup = "adult",
                DateOfBirth = LocalDate.FromDateTime(System.DateTime.Parse("2013-07-16")),
                EmailAddress = "john@example.com",
                FirstName = "John",
                FrequentFlyerNumber = "15885566",
                LastName = "Luhn",
                PassportNumber = "11117700225",
                PhoneNumber = "+1234567890",
                TicketNumber = "BA1236699999",
                Title = "Mr.",
                CountryCode = "US",
            },
            new AirlinePassenger() {
                AgeGroup = "adult",
                DateOfBirth = LocalDate.FromDateTime(System.DateTime.Parse("2013-07-16")),
                EmailAddress = "john@example.com",
                FirstName = "John",
                FrequentFlyerNumber = "15885566",
                LastName = "Luhn",
                PassportNumber = "11117700225",
                PhoneNumber = "+1234567890",
                TicketNumber = "BA1236699999",
                Title = "Mr.",
                CountryCode = "US",
            },
        },
        ReservationSystem = "Amadeus",
        RestrictedTicket = false,
        TicketDeliveryMethod = "electronic",
        TicketNumber = "123-1234-151555",
        TravelAgencyCode = "12345",
        TravelAgencyInvoiceNumber = "EG15555155",
        TravelAgencyName = "ACME Agency",
        TravelAgencyPlanName = "B733",
    },
});

// handle response
{
  "id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
  "expires_at": "2023-11-07T05:31:56Z",
  "cart_items": [
    {
      "name": "<string>",
      "quantity": 123,
      "unit_amount": 49999999,
      "discount_amount": 0,
      "tax_amount": 0,
      "external_identifier": "goprohd",
      "sku": "GPHD1078",
      "upc": "012345678905",
      "product_url": "https://example.com/catalog/go-pro-hd",
      "image_url": "https://example.com/images/go-pro-hd.jpg",
      "categories": [
        "camera",
        "travel",
        "gear"
      ],
      "product_type": "physical",
      "seller_country": "US",
      "tax_exempt": false,
      "unit_of_measure": "feet",
      "commodity_code": "43211503",
      "description": "A brief description of an interesting item.",
      "duty_amount": 1299,
      "shipping_amount": 1299
    }
  ],
  "metadata": {
    "cohort": "cohort-a",
    "order_id": "order-12345"
  },
  "buyer": {
    "display_name": "John Doe",
    "external_identifier": "buyer-12345",
    "billing_details": {
      "first_name": "John",
      "last_name": "Doe",
      "email_address": "john@example.com",
      "phone_number": "+1234567890",
      "address": {
        "city": "San Jose",
        "country": "US",
        "postal_code": "94560",
        "state": "California",
        "state_code": "US-CA",
        "house_number_or_name": "10",
        "line1": "Stafford Appartments",
        "line2": "29th Street",
        "organization": "Gr4vy"
      },
      "tax_id": {
        "value": "<string>",
        "kind": "ae.trn"
      }
    },
    "account_number": "<string>",
    "shipping_details": {
      "first_name": "John",
      "last_name": "Doe",
      "email_address": "john@example.com",
      "phone_number": "+1234567890",
      "address": {
        "city": "San Jose",
        "country": "US",
        "postal_code": "94560",
        "state": "California",
        "state_code": "US-CA",
        "house_number_or_name": "10",
        "line1": "Stafford Appartments",
        "line2": "29th Street",
        "organization": "Gr4vy"
      }
    }
  },
  "airline": {
    "booking_code": "X36Q9C",
    "is_cardholder_traveling": true,
    "issued_address": "123 Broadway, New York",
    "issued_at": "2013-07-16T19:23:00.000+00:00",
    "issuing_carrier_code": "649",
    "issuing_carrier_name": "Air Transat A.T. Inc",
    "issuing_iata_designator": "TS",
    "issuing_icao_code": "TSC",
    "legs": [
      {
        "arrival_airport": "LAX",
        "arrival_at": "2013-07-16T19:23:00.000+00:00",
        "arrival_city": "Los Angeles",
        "arrival_country": "US",
        "carrier_code": "649",
        "carrier_name": "Air Transat A.T. Inc",
        "iata_designator": "TS",
        "icao_code": "TSC",
        "coupon_number": "15885566",
        "departure_airport": "LHR",
        "departure_at": "2013-07-16T19:23:00.000+00:00",
        "departure_city": "London",
        "departure_country": "GB",
        "departure_tax_amount": 1200,
        "fare_amount": 129900,
        "fare_basis_code": "FY",
        "fee_amount": 1200,
        "flight_class": "E",
        "flight_number": "101",
        "route_type": "round_trip",
        "seat_class": "F",
        "stop_over": false,
        "tax_amount": 1200
      }
    ],
    "passenger_name_record": "JOHN L",
    "passengers": [
      {
        "age_group": "adult",
        "date_of_birth": "2013-07-16",
        "email_address": "john@example.com",
        "first_name": "John",
        "frequent_flyer_number": "15885566",
        "last_name": "Luhn",
        "passport_number": "11117700225",
        "phone_number": "+1234567890",
        "ticket_number": "BA1236699999",
        "title": "Mr.",
        "country_code": "US"
      }
    ],
    "reservation_system": "Amadeus",
    "restricted_ticket": false,
    "ticket_delivery_method": "electronic",
    "ticket_number": "123-1234-151555",
    "travel_agency_code": "12345",
    "travel_agency_invoice_number": "EG15555155",
    "travel_agency_name": "ACME Agency",
    "travel_agency_plan_name": "B733"
  },
  "type": "checkout-session",
  "payment_method": {
    "type": "payment-method",
    "id": "ef9496d8-53a5-4aad-8ca2-00eb68334389",
    "details": {
      "bin": "411111",
      "card_country": "US",
      "card_type": "credit",
      "card_issuer_name": "Bank of America NA"
    },
    "label": "1234",
    "method": "card",
    "scheme": "visa",
    "fingerprint": "a50b85c200ee0795d6fd33a5c66f37a4564f554355c5b46a756aac485dd168a4"
  }
}
This endpoint requires the checkout-sessions.write scope.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Headers

x-gr4vy-merchant-account-id
string | null

The ID of the merchant account to use for this request.

Example:

"default"

Body

application/json
cart_items
CartItem · object[] | null

An array of cart items that represents the line items of a transaction.

metadata
Metadata · object

Any additional information about the transaction that you would like to store as key-value pairs. This data is passed to payment service providers that support it.

Example:
{
"cohort": "cohort-a",
"order_id": "order-12345"
}
buyer
GuestBuyer · object

Provide buyer details for the transaction. No buyer resource will be created on Gr4vy when used.

airline
Airline · object

The airline addendum data which describes the airline booking associated with this transaction.

expires_in
number
default:3600

The time in seconds when this checkout session expires.

Required range: 3600 <= x <= 86400

Response

Successful Response

id
string<uuid>
required

The ID for the checkout session.

Example:

"4137b1cf-39ac-42a8-bad6-1c680d5dab6b"

expires_at
string<date-time>
required

The date and time when this checkout session expires.

Example:

"2013-07-16T19:23:00.000+00:00"

cart_items
CartItem · object[] | null

An array of cart items that represents the line items of a transaction.

metadata
Metadata · object

Any additional information about the transaction that you would like to store as key-value pairs. This data is passed to payment service providers that support it.

Example:
{
"cohort": "cohort-a",
"order_id": "order-12345"
}
buyer
GuestBuyer · object

Provide buyer details for the transaction. No buyer resource will be created on Gr4vy when used.

airline
Airline · object

The airline addendum data which describes the airline booking associated with this transaction.

type
string
default:checkout-session

Always checkout-session

Allowed value: "checkout-session"
Example:

"checkout-session"

payment_method
CheckoutSessionPaymentMethod · object

Information about the payment method stored on the checkout session.