5

我们使用 Android API 将忠诚卡添加到 Google Pay 应用程序。

链接- https://developers.google.com/pay/save/guides/loyalty/get-started-android

它工作正常。从我们的应用程序中点击保存到钱包,我们可以在 Google Pay 应用程序中看到已保存的会员卡。

现在我们需要通过 Android API更新添加的会员卡。我们检查了 API 文档,没有找到任何对它的引用。

是否可以更新忠诚卡,如果可以,如何更新?

4

2 回答 2

0

对于 PHP

我在 RestMethods.php 中创建了 2 个额外的方法,它们使用 Walletobjects.php 中定义的方法

 public function updateLoyaltyClass($classId, $objectPayload){
    $response = NULL;
    $service = new Google_Service_Walletobjects($this->client);

    try {
        $response = $service->loyaltyclass->update($classId, $objectPayload);
        $response["code"] = 200;
    } catch (Google_Service_Exception $gException)  {
        $response = $gException->getErrors();
        $response["code"] = $gException->getCode();
        echo("\n>>>> [START] Google Server Error response:");
        var_dump($response);
        echo("\n>>>> [END] Google Server Error response\n");
    } catch (Exception $e){
        var_dump($e->getMessage());
    }

return $response;

}


public function updateLoyaltyObject($objectId, $objectPayload){
    $response = NULL;
    $service = new Google_Service_Walletobjects($this->client);

    try {
        $response = $service->loyaltyobject->update($objectId, $objectPayload);
        $response["code"] = 200;
    } catch (Google_Service_Exception $gException)  {
        $response = $gException->getErrors();
        $response["code"] = $gException->getCode();
        echo("\n>>>> [START] Google Server Error response:");
        var_dump($response);
        echo("\n>>>> [END] Google Server Error response\n");
    } catch (Exception $e){
        var_dump($e->getMessage());
    }

return $response;
}

然后创建了我自己的 update.php,它重用了 ResourceDefinitions.php 类和对象,您可以在文档中进行内联编辑

<?php

require_once "Config.php"; // define constants
require_once 'RestMethods.php';
require_once "Services.php";
require_once 'Walletobjects.php';
require_once 'ResourceDefinitions.php';

$restMethods = RestMethods::getInstance();

$issuerUID = "Your Issuer ID";
$classUid = "Your Class ID";
$classId = sprintf("%s.%s" , $issuerUID, $classUid);
$objectUid= "Your Object ID"; 
$objectId = sprintf("%s.%s", $issuerUID, $objectUid);


//fetch object and class from resource
$objectResourcePayload = ResourceDefinitions::makeLoyaltyObjectResource($classId, $objectId);
$classResourcePayload = ResourceDefinitions::makeLoyaltyClassResource($classId);
//print_r($objectResourcePayload);
//print_r($classResourcePayload);

$classUpdateResponse = $restMethods->updateLoyaltyClass($classId,$classResourcePayload);
$objectUpdateResponse = $restMethods->updateLoyaltyObject($objectId,$objectResourcePayload);

print_r($classUpdateResponse);
print_r($objectUpdateResponse);



?>
于 2021-10-19T16:44:50.133 回答
0

您无法使用 Android API 编辑通行证,建议更新您的解决方案以使用 REST API。请参阅此处的注释https://developers.google.com/pay/passes/guides/get-started/basic-setup/get-access-to-android-sdk以供参考。

于 2020-03-04T19:30:29.313 回答