Membuat Class Kartu dan Objek Kartu

Hampir semua kartu yang dapat Anda berikan kepada pengguna akhir untuk disimpan di Google Wallet mereka ditentukan oleh dua komponen: Kelas Kartu dan Objek Kartu. Setiap kali memberikan kartu kepada pengguna, Anda memerlukan instance Class Kartu dan Objek Kartu, yang memberi tahu Google Wallet API jenis kartu apa yang harus dibuat, serta detail yang akan ditampilkan pada kartu, seperti nilai kartu voucher atau nama pemegang tiket.

Google Wallet API menyediakan kumpulan Class dan Objek Kartu yang telah ditentukan sebelumnya yang Anda buat instance-nya, lalu digunakan untuk membuat kartu yang diterbitkan untuk pengguna, seperti GiftCardClass dan GiftCardObject, GenericClass dan GenericObject, serta lainnya.

Setiap instance Objek Passes Class dan Passes Object didefinisikan sebagai objek JSON, yang memiliki serangkaian properti wajib dan opsional yang sesuai dengan kasus penggunaan tertentu yang dimaksudkan untuk jenis kartu tersebut.

Buat Kelas Kartu

Kelas Kartu dapat dianggap sebagai template bersama yang digunakan untuk membuat kartu. Class Kartu menentukan properti tertentu yang akan disertakan di semua kartu yang menggunakannya. Penerbit Kartu dapat membuat beberapa class, masing-masing dengan kumpulan properti khusus yang menentukan atribut seperti gaya dan tampilan, serta fitur tambahan seperti Smart Tap, serta Pendaftaran dan Login.

Kelas Kartu dapat dibuat menggunakan REST API Google Wallet, SDK Android Google Wallet, atau di Konsol Bisnis Google Wallet.

Untuk pengguna baru, Konsol Bisnis adalah cara termudah untuk mulai membuat Kelas Kartu, karena menyediakan antarmuka pengguna yang sederhana, tempat Anda dapat menentukan berbagai kolom Kelas Kartu pertama Anda dengan mengisi kolom formulir.

Untuk pengguna tingkat lanjut, membuat Class Kartu secara terprogram adalah pendekatan terbaik.

Menggunakan Konsol Bisnis Google Wallet

Untuk membuat Kelas Kartu di konsol Bisnis Google Wallet, lakukan langkah berikut:

  1. Buka Konsol Bisnis Google Pay dan Wallet, lalu login dengan Akun Penerbit Google Wallet API Anda.
  2. Di "Google Wallet API" klik "Kelola kartu" tombol.
  3. Di bagian 'Dapatkan akses publikasi', klik 'Buat kelas' tombol.
  4. Pilih jenis kartu dari dialog. Google Wallet menawarkan berbagai jenis kartu (Tiket Acara, Penawaran, Kartu Loyalitas, dll.). Untuk kasus penggunaan fleksibel, pilih "Generik" sebagai jenis kartu Anda.
  5. Isi nilai yang sesuai pada kolom yang wajib diisi.
  6. Klik 'Buat kelas' untuk menyimpan kelas.

Menggunakan REST API Google Wallet

Untuk membuat Kelas Kartu menggunakan REST API Google Wallet, kirim permintaan POST ke https://walletobjects.googleapis.com/walletobjects/v1/eventTicketClass. Untuk informasi selengkapnya, lihat dokumentasi referensi.

Java

Untuk memulai integrasi di Java, lihat contoh kode di GitHub.

/**
 * Create a class.
 *
 * @param issuerId The issuer ID being used for this request.
 * @param classSuffix Developer-defined unique ID for this pass class.
 * @return The pass class ID: "{issuerId}.{classSuffix}"
 */
public String createClass(String issuerId, String classSuffix) throws IOException {
  // Check if the class exists
  try {
    service.eventticketclass().get(String.format("%s.%s", issuerId, classSuffix)).execute();

    System.out.printf("Class %s.%s already exists!%n", issuerId, classSuffix);
    return String.format("%s.%s", issuerId, classSuffix);
  } catch (GoogleJsonResponseException ex) {
    if (ex.getStatusCode() != 404) {
      // Something else went wrong...
      ex.printStackTrace();
      return String.format("%s.%s", issuerId, classSuffix);
    }
  }

  // See link below for more information on required properties
  // https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass
  EventTicketClass newClass =
      new EventTicketClass()
          .setEventId(String.format("%s.%s", issuerId, classSuffix))
          .setEventName(
              new LocalizedString()
                  .setDefaultValue(
                      new TranslatedString().setLanguage("en-US").setValue("Event name")))
          .setId(String.format("%s.%s", issuerId, classSuffix))
          .setIssuerName("Issuer name")
          .setReviewStatus("UNDER_REVIEW");

  EventTicketClass response = service.eventticketclass().insert(newClass).execute();

  System.out.println("Class insert response");
  System.out.println(response.toPrettyString());

  return response.getId();
}

