taproot 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/Gemfile.lock +3 -3
- data/lib/braintree_account.rb +0 -2
- data/lib/taproot.rb +70 -15
- data/taproot.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79095cb633a355cf6539223cc590f73272f56a37
|
4
|
+
data.tar.gz: 46cb6db3f1822c9d827fe076b17b57b75af84437
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e57b9e7a12d6950b21ec3bc31335a3ed1ea4541bc1a3ff7c37ddef28dd4e1983c5014b7025bb0d38662dc96c50b4a8b422414d66140371fb6d6a8eee4e08cd27
|
7
|
+
data.tar.gz: 6f6a43d2e95c1d44617c61a943f8cc1dab7a6873a63a9bd3c179daca3bf539196b8f07ef1cb3ff15b615c62806e9a34b36ddae15fd5b130557f070dbcfef6b20
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
taproot (0.1.
|
4
|
+
taproot (0.1.5)
|
5
5
|
activesupport (~> 4.1.1)
|
6
6
|
awesome_print (~> 1.2.0)
|
7
7
|
braintree (~> 2.33.1)
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
i18n (0.6.11)
|
29
29
|
json (1.8.1)
|
30
30
|
method_source (0.8.2)
|
31
|
-
minitest (5.4.
|
31
|
+
minitest (5.4.1)
|
32
32
|
multi_json (1.10.1)
|
33
33
|
pry (0.9.12.6)
|
34
34
|
coderay (~> 1.0)
|
@@ -55,7 +55,7 @@ GEM
|
|
55
55
|
tins (~> 1.0)
|
56
56
|
thread_safe (0.3.4)
|
57
57
|
tilt (1.4.1)
|
58
|
-
tins (1.3.
|
58
|
+
tins (1.3.2)
|
59
59
|
tzinfo (1.2.2)
|
60
60
|
thread_safe (~> 0.1)
|
61
61
|
|
data/lib/braintree_account.rb
CHANGED
data/lib/taproot.rb
CHANGED
@@ -5,6 +5,7 @@ require "braintree"
|
|
5
5
|
require "term/ansicolor"
|
6
6
|
require "exception_handler"
|
7
7
|
require "config_manager"
|
8
|
+
require "base64"
|
8
9
|
|
9
10
|
class Taproot < Sinatra::Base
|
10
11
|
use ExceptionHandling
|
@@ -33,7 +34,6 @@ class Taproot < Sinatra::Base
|
|
33
34
|
end
|
34
35
|
|
35
36
|
get "/client_token" do
|
36
|
-
content_type :json
|
37
37
|
begin
|
38
38
|
if params["customer_id"]
|
39
39
|
Braintree::Customer.create(
|
@@ -41,19 +41,17 @@ class Taproot < Sinatra::Base
|
|
41
41
|
)
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
if params["touchDisabled"]
|
48
|
-
client_token["paypal"]["touchDisabled"] = true if client_token["paypalEnabled"]
|
49
|
-
end
|
44
|
+
decode = params.has_key?("decode")
|
45
|
+
params.delete("decode")
|
50
46
|
|
51
|
-
|
52
|
-
|
47
|
+
status 201
|
48
|
+
if decode
|
49
|
+
JSON.pretty_generate(_client_token(:decoded => true))
|
50
|
+
else
|
51
|
+
JSON.pretty_generate(:client_token => _client_token)
|
53
52
|
end
|
54
|
-
|
55
|
-
JSON.pretty_generate(client_token)
|
56
53
|
rescue Exception => e
|
54
|
+
content_type :json
|
57
55
|
status 422
|
58
56
|
JSON.pretty_generate(:message => e.message)
|
59
57
|
end
|
@@ -80,7 +78,7 @@ class Taproot < Sinatra::Base
|
|
80
78
|
|
81
79
|
content_type :json
|
82
80
|
if nonce
|
83
|
-
JSON.pretty_generate(sale(nonce, params.fetch(:amount,
|
81
|
+
JSON.pretty_generate(sale(nonce, params.fetch(:amount, 1)))
|
84
82
|
else
|
85
83
|
JSON.pretty_generate(
|
86
84
|
:message => "Required params: #{server_config[:nonce_param_names].join(", or ")}"
|
@@ -93,7 +91,28 @@ class Taproot < Sinatra::Base
|
|
93
91
|
|
94
92
|
content_type :json
|
95
93
|
if nonce
|
96
|
-
JSON.pretty_generate(sale(nonce, params.fetch(:amount,
|
94
|
+
JSON.pretty_generate(sale(nonce, params.fetch(:amount, 1)))
|
95
|
+
else
|
96
|
+
JSON.pretty_generate(
|
97
|
+
:message => "Required params: #{server_config[:nonce_param_names].join(", or ")}"
|
98
|
+
)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
post "/customers/:customer_id/vault" do
|
103
|
+
content_type :json
|
104
|
+
|
105
|
+
nonce = nonce_from_params
|
106
|
+
customer_id = params[:customer_id]
|
107
|
+
|
108
|
+
unless customer_id.present?
|
109
|
+
status 422
|
110
|
+
JSON.pretty_generate(:message => "Required param: customer_id")
|
111
|
+
return
|
112
|
+
end
|
113
|
+
|
114
|
+
if nonce
|
115
|
+
JSON.pretty_generate(vault(nonce, customer_id))
|
97
116
|
else
|
98
117
|
JSON.pretty_generate(
|
99
118
|
:message => "Required params: #{server_config[:nonce_param_names].join(", or ")}"
|
@@ -224,15 +243,51 @@ class Taproot < Sinatra::Base
|
|
224
243
|
|
225
244
|
result = Braintree::Transaction.sale(transaction_params)
|
226
245
|
|
227
|
-
if result.
|
246
|
+
if result.transaction.present?
|
247
|
+
void_result = Braintree::Transaction.void(result.transaction.id)
|
248
|
+
end
|
249
|
+
|
250
|
+
if result.success? and void_result.present? and void_result.success?
|
228
251
|
{:message => "created #{result.transaction.id} #{result.transaction.status}"}
|
229
252
|
else
|
230
|
-
{:message => result.message}
|
253
|
+
{:message => result.message || void_result.message}
|
231
254
|
end
|
255
|
+
|
232
256
|
rescue Exception => e
|
233
257
|
{:message => e.message}
|
234
258
|
end
|
235
259
|
|
260
|
+
def vault(nonce, customer_id)
|
261
|
+
log("Vaulting payment method #{nonce} for customer #{customer_id}")
|
262
|
+
|
263
|
+
result = Braintree::PaymentMethod.create({
|
264
|
+
:customer_id => customer_id,
|
265
|
+
:payment_method_nonce => nonce
|
266
|
+
})
|
267
|
+
|
268
|
+
if result.success?
|
269
|
+
{:message => "Vaulted payment method #{result.payment_method.token}"}
|
270
|
+
else
|
271
|
+
{:message => result.message}
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
def _client_token(options = {})
|
276
|
+
content_type :json
|
277
|
+
|
278
|
+
raw_client_token = Braintree::ClientToken.generate(params)
|
279
|
+
client_token = JSON.parse(Base64.decode64(raw_client_token))
|
280
|
+
if Braintree::Configuration.environment == :production
|
281
|
+
client_token["venmo"] = "production"
|
282
|
+
end
|
283
|
+
|
284
|
+
if options[:decoded]
|
285
|
+
client_token
|
286
|
+
else
|
287
|
+
Base64.strict_encode64(JSON.dump(client_token))
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
236
291
|
def _color_status(status)
|
237
292
|
if status >= 400
|
238
293
|
yellow status.to_s
|
data/taproot.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
13
|
gem.name = "taproot"
|
14
14
|
gem.require_paths = ["lib"]
|
15
|
-
gem.version = "0.1.
|
15
|
+
gem.version = "0.1.6"
|
16
16
|
|
17
17
|
gem.add_dependency "sinatra", "~> 1.4.5"
|
18
18
|
gem.add_dependency "braintree", "~> 2.33.1"
|