android_in_app_billing 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe03c374ca35357368e79abe1facece02f384799
4
- data.tar.gz: 86b324719b984675b71700ddece5990efd2de6dc
3
+ metadata.gz: 97580ae696924c35d2fac3368163abaf34205584
4
+ data.tar.gz: 1023ecc30ac9f98f00033b075a29348246c37b12
5
5
  SHA512:
6
- metadata.gz: 94957ff3b1014987e1208dfbef4f0173d9eb3ca5bf8e041c614a5fadf88d6722efde035b8889747661cfc505f7a33f99337d7c6ca5e21bfee06dcd35bda35dea
7
- data.tar.gz: 9cbb13f38fbeb36c4c767ee0d892c43b8d998a0b2d50b556e0a3592cb7f0bd739bed7fc85eab1b6c78426f686683624a2ff9934508d2e7f7b3c85e684bb1940c
6
+ metadata.gz: 4180326a9dd7526e1007b2bee7020bf90dd13af44639699a4df918bca48440cc7b755c086274eefe617a88ac28179f4513140b90f203619312999207853b7eb6
7
+ data.tar.gz: 4c26867335b907c2ccd70225750288301b1dde536c7587f47e82e114dbf59c3b4ff6e5d8deabf2cc0a3b7b13d85bd7b7870a971f3035cf291b5b9ced0908eea7
data/README.md CHANGED
@@ -59,6 +59,27 @@ subscription.expires_at # => some DateTime
59
59
  # ... (other attributes, see `AndroidInAppBilling::SubscriptionPurchase` and the link above)
