মেয়াদোত্তীর্ণ উপহার কার্ড

Google Wallet অ্যাপ্লিকেশানের "পাস" ট্যাবের অধীনে মেয়াদোত্তীর্ণ পাসগুলিকে লজিক্যালি গোষ্ঠীর মেয়াদ উত্তীর্ণ হিসাবে সেট করা৷ Google Wallet অ্যাপে একটি "মেয়াদ শেষ পাস" বিভাগ রয়েছে যাতে সমস্ত সংরক্ষণাগারভুক্ত বা নিষ্ক্রিয় পাস রয়েছে৷

নিম্নলিখিত শর্তগুলির মধ্যে অন্তত একটি সত্য হলে একটি পাস "মেয়াদ শেষ হওয়া পাস" বিভাগে সরানো হয়:

  • যখন object.validTimeInterval.end.date মেয়াদ শেষ হয়ে যায় তখন পাসটি 24 ঘন্টা পরে যেকোন সময় "মেয়াদ শেষ পাস"-এ চলে যায়।
  • অবজেক্ট object.state ফিল্ডের অবস্থা Expired , Inactive বা Completed হিসাবে চিহ্নিত করা হয়েছে।

নিম্নলিখিত কোড নমুনা Google Wallet API ব্যবহার করে একটি পাস অবজেক্টের মেয়াদ উত্তীর্ণ হতে দেখায়।

জাভা

জাভাতে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা পড়ুন।

/**
 * Expire an object.
 *
 * <p>Sets the object's state to Expired. If the valid time interval is already set, the pass will
 * expire automatically up to 24 hours after.
 *
 * @param issuerId The issuer ID being used for this request.
 * @param objectSuffix Developer-defined unique ID for this pass object.
 * @return The pass object ID: "{issuerId}.{objectSuffix}"
 */
public String expireObject(String issuerId, String objectSuffix) throws IOException {
  // Check if the object exists
  try {
    service.giftcardobject().get(String.format("%s.%s", issuerId, objectSuffix)).execute();
  } catch (GoogleJsonResponseException ex) {
    if (ex.getStatusCode() == 404) {
      // Object does not exist
      System.out.printf("Object %s.%s not found!%n", issuerId, objectSuffix);
      return String.format("%s.%s", issuerId, objectSuffix);
    } else {
      // Something else went wrong...
      ex.printStackTrace();
      return String.format("%s.%s", issuerId, objectSuffix);
    }
  }

  // Patch the object, setting the pass as expired
  GiftCardObject patchBody = new GiftCardObject().setState("EXPIRED");

  GiftCardObject response =
      service
          .giftcardobject()
          .patch(String.format("%s.%s", issuerId, objectSuffix), patchBody)
          .execute();

  System.out.println("Object expiration response");
  System.out.println(response.toPrettyString());

  return response.getId();
}

পিএইচপি

PHP-তে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা দেখুন।

/**
 * Expire an object.
 *
 * Sets the object's state to Expired. If the valid time interval is
 * already set, the pass will expire automatically up to 24 hours after.
 *
 * @param string $issuerId The issuer ID being used for this request.
 * @param string $objectSuffix Developer-defined unique ID for this pass object.
 *
 * @return string The pass object ID: "{$issuerId}.{$objectSuffix}"
 */
public function expireObject(string $issuerId, string $objectSuffix)
{
  // Check if the object exists
  try {
    $this->service->giftcardobject->get("{$issuerId}.{$objectSuffix}");
  } catch (Google\Service\Exception $ex) {
    if (!empty($ex->getErrors()) && $ex->getErrors()[0]['reason'] == 'resourceNotFound') {
      print("Object {$issuerId}.{$objectSuffix} not found!");
      return "{$issuerId}.{$objectSuffix}";
    } else {
      // Something else went wrong...
      print_r($ex);
      return "{$issuerId}.{$objectSuffix}";
    }
  }

  // Patch the object, setting the pass as expired
  $patchBody = new GiftCardObject([
    'state' => 'EXPIRED'
  ]);

  $response = $this->service->giftcardobject->patch("{$issuerId}.{$objectSuffix}", $patchBody);

  print "Object expiration response\n";
  print_r($response);

  return $response->id;
}

পাইথন

পাইথনে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা দেখুন।