PHP

Untuk memulai integrasi di PHP, lihat contoh kode di GitHub.

/**
 * Create a class.
 *
 * @param string $issuerId The issuer ID being used for this request.
 * @param string $classSuffix Developer-defined unique ID for this pass class.
 *
 * @return string The pass class ID: "{$issuerId}.{$classSuffix}"
 */
public function createClass(string $issuerId, string $classSuffix)
{
  // Check if the class exists
  try {
    $this->service->eventticketclass->get("{$issuerId}.{$classSuffix}");

    print("Class {$issuerId}.{$classSuffix} already exists!");
    return "{$issuerId}.{$classSuffix}";
  } catch (Google\Service\Exception $ex) {
    if (empty($ex->getErrors()) || $ex->getErrors()[0]['reason'] != 'classNotFound') {
      // Something else went wrong...
      print_r($ex);
      return "{$issuerId}.{$classSuffix}";
    }
  }

  // See link below for more information on required properties
  // https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass
  $newClass = new EventTicketClass([
    'eventId' => "{$issuerId}.{$classSuffix}",
    'eventName' => new LocalizedString([
      'defaultValue' => new TranslatedString([
        'language' => 'en-US',
        'value' => 'Event name'
      ])
    ]),
    'id' => "{$issuerId}.{$classSuffix}",
    'issuerName' => 'Issuer name',
    'reviewStatus' => 'UNDER_REVIEW'
  ]);

  $response = $this->service->eventticketclass->insert($newClass);

  print "Class insert response\n";
  print_r($response);

  return $response->id;
}

Python

Untuk memulai integrasi Anda di Python, lihat referensi contoh kode di GitHub.

def create_class(self, issuer_id: str, class_suffix: str) -> str:
    """Create a class.

    Args:
        issuer_id (str): The issuer ID being used for this request.
        class_suffix (str): Developer-defined unique ID for this pass class.

    Returns:
        The pass class ID: f"{issuer_id}.{class_suffix}"
    """

    # Check if the class exists
    try:
        self.client.eventticketclass().get(resourceId=f'{issuer_id}.{class_suffix}').execute()
    except HttpError as e:
        if e.status_code != 404:
            # Something else went wrong...
            print(e.error_details)
            return f'{issuer_id}.{class_suffix}'
    else:
        print(f'Class {issuer_id}.{class_suffix} already exists!')
        return f'{issuer_id}.{class_suffix}'

    # See link below for more information on required properties
    # https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass
    new_class = {
        'eventId': f'{issuer_id}.{class_suffix}',
        'eventName': {
            'defaultValue': {
                'language': 'en-US',
                'value': 'Event name'
            }
        },
        'id': f'{issuer_id}.{class_suffix}',
        'issuerName': 'Issuer name',
        'reviewStatus': 'UNDER_REVIEW'
    }

    response = self.client.eventticketclass().insert(body=new_class).execute()

    print('Class insert response')
    print(response)

    return f'{issuer_id}.{class_suffix}'

C#

Untuk memulai integrasi Anda di C#, lihat referensi contoh kode di GitHub.

