android_in_app_billing 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe03c374ca35357368e79abe1facece02f384799
4
+ data.tar.gz: 86b324719b984675b71700ddece5990efd2de6dc
5
+ SHA512:
6
+ metadata.gz: 94957ff3b1014987e1208dfbef4f0173d9eb3ca5bf8e041c614a5fadf88d6722efde035b8889747661cfc505f7a33f99337d7c6ca5e21bfee06dcd35bda35dea
7
+ data.tar.gz: 9cbb13f38fbeb36c4c767ee0d892c43b8d998a0b2d50b556e0a3592cb7f0bd739bed7fc85eab1b6c78426f686683624a2ff9934508d2e7f7b3c85e684bb1940c
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --require spec_helper.rb
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in android_in_app_billing.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2012 Square Inc.
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # AndroidInAppBilling
2
+
3
+ [![Build Status](https://secure.travis-ci.org/SPBTV/android_in_app_billing.png?branch=master)](http://travis-ci.org/SPBTV/android_in_app_billing)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'android_in_app_billing'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install android_in_app_billing
20
+
21
+ ## Usage
22
+
23
+ ### Configuration
24
+ ```ruby
25
+ AndroidInAppBilling.configure do |config|
26
+ config.package_name = 'com.example.android'
27
+ config.json_key_path = '/path/to/a/json_key.json'
28
+ config.package_public_key = 'RSA public key'
29
+ end
30
+ ```
31
+
32
+ ### Working with purchase data from android clients
33
+
34
+ `purchase_data` and `data_signature` are the values android app gets from a purchase request. See https://developer.android.com/google/play/billing/billing_reference.html#getBuyIntent
35
+
36
+ ```ruby
37
+ purchase = AndroidInAppBilling::InappPurchase.new(data: purchase_data, signature: data_signature)
38
+
39
+ # attribute accessors:
40
+ purchase.token # => JWT token
41
+ purchase.auto_renewing # => true/false
42
+ # ... (other attributes, see `AndroidInAppBilling::InappPurchase` and the link above)
43
+
44
+ # signature validation:
45
+ purchase.signature_valid? # => true/false
46
+ ```
47
+
48
+ ### Working with purchase updates
49
+
50
+ To get current subscription state this gem uses [android publisher v2 API](https://developers.google.com/android-publisher/api-ref/purchases/subscriptions)
51
+
52
+ ```ruby
53
+ client = AndroidInAppBilling::PublisherClient.new
54
+ subscription = client.get_subscription_purchase(purchase.product_id, purchase.token)
55
+
56
+ # attribute accessors:
57
+ subscription.payment_state # => 'pending' / 'trial' / 'received'
58
+ subscription.expires_at # => some DateTime
59
+ # ... (other attributes, see `AndroidInAppBilling::SubscriptionPurchase` and the link above)
60
+ ```
61
+
62
+ ## Development
63
+
64
+ 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.
65
+
66
+ 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).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/android_in_app_billing.
71
+
72
+
73
+ ## License
74
+
75
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
76
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'android_in_app_billing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "android_in_app_billing"
8
+ spec.version = AndroidInAppBilling::VERSION
9
+ spec.authors = ["dkrasnov"]
10
+ spec.email = ["dkrasnov@spbtv.com"]
11
+
12
+ spec.summary = %q{A toolkit to work with android in-app purchases}
13
+ spec.description = %q{Implements in-app purchase data parsing, signature validation, }
14
+ spec.homepage = "https://github.com/SPBTV/android_in_app_billing"
15
+ spec.license = "Apache 2.0"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency 'google-api-client', '~> 0.10.3'
25
+ spec.add_runtime_dependency 'dry-configurable', '~> 0.7'
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.14'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'factory_girl', '~> 4.0'
31
+ spec.add_development_dependency 'vcr', '~> 3.0'
32
+ spec.add_development_dependency 'webmock', '~> 3.0'
33
+ spec.add_development_dependency 'pry'
34
+ end
data/bin/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'android_in_app_billing'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ require 'pry'
10
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,31 @@
1
+ require 'json'
2
+ require 'openssl'
3
+ require 'base64'
4
+ require 'time'
5
+ require 'google/apis/androidpublisher_v2'
6
+ require 'dry-configurable'
7
+
8
+ # A toolkit to work with android in-app purchases
9
+ module AndroidInAppBilling
10
+ extend Dry::Configurable
11
+
12
+ ## SETTINGS
13
+ # This two settings are for android publisher api client
14
+ setting :package_name
15
+ setting :json_key_path
16
+
17
+ # This one is used to verify signature of an inapp purchase
18
+ setting :package_public_key
19
+
20
+ # Too small to have it's own file
21
+ module ParseTools
22
+ # @param millis [Integer]
23
+ # @return [DateTime]
24
+ # @raise ArgumentError
25
+ def millis_to_datetime(millis)
26
+ millis && DateTime.strptime((millis.to_f / 1000).to_s, '%s')
27
+ end
28
+ end
29
+ end
30
+
31
+ Dir[Pathname.new(__dir__).join('android_in_app_billing/*')].each { |path| require path }
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+ module AndroidInAppBilling
3
+ # Represents the INAPP_PURCHASE concept from Google Play In-app Billing v3 API
4
+ # (java API for Android devices), including both data and signature
5
+ #
6
+ # @see https://developer.android.com/google/play/billing/billing_reference.html
7
+ #
8
+ class InappPurchase < SimpleDelegator
9
+ include ParseTools
10
+
11
+ Attributes = Struct.new(
12
+ :raw, :signature, :order_id, :package_name, :product_id, :purchased_at,
13
+ :state, :developer_payload, :token, :auto_renewing
14
+ )
15
+
16
+ PURCHASE_STATES = {
17
+ 0 => 'purchased',
18
+ 1 => 'cancelled',
19
+ 2 => 'refunded'
20
+ }.freeze
21
+
22
+ # @param data [String]
23
+ # @param signature [String]
24
+ # @!attribute raw
25
+ # @return [String]
26
+ # @!attribute signature
27
+ # @return [String]
28
+ # @!attribute order_id
29
+ # @return [String]
30
+ # @!attribute package_name
31
+ # @return [String]
32
+ # @!attribute product_id
33
+ # @return [String]
34
+ # @!attribute purchased_at
35
+ # @return [DateTime]
36
+ # @!attribute state
37
+ # @return [String]
38
+ # @!attribute developer_payload
39
+ # @return [String]
40
+ # @!attribute token
41
+ # @return [String]
42
+ # @!attribute auto_renewing
43
+ # @return [Boolean]
44
+ def initialize(data:, signature:)
45
+ super Attributes.new(data, parse_signature(signature), *parse_data(data))
46
+ end
47
+
48
+ # @return [Hash]
49
+ def attributes
50
+ to_h.reject { |k, _| [:raw, :signature].include?(k) }
51
+ end
52
+
53
+ # @return [true, false]
54
+ def signature_valid?
55
+ signature_verifier.call
56
+ end
57
+
58
+ private
59
+
60
+ def parse_signature(signature)
61
+ Base64.decode64(signature)
62
+ end
63
+
64
+ def parse_data(raw_data) # rubocop:disable Metrics/MethodLength
65
+ data = JSON.parse(raw_data)
66
+
67
+ [
68
+ data.fetch('orderId', ''),
69
+ data.fetch('packageName'),
70
+ data.fetch('productId'),
71
+ millis_to_datetime(data.fetch('purchaseTime')),
72
+ PURCHASE_STATES[data.fetch('purchaseState')],
73
+ data.fetch('developerPayload', ''),
74
+ data.fetch('purchaseToken'),
75
+ data.fetch('autoRenewing')
76
+ ]
77
+ end
78
+
79
+ def signature_verifier
80
+ SignatureVerifier.new(data: raw, signature: signature)
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'publisher_client/client_builder'
3
+
4
+ module AndroidInAppBilling
5
+ # Client for android publisher v2 API
6
+ #
7
+ # @see https://developers.google.com/android-publisher/api-ref/
8
+ #
9
+ class PublisherClient
10
+ def initialize
11
+ @client = ClientBuilder.build
12
+ end
13
+
14
+ # @param product_id [String]
15
+ # @param token [String]
16
+ # @return [AndroidInAppBilling::SubscriptionPurchase]
17
+ # @raise Google::Apis::ClientError
18
+ # @raise Google::Apis::ServerError
19
+ # @raise Signet::AuthorizationError
20
+ def get_purchase_subscription(product_id, token)
21
+ response = client.get_purchase_subscription(package_name, product_id, token)
22
+ SubscriptionPurchase.new(response.to_h)
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :client
28
+
29
+ def package_name
30
+ AndroidInAppBilling.config.package_name
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+ module AndroidInAppBilling
3
+ class PublisherClient
4
+ # Knows how to build android publisher v2 api client
5
+ class ClientBuilder
6
+ SCOPE = ['https://www.googleapis.com/auth/androidpublisher'].freeze
7
+
8
+ class << self
9
+ # @return [Google::Apis::AndroidpublisherV2::AndroidPublisherService]
10
+ def build
11
+ client_class.new.tap do |client|
12
+ client.authorization = build_authorization
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def client_class
19
+ Google::Apis::AndroidpublisherV2::AndroidPublisherService
20
+ end
21
+
22
+ def build_authorization
23
+ json_key_io = StringIO.new(File.read(json_key_path))
24
+
25
+ Google::Auth::DefaultCredentials.make_creds(
26
+ scope: SCOPE,
27
+ json_key_io: json_key_io
28
+ )
29
+ end
30
+
31
+ def json_key_path
32
+ AndroidInAppBilling.config.json_key_path
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ module AndroidInAppBilling
3
+ # Verifies that signature matches to the signed data
4
+ #
5
+ class SignatureVerifier
6
+ # @param data [String]
7
+ # @param signature [String]
8
+ def initialize(data:, signature:)
9
+ @data = data
10
+ @signature = signature
11
+ end
12
+
13
+ # @return [true, false]
14
+ def call
15
+ public_key.verify(OpenSSL::Digest::SHA1.new, signature, data)
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :data, :signature, :public_key
21
+
22
+ def public_key
23
+ OpenSSL::PKey::RSA.new(public_key_pem)
24
+ end
25
+
26
+ def public_key_pem
27
+ AndroidInAppBilling.config.package_public_key
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+ module AndroidInAppBilling
3
+ # Represents SubscriptionPurchase resource from android publisher v2 API
4
+ # @see https://developers.google.com/android-publisher/api-ref/purchases/subscriptions
5
+ #
6
+ class SubscriptionPurchase < SimpleDelegator
7
+ include ParseTools
8
+
9
+ Attributes = Struct.new(
10
+ :kind, :auto_renewing, :country_code, :price_amount_micros,
11
+ :price_currency_code, :payment_state, :expires_at, :started_at,
12
+ :user_cancelled_at, :cancel_reason, :developer_payload
13
+ )
14
+
15
+ PAYMENT_STATES = {
16
+ 0 => 'pending',
17
+ 1 => 'received',
18
+ 2 => 'trial'
19
+ }.freeze
20
+
21
+ CANCEL_REASONS = {
22
+ 0 => 'user',
23
+ 1 => 'system'
24
+ }.freeze
25
+
26
+ # @param raw_subscription_purchase [Hash]
27
+ # @!attribute kind
28
+ # @return [String]
29
+ # @!attribute auto_renewing
30
+ # @return [true,false]
31
+ # @!attribute country_code
32
+ # @return [String]
33
+ # @!attribute price_amount_micros
34
+ # @return [Integer]
35
+ # @!attribute price_currency_code
36
+ # @return [String]
37
+ # @!attribute payment_state
38
+ # @return [String,nil]
39
+ # @!attribute expires_at
40
+ # @return [DateTime]
41
+ # @!attribute started_at
42
+ # @return [DateTime]
43
+ # @!attribute user_cancelled_at
44
+ # @return [DateTime,nil]
45
+ # @!attribute cancel_reason
46
+ # @return [String,nil]
47
+ # @!attribute developer_payload
48
+ # @return [String,nil]
49
+ def initialize(raw_subscription_purchase)
50
+ super Attributes.new(*parse_raw(raw_subscription_purchase))
51
+ end
52
+
53
+ private
54
+
55
+ def parse_raw(raw) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
56
+ [
57
+ raw.fetch(:kind),
58
+ raw.fetch(:auto_renewing),
59
+ raw.fetch(:country_code),
60
+ raw.fetch(:price_amount_micros).to_i,
61
+ raw.fetch(:price_currency_code),
62
+ PAYMENT_STATES[raw.fetch(:payment_state, nil)],
63
+ millis_to_datetime(raw.fetch(:expiry_time_millis)),
64
+ millis_to_datetime(raw.fetch(:start_time_millis)),
65
+ millis_to_datetime(raw.fetch(:user_cancellation_time_millis, nil)),
66
+ CANCEL_REASONS[raw.fetch(:cancel_reason, nil)],
67
+ raw.fetch(:developer_payload, nil)
68
+ ]
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module AndroidInAppBilling
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: android_in_app_billing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - dkrasnov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: google-api-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: dry-configurable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.7'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: factory_girl
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: 'Implements in-app purchase data parsing, signature validation, '
140
+ email:
141
+ - dkrasnov@spbtv.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - Gemfile
150
+ - LICENSE
151
+ - README.md
152
+ - Rakefile
153
+ - android_in_app_billing.gemspec
154
+ - bin/console
155
+ - bin/setup
156
+ - lib/android_in_app_billing.rb
157
+ - lib/android_in_app_billing/inapp_purchase.rb
158
+ - lib/android_in_app_billing/publisher_client.rb
159
+ - lib/android_in_app_billing/publisher_client/client_builder.rb
160
+ - lib/android_in_app_billing/signature_verifier.rb
161
+ - lib/android_in_app_billing/subscription_purchase.rb
162
+ - lib/android_in_app_billing/version.rb
163
+ homepage: https://github.com/SPBTV/android_in_app_billing
164
+ licenses:
165
+ - Apache 2.0
166
+ metadata: {}
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 2.6.11
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: A toolkit to work with android in-app purchases
187
+ test_files: []