We have added Loyalty Card to Google Pay App using Android API.
Link - https://developers.google.com/pay/save/guides/loyalty/get-started-android
It works fine. From our App on clicking Save to Wallet we are able to see the saved Loyalty Card in Google Pay App.
Now we need to update the added Loyalty card through Android API. We checked through the API document, we didn't find any reference to it.
Is it possible to update the Loyalty Card and if yes how?
For PHP
I create 2 extra methods in RestMethods.php that use the methods defined in 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;
}
Then created my own update.php which reuses the ResourceDefinitions.php class and objects, which you can edit inline with the documentation
<?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);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With