/// <summary>
/// Create a class.
/// </summary>
/// <param name="issuerId">The issuer ID being used for this request.</param>
/// <param name="classSuffix">Developer-defined unique ID for this pass class.</param>
/// <returns>The pass class ID: "{issuerId}.{classSuffix}"</returns>
public string CreateClass(string issuerId, string classSuffix)
{
  // Check if the class exists
  Stream responseStream = service.Eventticketclass
      .Get($"{issuerId}.{classSuffix}")
      .ExecuteAsStream();

  StreamReader responseReader = new StreamReader(responseStream);
  JObject jsonResponse = JObject.Parse(responseReader.ReadToEnd());

  if (!jsonResponse.ContainsKey("error"))
  {
    Console.WriteLine($"Class {issuerId}.{classSuffix} already exists!");
    return $"{issuerId}.{classSuffix}";
  }
  else if (jsonResponse["error"].Value<int>("code") != 404)
  {
    // Something else went wrong...
    Console.WriteLine(jsonResponse.ToString());
    return $"{issuerId}.{classSuffix}";
  }

  // See link below for more information on required properties
  // https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass
  EventTicketClass newClass = new EventTicketClass
  {
    EventId = $"{issuerId}.{classSuffix}",
    EventName = new LocalizedString
    {
      DefaultValue = new TranslatedString
      {
        Language = "en-US",
        Value = "Event name"
      }
    },
    Id = $"{issuerId}.{classSuffix}",
    IssuerName = "Issuer name",
    ReviewStatus = "UNDER_REVIEW"
  };

  responseStream = service.Eventticketclass
      .Insert(newClass)
      .ExecuteAsStream();

  responseReader = new StreamReader(responseStream);
  jsonResponse = JObject.Parse(responseReader.ReadToEnd());

  Console.WriteLine("Class insert response");
  Console.WriteLine(jsonResponse.ToString());

  return $"{issuerId}.{classSuffix}";
}

Node.js

Untuk memulai integrasi Anda di Node, lihat paket lengkap contoh kode di GitHub.

/**
 * Create a class.
 *
 * @param {string} issuerId The issuer ID being used for this request.
 * @param {string} classSuffix Developer-defined unique ID for this pass class.
 *
 * @returns {string} The pass class ID: `${issuerId}.${classSuffix}`
 */
async createClass(issuerId, classSuffix) {
  let response;

  // Check if the class exists
  try {
    response = await this.client.eventticketclass.get({
      resourceId: `${issuerId}.${classSuffix}`
    });

    console.log(`Class ${issuerId}.${classSuffix} already exists!`);

    return `${issuerId}.${classSuffix}`;
  } catch (err) {
    if (err.response && err.response.status !== 404) {
      // Something else went wrong...
      console.log(err);
      return `${issuerId}.${classSuffix}`;
    }
  }

  // See link below for more information on required properties
  // https://developers.google.com/wallet/tickets/events/rest/v1/eventticketclass
  let newClass = {
    'eventId': `${issuerId}.${classSuffix}`,
    'eventName': {
      'defaultValue': {
        'language': 'en-US',
        'value': 'Event name'
      }
    },
    'id': `${issuerId}.${classSuffix}`,
    'issuerName': 'Issuer name',
    'reviewStatus': 'UNDER_REVIEW'
  };

  response = await this.client.eventticketclass.insert({
    requestBody: newClass
  });

  console.log('Class insert response');
  console.log(response);

  return `${issuerId}.${classSuffix}`;
}

Go

Untuk memulai integrasi Anda di Go, lihat contoh kode lengkap kami di GitHub contoh kode di GitHub.

// Create a class.
func (d *demoEventticket) createClass(issuerId, classSuffix string) {
	eventticketClass := new(walletobjects.EventTicketClass)
	eventticketClass.Id = fmt.Sprintf("%s.%s", issuerId, classSuffix)
	eventticketClass.EventName = &walletobjects.LocalizedString{
		DefaultValue: &walletobjects.TranslatedString{
			Language: "en-us",
			Value:    "Event name",
		},
	}
	eventticketClass.IssuerName = "Issuer name"
	eventticketClass.ReviewStatus = "UNDER_REVIEW"
	res, err := d.service.Eventticketclass.Insert(eventticketClass).Do()
	if err != nil {
		log.Fatalf("Unable to insert class: %v", err)
	} else {
		fmt.Printf("Class insert id:\n%v\n", res.Id)
	}
}

Membuat Objek Kartu

Objek Kartu adalah instance Class Kartu. Untuk membuat Kartu Objek, Anda harus memberikan atribut berikut:

  • classId: id Class Kartu
  • id: ID unik untuk pelanggan Anda

    Lihat Template tata letak untuk informasi selengkapnya tentang bagaimana atribut-atribut ini direpresentasikan dalam tiket acara.

    Contoh kode untuk membuat Objek Kartu:

    Java

    Untuk memulai integrasi di Java, lihat contoh kode di GitHub.

    /**
     * Create an object.
     *
     * @param issuerId The issuer ID being used for this request.
     * @param classSuffix Developer-defined unique ID for this pass class.
     * @param objectSuffix Developer-defined unique ID for this pass object.
     * @return The pass object ID: "{issuerId}.{objectSuffix}"
     */
    public String createObject(String issuerId, String classSuffix, String objectSuffix)
        throws IOException {
      // Check if the object exists
      try {
        service.eventticketobject().get(String.format("%s.%s", issuerId, objectSuffix)).execute();
    
        System.out.printf("Object %s.%s already exists!%n", issuerId, objectSuffix);
        return String.format("%s.%s", issuerId, objectSuffix);
      } catch (GoogleJsonResponseException ex) {
        if (ex.getStatusCode() != 404) {
          // Something else went wrong...
          ex.printStackTrace();
          return String.format("%s.%s", issuerId, objectSuffix);
        }
      }
    
      // See link below for more information on required properties
      // https://developers.google.com/wallet/tickets/events/rest/v1/eventticketobject
      EventTicketObject newObject =
          new EventTicketObject()
              .setId(String.format("%s.%s", issuerId, objectSuffix))
              .setClassId(String.format("%s.%s", issuerId, classSuffix))
              .setState("ACTIVE")
              .setHeroImage(
                  new Image()
                      .setSourceUri(
                          new ImageUri()
                              .setUri(
                                  "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"))
                      .setContentDescription(
                          new LocalizedString()
                              .setDefaultValue(
                                  new TranslatedString()
                                      .setLanguage("en-US")
                                      .setValue("Hero image description"))))
              .setTextModulesData(
                      List.of(
                              new TextModuleData()
                                      .setHeader("Text module header")
                                      .setBody("Text module body")
                                      .setId("TEXT_MODULE_ID")))
              .setLinksModuleData(
                  new LinksModuleData()
                      .setUris(
                          Arrays.asList(
                              new Uri()
                                  .setUri("http://maps.google.com/")
                                  .setDescription("Link module URI description")
                                  .setId("LINK_MODULE_URI_ID"),
                              new Uri()
                                  .setUri("tel:6505555555")
                                  .setDescription("Link module tel description")
                                  .setId("LINK_MODULE_TEL_ID"))))
              .setImageModulesData(
                      List.of(
                              new ImageModuleData()
                                      .setMainImage(
                                              new Image()
                                                      .setSourceUri(
                                                              new ImageUri()
                                                                      .setUri(
                                                                              "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"))
                                                      .setContentDescription(
                                                              new LocalizedString()
                                                                      .setDefaultValue(
                                                                              new TranslatedString()
                                                                                      .setLanguage("en-US")
                                                                                      .setValue("Image module description"))))
                                      .setId("IMAGE_MODULE_ID")))
              .setBarcode(new Barcode().setType("QR_CODE").setValue("QR code value"))
              .setLocations(
                      List.of(
                              new LatLongPoint()
                                      .setLatitude(37.424015499999996)
                                      .setLongitude(-122.09259560000001)))
              .setSeatInfo(
                  new EventSeat()
                      .setSeat(
                          new LocalizedString()
                              .setDefaultValue(
                                  new TranslatedString().setLanguage("en-US").setValue("42")))
                      .setRow(
                          new LocalizedString()
                              .setDefaultValue(
                                  new TranslatedString().setLanguage("en-US").setValue("G3")))
                      .setSection(
                          new LocalizedString()
                              .setDefaultValue(
                                  new TranslatedString().setLanguage("en-US").setValue("5")))
                      .setGate(
                          new LocalizedString()
                              .setDefaultValue(
                                  new TranslatedString().setLanguage("en-US").setValue("A"))))
              .setTicketHolderName("Ticket holder name")
              .setTicketNumber("Ticket number");
    
      EventTicketObject response = service.eventticketobject().insert(newObject).execute();
    
      System.out.println("Object insert response");
      System.out.println(response.toPrettyString());
    
      return response.getId();
    }
    

    PHP

    Untuk memulai integrasi di PHP, lihat contoh kode di GitHub.

    /**
     * Create an object.
     *
     * @param string $issuerId The issuer ID being used for this request.
     * @param string $classSuffix Developer-defined unique ID for this pass class.
     * @param string $objectSuffix Developer-defined unique ID for this pass object.
     *
     * @return string The pass object ID: "{$issuerId}.{$objectSuffix}"
     */
    public function createObject(string $issuerId, string $classSuffix, string $objectSuffix)
    {
      // Check if the object exists
      try {
        $this->service->eventticketobject->get("{$issuerId}.{$objectSuffix}");
    
        print("Object {$issuerId}.{$objectSuffix} already exists!");
        return "{$issuerId}.{$objectSuffix}";
      } catch (Google\Service\Exception $ex) {
        if (empty($ex->getErrors()) || $ex->getErrors()[0]['reason'] != 'resourceNotFound') {
          // Something else went wrong...
          print_r($ex);
          return "{$issuerId}.{$objectSuffix}";
        }
      }
    
      // See link below for more information on required properties
      // https://developers.google.com/wallet/tickets/events/rest/v1/eventticketobject
      $newObject = new EventTicketObject([
        'id' => "{$issuerId}.{$objectSuffix}",
        'classId' => "{$issuerId}.{$classSuffix}",
        'state' => 'ACTIVE',
        'heroImage' => new Image([
          'sourceUri' => new ImageUri([
            'uri' => 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
          ]),
          'contentDescription' => new LocalizedString([
            'defaultValue' => new TranslatedString([
              'language' => 'en-US',
              'value' => 'Hero image description'
            ])
          ])
        ]),
        'textModulesData' => [
          new TextModuleData([
            'header' => 'Text module header',
            'body' => 'Text module body',
            'id' => 'TEXT_MODULE_ID'
          ])
        ],
        'linksModuleData' => new LinksModuleData([
          'uris' => [
            new Uri([
              'uri' => 'http://maps.google.com/',
              'description' => 'Link module URI description',
              'id' => 'LINK_MODULE_URI_ID'
            ]),
            new Uri([
              'uri' => 'tel:6505555555',
              'description' => 'Link module tel description',
              'id' => 'LINK_MODULE_TEL_ID'
            ])
          ]
        ]),
        'imageModulesData' => [
          new ImageModuleData([
            'mainImage' => new Image([
              'sourceUri' => new ImageUri([
                'uri' => 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
              ]),
              'contentDescription' => new LocalizedString([
                'defaultValue' => new TranslatedString([
                  'language' => 'en-US',
                  'value' => 'Image module description'
                ])
              ])
            ]),
            'id' => 'IMAGE_MODULE_ID'
          ])
        ],
        'barcode' => new Barcode([
          'type' => 'QR_CODE',
          'value' => 'QR code value'
        ]),
        'locations' => [
          new LatLongPoint([
            'latitude' => 37.424015499999996,
            'longitude' =>  -122.09259560000001
          ])
        ],
        'seatInfo' => new EventSeat([
          'seat' => new LocalizedString([
            'defaultValue' => new TranslatedString([
              'language' => 'en-US',
              'value' => '42'
            ])
          ]),
          'row' => new LocalizedString([
            'defaultValue' => new TranslatedString([
              'language' => 'en-US',
              'value' => 'G3'
            ])
          ]),
          'section' => new LocalizedString([
            'defaultValue' => new TranslatedString([
              'language' => 'en-US',
              'value' => '5'
            ])
          ]),
          'gate' => new LocalizedString([
            'defaultValue' => new TranslatedString([
              'language' => 'en-US',
              'value' => 'A'
            ])
          ])
        ]),
        'ticketHolderName' => 'Ticket holder name',
        'ticketNumber' => 'Ticket number'
      ]);
    
      $response = $this->service->eventticketobject->insert($newObject);
    
      print "Object insert response\n";
      print_r($response);
    
      return $response->id;
    }
    

    Python

    Untuk memulai integrasi Anda di Python, lihat referensi contoh kode di GitHub.

    def create_object(self, issuer_id: str, class_suffix: str,
                      object_suffix: str) -> str:
        """Create an object.
    
        Args:
            issuer_id (str): The issuer ID being used for this request.
            class_suffix (str): Developer-defined unique ID for the pass class.
            object_suffix (str): Developer-defined unique ID for the pass object.
    
        Returns:
            The pass object ID: f"{issuer_id}.{object_suffix}"
        """
    
        # Check if the object exists
        try:
            self.client.eventticketobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
        except HttpError as e:
            if e.status_code != 404:
                # Something else went wrong...
                print(e.error_details)
                return f'{issuer_id}.{object_suffix}'
        else:
            print(f'Object {issuer_id}.{object_suffix} already exists!')
            return f'{issuer_id}.{object_suffix}'
    
        # See link below for more information on required properties
        # https://developers.google.com/wallet/tickets/events/rest/v1/eventticketobject
        new_object = {
            'id': f'{issuer_id}.{object_suffix}',
            'classId': f'{issuer_id}.{class_suffix}',
            'state': 'ACTIVE',
            'heroImage': {
                'sourceUri': {
                    'uri':
                        'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
                },
                'contentDescription': {
                    'defaultValue': {
                        'language': 'en-US',
                        'value': 'Hero image description'
                    }
                }
            },
            'textModulesData': [{
                'header': 'Text module header',
                'body': 'Text module body',
                'id': 'TEXT_MODULE_ID'
            }],
            'linksModuleData': {
                'uris': [{
                    'uri': 'http://maps.google.com/',
                    'description': 'Link module URI description',
                    'id': 'LINK_MODULE_URI_ID'
                }, {
                    'uri': 'tel:6505555555',
                    'description': 'Link module tel description',
                    'id': 'LINK_MODULE_TEL_ID'
                }]
            },
            'imageModulesData': [{
                'mainImage': {
                    'sourceUri': {
                        'uri':
                            'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
                    },
                    'contentDescription': {
                        'defaultValue': {
                            'language': 'en-US',
                            'value': 'Image module description'
                        }
                    }
                },
                'id': 'IMAGE_MODULE_ID'
            }],
            'barcode': {
                'type': 'QR_CODE',
                'value': 'QR code'
            },
            'locations': [{
                'latitude': 37.424015499999996,
                'longitude': -122.09259560000001
            }],
            'seatInfo': {
                'seat': {
                    'defaultValue': {
                        'language': 'en-US',
                        'value': '42'
                    }
                },
                'row': {
                    'defaultValue': {
                        'language': 'en-US',
                        'value': 'G3'
                    }
                },
                'section': {
                    'defaultValue': {
                        'language': 'en-US',
                        'value': '5'
                    }
                },
                'gate': {
                    'defaultValue': {
                        'language': 'en-US',
                        'value': 'A'
                    }
                }
            },
            'ticketHolderName': 'Ticket holder name',
            'ticketNumber': 'Ticket number'
        }
    
        # Create the object
        response = self.client.eventticketobject().insert(body=new_object).execute()
    
        print('Object insert response')
        print(response)
    
        return f'{issuer_id}.{object_suffix}'
    
    

    C#

    Untuk memulai integrasi Anda di C#, lihat referensi contoh kode di GitHub.

    /// <summary>
    /// Create an object.
    /// </summary>
    /// <param name="issuerId">The issuer ID being used for this request.</param>
    /// <param name="classSuffix">Developer-defined unique ID for this pass class.</param>
    /// <param name="objectSuffix">Developer-defined unique ID for this pass object.</param>
    /// <returns>The pass object ID: "{issuerId}.{objectSuffix}"</returns>
    public string CreateObject(string issuerId, string classSuffix, string objectSuffix)
    {
      // Check if the object exists
      Stream responseStream = service.Eventticketobject
          .Get($"{issuerId}.{objectSuffix}")
          .ExecuteAsStream();
    
      StreamReader responseReader = new StreamReader(responseStream);
      JObject jsonResponse = JObject.Parse(responseReader.ReadToEnd());
    
      if (!jsonResponse.ContainsKey("error"))
      {
        Console.WriteLine($"Object {issuerId}.{objectSuffix} already exists!");
        return $"{issuerId}.{objectSuffix}";
      }
      else if (jsonResponse["error"].Value<int>("code") != 404)
      {
        // Something else went wrong...
        Console.WriteLine(jsonResponse.ToString());
        return $"{issuerId}.{objectSuffix}";
      }
    
      // See link below for more information on required properties
      // https://developers.google.com/wallet/tickets/events/rest/v1/eventticketobject
      EventTicketObject newObject = new EventTicketObject
      {
        Id = $"{issuerId}.{objectSuffix}",
        ClassId = $"{issuerId}.{classSuffix}",
        State = "ACTIVE",
        HeroImage = new Image
        {
          SourceUri = new ImageUri
          {
            Uri = "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg"
          },
          ContentDescription = new LocalizedString
          {
            DefaultValue = new TranslatedString
            {
              Language = "en-US",
              Value = "Hero image description"
            }
          }
        },
        TextModulesData = new List<TextModuleData>
        {
          new TextModuleData
          {
            Header = "Text module header",
            Body = "Text module body",
            Id = "TEXT_MODULE_ID"
          }
        },
        LinksModuleData = new LinksModuleData
        {
          Uris = new List<Google.Apis.Walletobjects.v1.Data.Uri>
          {
            new Google.Apis.Walletobjects.v1.Data.Uri
            {
              UriValue = "http://maps.google.com/",
              Description = "Link module URI description",
              Id = "LINK_MODULE_URI_ID"
            },
            new Google.Apis.Walletobjects.v1.Data.Uri
            {
              UriValue = "tel:6505555555",
              Description = "Link module tel description",
              Id = "LINK_MODULE_TEL_ID"
            }
          }
        },
        ImageModulesData = new List<ImageModuleData>
        {
          new ImageModuleData
          {
            MainImage = new Image
            {
              SourceUri = new ImageUri
              {
                Uri = "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg"
              },
              ContentDescription = new LocalizedString
              {
                DefaultValue = new TranslatedString
                {
                  Language = "en-US",
                  Value = "Image module description"
                }
              }
            },
            Id = "IMAGE_MODULE_ID"
          }
        },
        Barcode = new Barcode
        {
          Type = "QR_CODE",
          Value = "QR code"
        },
        Locations = new List<LatLongPoint>
        {
          new LatLongPoint
          {
            Latitude = 37.424015499999996,
            Longitude = -122.09259560000001
          }
        },
        SeatInfo = new EventSeat
        {
          Seat = new LocalizedString
          {
            DefaultValue = new TranslatedString
            {
              Language = "en-US",
              Value = "42"
            }
          },
          Row = new LocalizedString
          {
            DefaultValue = new TranslatedString
            {
              Language = "en-US",
              Value = "G3"
            }
          },
          Section = new LocalizedString
          {
            DefaultValue = new TranslatedString
            {
              Language = "en-US",
              Value = "5"
            }
          },
          Gate = new LocalizedString
          {
            DefaultValue = new TranslatedString
            {
              Language = "en-US",
              Value = "A"
            }
          }
        },
        TicketHolderName = "Ticket holder name",
        TicketNumber = "Ticket number"
      };
    
      responseStream = service.Eventticketobject
          .Insert(newObject)
          .ExecuteAsStream();
      responseReader = new StreamReader(responseStream);
      jsonResponse = JObject.Parse(responseReader.ReadToEnd());
    
      Console.WriteLine("Object insert response");
      Console.WriteLine(jsonResponse.ToString());
    
      return $"{issuerId}.{objectSuffix}";
    }
    

    Node.js

    Untuk memulai integrasi Anda di Node, lihat paket lengkap contoh kode di GitHub.

    /**
     * Create an object.
     *
     * @param {string} issuerId The issuer ID being used for this request.
     * @param {string} classSuffix Developer-defined unique ID for the pass class.
     * @param {string} objectSuffix Developer-defined unique ID for the pass object.
     *
     * @returns {string} The pass object ID: `${issuerId}.${objectSuffix}`
     */
    async createObject(issuerId, classSuffix, objectSuffix) {
      let response;
    
      // Check if the object exists
      try {
        response = await this.client.eventticketobject.get({
          resourceId: `${issuerId}.${objectSuffix}`
        });
    
        console.log(`Object ${issuerId}.${objectSuffix} already exists!`);
    
        return `${issuerId}.${objectSuffix}`;
      } catch (err) {
        if (err.response && err.response.status !== 404) {
          // Something else went wrong...
          console.log(err);
          return `${issuerId}.${objectSuffix}`;
        }
      }
    
      // See link below for more information on required properties
      // https://developers.google.com/wallet/tickets/events/rest/v1/eventticketobject
      let newObject = {
        'id': `${issuerId}.${objectSuffix}`,
        'classId': `${issuerId}.${classSuffix}`,
        'state': 'ACTIVE',
        'heroImage': {
          'sourceUri': {
            'uri': 'https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg'
          },
          'contentDescription': {
            'defaultValue': {
              'language': 'en-US',
              'value': 'Hero image description'
            }
          }
        },
        'textModulesData': [
          {
            'header': 'Text module header',
            'body': 'Text module body',
            'id': 'TEXT_MODULE_ID'
          }
        ],
        'linksModuleData': {
          'uris': [
            {
              'uri': 'http://maps.google.com/',
              'description': 'Link module URI description',
              'id': 'LINK_MODULE_URI_ID'
            },
            {
              'uri': 'tel:6505555555',
              'description': 'Link module tel description',
              'id': 'LINK_MODULE_TEL_ID'
            }
          ]
        },
        'imageModulesData': [
          {
            'mainImage': {
              'sourceUri': {
                'uri': 'http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg'
              },
              'contentDescription': {
                'defaultValue': {
                  'language': 'en-US',
                  'value': 'Image module description'
                }
              }
            },
            'id': 'IMAGE_MODULE_ID'
          }
        ],
        'barcode': {
          'type': 'QR_CODE',
          'value': 'QR code'
        },
        'locations': [
          {
            'latitude': 37.424015499999996,
            'longitude': -122.09259560000001
          }
        ],
        'seatInfo': {
          'seat': {
            'defaultValue': {
              'language': 'en-US',
              'value': '42'
            }
          },
          'row': {
            'defaultValue': {
              'language': 'en-US',
              'value': 'G3'
            }
          },
          'section': {
            'defaultValue': {
              'language': 'en-US',
              'value': '5'
            }
          },
          'gate': {
            'defaultValue': {
              'language': 'en-US',
              'value': 'A'
            }
          }
        },
        'ticketHolderName': 'Ticket holder name',
        'ticketNumber': 'Ticket number'
      };
    
      response = await this.client.eventticketobject.insert({
        requestBody: newObject
      });
    
      console.log('Object insert response');
      console.log(response);
    
      return `${issuerId}.${objectSuffix}`;
    }
    

    Go

    Untuk memulai integrasi Anda di Go, lihat contoh kode lengkap kami di GitHub contoh kode di GitHub.

    // Create an object.
    func (d *demoEventticket) createObject(issuerId, classSuffix, objectSuffix string) {
    	eventticketObject := new(walletobjects.EventTicketObject)
    	eventticketObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
    	eventticketObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
    	eventticketObject.TicketHolderName = "Ticket holder name"
    	eventticketObject.TicketNumber = "Ticket number"
    	eventticketObject.State = "ACTIVE"
    	eventticketObject.HeroImage = &walletobjects.Image{
    		SourceUri: &walletobjects.ImageUri{
    			Uri: "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
    		},
    	}
    	eventticketObject.Barcode = &walletobjects.Barcode{
    		Type:  "QR_CODE",
    		Value: "QR code",
    	}
    	eventticketObject.Locations = []*walletobjects.LatLongPoint{
    		&walletobjects.LatLongPoint{
    			Latitude:  37.424015499999996,
    			Longitude: -122.09259560000001,
    		},
    	}
    	eventticketObject.LinksModuleData = &walletobjects.LinksModuleData{
    		Uris: []*walletobjects.Uri{
    			&walletobjects.Uri{
    				Id:          "LINK_MODULE_URI_ID",
    				Uri:         "http://maps.google.com/",
    				Description: "Link module URI description",
    			},
    			&walletobjects.Uri{
    				Id:          "LINK_MODULE_TEL_ID",
    				Uri:         "tel:6505555555",
    				Description: "Link module tel description",
    			},
    		},
    	}
    	eventticketObject.ImageModulesData = []*walletobjects.ImageModuleData{
    		&walletobjects.ImageModuleData{
    			Id: "IMAGE_MODULE_ID",
    			MainImage: &walletobjects.Image{
    				SourceUri: &walletobjects.ImageUri{
    					Uri: "http://farm4.staticflickr.com/3738/12440799783_3dc3c20606_b.jpg",
    				},
    			},
    		},
    	}
    	eventticketObject.TextModulesData = []*walletobjects.TextModuleData{
    		&walletobjects.TextModuleData{
    			Body:   "Text module body",
    			Header: "Text module header",
    			Id:     "TEXT_MODULE_ID",
    		},
    	}
    	eventticketObject.SeatInfo = &walletobjects.EventSeat{
    		Gate: &walletobjects.LocalizedString{
    			DefaultValue: &walletobjects.TranslatedString{
    				Language: "en-us",
    				Value:    "A",
    			},
    		},
    		Section: &walletobjects.LocalizedString{
    			DefaultValue: &walletobjects.TranslatedString{
    				Language: "en-us",
    				Value:    "5",
    			},
    		},
    		Row: &walletobjects.LocalizedString{
    			DefaultValue: &walletobjects.TranslatedString{
    				Language: "en-us",
    				Value:    "G3",
    			},
    		},
    		Seat: &walletobjects.LocalizedString{
    			DefaultValue: &walletobjects.TranslatedString{
    				Language: "en-us",
    				Value:    "42",
    			},
    		},
    	}
    
    	res, err := d.service.Eventticketobject.Insert(eventticketObject).Do()
    	if err != nil {
    		log.Fatalf("Unable to insert object: %v", err)
    	} else {
    		fmt.Printf("Object insert id:\n%s\n", res.Id)
    	}
    }
    
    

    Setelah selesai, Objek Kartu pelanggan Anda akan dibuat di server tertentu. Namun, pada tahap ini, Objek Kartu belum ditautkan ke Pengguna Google atau perangkatnya. Agar kartu dapat dikaitkan dengan Pengguna Google Wallet, Anda harus menerbitkan kartu.