【问题标题】:Updating Google Pay App Loyalty Card through API通过 API 更新 Google Pay App Loyalty Card
【发布时间】:2018-10-23 19:34:35
【问题描述】:

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

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

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

现在我们需要通过 Android API更新添加的忠诚度卡。我们检查了 API 文档,没有找到任何参考。

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

【问题讨论】:

标签: android google-pay


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    对于 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-07-13
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 2018-07-03
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      相关资源
      最近更新 更多