Giter Club home page Giter Club logo

Comments (5)

ncalteen avatar ncalteen commented on September 2, 2024

Hello,

Congratulations on integrating Google Wallet into your application :)

There are two main properties that must be set in a pass object to enable upcoming notifications:

  • genericobject.notifications
  • genericobject.validTimeInterval

There are a couple important things to consider when setting these:

  • This is configured on the pass object, not on the pass class.
  • Make sure to specify the fully-qualified class for any Google.Apis.Walletobjects.v1.Data.DateTime fields (so they aren't confused with System.DateTime).
  • In the notifications configuration, expiryNotification takes precedence over upcomingNotification. If you plan to set expiryNotification, setting upcomingNotification will have no effect.
  • The start property of validTimeInterval must be set for upcomingNotification to work.
  • Including an offset in the value of the start property will make it a specific time across the entire world. If you do not include an offset, the time will be for the local time zone the pass holder is in.

I've included a basic generic pass object definition below that includes the needed settings. Please give it a try and let me know if you run into any trouble!

GenericObject genericObject = new GenericObject
{
  Id = $"{issuerId}.{objectSuffix}",
  ClassId = $"{issuerId}.{classSuffix}",
  CardTitle = new LocalizedString
  {
    DefaultValue = new TranslatedString
    {
      Language = "en-US",
      Value = "Demo GenericObject Notifications"
    }
  },
  Header = new LocalizedString
  {
    DefaultValue = new TranslatedString
    {
      Language = "en-US",
      Value = "DboukAli98"
    }
  },
  Notifications = new Notifications
  {
    UpcomingNotification = new UpcomingNotification
    {
      EnableNotification = true
    }
  },
  ValidTimeInterval = new TimeInterval
  {
    Start = new Google.Apis.Walletobjects.v1.Data.DateTime
    {
      Date = "2022-11-15T10:30:00.00"
    }
  }
};

from rest-samples.

DboukAli98 avatar DboukAli98 commented on September 2, 2024

Thank you very much @ncalteen !
One last question what is the AddMessage property in Loyalty Pass ? I'll be glad to know more , because the official documentation is really ambiguous .
Thanks once again for your help,

from rest-samples.

DboukAli98 avatar DboukAli98 commented on September 2, 2024

And another thing can upcoming notifications be customized or they are not customizable?

from rest-samples.

ncalteen avatar ncalteen commented on September 2, 2024

Edit: Sorry, I dropped in huge images in my initial reply...

I'm happy to help! :)

The AddMessage method lets you add text data to pass details. You can add messages either to classes or objects. Adding a message to a class will affect all pass holders, while adding a message to an object affects only the user(s) who have that specific object in their wallet.

When you add a message to a pass, it appears in the pass details section. I made a very simple example below. In this case, I have a loyalty card for my coffee shop (if only I could fit one in my office...) and want to let users know I have a new mocha available. I can add this message so it will appear in my pass details.

From the user's point of view, they will first open their pass in Google Wallet:

drawing

Next, they will select Details and see the new message I added.

drawing

The code to do this for a pass object is below. I'd recommend including an ID in the message so that they can be managed more easily, and making sure that the ID is not one that would likely be duplicated later (if this is something you plan to do).

AddMessageRequest request = new AddMessageRequest
{
  Message = new Message
  {
    Id = "2022-11-15_MochaAnnouncement",
    Body = "Try our new Mocha today!"
  }
};

Stream responseStream = DemoLoyalty.service.Loyaltyobject
            .Addmessage(request, $"{issuerId}.{objectSuffix}")
            .ExecuteAsStream();
StreamReader responseReader = new StreamReader(responseStream);
JObject jsonResponse = JObject.Parse(responseReader.ReadToEnd());

Console.WriteLine("Message insert response");
Console.WriteLine(jsonResponse.ToString());

To answer your second question, notification text can't be customized currently. The specific text will always be:

  • Upcoming notification: genericObject.cardTitle is available now
  • Expiry notification: genericObject.cardTitle expires in [x] days

from rest-samples.

DboukAli98 avatar DboukAli98 commented on September 2, 2024

Thanks very much @ncalteen you really cleared the path!

from rest-samples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.