Giter Club home page Giter Club logo

google-wallet's Introduction

Google Wallet Library

The Google Wallet library provides a convenient way to manage Google Wallet functionality in your TypeScript or JavaScript projects. It offers a simple and intuitive interface for integrating with the Google Wallet REST API.

References/Links

Google Wallet Tutorial

Google Wallet Documentation


Installation

You can install the library via npm:

npm install google-wallet

Usage

Importing the Library

  • Loyalty Card

    import {
      LoyaltyClient,
      LoyaltyClass,
      LoyaltyObject
    } from "google-wallet/lib/esm/loyalty"; //works with esm and ecs
  • Generic Card

    import {
      GenericClient,
      GenericClass,
      GenericObject
    } from "google-wallet/lib/cjs/generic";
  • Gift Card

    import {
      GiftCardClient,
      GiftCardClass,
      GiftCardObject
    } from "google-wallet/lib/esm/gift-card";
  • Offer

    import {
      OfferClient,
      OfferClass,
      OfferObject
    } from "google-wallet/lib/esm/offer";
  • Boarding Passes

    import { ... } from "google-wallet/lib/esm/boarding-pass";
  • Events

    import { ... } from "google-wallet/lib/esm/event";
  • This library includes typings for Boarding Passes and Events, enabling you to work with these Google Wallet features. However, it currently does not provide a built-in client implementation for interacting with the Google REST API endpoints. If you require functionality specific to these features, you are encouraged to implement the client yourself or refer to any available documentation on their usage. Contributions regarding the client implementation or relevant documentation are highly appreciated and can benefit the community.

Configuration

Before using the library, you need to configure your Google application credentials. Make sure you have a valid Google Cloud project and the required credentials in JSON format.

const GOOGLE_APPLICATION_CREDENTIALS = JSON.parse(
  process.env.GOOGLE_APPLICATION_CREDENTIALS
);

Example: Creating Loyalty Cards

To create or manage loyalty cards using the library, you can follow this example:

const loyalty = new LoyaltyClient(GOOGLE_APPLICATION_CREDENTIALS);

// Create a loyalty class
const classPrefix = "fixeloyalty_class";
const classData: LoyaltyClass = {
  // Define the class data
};

let loyaltyClass = await loyalty.getClass(issuerId, classPrefix);
if (!loyaltyClass) {
  loyaltyClass = await loyalty.createClass(classData);
} else {
  loyaltyClass = await loyalty.patchClass(classData);
}

// Create or update a loyalty object
const objectSuffix = "loyalty_object";
const objectData: LoyaltyObject = {
  // Define the object data
};

let loyaltyObject = await loyalty.getObject(issuerId, objectSuffix);
if (!loyaltyObject) {
  loyaltyObject = await loyalty.createObject(objectData);
} else {
  // Update the object data
  loyaltyObject = await loyalty.patchObject(objectData);
}

Generate JWT token and save URL

import jwt from "jsonwebtoken";
const token = jwt.sign({
  iss: GOOGLE_APPLICATION_CREDENTIALS.client_email,
  aud: "google",
  origins: ["www.example.com"],
  typ: "savetowallet",
  payload: {
    // The listed classes and objects will be created
    loyaltyClasses: [loyaltyClass],
    loyaltyObjects: [loyaltyObject],
  },
}, GOOGLE_APPLICATION_CREDENTIALS.private_key, {
  algorithm: "RS256",
});
const saveUrl = `https://pay.google.com/gp/v/save/${token}`;

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request on the GitHub repository.

License

This project is licensed under the MIT License.

Contact

For any inquiries or questions, you can reach out to the project maintainer creating a new issue.

google-wallet's People

Contributors

dependabot[bot] avatar iquirino avatar pierrecrb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

google-wallet's Issues

Extracting just the typescript types from the repo

Hiya, great work on the repo! I'm working on integrating google wallet, and having the loyaltyObject and loyaltyClass typed would be extremely useful, however I don't want to add a new runtime dependency. Would you be opposed to me forking the repo to create one with just types? Alternatively, would you mind if the types were contributed to DefinitelyTyped?

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.