def expire_object(self, issuer_id: str, object_suffix: str) -> str:
    """Expire an object.

    Sets the object's state to Expired. If the valid time interval is
    already set, the pass will expire automatically up to 24 hours after.

    Args:
        issuer_id (str): The issuer ID being used for this request.
        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:
        response = self.client.giftcardobject().get(resourceId=f'{issuer_id}.{object_suffix}').execute()
    except HttpError as e:
        if e.status_code == 404:
            print(f'Object {issuer_id}.{object_suffix} not found!')
            return f'{issuer_id}.{object_suffix}'
        else:
            # Something else went wrong...
            print(e.error_details)
            return f'{issuer_id}.{object_suffix}'

    # Patch the object, setting the pass as expired
    patch_body = {'state': 'EXPIRED'}

    response = self.client.giftcardobject().patch(
        resourceId=f'{issuer_id}.{object_suffix}',
        body=patch_body).execute()

    print('Object expiration response')
    print(response)

    return f'{issuer_id}.{object_suffix}'

সি#

C# এ আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনাগুলি পড়ুন।

/// <summary>
/// Expire an object.
/// <para />
/// Sets the object's state to Expired. If the valid time interval is already
/// set, the pass will expire automatically up to 24 hours after.
/// </summary>
/// <param name="issuerId">The issuer ID being used for this request.</param>
/// <param name="objectSuffix">Developer-defined unique ID for this pass object.</param>
/// <returns>The pass object ID: "{issuerId}.{objectSuffix}"</returns>
public string ExpireObject(string issuerId, string objectSuffix)
{
  // Check if the object exists
  Stream responseStream = service.Giftcardobject
      .Get($"{issuerId}.{objectSuffix}")
      .ExecuteAsStream();

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

  if (jsonResponse.ContainsKey("error"))
  {
    if (jsonResponse["error"].Value<int>("code") == 404)
    {
      // Object does not exist
      Console.WriteLine($"Object {issuerId}.{objectSuffix} not found!");
      return $"{issuerId}.{objectSuffix}";
    }
    else
    {
      // Something else went wrong...
      Console.WriteLine(jsonResponse.ToString());
      return $"{issuerId}.{objectSuffix}";
    }
  }

  // Patch the object, setting the pass as expired
  GiftCardObject patchBody = new GiftCardObject
  {
    State = "EXPIRED"
  };

  responseStream = service.Giftcardobject
      .Patch(patchBody, $"{issuerId}.{objectSuffix}")
      .ExecuteAsStream();

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

  Console.WriteLine("Object expiration response");
  Console.WriteLine(jsonResponse.ToString());

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

Node.js

নোডে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ আমাদের সম্পূর্ণ কোড নমুনা পড়ুন।

/**
 * Expire an object.
 *
 * Sets the object's state to Expired. If the valid time interval is
 * already set, the pass will expire automatically up to 24 hours after.
 *
 * @param {string} issuerId The issuer ID being used for this request.
 * @param {string} objectSuffix Developer-defined unique ID for the pass object.
 *
 * @returns {string} The pass object ID: `${issuerId}.${objectSuffix}`
 */
async expireObject(issuerId, objectSuffix) {
  let response;

  // Check if the object exists
  try {
    response = await this.client.giftcardobject.get({
      resourceId: `${issuerId}.${objectSuffix}`
    });
  } catch (err) {
    if (err.response && err.response.status === 404) {
      console.log(`Object ${issuerId}.${objectSuffix} not found!`);
      return `${issuerId}.${objectSuffix}`;
    } else {
      // Something else went wrong...
      console.log(err);
      return `${issuerId}.${objectSuffix}`;
    }
  }

  // Patch the object, setting the pass as expired
  let patchBody = {
    'state': 'EXPIRED'
  };

  response = await this.client.giftcardobject.patch({
    resourceId: `${issuerId}.${objectSuffix}`,
    requestBody: patchBody
  });

  console.log('Object expiration response');
  console.log(response);

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

যাও

Go-তে আপনার ইন্টিগ্রেশন শুরু করতে, GitHub-এ GitHub কোড নমুনাগুলিতে আমাদের সম্পূর্ণ কোড নমুনা দেখুন।

// Expire an object.
//
// Sets the object's state to Expired. If the valid time interval is
// already set, the pass will expire automatically up to 24 hours after.
func (d *demoGiftcard) expireObject(issuerId, objectSuffix string) {
	giftcardObject := &walletobjects.GiftCardObject{
		State: "EXPIRED",
	}
	res, err := d.service.Giftcardobject.Patch(fmt.Sprintf("%s.%s", issuerId, objectSuffix), giftcardObject).Do()
	if err != nil {
		log.Fatalf("Unable to patch object: %v", err)
	} else {
		fmt.Printf("Object expiration id:\n%s\n", res.Id)
	}
}