コード スニペット

次のいずれかのパスカテゴリを選択して、使用方法の詳細をご覧ください。


このセクションでは、搭乗券のコード スニペットについて説明します。次のクラスとオブジェクトを扱います。

JSON FlightClass

FlightClass を定義したら、次の REST URI に対する POST リクエストを行って挿入します。

https://walletobjects.googleapis.com/walletobjects/v1/flightClass

strict=true パラメータを REST URI に追加して厳密なエラー解析を有効にし、重複している ID フィールドなどの追加のエラーを検出します。

https://walletobjects.googleapis.com/walletobjects/v1/flightClass?strict=true

次の例は、FlightClass を表す JSON リソースを示しています。JSON は POST リクエストの本文に含めて送信する必要があります。次のコードサンプルは、FlightClass を定義して挿入する方法を具体的に示しています。

リソース

{
    "kind": "walletobjects#flightClass",
    "id": string,
    "issuerName": string,
    "reviewStatus": string,
    "localScheduledDepartureDateTime": string,
    "flightHeader": {
        "kind": "walletobjects#flightHeader",
        "carrier": {
            "kind": "walletobjects#flightCarrier",
            "carrierIataCode": string,
            "airlineName": {
                "kind": "walletobjects#localizedString",
                "translatedValues": [{
                    "kind": "walletobjects#translatedString",
                    "language": string,
                    "value": string
                }],
                "defaultValue": {
                    "kind": "walletobjects#translatedString",
                    "language": string,
                    "value": string
                }
            },
            "airlineLogo": {
                "kind": "walletobjects#image",
                "sourceUri": {
                    "kind": "walletobjects#uri",
                    "uri": string,
                    "description": string,
                    "localizedDescription": {
                        "kind": "walletobjects#localizedString",
                        "translatedValues": [{
                            "kind": "walletobjects#translatedString",
                            "language": string,
                            "value": string
                        }],
                        "defaultValue": {
                            "kind": "walletobjects#translatedString",
                            "language": string,
                            "value": string
                        }
                    }
                }
            },
            "airlineAllianceLogo": {
                "kind": "walletobjects#image",
                "sourceUri": {
                    "kind": "walletobjects#uri",
                    "uri": string,
                    "description": string,
                    "localizedDescription": {
                        "kind": "walletobjects#localizedString",
                        "translatedValues": [{
                            "kind": "walletobjects#translatedString",
                            "language": string,
                            "value": string
                        }],
                        "defaultValue": {
                            "kind": "walletobjects#translatedString",
                            "language": string,
                            "value": string
                        }
                    }
                }
            }
        },
        "flightNumber": string
    },
    "origin": {
        "kind": "walletobjects#airportInfo",
        "airportIataCode": string,
        "terminal": string,
        "gate": string
    },
    "destination": {
        "kind": "walletobjects#airportInfo",
        "airportIataCode": string,
        "terminal": string,
        "gate": string
    }
}

Java

// Define the Image Module Data
List imageModuleData = new ArrayList();

ImageModuleData image = new ImageModuleData().setMainImage(
    new Image().setSourceUri(
        new ImageUri().setUri("http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg")));

imageModuleData.add(image);

// Define Links Module Data
List uris = new ArrayList();
Uri uri1 = new Uri().setDescription("Nearby Locations").setUri("http://maps.google.com/?q=google");
Uri uri2 = new Uri().setDescription("Call Customer Service").setUri("tel:6505555555");

uris.add(uri1);
uris.add(uri2);

LinksModuleData linksModuleData = new LinksModuleData().setUris(uris);

// Define Text Areas
List textModulesData = new ArrayList();

TextModuleData details = new TextModuleData().setHeader("Custom Flight Details").setBody(
    "Baconrista flights has served snacks in-flight since its founding.");

textModulesData.add(details);

// Define Geofence locations
List locations = new ArrayList();
locations.add(new LatLongPoint().setLatitude(37.422601).setLongitude(
    -122.085286));
locations.add(new LatLongPoint().setLatitude(37.424354).setLongitude(
    -122.09508869999999));
locations.add(new LatLongPoint().setLatitude(40.7406578).setLongitude(
    -74.00208940000002));

// Define Flight details
CarrierData carrier = new CarrierData().setCarrierIataCode("LX");
FlightHeaderData flightHeaderData = new FlightHeaderData().setCarrier(carrier).setFlightNumber("123")
OriginData origin = new OriginData().setAirportIataCode("LAX").setGate("B2").setTerminal("1");
DestinationData destination = new DestinationData().setAirportIataCode("SFO").setGate("C3").setTerminal("2");