60
60
  ```
61
61
 
62
+ ## Testing
63
+
64
+ This gem provides a factory to generate raw purchase data+signature, which you can use in your tests:
65
+
66
+ ```ruby
67
+ require 'android_in_app_billing/testing'
68
+
69
+ # See lib/factories/raw_inapp_purchase.rb for the list of attributes
70
+ raw = build(:android_in_app_billing_raw_inapp_purchase)
71
+ # => { data: "...", signature: "..." }
72
+
73
+ # Factory signs purchase data using AndroidInAppBilling::Testing::PRIVATE_KEY.
74
+ # If you want to verify this signature, you should configure AndroidInAppBilling
75
+ # to use correspondent public key
76
+ AndroidInAppBilling.config.package_public_key = AndroidInAppBilling::Testing::PUBLIC_KEY
77
+
78
+ # Then signature verification will pass
79
+ inapp = AndroidInAppBilling::InAppPurchase.new(raw)
80
+ inapp.signature_valid? # => true
81
+ ```
82
+
62
83
  ## Development
63
84
 
64
85
  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.
@@ -67,10 +88,10 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
67
88
 
68
89
  ## Contributing
69
90
 
70
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/android_in_app_billing.
91
+ Bug reports and pull requests are welcome on GitHub at https://github.com/SPBTV/android_in_app_billing.
71
92
 
72
93
 
73
94
  ## License
74
95
 
75
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
96
+ The gem is available as open source under the terms of the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0).
76
97
 
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+ module AndroidInAppBilling
3
+ module Testing
4
+ # Both public and private keys were generated using this code:
5
+ #
6
+ # require 'openssl'
7
+ #
8
+ # key = OpenSSL::PKey::RSA.new(2048)
9
+ #
10
+ # key.public_key.to_pem # => public key
11
+ # key.to_pem # => private key
12
+ PUBLIC_KEY = <<-KEY.gsub(/^\s*/, '')
13
+ -----BEGIN PUBLIC KEY-----
14
+ MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0VZoxr2Z4Z55PR9DnBEl
15
+ xNneoXvBEofqT0lstG/TKLaNdIGnyZASO0cupb1U08H/2qGIRFznSCJyW4H69Qsv
16
+ FLQQCPy7mitA9HPK5FQ9/7//lwNBvZkxPaNGNbjpX2/nolQUjLJ8Mz088vfVBvf/
17
+ WaabsjkIWtKIQgRWJU/Xa/Hbj8v5YcC500B4KiyMSKwKaOPylcQW3fX5w2f+JZbh
18
+ krmqK+yQimvny07e/g6bS5BeJwmA9NG5PxGtM1ifgTK9ahypUkr6zb6Fy22POepO
19
+ 4PfXEIaE9rHrMkVE7A48SrSaB1yR0vubxp98oLLgFcpFYip+YFcuVqWGam13187a
20
+ 5wIDAQAB
21
+ -----END PUBLIC KEY-----
22
+ KEY
23
+
24
+ # Is used only for purchase data signing
25
+ PRIVATE_KEY = <<-KEY.gsub(/^\s*/, '')
26
+ -----BEGIN RSA PRIVATE KEY-----
27
+ MIIEowIBAAKCAQEA0VZoxr2Z4Z55PR9DnBElxNneoXvBEofqT0lstG/TKLaNdIGn
28
+ yZASO0cupb1U08H/2qGIRFznSCJyW4H69QsvFLQQCPy7mitA9HPK5FQ9/7//lwNB
29
+ vZkxPaNGNbjpX2/nolQUjLJ8Mz088vfVBvf/WaabsjkIWtKIQgRWJU/Xa/Hbj8v5
30
+ YcC500B4KiyMSKwKaOPylcQW3fX5w2f+JZbhkrmqK+yQimvny07e/g6bS5BeJwmA
31
+ 9NG5PxGtM1ifgTK9ahypUkr6zb6Fy22POepO4PfXEIaE9rHrMkVE7A48SrSaB1yR
32
+ 0vubxp98oLLgFcpFYip+YFcuVqWGam13187a5wIDAQABAoIBAQC9/YaqmXoH4yR1
33
+ 7OIXyxhUSMheF0tr3h8yRpl6SeODl+taSjJWJYPmePxFQEi0x+XGL8TVBtyCA4F2
34
+ u8lgjP319FZ5UaeSjJ8vPchu4mZCr6bxD+uigF7Ial9WcrScAZxhH55m87b1aibe
35
+ /T9CS+JdI3E7l7eVdm5kPDtTMdt6Ayu/JIdPARdgOvh3Ez82I3ZO8HtgQ6bVD8J4
36
+ x/UJSyqQkGuWi+pOaz3bWao/DlfilLhySov430xEWoH5FmOIgxqdVb3Lb0HlCFiQ
37
+ 2L9lsCyLZQplf1SQLbF+LDEg/l4cWVwWPBcCg5Gy/dXj3a3KQyowiZcnKPAGW+2o
38
+ ZAcRjc9BAoGBAO2+1M/I918Os3IDQEuza+63N6YsgpKNdqBDokGuNpJz6pnefRFY
39
+ 6a5HKmCds/3YDhqijXNrMUWN9LRW7pQaxVZgnmo2hO/uYpgP+CaLX+FTc5gKB8RU
40
+ Ujp4YvnBomSzGIBpUR8j/ioVKGfXKdagJFnTUHBUsLn5ktaYj8pjnyM9AoGBAOFp
41
+ L+DTzQLkbLCLweianDp3NpD++CWOIucC4MZGI1BYBYROti55sCwyePcOeQXYIgxl
42
+ hH8CiXa9lS4299lXUVPA4ATp7dtoNzNHfKN2qOzDQfl/K8NbQzVFjI/EDs+655KT
43
+ 68hbEZpdAY/WxrJzZ+yBlEwoOmlHkhEjxZPhqIjzAoGAEH3GQUuNbTiV1fjHwviF
44
+ Kh/nak14GTZa3i8S2D9/ZZVI1reKMWPbgc1J8T2/OIJ+J/bSnQj4d/yq1r+Y+QkK
45
+ Wz2Ef5WcjxAYIrgo3HOaiQTC5e78LvAya//hzbVS0G1j67Rifih+/uhMzzcrncmp
46
+ +9keoUwenifjuaMHhmB2r3kCgYAP69MS6ULgwmue6LAwksMYKhVzll7GoEx8zqo7
47
+ tvaFlUIGf1zE2ZmE9aevo5kOvZ5iC8WZBv/YoDlqQz2sX0uCQ+xOzIsdZTYI7DK0
48
+ hQwXdQ8y5TWdHdQYbiooeWumZog2xTXxN+V9ZrZWh5APSLF9dgWYf3rotsJtbX5m
49
+ HJk/2wKBgG8NCzqi/INQNdDBsSDPdi1oU2nvI/eQfGcnvyvuDHmd3nd/GrPkHUHn
50
+ suAxetCm2u/Q0B+V+5szG3UyF/AIiKoYdBf2fwnAxEyRebQFCisGxzb6izxM/z6V
51
+ 8NweZnhm8CMgaka6W+IjKu2OB3CeqIPDzKo+GY5ArdEcsgjtuo9n
52
+ -----END RSA PRIVATE KEY-----
53
+ KEY
54
+ end
55
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+ FactoryGirl.define do
3
+ factory :android_in_app_billing_raw_inapp_purchase, class: Hash do
4
+ package_name 'com.spbtv.android.rspec'
5
+ product_id 'test_subscription'
6
+ purchase_time { (Date.today - 1) }
7
+ purchase_state 0
8
+ developer_payload ''
9
+ purchase_token 'kicgkmmieakfkgfnkclldoao.AO-J1OyAN-PCXHeriJ7W99KLeA_hZhqOZS3vnA9a5Mo1fyFhg4iF61FMVOfCq8B9Jc5tzknR-Et58T79LsdIEWH2vBHOkSHJDOBTnknZgaSuhKjoGXq33M2VQxbQaz_KrQLRAZGPn7-gxQXcqaxvorNj4c2Q_1jaA'
10
+ auto_renewing true
11
+ order_id 'GPA.1234-5678-9012-34567'
12
+
13
+ trait :cancelled do
14
+ purchase_state 1
15
+ auto_renewing false
16
+ end
17
+
18
+ # After successfull in-app purchase, clients send us purchase data and
19
+ # it's signature. Data is a json string. Signature is base64-encoded.
20
+ #
21
+ initialize_with do
22
+ data = attributes
23
+
24
+ # Google uses milliseconds since the epoch as timestamps
25
+ data[:purchase_time] = data[:purchase_time].strftime('%s%3N')
26
+
27
+ # Google uses lowerCamelCase for data field names
28
+ to_lower_camelcase = Proc.new do |str|
29
+ str.split('_').map.with_index { |part, i| i == 0 ? part : part.capitalize }.join
30
+ end
31
+ data = data.map { |k, v| [to_lower_camelcase.call(k.to_s), v] }.to_h
32
+
33
+ data_json = data.to_json
34
+
35
+ # Google uses SHA1 when signing data
36
+ private_key = OpenSSL::PKey::RSA.new(AndroidInAppBilling::Testing::PRIVATE_KEY)
37
+ signature = private_key.sign(OpenSSL::Digest::SHA1.new, data_json)
38
+ # And then encodes signature using base64
39
+ base64_encoded_signature = Base64.encode64(signature).delete("\n")
40
+
41
+ { data: data_json, signature: base64_encoded_signature }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ require 'factory_girl'
2
+
3
+ require_relative './testing/constants.rb'
4
+ require_relative './testing/factories.rb'
5
+
6
+ module AndroidInAppBilling
7
+ module Testing
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module AndroidInAppBilling
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: android_in_app_billing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - dkrasnov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-16 00:00:00.000000000 Z
11
+ date: 2017-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -159,6 +159,9 @@ files:
159
159
  - lib/android_in_app_billing/publisher_client/client_builder.rb
160
160
  - lib/android_in_app_billing/signature_verifier.rb
161
161
  - lib/android_in_app_billing/subscription_purchase.rb
162
+ - lib/android_in_app_billing/testing.rb
163
+ - lib/android_in_app_billing/testing/constants.rb
164
+ - lib/android_in_app_billing/testing/factories.rb
162
165
  - lib/android_in_app_billing/version.rb
163
166
  homepage: https://github.com/SPBTV/android_in_app_billing
164
167
  licenses: