पास क्लास और पास ऑब्जेक्ट बनाएं

असली उपयोगकर्ता के Google Wallet में सेव करने के लिए, आपके पास करीब-करीब सभी पास की जानकारी होती है. ये दो कॉम्पोनेंट होते हैं: पास की क्लास और पास ऑब्जेक्ट. किसी उपयोगकर्ता को पास जारी करने के लिए, आपको पास क्लास और पास ऑब्जेक्ट, दोनों के इंस्टेंस की ज़रूरत होगी. इससे Google Wallet API को पता चलता है कि किस तरह का पास बनाना है. साथ ही, पास पर दिखाने के लिए उपहार कार्ड की वैल्यू या टिकटधारक के नाम जैसी जानकारी भी देनी होगी.

Google Wallet API, पास की क्लास और पास से जुड़े ऑब्जेक्ट का पहले से तय सेट उपलब्ध कराता है, जिनके इंस्टेंस बनाए जाते हैं. इसके बाद, इसका इस्तेमाल किसी उपयोगकर्ता के लिए जारी किया जाने वाला पास बनाने के लिए किया जाता है. जैसे, GiftCardClass, GiftCardObject, GenericClass, और GenericObject वगैरह.

हर पास क्लास और पास ऑब्जेक्ट इंस्टेंस को JSON ऑब्जेक्ट के तौर पर तय किया जाता है. इसमें ज़रूरी और वैकल्पिक प्रॉपर्टी का एक सेट होता है. यह सेट, उस पास टाइप के इस्तेमाल के खास उदाहरण से मेल खाता है.

पास की क्लास बनाएं

पास क्लास को शेयर किया गया ऐसा टेंप्लेट माना जा सकता है जिसका इस्तेमाल करके पास बनाए जाते हैं. पास क्लास से कुछ प्रॉपर्टी के बारे में पता चलता है. इन्हें इस्तेमाल करने वाले सभी पास में शामिल किया जाएगा. पास जारी करने वाला व्यक्ति, कई क्लास बना सकता है. हर क्लास में प्रॉपर्टी का ऐसा खास सेट होता है जो स्टाइल और लुक जैसे एट्रिब्यूट के बारे में बताता है. साथ ही, इसमें स्मार्ट टैप, रजिस्ट्रेशन, और साइन इन जैसी अतिरिक्त सुविधाएं भी मिलती हैं.

पास क्लास, Google Wallet REST API, Google Wallet Android SDK या Google Wallet Business Console का इस्तेमाल करके बनाई जा सकती हैं.

नए उपयोगकर्ताओं के लिए, Business Console, पास की कैटगरी बनाने का सबसे आसान तरीका है. इससे, एक आसान यूज़र इंटरफ़ेस मिलता है. इसमें फ़ॉर्म फ़ील्ड भरकर, पहली पास क्लास के अलग-अलग फ़ील्ड तय किए जा सकते हैं.

ज़्यादा जानकार उपयोगकर्ताओं के लिए, प्रोग्राम के हिसाब से पास की क्लास बनाना सबसे सही तरीका है.

Google Wallet Business Console का इस्तेमाल करना

Google Wallet Business कंसोल में पास की क्लास बनाने के लिए, ये काम करें:

  1. Google Pay और Wallet Business Console पर जाएं और अपने Google Wallet API जारी करने वाले खाते से साइन इन करें.
  2. "Google Wallet API" कार्ड पर मौजूद, "पास मैनेज करें" बटन पर क्लिक करें.
  3. 'पब्लिश करने का ऐक्सेस पाएं' में जाकर, 'क्लास बनाएं' बटन पर क्लिक करें.
  4. डायलॉग से पास का टाइप चुनें. Google Wallet कई तरह के पास ऑफ़र करता है, जैसे कि इवेंट का टिकट, ऑफ़र, लॉयल्टी कार्ड वगैरह. सुविधाजनक इस्तेमाल के उदाहरण के लिए, अपने पास टाइप के तौर पर "सामान्य" को चुनें.
  5. ज़रूरी फ़ील्ड में सही वैल्यू भरें.
  6. अपनी क्लास सेव करने के लिए, 'क्लास बनाएं' बटन पर क्लिक करें.