FlightClass wobClass = new FlightClass()
    .setId('2945482443380251551.ExampleFlightClass1')
    .setIssuerName("Baconrista Flights")
    .setReviewStatus("underReview")
    .setLinksModuleData(linksModuleData)
    .setImageModulesData(imageModuleData)
    .setTextModulesData(textModulesData)
     .setLocalScheduledDepartureDateTime("2027-03-05T06:30:00")
    .setFlightHeader(flightHeaderData)
    .setOrigin(origin)
    .setDestination(destination);

FlightClass response = client.flightclass().insert(wobClass).execute();

PHP

// A list of locations at which the Wallet Class can be used.
$locations = array(
    array(
        'kind' => 'walletobjects#latLongPoint',
        'latitude' => 37.424015499999996,
        'longitude' => -122.09259560000001
    ),
    array(
        'kind' => 'walletobjects#latLongPoint',
        'latitude' => 37.424354,
        'longitude' => -122.09508869999999
    ),
    array(
        'kind' => 'walletobjects#latLongPoint',
        'latitude' => 37.7901435,
        'longitude' => -122.39026709999997
    ),
    array(
        'kind' => 'walletobjects#latLongPoint',
        'latitude' => 40.7406578,
        'longitude' => -74.00208940000002
    )
);
// Source uri of title image.
$uriTitleImageInstance = new Google_Service_Walletobjects_ImageUri();
$imageTitleImageInstance = new Google_Service_Walletobjects_Image();
$uriTitleImageInstance->setUri(
    'http://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
);
$imageTitleImageInstance->setSourceUri($uriTitleImageInstance);
// Define text module data.
$textModulesData = array(
    array(
        'header' => 'Custom Flight Details',
        'body' => 'Baconrista flights has served snacks in-flight since its founding.'
    )
);
// Define links module data.
$linksModuleData = new Google_Service_Walletobjects_LinksModuleData();
$uris = array (
    array(
        'uri' => 'http://maps.google.com/map?q=google',
        'kind' => 'walletobjecs#uri',
        'description' => 'Nearby Locations'
    ),
    array(
        'uri' => 'tel:6505555555',
        'kind' => 'walletobjecs#uri',
        'description' => 'Call Customer Service'
    )
);
$linksModuleData->setUris($uris);

