webpay 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +1 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +13 -0
  5. data/Rakefile +6 -0
  6. data/gemfiles/no_doc_gems +9 -0
  7. data/lib/webpay/client.rb +19 -1
  8. data/lib/webpay/version.rb +1 -1
  9. data/lib/webpay/webpay_error.rb +7 -1
  10. data/spec/resources/account/delete.txt +15 -0
  11. data/spec/resources/account/retrieve.txt +23 -0
  12. data/spec/resources/charges/all.txt +102 -0
  13. data/spec/resources/charges/capture.txt +41 -0
  14. data/spec/resources/charges/create_with_card.txt +41 -0
  15. data/spec/resources/charges/create_with_customer.txt +41 -0
  16. data/spec/resources/charges/refund.txt +41 -0
  17. data/spec/resources/charges/retrieve.txt +39 -0
  18. data/spec/resources/charges/retrieve_not_captured.txt +39 -0
  19. data/spec/resources/customers/all.txt +76 -0
  20. data/spec/resources/customers/create.txt +31 -0
  21. data/spec/resources/customers/delete.txt +16 -0
  22. data/spec/resources/customers/retrieve.txt +31 -0
  23. data/spec/resources/customers/update.txt +31 -0
  24. data/spec/resources/errors/bad_request.txt +18 -0
  25. data/spec/resources/errors/broken_json.txt +16 -0
  26. data/spec/resources/errors/card_error.txt +19 -0
  27. data/spec/resources/errors/not_found.txt +18 -0
  28. data/spec/resources/errors/unauthorized.txt +16 -0
  29. data/spec/resources/errors/unknown_api_error.txt +17 -0
  30. data/spec/resources/events/all_with_type.txt +164 -0
  31. data/spec/resources/events/retrieve.txt +41 -0
  32. data/spec/resources/tokens/create.txt +30 -0
  33. data/spec/resources/tokens/retrieve.txt +30 -0
  34. data/spec/spec_helper.rb +37 -0
  35. data/spec/webpay/account_spec.rb +24 -0
  36. data/spec/webpay/charge_spec.rb +115 -0
  37. data/spec/webpay/customer_spec.rb +94 -0
  38. data/spec/webpay/event_spec.rb +30 -0
  39. data/spec/webpay/token_spec.rb +33 -0
  40. data/spec/webpay/webpay_error_spec.rb +58 -0
  41. data/webpay.gemspec +2 -0
  42. metadata +103 -22
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ef4f5f3eee2ae39a2d17886fad71936960b2ef6e
4
+ data.tar.gz: 0008216204339d22ffe67b068792c69b89f921cf
5
+ SHA512:
6
+ metadata.gz: 5ffca8da5481be4ffb948c4dd58e99d86e854984e735457769f7d3f697e36a9df2fd3b112c43938b956275f66a3351533ed059f3089a5323fea669aa79f6513d
7
+ data.tar.gz: 826518c40f8ff23ec697e0913db2626366b93299226fc5762a8588911d8669d2c3e634f1502dec20db7ef9a31393536829fa79afcf3711bc3b343d04d577ee93
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  Gemfile.lock
6
+ gemfiles/*.lock
6
7
  lib/bundler/man
7
8
  pkg
8
9
  rdoc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-head
6
+ - rbx-19mode
7
+ gemfile:
8
+ - gemfiles/no_doc_gems
9
+ script: "bundle exec rake"
10
+ notifications:
11
+ hipchat:
12
+ rooms:
13
+ secure: ykLsXlebzR9nnb+9ttpCySOg2hE4Ve699s2Owd7YahcZyVNxnG4q1P8Mps4jFlOgPNQ6JwkcB4A6QLavavtJlX7vXTDj1GD+zVAScjbtN/6ZV94S2eHA7hBUXHUwBmH0Cw5glrFoPEDBsQdOYbrOrJKwFNEhUTHdY0SRgEXv5Wo=
data/Rakefile CHANGED
@@ -1 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'faraday', '~> 0.8.7'
4
+ gem 'rake'
5
+
6
+ group :test do
7
+ gem 'rspec', '~> 2.14.0'
8
+ gem 'webmock', '~> 1.13.0'
9
+ end
data/lib/webpay/client.rb CHANGED
@@ -39,7 +39,7 @@ module WebPay
39
39
  case response.status
40
40
  when 200..299
41
41
  begin
42
- JSON.parse(response.body)
42
+ JSON.parse(response.body.force_encoding(infer_encoding(response)))
43
43
  rescue JSON::ParserError => e
44
44
  raise WebPay::APIConnectionError.new("Response JSON is broken. #{e.message}: #{response.body}", e)
45
45
  end
@@ -58,5 +58,23 @@ module WebPay
58
58
  handle_response(response)
59
59
  end
60
60
  end
61
+
62
+ private
63
+
64
+ # Infer encoding from response
65
+ #
66
+ # @param response [Faraday::Response]
67
+ # @return [Encoding]
68
+ def infer_encoding(response)
69
+ unless (type = response.headers['content-type']) &&
70
+ (charset = type.split(';').find { |field| field.include?('charset=') })
71
+ return Encoding.default_external
72
+ end
73
+
74
+ encoding_string = charset.split('=', 2).last.strip
75
+ Encoding.find(encoding_string)
76
+ rescue
77
+ Encoding.default_external
78
+ end
61
79
  end
62
80
  end
@@ -1,5 +1,5 @@
1
1
  module WebPay
2
2
 
3
3
  # Version of WebPay gem
4
- VERSION = "2.0.2"
4
+ VERSION = "2.0.3"
5
5
  end
@@ -1,3 +1,4 @@
1
+ require 'json'
1
2
  module WebPay
2
3
 
3
4
  # Abstract error class for WebPay errors.
@@ -7,7 +8,12 @@ module WebPay
7
8
  # @api private
8
9
  # @return [WebPayError]
9
10
  def self.from_response(status, body)
10
- hash = JSON.load(body)
11
+ hash =
12
+ begin
13
+ JSON.load(body)
14
+ rescue JSON::ParserError => e
15
+ return WebPay::APIConnectionError.new("Response JSON is broken. #{e.message}: #{body}", e)
16
+ end
11
17
  unless hash['error']
12
18
  return APIConnectionError.new("Invalid response #{body}")
13
19
  end
@@ -0,0 +1,15 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json; charset=utf-8
3
+ X-Ua-Compatible: IE=Edge
4
+ Etag: "ffc2622aa8286367b501554d9625bc7e"
5
+ Cache-Control: max-age=0, private, must-revalidate
6
+ X-Request-Id: b90a98ba6c730796bb4651b30eefcf3d
7
+ X-Runtime: 0.030542
8
+ Server: WEBrick/1.3.1 (Ruby/1.9.3/2013-02-22)
9
+ Date: Wed, 11 Sep 2013 12:50:01 GMT
10
+ Content-Length: 22
11
+ Connection: Keep-Alive
12
+
13
+ {
14
+ "deleted": true
15
+ }
@@ -0,0 +1,23 @@
1
+ HTTP/1.1 200 OK
2
+ Content-Type: application/json; charset=utf-8
3
+ X-Ua-Compatible: IE=Edge
4
+ Etag: "bfda5f4ce8f4baff2dc95b81d3eeddc8"
5
+ Cache-Control: max-age=0, private, must-revalidate
6
+ X-Request-Id: ac424d922fefdd1625e41bda0e13f4b8
7
+ X-Runtime: 0.057802
8
+ Server: WEBrick/1.3.1 (Ruby/1.9.3/2013-02-22)
9
+ Date: Wed, 11 Sep 2013 12:48:50 GMT
10
+ Content-Length: 234
11
+ Connection: Keep-Alive
12
+
13
+ {
14
+ "object": "account",
15
+ "id": "acct_2Cmdexb7J2r78rz",
16
+ "email": "test-me@example.com",
17
+ "statement_descriptor": null,
18
+ "details_submitted": false,
19
+ "charge_enabled": false,
20
+ "currencies_supported": [
21
+ "jpy"
22
+ ]
23
+ }
@@ -0,0 +1,102 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.4.1
3
+ Date: Sun, 08 Sep 2013 05:37:38 GMT
4
+ Content-Type: application/json; charset=utf-8
5
+ Transfer-Encoding: chunked
6
+ Connection: keep-alive
7
+ Status: 200 OK
8
+ X-UA-Compatible: IE=Edge,chrome=1
9
+ ETag: "1ef28b71a9c2922209c711d6337dc268"
10
+ Cache-Control: must-revalidate, private, max-age=0
11
+ X-Request-Id: d70772065116ff711cb28778dabd50ed
12
+ X-Runtime: 0.023629
13
+ X-Rack-Cache: miss
14
+
15
+ {
16
+ "object": "list",
17
+ "url": "/v1/charges",
18
+ "count": 11,
19
+ "data": [
20
+ {
21
+ "id": "ch_2X01NDedxdrRcA3",
22
+ "object": "charge",
23
+ "livemode": false,
24
+ "currency": "jpy",
25
+ "description": "Test Charge from Java",
26
+ "amount": 1000,
27
+ "amount_refunded": 0,
28
+ "customer": "cus_fgR4vI92r54I6oK",
29
+ "created": 1378617627,
30
+ "paid": true,
31
+ "refunded": false,
32
+ "failure_message": null,
33
+ "card": {
34
+ "object": "card",
35
+ "exp_year": 2014,
36
+ "exp_month": 11,
37
+ "fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
38
+ "name": "KEI KUBO",
39
+ "country": "JP",
40
+ "type": "Visa",
41
+ "cvc_check": "pass",
42
+ "last4": "4242"
43
+ },
44
+ "captured": true,
45
+ "expire_time": 1379222427
46
+ },
47
+ {
48
+ "id": "ch_2SS17Oh1r8d2djE",
49
+ "object": "charge",
50
+ "livemode": false,
51
+ "currency": "jpy",
52
+ "description": "Test Charge from Java",
53
+ "amount": 1000,
54
+ "amount_refunded": 0,
55
+ "customer": null,
56
+ "created": 1378609168,
57
+ "paid": true,
58
+ "refunded": false,
59
+ "failure_message": null,
60
+ "card": {
61
+ "object": "card",
62
+ "exp_year": 2015,
63
+ "exp_month": 12,
64
+ "fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
65
+ "name": "YUUKO SHIONJI",
66
+ "country": "JP",
67
+ "type": "Visa",
68
+ "cvc_check": "pass",
69
+ "last4": "4242"
70
+ },
71
+ "captured": true,
72
+ "expire_time": null
73
+ },
74
+ {
75
+ "id": "ch_2SS4fK4IL96535y",
76
+ "object": "charge",
77
+ "livemode": false,
78
+ "currency": "jpy",
79
+ "description": "Test Charge from Java",
80
+ "amount": 1000,
81
+ "amount_refunded": 0,
82
+ "customer": "cus_fgR4vI92r54I6oK",
83
+ "created": 1378607167,
84
+ "paid": true,
85
+ "refunded": false,
86
+ "failure_message": null,
87
+ "card": {
88
+ "object": "card",
89
+ "exp_year": 2014,
90
+ "exp_month": 11,
91
+ "fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
92
+ "name": "KEI KUBO",
93
+ "country": "JP",
94
+ "type": "Visa",
95
+ "cvc_check": "pass",
96
+ "last4": "4242"
97
+ },
98
+ "captured": true,
99
+ "expire_time": null
100
+ }
101
+ ]
102
+ }
@@ -0,0 +1,41 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.4.1
3
+ Date: Sun, 08 Sep 2013 05:22:08 GMT
4
+ Content-Type: application/json; charset=utf-8
5
+ Transfer-Encoding: chunked
6
+ Connection: keep-alive
7
+ Status: 200 OK
8
+ X-UA-Compatible: IE=Edge,chrome=1
9
+ ETag: "2672411c723a31aaf67ed4fa6ac0aad4"
10
+ Cache-Control: max-age=0, private, must-revalidate
11
+ X-Request-Id: ce69847ff19fc25f9376d2affc8e8a44
12
+ X-Runtime: 0.063278
13
+ X-Rack-Cache: invalidate, pass
14
+
15
+ {
16
+ "id": "ch_2X01NDedxdrRcA3",
17
+ "object": "charge",
18
+ "livemode": false,
19
+ "currency": "jpy",
20
+ "description": "Test Charge from Java",
21
+ "amount": 1000,
22
+ "amount_refunded": 0,
23
+ "customer": "cus_fgR4vI92r54I6oK",
24
+ "created": 1378617627,
25
+ "paid": true,
26
+ "refunded": false,
27
+ "failure_message": null,
28
+ "card": {
29
+ "object": "card",
30
+ "exp_year": 2014,
31
+ "exp_month": 11,
32
+ "fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
33
+ "name": "KEI KUBO",
34
+ "country": "JP",
35
+ "type": "Visa",
36
+ "cvc_check": "pass",
37
+ "last4": "4242"
38
+ },
39
+ "captured": true,
40
+ "expire_time": 1379222427
41
+ }
@@ -0,0 +1,41 @@
1
+ HTTP/1.1 201 Created
2
+ Server: nginx/1.4.1
3
+ Date: Sun, 08 Sep 2013 02:59:29 GMT
4
+ Content-Type: application/json; charset=utf-8
5
+ Transfer-Encoding: chunked
6
+ Connection: keep-alive
7
+ Status: 201 Created
8
+ X-UA-Compatible: IE=Edge,chrome=1
9
+ ETag: "12298cbfe1c3cc7943d352edc90582ae"
10
+ Cache-Control: max-age=0, private, must-revalidate
11
+ X-Request-Id: 7f97fc1c9cbdf3ca648d0460bd381b93
12
+ X-Runtime: 0.078686
13
+ X-Rack-Cache: invalidate, pass
14
+
15
+ {
16
+ "id": "ch_2SS17Oh1r8d2djE",
17
+ "object": "charge",
18
+ "livemode": false,
19
+ "currency": "jpy",
20
+ "description": "Test Charge from Java",
21
+ "amount": 1000,
22
+ "amount_refunded": 0,
23
+ "customer": null,
24
+ "created": 1378609168,
25
+ "paid": true,
26
+ "refunded": false,
27
+ "failure_message": null,
28
+ "card": {
29
+ "object": "card",
30
+ "exp_year": 2015,
31
+ "exp_month": 12,
32
+ "fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
33
+ "name": "YUUKO SHIONJI",
34
+ "country": "JP",
35
+ "type": "Visa",
36
+ "cvc_check": "pass",
37
+ "last4": "4242"
38
+ },
39
+ "captured": true,
40
+ "expire_time": null
41
+ }
@@ -0,0 +1,41 @@
1
+ HTTP/1.1 201 Created
2
+ Server: nginx/1.4.1
3
+ Date: Sun, 08 Sep 2013 02:26:07 GMT
4
+ Content-Type: application/json; charset=utf-8
5
+ Transfer-Encoding: chunked
6
+ Connection: keep-alive
7
+ Status: 201 Created
8
+ X-UA-Compatible: IE=Edge,chrome=1
9
+ ETag: "2fdfa89815507564c93a11caffc5c609"
10
+ Cache-Control: max-age=0, private, must-revalidate
11
+ X-Request-Id: afd5d071121b5b0ca28b1e1ad96ec40a
12
+ X-Runtime: 0.129481
13
+ X-Rack-Cache: invalidate, pass
14
+
15
+ {
16
+ "id": "ch_2SS4fK4IL96535y",
17
+ "object": "charge",
18
+ "livemode": false,
19
+ "currency": "jpy",
20
+ "description": "Test Charge from Java",
21
+ "amount": 1000,
22
+ "amount_refunded": 0,
23
+ "customer": "cus_fgR4vI92r54I6oK",
24
+ "created": 1378607167,
25
+ "paid": true,
26
+ "refunded": false,
27
+ "failure_message": null,
28
+ "card": {
29
+ "object": "card",
30
+ "exp_year": 2014,
31
+ "exp_month": 11,
32
+ "fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
33
+ "name": "KEI KUBO",
34
+ "country": "JP",
35
+ "type": "Visa",
36
+ "cvc_check": "pass",
37
+ "last4": "4242"
38
+ },
39
+ "captured": true,
40
+ "expire_time": null
41
+ }
@@ -0,0 +1,41 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.4.1
3
+ Date: Sun, 08 Sep 2013 04:49:14 GMT
4
+ Content-Type: application/json; charset=utf-8
5
+ Transfer-Encoding: chunked
6
+ Connection: keep-alive
7
+ Status: 200 OK
8
+ X-UA-Compatible: IE=Edge,chrome=1
9
+ ETag: "00ea9522e0f29d3e2a494f30105fe841"
10
+ Cache-Control: max-age=0, private, must-revalidate
11
+ X-Request-Id: 20141aa82edd1939c6b0ce64d5a87fa7
12
+ X-Runtime: 0.055769
13
+ X-Rack-Cache: invalidate, pass
14
+
15
+ {
16
+ "id": "ch_bWp5EG9smcCYeEx",
17
+ "object": "charge",
18
+ "livemode": false,
19
+ "currency": "jpy",
20
+ "description": "アイテムの購入",
21
+ "amount": 400,
22
+ "amount_refunded": 400,
23
+ "customer": null,
24
+ "created": 1370746452,
25
+ "paid": true,
26
+ "refunded": true,
27
+ "failure_message": null,
28
+ "card": {
29
+ "object": "card",
30
+ "exp_year": 2014,
31
+ "exp_month": 11,
32
+ "fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
33
+ "name": "KEI KUBO",
34
+ "country": "JP",
35
+ "type": "Visa",
36
+ "cvc_check": "pass",
37
+ "last4": "4242"
38
+ },
39
+ "captured": true,
40
+ "expire_time": null
41
+ }
@@ -0,0 +1,39 @@
1
+ HTTP/1.1 200 OK
2
+ Server: nginx/1.4.1
3
+ Date: Sun, 08 Sep 2013 04:22:03 GMT
4
+ Content-Type: application/json; charset=utf-8
5
+ Transfer-Encoding: chunked
6
+ Connection: keep-alive
7
+ Status: 200 OK
8
+ X-UA-Compatible: IE=Edge,chrome=1
9
+ ETag: "e1d70d19ea7666f4a7016055b3274b43"
10
+ Cache-Control: must-revalidate, private, max-age=0
11
+ X-Request-Id: 8ea33d9a3dc18348206d68f2408c7866
12
+
13
+ {
14
+ "id": "ch_bWp5EG9smcCYeEx",
15
+ "object": "charge",
16
+ "livemode": false,
17
+ "currency": "jpy",
18
+ "description": "アイテムの購入",
19
+ "amount": 400,
20
+ "amount_refunded": 0,
21
+ "customer": null,
22
+ "created": 1370746452,
23
+ "paid": true,
24
+ "refunded": false,
25
+ "failure_message": null,
26
+ "card": {
27
+ "object": "card",
28
+ "exp_year": 2014,
29
+ "exp_month": 11,
30
+ "fingerprint": "215b5b2fe460809b8bb90bae6eeac0e0e0987bd7",
31
+ "name": "KEI KUBO",
32
+ "country": "JP",
33
+ "type": "Visa",
34
+ "cvc_check": "pass",
35
+ "last4": "4242"
36
+ },
37
+ "captured": true,
38
+ "expire_time": null
39
+ }