Google Wallet REST API का इस्तेमाल करना

Google Wallet REST API का इस्तेमाल करके पास की क्लास बनाने के लिए, https://walletobjects.googleapis.com/walletobjects/v1/loyaltyClass को POST का अनुरोध भेजें. ज़्यादा जानकारी के लिए, रेफ़रंस दस्तावेज़ देखें.

Java

Java में इंटिग्रेशन शुरू करने के लिए, 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.loyaltyclass().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/retail/loyalty-cards/rest/v1/loyaltyclass
  LoyaltyClass newClass =
      new LoyaltyClass()
          .setId(String.format("%s.%s", issuerId, classSuffix))
          .setIssuerName("Issuer name")
          .setReviewStatus("UNDER_REVIEW")
          .setProgramName("Program name")
          .setProgramLogo(
              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("Logo description"))));

  LoyaltyClass response = service.loyaltyclass().insert(newClass).execute();

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

  return response.getId();
}

PHP

PHP में अपना इंटिग्रेशन शुरू करने के लिए, 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->loyaltyclass->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/retail/loyalty-cards/rest/v1/loyaltyclass
  $newClass = new LoyaltyClass([
    'id' => "{$issuerId}.{$classSuffix}",
    'issuerName' => 'Issuer name',
    'reviewStatus' => 'UNDER_REVIEW',
    'programName' => 'Program name',
    'programLogo' => new Image([
      'sourceUri' => new ImageUri([
        'uri' => 'http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg'
      ]),
      'contentDescription' => new LocalizedString([
        'defaultValue' => new TranslatedString([
          'language' => 'en-US',
          'value' => 'Logo description'
        ])
      ])
    ])
  ]);

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

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

  return $response->id;
}

Python

Python में इंटिग्रेशन शुरू करने के लिए, 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.loyaltyclass().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/retail/loyalty-cards/rest/v1/loyaltyclass
    new_class = {
        'id': f'{issuer_id}.{class_suffix}',
        'issuerName': 'Issuer name',
        'reviewStatus': 'UNDER_REVIEW',
        'programName': 'Program name',
        'programLogo': {
            'sourceUri': {
                'uri':
                    'http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg'
            },
            'contentDescription': {
                'defaultValue': {
                    'language': 'en-US',
                    'value': 'Logo description'
                }
            }
        }
    }

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

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

    return f'{issuer_id}.{class_suffix}'

C#

C# में इंटिग्रेशन शुरू करने के लिए, 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.Loyaltyclass
      .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/retail/loyalty-cards/rest/v1/loyaltyclass
  LoyaltyClass newClass = new LoyaltyClass
  {
    Id = $"{issuerId}.{classSuffix}",
    IssuerName = "Issuer name",
    ReviewStatus = "UNDER_REVIEW",
    ProgramName = "Program name",
    ProgramLogo = new Image
    {
      SourceUri = new ImageUri
      {
        Uri = "http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg"
      },
      ContentDescription = new LocalizedString
      {
        DefaultValue = new TranslatedString
        {
          Language = "en-US",
          Value = "Logo description"
        }
      }
    }
  };

  responseStream = service.Loyaltyclass
      .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

नोड में इंटिग्रेशन शुरू करने के लिए, 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.loyaltyclass.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/retail/loyalty-cards/rest/v1/loyaltyclass
  let newClass = {
    'id': `${issuerId}.${classSuffix}`,
    'issuerName': 'Issuer name',
    'reviewStatus': 'UNDER_REVIEW',
    'programName': 'Program name',
    'programLogo': {
      'sourceUri': {
        'uri': 'http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg'
      },
      'contentDescription': {
        'defaultValue': {
          'language': 'en-US',
          'value': 'Logo description'
        }
      }
    }
  };

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

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

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