$uriModuleImageInstance = new Google_Service_Walletobjects_ImageUri();
$uriModuleImageInstance->setUri(
    'http://farm8.staticflickr.com/7401/11177116434_d8e600bba6_o.jpg'
);
$uriModuleImageInstance->setDescription('Flights perks);
$imageModuleImageInstance = new Google_Service_Walletobjects_Image();
$imageModuleImageInstance->setSourceUri($uriModuleImageInstance);
$imagesModuleData = new Google_Service_Walletobjects_ImageModuleData();
$imagesModuleData->setMainImage($imageModuleImageInstance);
$imagesModuleDataArr = array ($imagesModuleData);

// Define Flight details
$carrier = array( 'carrierIataCode' => 'LX' );
$flightHeaderData = array(
    'carrier' => $carrier,
    'flightNumber' => '123'
);
$origin = array(
    'airportIataCode' => 'LAX',
    'gate' => 'B2',
    'terminal' => '1'
);
$destination = array(
    'airportIataCode' => 'SFO',
    'gate' => 'C1',
    'terminal' => '2'
);

// Create wallet class.
$wobClass = new Google_Service_Walletobjects_FlightClass();
$flightClass->setId('2945482443380251551.FlightClass');
$wobClass->setIssuerName('Baconrista Flights');
$wobClass->setLinksModuleData($linksModuleData);
$wobClass->setTextModulesData($textModulesData);
$wobClass->setImageModulesData($imagesModuleDataArr);
$wobClass->setReviewStatus('underReview');
$wobClass->setLocations($locations);
$wobClass->setLocalScheduledDepartureDateTime("2027-03-05T06:30:00")
$wobClass->setFlightHeader($flightHeaderData)
$wobClass->setOrigin($origin)
$wobClass->setDestination($destination);

$service->flightclass->insert($wobClass);

Python

api_object = generate_flight_class(
      '1234567', 'ExampleFlightClass')
api_request = service.flightclass().insert(body=api_object)
api_response = api_request.execute()

def generate_flight_class(issuer_id, class_id):
  flight_class = {
      'kind': 'walletobjects#flightClass',
      'id': '%s.%s' % (issuer_id, class_id),
      'issuerName': 'Baconrista Flights',
      'locations': [{
          'kind': 'walletobjects#latLongPoint',
          'latitude': 37.424015499999996,
          'longitude': -122.09259560000001
          },{
          'kind': 'walletobjects#latLongPoint',
          'latitude': 37.424354,
          'longitude': -122.09508869999999
          },{
          'kind': 'walletobjects#latLongPoint',
          'latitude': 37.7901435,
          'longitude': -122.39026709999997
          },{
          'kind': 'walletobjects#latLongPoint',
          'latitude': 40.7406578,
          'longitude': -74.00208940000002
      }],
      'reviewStatus': 'underReview',
      'review': {
          'comments': 'Real auto approval by system'
      },
      'textModulesData': [
        {
          'header': 'Custom Flight Details',
          'body': 'Baconrista flights has served snacks in-flight since its founding.'
         }
       ],
      'linksModuleData': {
        'uris': [
          {
            'kind': 'walletobjects#uri',
            'uri': 'http://maps.google.com/map?q=google',
            'description': 'Nearby Locations'
          },{
            'kind': 'walletobjects#uri',
            'uri': 'tel:6505555555',
            'description': 'Call Customer Service'
          }]
      },
      'imageModulesData': [
        {
          'mainImage': {
            'kind': 'walletobjects#image',
            'sourceUri': {
              'kind': 'walletobjects#uri',
              'uri':  'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg',
              'description': 'Flight perks'
            }
          }
        }
      ],
      'localScheduledDepartureDateTime' : '2027-03-05T06:30:00',
      'flightHeader' : {
        'carrier' : {
          'carrierIataCode' : 'LX'
        },
        'flightNumber' : '123'
      },
      'origin' : {
        'airportIataCode' : 'LAX',
        'gate' : 'A1',
        'terminal' : '1'
      },
      'destination' : {
        'airportIataCode' : 'SFO',
        'gate' : 'C3',
        'terminal' : '2'
      },
    }
  return flight_class

JSON FlightObject

次のサンプルでは、FlightObject を定義します。

リソース

{
    "kind": "walletobjects#flightObject",
    "id": string,
    "classId": string,
    "state": string,
    "passengerName": string,
    "boardingAndSeatingInfo": {
        "kind": "walletobjects#boardingAndSeatingInfo",
        "boardingGroup": string,
        "seatNumber": string,
        "boardingPosition": string,
        "sequenceNumber": string,
        "seatClass": string,
        "boardingPrivilegeImage": {
            "kind": "walletobjects#image",
            "sourceUri": {
                "kind": "walletobjects#uri",
                "uri": string,
                "description": string,
                "localizedDescription": {
                    "kind": "walletobjects#localizedString",
                    "translatedValues": [{
                        "kind": "walletobjects#translatedString",
                        "language": string,
                        "value": string
                    }],
                    "defaultValue": {
                        "kind": "walletobjects#translatedString",
                        "language": string,
                        "value": string
                    }
                }
            }
        },
        "boardingDoor": string
    },
    "reservationInfo": {
        "kind": "walletobjects#reservationInfo",
        "confirmationCode": string,
        "eticketNumber": string,
        "frequentFlyerInfo": {
            "kind": "walletobjects#frequentFlyerInfo",
            "frequentFlyerProgramName": {
                "kind": "walletobjects#localizedString",
                "translatedValues": [{
                    "kind": "walletobjects#translatedString",
                    "language": string,
                    "value": string
                }],
                "defaultValue": {
                    "kind": "walletobjects#translatedString",
                    "language": string,
                    "value": string
                }
            },
            "frequentFlyerNumber": string
        }
    }
}

Java

// Define Boarding and Seating Info
BoardingAndSeatingInfo boardingAndSeatingInfo = new BoardingAndSeatingInfo().setSeatNumber("42").setBoardingGroup('B');

// Define Reservation Info
ReservationInfo reservationInfo = new ReservationInfo().setConfirmationCode("42aQw");

// Define Wallet Object
FlightObject object = new FlightObject()
	.setClassId('2945482443380251551.ExampleFlightClass1')
    .setId('2945482443380251551.ExampleFlightObject1')
    .setState("active")
    .setPassengerName("Sir Bacon the IV")
    .setBoardingAndSeatingInfo(boardingAndSeatingInfo)
    .setReservationInfo(reservationInfo);

PHP

// Define Boarding and Seating Info
$boardingAndSeatingInfo = new BoardingAndSeatingInfo();
$boardingAndSeatingInfo->setSeatNumber("42");
$boardingAndSeatingInfo->setBoardingGroup('B');

// Define Reservation Info
$reservationInfo = new ReservationInfo()
$reservationInfo->setConfirmationCode("42aQw");

// Create wallet object.
$flightObject = new Google_Service_Walletobjects_FlightObject();
$flightObject->setClassId('2945482443380251551.FlightClass');
$flightObject->setId('2945482443380251551.FlightObject');
$flightObject->setState('active');
$flightObject->setPassengerName("Sir Bacon the IV");
$flightObject->setBoardingAndSeatingInfo($boardingAndSeatingInfo);
$flightObject->setReservationInfo($reservationInfo);

Python

flight_object = {
      'kind': 'walletobjects#flightObject',
      'classId': '1234567.ExampleFlightClass',
      'id': '1234567.ExampleFlightObject',
      'state': 'active',
      'passengerName' : 'Sir Bacon the IV',
      'boardingAndSeatingInfo' : {
        'seatNumber' : '42',
        'boardingGroup' : 'B'
      },
      'reservationInfo' : {
        'confirmationCode' : '42aQw'
      }
  }

FlightObject を挿入する方法は 2 つあります。

1 つ目の方法は、次の REST URI に対して(定義されたオブジェクトを本文に含めた)POST リクエストを行うことです。

https://walletobjects.googleapis.com/walletobjects/v1/flightObject

2 つ目の方法は、FlightObject 定義から JSON Web Token(JWT)を作成し、その JWT を [Google Pay に保存] ボタンに配置することです。詳しくは、REST API にアクセスするをご覧ください。

Android API を使用した FlightObject の追加

Android API を使用した FlightObjects の追加は、現在利用できません。

JWT リンクとインテント メソッドを使用するの説明に従って、ACTION_VIEW インテントで JWT リンクを呼び出すことで、アプリから REST API を使用できます。

複数の乗客を保存するボタン

[Google Pay に保存] ボタンまたはウェブリンクを 1 回クリックするだけで、同じフライト区間または複数のフライト区間に、複数の乗客を保存できます。

署名する JSON Web Token(JWT)の配列に複数のパスを含めます。以下では、2 つの例を紹介します(詳細は、複数のパスを保存するボタンの作成をご覧ください)。

  1. この例では、同じパスのオブジェクトを 1 つの JWT で保存しています。事前に挿入されたフライトクラスとオブジェクトを使用して、各オブジェクトの ID のみを送信します。classId プロパティは必須ではありません。ここでは、説明のために使用しています。

    {
       "aud": "google",
       "origins": [],
       "iss": "your_iam_account@appspot.gserviceaccount.com",
       "iat": 1534891254,
       "typ": "savetowallet",
       "payload": {
           "flightObjects": [
               {
                   "classId": "<my_issuer_id>.FlightClass_A",
                   "id": "<my_issuer_id>.FlightObject_A_01"
               },
               {
                   "classId": "<my_issuer_id>.FlightClass_A",
                   "id": "<my_issuer_id>.FlightObject_A_02"
               }
           ]
       }
    }
  2. この例では、クラスだけでなく、このクラスを参照する複数のオブジェクトを定義しています。ユーザーがパスを保存すると、クラスとオブジェクトの両方が挿入されます。

    {
        "aud": "google",
        "origins": [
            "http://localhost:8080"
        ],
        "iss": "s2googlepay-api@sunlit-pixel-197421.google.com.iam.gserviceaccount.com",
        "iat": 1536886148,
        "typ": "savetoandroidpay",
        "payload": {
            "flightObjects": [
                {
                    "classId": "<my_issuer_id>.FlightClass_A",
                    "state": "active",
                    "passengerName": "test name adHoc",
                    "id": "<my_issuer_id>.FlightObject_A",
                    "reservationInfo": {
                        "confirmationCode": "testcode"
                    }
                },
                {
                    "classId": "<my_issuer_id>.FlightClass_A",
                    "state": "active",
                    "passengerName": "test name",
                    "id": "<my_issuer_id>.flight_multi_0913-obj01-copy",
                    "reservationInfo": {
                        "confirmationCode": "testcode"
                    }
                }
            ],
            "flightClasses": [
                {
                    "origin": {
                        "terminal": "2",
                        "gate": "A1",
                        "kind": "walletobjects#airportInfo",
                        "airportIataCode": "SFO"
                    },
                    "kind": "walletobjects#flightClass",
                    "reviewStatus": "underReview",
                    "destination": {
                        "terminal": "1",
                        "gate": "B3",
                        "kind": "walletobjects#airportInfo",
                        "airportIataCode": "TPE"
                    },
                    "id": "<my_issuer_id>.FlightClass_A",
                    "flightHeader": {
                        "carrier": {
                            "carrierIataCode": "BR"
                        },
                        "flightNumber": "123"
                    },
                    "localScheduledDepartureDateTime": "2027-03-05T06:30:00",
                    "issuerName": "Baconrista Airlines"
                }
            ]
        }
    }