تذاكر حضور الفعاليات المنتهية الصلاحية

تظهر في "محفظة Google" عبارة "البطاقات المنتهية الصلاحية". يتضمّن كل البطاقات المؤرشفة أو غير النشطة

نقل بطاقة إلى قسم "البطاقات المنتهية الصلاحية" في حال استيفاء أحد الشروط التالية على الأقل:

  • مرّ 72 ساعة على الأقل منذ انتهاء صلاحية class.dateTime.end. إذا لم يتم تحديد السمة class.dateTime.end، يتم استخدام السمة class.dateTime.start. بدلاً من ذلك. يتم نقل البطاقة إلى قسم "البطاقات المنتهية الصلاحية" في أي وقت خلال مدة تتراوح بين 72 و96 ساعة بعد انتهاء صلاحية class.dateTime.end أو class.dateTime.start.
  • عند نقل بطاقة object.validTimeInterval.end.date expires إلى القسم "البطاقات المنتهية الصلاحية" في أي وقت بعد مرور مدة تصل إلى 24 ساعة.
  • يتم تصنيف حالة حقل الكائن object.state على أنّها Expired أو Inactive أو Completed.

يوضّح نموذج الرمز البرمجي التالي عنصرًا اقترب موعد انتهاء صلاحيته باستخدام نموذج واجهة برمجة التطبيقات للمحفظة.

Java

لبدء الدمج في Java، راجع عيّنات من الرموز البرمجية على 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.eventticketobject().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
  EventTicketObject patchBody = new EventTicketObject().setState("EXPIRED");

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

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

  return response.getId();
}

PHP

لبدء عملية الدمج باستخدام لغة 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->eventticketobject->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 EventTicketObject([
    'state' => 'EXPIRED'
  ]);

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

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

  return $response->id;
}

Python

لبدء عملية الدمج في بايثون، يُرجى الرجوع إلى عيّنات من الرموز البرمجية على 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.eventticketobject().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.eventticketobject().patch(
        resourceId=f'{issuer_id}.{object_suffix}',
        body=patch_body).execute()

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

    return f'{issuer_id}.{object_suffix}'

#C

لبدء الدمج في 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.Eventticketobject
      .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
  EventTicketObject patchBody = new EventTicketObject
  {
    State = "EXPIRED"
  };

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

لبدء عملية الدمج في Node، يُرجى الرجوع إلى عيّنات من الرموز البرمجية على 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.eventticketobject.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.eventticketobject.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 *demoEventticket) expireObject(issuerId, objectSuffix string) {
	eventticketObject := &walletobjects.EventTicketObject{
		State: "EXPIRED",
	}
	res, err := d.service.Eventticketobject.Patch(fmt.Sprintf("%s.%s", issuerId, objectSuffix), eventticketObject).Do()
	if err != nil {
		log.Fatalf("Unable to patch object: %v", err)
	} else {
		fmt.Printf("Object expiration id:\n%s\n", res.Id)
	}
}