शुरू करें

Go में अपना इंटिग्रेशन शुरू करने के लिए, GitHub पर हमारे पूरे कोड सैंपल देखें GitHub पर कोड सैंपल.

// Create a class.
func (d *demoLoyalty) createClass(issuerId, classSuffix string) {
	logo := walletobjects.Image{
		SourceUri: &walletobjects.ImageUri{
			Uri: "http://farm8.staticflickr.com/7340/11177041185_a61a7f2139_o.jpg",
		},
	}
	loyaltyClass := new(walletobjects.LoyaltyClass)
	loyaltyClass.Id = fmt.Sprintf("%s.%s", issuerId, classSuffix)
	loyaltyClass.ProgramName = "Program name"
	loyaltyClass.IssuerName = "Issuer name"
	loyaltyClass.ReviewStatus = "UNDER_REVIEW"
	loyaltyClass.ProgramLogo = &logo
	res, err := d.service.Loyaltyclass.Insert(loyaltyClass).Do()
	if err != nil {
		log.Fatalf("Unable to insert class: %v", err)
	} else {
		fmt.Printf("Class insert id:\n%v\n", res.Id)
	}
}

पास ऑब्जेक्ट बनाएं

पास्स ऑब्जेक्ट, पास क्लास का एक इंस्टेंस है. पास ऑब्जेक्ट बनाने के लिए, आपको ये एट्रिब्यूट देने होंगे:

  • classId: पास की कैटगरी का id
  • id: आपके ग्राहक के लिए एक यूनीक आईडी

    लॉयल्टी कार्ड में इन एट्रिब्यूट को कैसे दिखाया जाता है, इस बारे में ज़्यादा जानकारी के लिए, लेआउट टेंप्लेट देखें.

    पास ऑब्जेक्ट बनाने के लिए कोड सैंपल:

    Java

    Java में इंटिग्रेशन शुरू करने के लिए, 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.loyaltyobject().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/retail/loyalty-cards/rest/v1/loyaltyobject
      LoyaltyObject newObject =
          new LoyaltyObject()
              .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)))
              .setAccountId("Account ID")
              .setAccountName("Account name")
              .setLoyaltyPoints(
                  new LoyaltyPoints()
                      .setLabel("Points")
                      .setBalance(new LoyaltyPointsBalance().setInt(800)));
    
      LoyaltyObject response = service.loyaltyobject().insert(newObject).execute();
    
      System.out.println("Object insert response");
      System.out.println(response.toPrettyString());
    
      return response.getId();
    }
    

    PHP

    PHP में अपना इंटिग्रेशन शुरू करने के लिए, 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->loyaltyobject->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/retail/loyalty-cards/rest/v1/loyaltyobject
      $newObject = new LoyaltyObject([
        '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
          ])
        ],
        'accountId' => 'Account ID',
        'accountName' => 'Account name',
        'loyaltyPoints' => new LoyaltyPoints([
          'balance' => new LoyaltyPointsBalance([
            'int' => 800
          ])
        ])
      ]);
    
      $response = $this->service->loyaltyobject->insert($newObject);
    
      print "Object insert response\n";
      print_r($response);
    
      return $response->id;
    }
    

    Python

    Python में इंटिग्रेशन शुरू करने के लिए, 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.loyaltyobject().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/retail/loyalty-cards/rest/v1/loyaltyobject
        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
            }],
            'accountId': 'Account id',
            'accountName': 'Account name',
            'loyaltyPoints': {
                'label': 'Points',
                'balance': {
                    'int': 800
                }
            }
        }
    
        # Create the object
        response = self.client.loyaltyobject().insert(body=new_object).execute()
    
        print('Object insert response')
        print(response)
    
        return f'{issuer_id}.{object_suffix}'
    
    

    C#

    C# में इंटिग्रेशन शुरू करने के लिए, 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.Loyaltyobject
          .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/retail/loyalty-cards/rest/v1/loyaltyobject
      LoyaltyObject newObject = new LoyaltyObject
      {
        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
          }
        },
        AccountId = "Account id",
        AccountName = "Account name",
        LoyaltyPoints = new LoyaltyPoints
        {
          Label = "Points",
          Balance = new LoyaltyPointsBalance
          {
            Int__ = 800
          }
        }
      };
    
      responseStream = service.Loyaltyobject
          .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

    नोड में इंटिग्रेशन शुरू करने के लिए, 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.loyaltyobject.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/retail/loyalty-cards/rest/v1/loyaltyobject
      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
          }
        ],
        'accountId': 'Account id',
        'accountName': 'Account name',
        'loyaltyPoints': {
          'label': 'Points',
          'balance': {
            'int': 800
          }
        }
      };
    
      response = await this.client.loyaltyobject.insert({
        requestBody: newObject
      });
    
      console.log('Object insert response');
      console.log(response);
    
      return `${issuerId}.${objectSuffix}`;
    }
    

    शुरू करें

    Go में अपना इंटिग्रेशन शुरू करने के लिए, GitHub पर हमारे पूरे कोड सैंपल देखें GitHub पर कोड सैंपल.

    // Create an object.
    func (d *demoLoyalty) createObject(issuerId, classSuffix, objectSuffix string) {
    	loyaltyObject := new(walletobjects.LoyaltyObject)
    	loyaltyObject.Id = fmt.Sprintf("%s.%s", issuerId, objectSuffix)
    	loyaltyObject.ClassId = fmt.Sprintf("%s.%s", issuerId, classSuffix)
    	loyaltyObject.AccountName = "Account name"
    	loyaltyObject.AccountId = "Account id"
    	loyaltyObject.State = "ACTIVE"
    	loyaltyObject.LoyaltyPoints = &walletobjects.LoyaltyPoints{
    		Balance: &walletobjects.LoyaltyPointsBalance{Int: 800},
    		Label:   "Points",
    	}
    	loyaltyObject.HeroImage = &walletobjects.Image{
    		SourceUri: &walletobjects.ImageUri{
    			Uri: "https://farm4.staticflickr.com/3723/11177041115_6e6a3b6f49_o.jpg",
    		},
    	}
    	loyaltyObject.Barcode = &walletobjects.Barcode{
    		Type:  "QR_CODE",
    		Value: "QR code",
    	}
    	loyaltyObject.Locations = []*walletobjects.LatLongPoint{
    		&walletobjects.LatLongPoint{
    			Latitude:  37.424015499999996,
    			Longitude: -122.09259560000001,
    		},
    	}
    	loyaltyObject.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",
    			},
    		},
    	}
    	loyaltyObject.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",
    				},
    			},
    		},
    	}
    	loyaltyObject.TextModulesData = []*walletobjects.TextModuleData{
    		&walletobjects.TextModuleData{
    			Body:   "Text module body",
    			Header: "Text module header",
    			Id:     "TEXT_MODULE_ID",
    		},
    	}
    
    	res, err := d.service.Loyaltyobject.Insert(loyaltyObject).Do()
    	if err != nil {
    		log.Fatalf("Unable to insert object: %v", err)
    	} else {
    		fmt.Printf("Object insert id:\n%s\n", res.Id)
    	}
    }
    
    

    पूरा होने के बाद, आपके ग्राहक का पास ऑब्जेक्ट सर्वर पर बना दिया जाएगा. हालांकि, इस चरण में पास ऑब्जेक्ट को किसी Google उपयोगकर्ता या उसके डिवाइस से लिंक नहीं किया गया है. पास को Google Wallet उपयोगकर्ता के साथ जोड़ने के लिए, आपको पास जारी करना होगा.