mozpay 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/mozpay.rb +1 -0
- data/lib/mozpay/base.rb +180 -0
- data/lib/mozpay/version.rb +3 -0
- data/test/test_mozpay.rb +8 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6d900afc8385d9d40d8ea14972672e78cd6ff87f
|
4
|
+
data.tar.gz: 4aef6ed73b3824ccf2670704540a422506b8ca68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 272644a5d559370b657b227a7ebde2f1d2266d020ea226efb3c61f75479bc2bced177d1c3e7dc43507b6c9f310e0d179a9fe982a4f94c02ad22fb39e2c84cea8
|
7
|
+
data.tar.gz: 9fef5293d9eb6ecf1074dfb652cb06c5fbcbe64c93ebcda7a91e5c40cef95657c70b311c64513ab44b9c07ec632af6910ad4e1632707ac7792a923c52a37fe4b
|
data/lib/mozpay.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'mozpay/base'
|
data/lib/mozpay/base.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'jwt'
|
2
|
+
|
3
|
+
class Pay
|
4
|
+
|
5
|
+
# This is here solely to make sure I set up tests correctly.
|
6
|
+
|
7
|
+
def self.hi
|
8
|
+
return "Hello world!"
|
9
|
+
end
|
10
|
+
|
11
|
+
# This array keeps track of the tokens waiting for marketplace responses
|
12
|
+
|
13
|
+
@@purchaseQueue = {}
|
14
|
+
|
15
|
+
##
|
16
|
+
# Check purchaseQueue to see if token has resolved
|
17
|
+
#
|
18
|
+
# @param {Object} token
|
19
|
+
# @api public
|
20
|
+
##
|
21
|
+
|
22
|
+
def self.checkQueue(token)
|
23
|
+
status = @@purchaseQueue[token]
|
24
|
+
if status
|
25
|
+
if status != 'processing'
|
26
|
+
delete @@purchaseQueue[token]
|
27
|
+
end
|
28
|
+
return status || 'notfound'
|
29
|
+
else
|
30
|
+
return 'notfound'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# ##
|
35
|
+
# # Receive successful postback and mark token in queue accordingly
|
36
|
+
# #
|
37
|
+
# # @param {Object} token
|
38
|
+
# # @api public
|
39
|
+
# ##
|
40
|
+
|
41
|
+
# def self.postback(token)
|
42
|
+
# purchaseQueue[token] = 'success'
|
43
|
+
# end
|
44
|
+
|
45
|
+
# ##
|
46
|
+
# # Receive chargeback and mark token in queue accordingly
|
47
|
+
# #
|
48
|
+
# # @param {Object} settings
|
49
|
+
# # @api public
|
50
|
+
# ##
|
51
|
+
|
52
|
+
# def self.chargeback(token)
|
53
|
+
# purchaseQueue[token] = 'failure'
|
54
|
+
# end
|
55
|
+
|
56
|
+
# ##
|
57
|
+
# # Configure global settings.
|
58
|
+
# #
|
59
|
+
# # @param {Object} settings
|
60
|
+
# # @api public
|
61
|
+
# ##
|
62
|
+
|
63
|
+
# defaultConfig { 'mozPayAudience' => 'marketplace.firefox.com', 'mozPayType' => 'mozilla/payments/pay/', 'mozPayRoutePrefix' => '/mozpay'}
|
64
|
+
# config = defaultConfig;
|
65
|
+
|
66
|
+
# def self.configure(options)
|
67
|
+
# begin
|
68
|
+
# options = config.clone().merge(options)
|
69
|
+
# # don't I want to assign to config here?
|
70
|
+
# rescue
|
71
|
+
# raise 'Problem with options passed in, probably they were bad for some reason.'
|
72
|
+
# end
|
73
|
+
|
74
|
+
# if config['mozPayKey'].empty? || config['mozPaySecret'].empty?
|
75
|
+
# raise 'Missing mozPayKey or mozPaySecret'
|
76
|
+
# end
|
77
|
+
|
78
|
+
# puts(options)
|
79
|
+
# # 'cause I'm not sure if I did this right
|
80
|
+
# end
|
81
|
+
|
82
|
+
# def self.resetConfig
|
83
|
+
# config = defaultConfig
|
84
|
+
# # or should this be nil
|
85
|
+
# end
|
86
|
+
|
87
|
+
##
|
88
|
+
# Encode a JWT payment request.
|
89
|
+
#
|
90
|
+
# @param {Object} request
|
91
|
+
# @api public
|
92
|
+
##
|
93
|
+
|
94
|
+
def self.request(payload)
|
95
|
+
jwt_encoded = JWT.encode(payload, config.mozPaySecret, "HS256")
|
96
|
+
purchaseQueue[payload[productData]] = 'processing';
|
97
|
+
return jwt_encoded
|
98
|
+
end
|
99
|
+
|
100
|
+
# ##
|
101
|
+
# # Verify an incoming JWT payment notice.
|
102
|
+
# #
|
103
|
+
# # @param {String} encoded JWT
|
104
|
+
# # @api public
|
105
|
+
# ##
|
106
|
+
|
107
|
+
# def self.verify
|
108
|
+
# return JWT.decode(foreignJWT, config.mozPaySecret)
|
109
|
+
# end
|
110
|
+
|
111
|
+
# ##
|
112
|
+
# # Issue a JWT object (i.e. not encoded) for a payment request.
|
113
|
+
# #
|
114
|
+
# # @param {Object} request
|
115
|
+
# # @api public
|
116
|
+
# ##
|
117
|
+
|
118
|
+
# def self.issueRequest(request)
|
119
|
+
# requireConfig()
|
120
|
+
# return { 'iss' => config.mozPayKey, 'aud' => config.mozPayAudience, 'type' => 'config.mozPayType', 'iat' => self.now(), 'exp' => (self.now() + 3600), 'request' => request }
|
121
|
+
# end
|
122
|
+
|
123
|
+
# ##
|
124
|
+
# # Validate the JWT iat/exp/nbf claims.
|
125
|
+
# ##
|
126
|
+
# # pay.validateClaims = function(data) {
|
127
|
+
# # var now = pay.now();
|
128
|
+
# # if (!data.exp || !data.iat) {
|
129
|
+
# # throw new Error('JWT is missing the iat or exp claim properties');
|
130
|
+
# # }
|
131
|
+
# # if (+data.exp < now) {
|
132
|
+
# # throw new Error('JWT from iss ' + data.iss + ' expired: ' + data.exp + ' < ' + now);
|
133
|
+
# # }
|
134
|
+
# # if (data.nbf) {
|
135
|
+
# # // Honor the optional nbf (not before) timestamp.
|
136
|
+
# # if (+data.nbf > (now + 120)) { // pad for clock skew
|
137
|
+
# # throw new Error('JWT from iss ' + data.iss + ' cannot be processed: nbf=' + data.nbf + ' > ' + now);
|
138
|
+
# # }
|
139
|
+
# # }
|
140
|
+
# # }
|
141
|
+
# def self.validateClaims(data)
|
142
|
+
# now = self.now()
|
143
|
+
|
144
|
+
# if !data.has_key?('exp') || !data.has_key?('iat')
|
145
|
+
# raise 'JWT is missing the iat or exp claim properties'
|
146
|
+
# end
|
147
|
+
|
148
|
+
# if data['exp'] < now
|
149
|
+
# raise 'JWT from iss' + data['iss'] + ' expired ' + data['exp'] + ' < ' + now
|
150
|
+
# end
|
151
|
+
|
152
|
+
# if data.has_key?('nbf')
|
153
|
+
# # Honor the optional nbf (not before) timestamp
|
154
|
+
# if data['nbf'] > (now + 120) # pad for clock skew
|
155
|
+
# raise 'JWT from iss' + data['iss'] + ' cannot be processed: nbf = ' + data['nbf'] + ' > ' + now
|
156
|
+
# end
|
157
|
+
# end
|
158
|
+
|
159
|
+
# end
|
160
|
+
|
161
|
+
|
162
|
+
# ##
|
163
|
+
# # Return current UTC unix timestamp.
|
164
|
+
# ##
|
165
|
+
|
166
|
+
# def self.now
|
167
|
+
# return Time.new()
|
168
|
+
# end
|
169
|
+
|
170
|
+
# ##
|
171
|
+
# # Check if configure() has been called
|
172
|
+
# ##
|
173
|
+
|
174
|
+
# def self.requireConfig
|
175
|
+
# if !config
|
176
|
+
# raise 'configure() must be called before anything else.'
|
177
|
+
# end
|
178
|
+
# end
|
179
|
+
|
180
|
+
end
|
data/test/test_mozpay.rb
ADDED
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mozpay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Angelina Fabbro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jwt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.8
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.8
|
27
|
+
description: This is a rubygem for processing navigator.mozPay() payments on a server.
|
28
|
+
email:
|
29
|
+
- angelina@mozilla.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/mozpay/base.rb
|
35
|
+
- lib/mozpay/version.rb
|
36
|
+
- lib/mozpay.rb
|
37
|
+
- test/test_mozpay.rb
|
38
|
+
homepage: ''
|
39
|
+
licenses: []
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.1.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Implements navigator.mozPay()
|
61
|
+
test_files:
|
62
|
+
- test/test_mozpay.rb
|