google-wallet
TypeScript icon, indicating that this package has built-in type declarations

1.0.18 • Public • Published

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.

Google Wallet Tutorial

Google Wallet Documentation


Installation

You can install the library via npm:

npm install google-wallet

Usage

Importing the Library

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.

Readme

Keywords

Package Sidebar

Install

npm i google-wallet

Weekly Downloads

4,903

Version

1.0.18

License

ISC

Unpacked Size

1.12 MB

Total Files

2476

Last publish

Collaborators

  • iquirino