├── .rspec ├── lib ├── googlepay │ ├── version.rb │ ├── configuration.rb │ ├── event_ticket_class.rb │ └── event_ticket_object.rb └── googlepay.rb ├── bin ├── console └── setup ├── .travis.yml ├── Rakefile ├── .gitignore ├── Gemfile ├── spec ├── googlepay_spec.rb ├── spec_helper.rb └── googlepay │ ├── event_ticket_object_spec.rb │ └── event_ticket_class_spec.rb ├── EXAMPLE.md ├── LICENSE.txt ├── googlepay.gemspec ├── Gemfile.lock ├── CODE_OF_CONDUCT.md └── README.md /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | --require spec_helper 4 | -------------------------------------------------------------------------------- /lib/googlepay/version.rb: -------------------------------------------------------------------------------- 1 | module Googlepay 2 | VERSION = "0.2.0" 3 | end 4 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "googlepay" 5 | require "pry" 6 | Pry.start 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | sudo: false 3 | language: ruby 4 | cache: bundler 5 | rvm: 6 | - 2.6.2 7 | before_install: gem install bundler -v 2.0.1 8 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require "rspec/core/rake_task" 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task :default => :spec 7 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /lib/googlepay/configuration.rb: -------------------------------------------------------------------------------- 1 | module Googlepay 2 | class Configuration 3 | attr_accessor :service_account 4 | 5 | def initialize 6 | @service_account = nil 7 | end 8 | end 9 | end -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /_yardoc/ 4 | /coverage/ 5 | /doc/ 6 | /pkg/ 7 | /spec/reports/ 8 | /spec/vcr_cassettes 9 | /tmp/ 10 | 11 | # rspec failure tracking 12 | .rspec_status 13 | 14 | .env -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | # Specify your gem's dependencies in googlepay.gemspec 4 | gemspec 5 | 6 | group :test do 7 | gem 'dotenv' 8 | gem 'simplecov' 9 | gem 'webmock' 10 | gem 'vcr' 11 | end -------------------------------------------------------------------------------- /spec/googlepay_spec.rb: -------------------------------------------------------------------------------- 1 | RSpec.describe Googlepay do 2 | it "has a version number" do 3 | expect(Googlepay::VERSION).not_to be nil 4 | end 5 | 6 | it "fetches an authentication token", vcr: {cassette_name: :fetch_token} do 7 | result = Googlepay.fetch_token 8 | expect(result.class).to eq(String) 9 | expect(result).to include('ya29.') 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'bundler/setup' 2 | require 'dotenv/load' 3 | require 'googlepay' 4 | require 'simplecov' 5 | SimpleCov.start 6 | require 'vcr' 7 | 8 | RSpec.configure do |config| 9 | config.example_status_persistence_file_path = ".rspec_status" 10 | config.disable_monkey_patching! 11 | config.expect_with :rspec do |c| 12 | c.syntax = :expect 13 | end 14 | 15 | config.before(:all) do 16 | Googlepay.configure do |config| 17 | config.service_account = eval(ENV['SERVICE_ACCOUNT']) 18 | end 19 | end 20 | end 21 | 22 | VCR.configure do |c| 23 | c.cassette_library_dir = 'spec/vcr_cassettes' 24 | c.hook_into :webmock 25 | c.allow_http_connections_when_no_cassette = false 26 | c.default_cassette_options = {record: :new_episodes} 27 | c.configure_rspec_metadata! 28 | c.ignore_hosts 'codeclimate.com' 29 | end -------------------------------------------------------------------------------- /spec/googlepay/event_ticket_object_spec.rb: -------------------------------------------------------------------------------- 1 | 2 | RSpec.describe Googlepay::EventTicketObject do 3 | 4 | before(:each) do 5 | @parameters = { 6 | "classId": "3388000000002437969.123456789", 7 | "id": "3388000000002437969.23456", 8 | "state": "active", 9 | "origin": "https://brittanymartin.dev" 10 | } 11 | end 12 | 13 | describe '#new' do 14 | it 'works' do 15 | parameters = @parameters 16 | result = Googlepay::EventTicketObject.new(parameters) 17 | expect(result.class).to eq(Googlepay::EventTicketObject) 18 | end 19 | end 20 | 21 | describe '#create' do 22 | it 'works', vcr: {cassette_name: :create_event_ticket_object} do 23 | event_ticket_object = Googlepay::EventTicketObject.new(@parameters) 24 | result = event_ticket_object.create 25 | expect(result.class).to be(String) 26 | end 27 | end 28 | 29 | end 30 | -------------------------------------------------------------------------------- /lib/googlepay/event_ticket_class.rb: -------------------------------------------------------------------------------- 1 | module Googlepay 2 | class EventTicketClass 3 | 4 | EVENT_URL = 'https://www.googleapis.com/walletobjects/v1/eventTicketClass' 5 | 6 | def initialize(parameters) 7 | @parameters = parameters 8 | end 9 | 10 | def create 11 | result = HTTParty.post("#{EVENT_URL}?access_token=#{Googlepay.token}", 12 | :body => @parameters.to_json, 13 | :headers => { 'Content-Type' => 'application/json' } ) 14 | return result if result['error'].nil? 15 | update if result['error']['code'] == 409 16 | end 17 | 18 | def update 19 | HTTParty.put("#{EVENT_URL}/#{@parameters[:id]}?access_token=#{Googlepay.token}", 20 | :body => @parameters.to_json, 21 | :headers => { 'Content-Type' => 'application/json' } ) 22 | end 23 | end 24 | 25 | end -------------------------------------------------------------------------------- /EXAMPLE.md: -------------------------------------------------------------------------------- 1 | ### JSON EventTicketClass 2 | 3 | parameters = 4 | { 5 | "kind": "walletobjects#eventTicketClass", 6 | "id": "3388000000002437969.123456789", 7 | "reviewStatus": "underReview", 8 | "issuerName": "Your Company Name", 9 | "eventName": { 10 | "kind": "walletobjects#localizedString", 11 | "translatedValues": [ 12 | { 13 | "kind": "walletobjects#translatedString", 14 | "language": "en-US", 15 | "value": "Exciting Event" 16 | } ], 17 | "defaultValue": { 18 | "kind": "walletobjects#translatedString", 19 | "language": "en-US", 20 | "value": "Ticket" 21 | } 22 | } 23 | } 24 | 25 | ### JSON EventTicketObject 26 | 27 | parameters = 28 | { 29 | "classId": "3388000000002437969.1234567890", 30 | "id": "3388000000002437969.123", 31 | "state": "active", 32 | "origin": "https://brittanymartin.dev" 33 | } 34 | -------------------------------------------------------------------------------- /lib/googlepay.rb: -------------------------------------------------------------------------------- 1 | require 'googleauth' 2 | require 'httparty' 3 | require 'tempfile' 4 | require 'zeitwerk' 5 | 6 | loader = Zeitwerk::Loader.for_gem 7 | loader.setup 8 | 9 | module Googlepay 10 | 11 | SCOPE = 'https://www.googleapis.com/auth/wallet_object.issuer' 12 | 13 | def self.token 14 | fetch_token 15 | end 16 | 17 | class << self 18 | attr_accessor :configuration 19 | end 20 | 21 | def self.configuration 22 | @configuration ||= Configuration.new 23 | end 24 | 25 | def self.reset 26 | @configuration = Configuration.new 27 | end 28 | 29 | def self.configure 30 | yield(configuration) 31 | end 32 | 33 | private 34 | 35 | def self.fetch_token 36 | json_key = Tempfile.new 37 | json_key.write(Googlepay.configuration.service_account.to_json) 38 | json_key.rewind 39 | authorizer = Google::Auth::ServiceAccountCredentials.make_creds( 40 | json_key_io: json_key, 41 | scope: SCOPE 42 | ) 43 | json_key.close 44 | authorizer.fetch_access_token!['access_token'] 45 | end 46 | 47 | def self.root 48 | File.expand_path '../..', __FILE__ 49 | end 50 | 51 | end -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Brittany Martin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/googlepay/event_ticket_object.rb: -------------------------------------------------------------------------------- 1 | module Googlepay 2 | class EventTicketObject 3 | 4 | EVENT_URL = 'https://www.googleapis.com/walletobjects/v1/eventTicketObject?' 5 | 6 | def initialize(parameters) 7 | @parameters = parameters 8 | end 9 | 10 | def create 11 | rsa_private = OpenSSL::PKey::RSA.new Googlepay.configuration.service_account[:private_key] 12 | create_event_object(@parameters) 13 | payload = { 14 | "iss": Googlepay.configuration.service_account[:client_email], 15 | "aud": 'google', 16 | "typ": 'savetoandroidpay', 17 | "iat": Time.now.utc.to_i, 18 | "payload": { 19 | 'eventTicketObjects': [@parameters.dup.tap { |h| h.delete(:origin) }] 20 | }, 21 | 'origins': @parameters.fetch(:origin) 22 | } 23 | JWT.encode payload, rsa_private, 'RS256' 24 | end 25 | 26 | private 27 | 28 | def create_event_object(event_ticket) 29 | result = HTTParty.post("#{EVENT_URL}access_token=#{Googlepay.token}", 30 | :body => event_ticket.to_json, 31 | :headers => { 'Content-Type' => 'application/json' } ) 32 | end 33 | end 34 | 35 | end -------------------------------------------------------------------------------- /spec/googlepay/event_ticket_class_spec.rb: -------------------------------------------------------------------------------- 1 | RSpec.describe Googlepay::EventTicketClass do 2 | 3 | before(:each) do 4 | @parameters = { 5 | "kind": "walletobjects#eventTicketClass", 6 | "id": "3388000000002437969.123456789", 7 | "reviewStatus": "underReview", 8 | "issuerName": "Your Company Name", 9 | "eventName": { 10 | "kind": "walletobjects#localizedString", 11 | "translatedValues": [ { 12 | "kind": "walletobjects#translatedString", 13 | "language": "en-US", 14 | "value": "Your Event Title" 15 | }], 16 | "defaultValue": { 17 | "kind": "walletobjects#translatedString", 18 | "language": "en-US", 19 | "value": "Ticket" 20 | } 21 | } 22 | } 23 | end 24 | 25 | describe '#new' do 26 | it 'works' do 27 | parameters = @parameters 28 | result = Googlepay::EventTicketClass.new(parameters) 29 | expect(result.class).to eq(Googlepay::EventTicketClass) 30 | end 31 | end 32 | 33 | describe '#create' do 34 | it 'works', vcr: {cassette_name: :create_event_ticket_class} do 35 | parameters = @parameters 36 | event_ticket_class = Googlepay::EventTicketClass.new(parameters) 37 | result = event_ticket_class.create 38 | expect(result["kind"]).to eq("walletobjects#eventTicketClass") 39 | expect(result.code).to eq(200) 40 | end 41 | end 42 | 43 | describe '#update' do 44 | it 'works', vcr: {cassette_name: :update_event_ticket_class} do 45 | parameters = @parameters 46 | @parameters[:eventName][:defaultValue][:value] = 'Updated Ticket' 47 | event_ticket_class = Googlepay::EventTicketClass.new(parameters) 48 | result = event_ticket_class.update 49 | expect(result['eventName']['defaultValue']['value']).to eq('Updated Ticket') 50 | expect(result.code).to eq(200) 51 | end 52 | end 53 | 54 | end 55 | -------------------------------------------------------------------------------- /googlepay.gemspec: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | lib = File.expand_path("../lib", __FILE__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require "googlepay/version" 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = "googlepay" 9 | spec.version = Googlepay::VERSION 10 | spec.authors = ["Brittany Martin"] 11 | spec.email = ["brittany.jill.martin@gmail.com"] 12 | 13 | spec.summary = "An engaging way to offer passes, loyalty programs, and more with Google Pay." 14 | spec.homepage = "https://github.com/regularlady/googlepay" 15 | spec.license = "MIT" 16 | 17 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' 18 | # to allow pushing to a single host or delete this section to allow pushing to any host. 19 | if spec.respond_to?(:metadata) 20 | spec.metadata["homepage_uri"] = spec.homepage 21 | spec.metadata["source_code_uri"] = spec.homepage 22 | spec.metadata["changelog_uri"] = spec.homepage 23 | else 24 | raise "RubyGems 2.0 or newer is required to protect against " \ 25 | "public gem pushes." 26 | end 27 | 28 | # Specify which files should be added to the gem when it is released. 29 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 30 | spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do 31 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 32 | end 33 | spec.bindir = "exe" 34 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 35 | spec.require_paths = ["lib"] 36 | spec.required_ruby_version = ">= 2.2.0" 37 | 38 | spec.add_development_dependency "bundler", "~> 2.0" 39 | spec.add_development_dependency "pry" 40 | spec.add_development_dependency "rake", ">= 12.3.3" 41 | spec.add_development_dependency "rspec", "~> 3.0" 42 | 43 | spec.add_dependency "googleauth" 44 | spec.add_dependency "httparty" 45 | spec.add_dependency "json" 46 | spec.add_dependency "zeitwerk" 47 | end 48 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | googlepay (0.2.0) 5 | googleauth 6 | httparty 7 | json 8 | zeitwerk 9 | 10 | GEM 11 | remote: https://rubygems.org/ 12 | specs: 13 | addressable (2.7.0) 14 | public_suffix (>= 2.0.2, < 5.0) 15 | coderay (1.1.3) 16 | crack (0.4.3) 17 | safe_yaml (~> 1.0.0) 18 | diff-lcs (1.4.4) 19 | docile (1.3.2) 20 | dotenv (2.7.5) 21 | faraday (1.0.1) 22 | multipart-post (>= 1.2, < 3) 23 | googleauth (0.13.0) 24 | faraday (>= 0.17.3, < 2.0) 25 | jwt (>= 1.4, < 3.0) 26 | memoist (~> 0.16) 27 | multi_json (~> 1.11) 28 | os (>= 0.9, < 2.0) 29 | signet (~> 0.14) 30 | hashdiff (1.0.1) 31 | httparty (0.18.1) 32 | mime-types (~> 3.0) 33 | multi_xml (>= 0.5.2) 34 | json (2.3.1) 35 | jwt (2.2.1) 36 | memoist (0.16.2) 37 | method_source (1.0.0) 38 | mime-types (3.3.1) 39 | mime-types-data (~> 3.2015) 40 | mime-types-data (3.2020.0512) 41 | multi_json (1.14.1) 42 | multi_xml (0.6.0) 43 | multipart-post (2.1.1) 44 | os (1.1.0) 45 | pry (0.13.1) 46 | coderay (~> 1.1) 47 | method_source (~> 1.0) 48 | public_suffix (4.0.5) 49 | rake (13.0.1) 50 | rspec (3.9.0) 51 | rspec-core (~> 3.9.0) 52 | rspec-expectations (~> 3.9.0) 53 | rspec-mocks (~> 3.9.0) 54 | rspec-core (3.9.2) 55 | rspec-support (~> 3.9.3) 56 | rspec-expectations (3.9.2) 57 | diff-lcs (>= 1.2.0, < 2.0) 58 | rspec-support (~> 3.9.0) 59 | rspec-mocks (3.9.1) 60 | diff-lcs (>= 1.2.0, < 2.0) 61 | rspec-support (~> 3.9.0) 62 | rspec-support (3.9.3) 63 | safe_yaml (1.0.5) 64 | signet (0.14.0) 65 | addressable (~> 2.3) 66 | faraday (>= 0.17.3, < 2.0) 67 | jwt (>= 1.5, < 3.0) 68 | multi_json (~> 1.10) 69 | simplecov (0.18.5) 70 | docile (~> 1.1) 71 | simplecov-html (~> 0.11) 72 | simplecov-html (0.12.2) 73 | vcr (6.0.0) 74 | webmock (3.8.3) 75 | addressable (>= 2.3.6) 76 | crack (>= 0.3.2) 77 | hashdiff (>= 0.4.0, < 2.0.0) 78 | zeitwerk (2.3.1) 79 | 80 | PLATFORMS 81 | ruby 82 | 83 | DEPENDENCIES 84 | bundler (~> 2.0) 85 | dotenv 86 | googlepay! 87 | pry 88 | rake (>= 12.3.3) 89 | rspec (~> 3.0) 90 | simplecov 91 | vcr 92 | webmock 93 | 94 | BUNDLED WITH 95 | 2.1.4 96 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at brittany.jill.martin@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ 75 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Googlepay 2 | 3 | ## Installation 4 | 5 | A Ruby interface to the Google Pay API. Currently focused on the Google Pay for Passes part of the API, with the intention of integrating with Google Pay for Payments in the future. 6 | 7 | ```ruby 8 | gem 'googlepay' 9 | ``` 10 | 11 | And then execute: 12 | 13 | $ bundle 14 | 15 | Or install it yourself as: 16 | 17 | $ gem install googlepay 18 | 19 | ## Try It 20 | 21 | To try an implementation of the gem, try it [here](https://google-pay-demo.herokuapp.com/) or view the demo code [here](https://github.com/regularlady/googlepay-demo). 22 | 23 | ## Setup 24 | 25 | In order to use the googlepay gem, you will need to have a Google Service account setup. 26 | 27 | #### Access to the REST API 28 | 29 | 1. Sign up for a [Google Cloud Platform](https://cloud.google.com/) account. 30 | 2. Create a new project. 31 | 3. Within the new project, set up a [Service Account](https://cloud.google.com/iam/docs/service-accounts). 32 | 4. Click on Actions on your new Service Account, Create Key, generate a JSON key and download. 33 | 5. Add the file into an initializer in your project. 34 | 35 | Example: initializers/googlepay.rb 36 | 37 | require 'googlepay' 38 | 39 | Googlepay.configure do |config| 40 | config.service_account = { 41 | "type": "service_account", 42 | "project_id": "", 43 | "private_key_id": "", 44 | "private_key": "", 45 | "client_email": "", 46 | "client_id": "", 47 | "auth_uri": "https://accounts.google.com/o/oauth2/auth", 48 | "token_uri": "https://oauth2.googleapis.com/token", 49 | "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", 50 | "client_x509_cert_url": "" 51 | } 52 | end 53 | 54 | preferably by storing them as an ENV VAR in YAML format. 55 | 56 | require 'googlepay' 57 | 58 | Googlepay.configure do |config| 59 | config.service_account = Rails.application.credentials.service_account 60 | #config.service_account = ENV['SERVICE_ACCOUNT'] 61 | end 62 | 63 | #### Tie your service account to your Google Pay API for Passes account 64 | 65 | Visit [here](https://developers.google.com/pay/passes/guides/get-started/basic-setup/get-access-to-rest-api) to learn how to work with Google on getting registered for a Google Pay API for Passes account and to access the Google Pay API for Passes Merchant Center. Once registered in the Merchant Center, save your Issuer ID. 66 | 67 | #### Enable the Google Pay API 68 | 69 | Visit https://console.developers.google.com/apis/api/walletobjects.googleapis.com/overview?project={YOUR PROJECT} to enable the API for your project. Without doing so will cause this error: 70 | 71 | Google Pay Passes API has not been used in project 615220349094 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/walletobjects.googleapis.com/overview?project={ID} then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. 72 | 73 | #### Use OAuth 2.0 for your Server to Server application 74 | 75 | This gem takes care of this for you, thanks to [googleauth](https://github.com/googleapis/google-auth-library-ruby). 76 | 77 | ## Usage 78 | 79 | ### Event Tickets 80 | 81 | JSON EventTicketClass must be created before EventTicketObjects can be created. 82 | 83 | Refer to the [Google Pay for Passes Code Snippets](https://developers.google.com/pay/passes/guides/pass-verticals/event-tickets/code-snippets) to build a JSON Object. I have also included simplified examples in EXAMPLE.md and you can review the specs for uses. 84 | 85 | #### Create/Update EventTicketClass 86 | 87 | parameters = JSON Object 88 | id = Googlepay::EventTicketClass.new(parameters)[:id] 89 | 90 | Use the Issuer ID and a Unique ID formatted {Issuer ID.Unique ID} for the ID of the JSON object. If the ID exists already, the gem will update the EventTicketClass automatically. 91 | 92 | More documentation [here](https://developers.google.com/pay/passes/rest/v1/eventticketclass). 93 | 94 | #### Create EventTicketObject 95 | 96 | Googlepay::EventTicketObject.new(parameters) 97 | 98 | Use the Class ID and a Unique ID formatted {Issuer ID.Unique ID} for the ID of the JSON object. Include the array of domains to whitelist JWT saving functionality in the origin parameter. The Google Pay API for Passes button will not render when the origins field is not defined. You could potentially get an "Load denied by X-Frame-Options" or "Refused to display" messages in the browser console when the origins field is not defined. 99 | 100 | More documentation [here](https://developers.google.com/pay/passes/rest/v1/eventticketobject). 101 | 102 | ## Development 103 | 104 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 105 | 106 | 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). 107 | 108 | ## Contributing 109 | 110 | Bug reports and pull requests are welcome on GitHub at https://github.com/regularlady/googlepay. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. 111 | 112 | ## License 113 | 114 | The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). 115 | 116 | The googlepay gem is not affiliated with or endorsed by Google. 117 | 118 | ## Code of Conduct 119 | 120 | Everyone interacting in the Googlepay project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/googlepay/blob/master/CODE_OF_CONDUCT.md). 121 | --------------------------------------------------------------------------------