Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vergilet/google_wallet

Unofficial Ruby Gem for Google Wallet API.
https://github.com/vergilet/google_wallet

gem google-wallet google-wallet-api ruby

Last synced: 2 months ago
JSON representation

Unofficial Ruby Gem for Google Wallet API.

Awesome Lists containing this project

README

        







# GoogleWallet
Unofficial Ruby Gem for [Google Wallet API](https://developers.google.com/wallet).

## Prerequisites
Before you use the Google Wallet API for an integration, complete first four steps from [this guide](https://developers.google.com/wallet/tickets/events/web/prerequisites).

*The 1st step will provide you with **IssuerID**=33880000000XXXXXXXX and*

*on the 3rd step you are going to obtain **key.json**, those are needed for the gem initialization.*

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'google_wallet'
```

And then execute:

$ bundle install

Or install it yourself as:

$ gem install google_wallet

## Usage

Create initializer:
```ruby
# config/initializers/google_wallet.rb

GoogleWallet.configure do |config|
config.load_credentials_from_file('./key.json')
config.issuer_id = '33880000000XXXXXXXX'
config.debug_mode = true
config.logger = Logger.new(STDOUT)
end
```

### EventTicket

#### Create class (event representation):
```ruby
event_attributes = {
# required fields
class_identifier: 'Event-123456',
event_name: 'Solo Singing Contest #1 Yay!',
issuer_name: 'iChar System',

# other fields
event_id: '123456',
logo_url: 'https://images.unsplash.com/photo-1475721027785-f74eccf877e2?auto=format&fit=crop&w=360&h=360',
hero_image_url: 'https://images.unsplash.com/photo-1501281668745-f7f57925c3b4?auto=format&fit=crop&w=1032&h=336',
homepage_url: 'https://example.com',
country_code: 'no',
venue_name: 'Opera Theater',
venue_address: "Shevchenka street 41/5, Ukraine, Kyiv",
start_date_time: '2023-09-27T22:30',
end_date_time: '2023-09-28T01:30',
hex_background_color: '#ff0077',
callback_url: 'https://example.com/gpass_callback'
}

# Create Resource of EventTicket Class
event = GoogleWallet::Resources::EventTicket::Class.new(attributes: event_attributes)

# Push Class to Google Wallet API
event.push
```

#### Create object (ticket representation):
```ruby
ticket_attributes = {
# required fields
object_identifier: 'fd9b637f-0381-42ad-9161-b4d887d79d9f',
class_identifier: 'Event-123456',

# other fields
grouping_id: 'order-12345',
ticket_type: 'VIP Adult Plus',
section: 'The Sponsor Felt-F Overpower',
seat: '65',
row: '17',
gate: 'G3, G4',
ticket_holder_name: 'Yaro Developer',
qr_code_value: '12345678',
ticket_number: 'cdeqw',
valid_time_start: '2023-09-27T22:30',
valid_time_end: '2023-09-28T02:00',
micros: 82_000_000,
currency_code: 'NOK',
hex_background_color: '#0090ff'
}

# Create Resource of EventTicket Object
ticket = GoogleWallet::Resources::EventTicket::Object.new(attributes: ticket_attributes)

# Push Object to Google Wallet API

# Option 1 (Recommended):
# Separated push and sign
ticket.push
jwt = ticket.sign(push_resource: false)

# Option 2:
# Combined - just use sign
jwt = ticket.sign # default is push_resource: true

# visit output link via authenticated browser
# or send it to you android device with Wallet app.
"https://pay.google.com/gp/v/save/#{jwt}"

```

#### Separation of Ticket Push and JWT Signing
The gem offers a distinct advantage when pushing tickets separately from the signing phase. If tickets are pushed individually, the subsequent signing method utilizes only the ticket identifiers during the JWT signing process, rather than the entire ticket objects.

*Advantages of Using Ticket Identifiers:*

*By employing ticket identifiers in the signing process instead of the full ticket objects, it significantly reduces the length of the final link generated. This streamlined approach allows for a more efficient and concise link that can be easily sent to the user.*

### Result



## Development

After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/vergilet/google_wallet.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).