judopay 2.1.0 → 2.1.3

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.
Files changed (122) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +24 -23
  3. data/.rspec +1 -1
  4. data/.rubocop.yml +54 -51
  5. data/.travis.yml +6 -6
  6. data/CHANGELOG.md +17 -17
  7. data/Gemfile +4 -4
  8. data/LICENSE +21 -21
  9. data/README.md +96 -94
  10. data/Rakefile +22 -22
  11. data/judopay.gemspec +38 -38
  12. data/lib/certs/digicert_sha256_ca.pem +49 -49
  13. data/lib/certs/rapidssl_ca.crt +63 -63
  14. data/lib/faraday/judo_mashify.rb +11 -11
  15. data/lib/faraday/raise_http_exception.rb +19 -19
  16. data/lib/judopay.rb +70 -70
  17. data/lib/judopay/api.rb +10 -10
  18. data/lib/judopay/connection.rb +77 -77
  19. data/lib/judopay/core_ext/hash.rb +29 -29
  20. data/lib/judopay/core_ext/string.rb +32 -32
  21. data/lib/judopay/error.rb +117 -115
  22. data/lib/judopay/mash.rb +11 -11
  23. data/lib/judopay/model.rb +134 -134
  24. data/lib/judopay/models/android_payment.rb +26 -26
  25. data/lib/judopay/models/android_preauth.rb +8 -8
  26. data/lib/judopay/models/apple_payment.rb +26 -26
  27. data/lib/judopay/models/apple_preauth.rb +9 -9
  28. data/lib/judopay/models/card_address.rb +11 -11
  29. data/lib/judopay/models/card_payment.rb +33 -33
  30. data/lib/judopay/models/card_preauth.rb +11 -11
  31. data/lib/judopay/models/collection.rb +16 -16
  32. data/lib/judopay/models/encrypt_details.rb +18 -0
  33. data/lib/judopay/models/inner/pk_payment.rb +17 -17
  34. data/lib/judopay/models/inner/pk_payment_token.rb +13 -13
  35. data/lib/judopay/models/inner/transmitted_field.rb +39 -39
  36. data/lib/judopay/models/inner/wallet.rb +30 -30
  37. data/lib/judopay/models/market/collection.rb +10 -10
  38. data/lib/judopay/models/market/payment.rb +10 -10
  39. data/lib/judopay/models/market/preauth.rb +10 -10
  40. data/lib/judopay/models/market/refund.rb +10 -10
  41. data/lib/judopay/models/market/transaction.rb +10 -10
  42. data/lib/judopay/models/one_use_token_payment.rb +29 -0
  43. data/lib/judopay/models/payment.rb +8 -8
  44. data/lib/judopay/models/preauth.rb +8 -8
  45. data/lib/judopay/models/refund.rb +16 -16
  46. data/lib/judopay/models/register_card.rb +27 -27
  47. data/lib/judopay/models/save_card.rb +24 -25
  48. data/lib/judopay/models/token_payment.rb +30 -30
  49. data/lib/judopay/models/token_preauth.rb +10 -10
  50. data/lib/judopay/models/transaction.rb +8 -8
  51. data/lib/judopay/models/void.rb +19 -19
  52. data/lib/judopay/models/web_payments/payment.rb +28 -28
  53. data/lib/judopay/models/web_payments/preauth.rb +10 -10
  54. data/lib/judopay/models/web_payments/transaction.rb +19 -19
  55. data/lib/judopay/models/web_payments/web_payment_operation.rb +8 -8
  56. data/lib/judopay/null_logger.rb +9 -11
  57. data/lib/judopay/request.rb +50 -50
  58. data/lib/judopay/response.rb +7 -7
  59. data/lib/judopay/serializer.rb +27 -27
  60. data/lib/judopay/version.rb +4 -4
  61. data/spec/factories.rb +227 -208
  62. data/spec/faraday/response_spec.rb +27 -27
  63. data/spec/fixtures/card_payments/create.json +21 -21
  64. data/spec/fixtures/card_payments/create_3dsecure.json +7 -7
  65. data/spec/fixtures/card_payments/create_bad_request.json +12 -12
  66. data/spec/fixtures/card_payments/create_declined.json +23 -23
  67. data/spec/fixtures/card_payments/validate.json +4 -4
  68. data/spec/fixtures/token_payments/create.json +21 -21
  69. data/spec/fixtures/transactions/all.json +237 -237
  70. data/spec/fixtures/transactions/android_payment.json +26 -26
  71. data/spec/fixtures/transactions/apple_payment.json +26 -26
  72. data/spec/fixtures/transactions/find.json +22 -22
  73. data/spec/fixtures/transactions/find_not_found.json +4 -4
  74. data/spec/fixtures/transactions/register_card.json +28 -28
  75. data/spec/fixtures/transactions/save_card.json +27 -27
  76. data/spec/fixtures/transactions/void.json +26 -26
  77. data/spec/fixtures/web_payments/payments/create.json +3 -3
  78. data/spec/fixtures/web_payments/payments/find.json +38 -38
  79. data/spec/judopay/android_payment_spec.rb +74 -74
  80. data/spec/judopay/apple_payment_spec.rb +80 -80
  81. data/spec/judopay/card_address_spec.rb +10 -10
  82. data/spec/judopay/card_payment_spec.rb +51 -63
  83. data/spec/judopay/card_preauth_spec.rb +35 -35
  84. data/spec/judopay/collection_spec.rb +26 -26
  85. data/spec/judopay/core_ext/hash_spec.rb +24 -24
  86. data/spec/judopay/core_ext/string_spec.rb +16 -16
  87. data/spec/judopay/error_spec.rb +70 -70
  88. data/spec/judopay/judopay_spec.rb +19 -19
  89. data/spec/judopay/market/collection_spec.rb +26 -26
  90. data/spec/judopay/market/payment_spec.rb +14 -14
  91. data/spec/judopay/market/preauth_spec.rb +14 -14
  92. data/spec/judopay/market/refund_spec.rb +26 -26
  93. data/spec/judopay/market/transaction_spec.rb +14 -14
  94. data/spec/judopay/payment_spec.rb +14 -14
  95. data/spec/judopay/preauth_spec.rb +14 -14
  96. data/spec/judopay/refund_spec.rb +26 -26
  97. data/spec/judopay/register_card_spec.rb +24 -24
  98. data/spec/judopay/save_card_spec.rb +23 -23
  99. data/spec/judopay/token_payment_spec.rb +22 -22
  100. data/spec/judopay/token_preauth_spec.rb +22 -22
  101. data/spec/judopay/transaction_spec.rb +51 -51
  102. data/spec/judopay/void_spec.rb +24 -24
  103. data/spec/judopay/web_payments/payment_spec.rb +16 -16
  104. data/spec/judopay/web_payments/preauth_spec.rb +16 -16
  105. data/spec/judopay/web_payments/transaction_spec.rb +15 -15
  106. data/spec/spec_helper.rb +41 -41
  107. data/test/additions_payment_test.rb +30 -0
  108. data/test/authentication_test.rb +23 -23
  109. data/test/base/integration_base.rb +20 -20
  110. data/test/base/payments_tests.rb +47 -47
  111. data/test/base/token_payment_tests.rb +98 -98
  112. data/test/card_details_test.rb +21 -21
  113. data/test/configuration_test.rb +35 -35
  114. data/test/helper/assertion_helper.rb +29 -29
  115. data/test/payment_test.rb +10 -10
  116. data/test/preauth_test.rb +10 -10
  117. data/test/register_card_test.rb +42 -42
  118. data/test/save_card_test.rb +23 -0
  119. data/test/token_payment_test.rb +10 -10
  120. data/test/token_preauth_test.rb +10 -10
  121. data/test/void_test.rb +45 -45
  122. metadata +18 -12
@@ -1,26 +1,26 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/judopay/models/refund'
3
-
4
- describe Judopay::Refund do
5
- it 'should list all refunds' do
6
- stub_get('/transactions/refunds').
7
- to_return(:status => 200,
8
- :body => lambda { |_request| fixture('transactions/all.json') })
9
-
10
- transactions = Judopay::Refund.all
11
- expect(transactions).to be_a(Hash)
12
- expect(transactions.results[0].amount).to eq(1.01)
13
- end
14
-
15
- it 'should create a new refund given a valid payment reference' do
16
- stub_post('/transactions/refunds').
17
- to_return(:status => 200,
18
- :body => lambda { |_request| fixture('card_payments/create.json') })
19
-
20
- refund = build(:refund)
21
- response = refund.create
22
-
23
- expect(response).to be_a(Hash)
24
- expect(response.result).to eq('Success')
25
- end
26
- end
1
+ require 'spec_helper'
2
+ require_relative '../../lib/judopay/models/refund'
3
+
4
+ describe Judopay::Refund do
5
+ it 'should list all refunds' do
6
+ stub_get('/transactions/refunds').
7
+ to_return(:status => 200,
8
+ :body => lambda { |_request| fixture('transactions/all.json') })
9
+
10
+ transactions = Judopay::Refund.all
11
+ expect(transactions).to be_a(Hash)
12
+ expect(transactions.results[0].amount).to eq(1.01)
13
+ end
14
+
15
+ it 'should create a new refund given a valid payment reference' do
16
+ stub_post('/transactions/refunds').
17
+ to_return(:status => 200,
18
+ :body => lambda { |_request| fixture('card_payments/create.json') })
19
+
20
+ refund = build(:refund)
21
+ response = refund.create
22
+
23
+ expect(response).to be_a(Hash)
24
+ expect(response.result).to eq('Success')
25
+ end
26
+ end
@@ -1,24 +1,24 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/judopay/models/register_card'
3
-
4
- describe Judopay::RegisterCard do
5
- it 'should register a new card with valid card details' do
6
- stub_post('/transactions/registercard').
7
- to_return(:status => 200,
8
- :body => lambda { |_request| fixture('transactions/register_card.json') })
9
-
10
- register_card = build(:register_card)
11
- response = register_card.create
12
-
13
- expect(response).to be_a(Hash)
14
- expect(response.result).to eq('Success')
15
- expect(response.type).to eq('PreAuth')
16
- expect(response.amount).to eq('1.01')
17
- end
18
-
19
- it 'should return a bad request exception if basic validation fails' do
20
- expect(lambda do
21
- Judopay::RegisterCard.new.create
22
- end).to raise_error(Judopay::ValidationError)
23
- end
24
- end
1
+ require 'spec_helper'
2
+ require_relative '../../lib/judopay/models/register_card'
3
+
4
+ describe Judopay::RegisterCard do
5
+ it 'should register a new card with valid card details' do
6
+ stub_post('/transactions/registercard').
7
+ to_return(:status => 200,
8
+ :body => lambda { |_request| fixture('transactions/register_card.json') })
9
+
10
+ register_card = build(:register_card)
11
+ response = register_card.create
12
+
13
+ expect(response).to be_a(Hash)
14
+ expect(response.result).to eq('Success')
15
+ expect(response.type).to eq('PreAuth')
16
+ expect(response.amount).to eq('1.01')
17
+ end
18
+
19
+ it 'should return a bad request exception if basic validation fails' do
20
+ expect(lambda do
21
+ Judopay::RegisterCard.new.create
22
+ end).to raise_error(Judopay::ValidationError)
23
+ end
24
+ end
@@ -1,23 +1,23 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/judopay/models/save_card'
3
-
4
- describe Judopay::SaveCard do
5
- it 'should save a new card with valid card details' do
6
- stub_post('/transactions/savecard').
7
- to_return(:status => 200,
8
- :body => lambda { |_request| fixture('transactions/save_card.json') })
9
-
10
- save_card = build(:save_card)
11
- response = save_card.create
12
-
13
- expect(response).to be_a(Hash)
14
- expect(response.result).to eq('Success')
15
- expect(response.type).to eq('Register')
16
- end
17
-
18
- it 'should return a bad request exception if basic validation fails' do
19
- expect(lambda do
20
- Judopay::SaveCard.new.create
21
- end).to raise_error(Judopay::ValidationError)
22
- end
23
- end
1
+ require 'spec_helper'
2
+ require_relative '../../lib/judopay/models/save_card'
3
+
4
+ describe Judopay::SaveCard do
5
+ it 'should save a new card with valid card details' do
6
+ stub_post('/transactions/savecard').
7
+ to_return(:status => 200,
8
+ :body => lambda { |_request| fixture('transactions/save_card.json') })
9
+
10
+ save_card = build(:save_card)
11
+ response = save_card.create
12
+
13
+ expect(response).to be_a(Hash)
14
+ expect(response.result).to eq('Success')
15
+ expect(response.type).to eq('Register')
16
+ end
17
+
18
+ it 'should return a bad request exception if basic validation fails' do
19
+ expect(lambda do
20
+ Judopay::SaveCard.new.create
21
+ end).to raise_error(Judopay::ValidationError)
22
+ end
23
+ end
@@ -1,22 +1,22 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/judopay/models/token_preauth'
3
-
4
- describe Judopay::TokenPayment do
5
- it 'should create a new payment given a valid payment token and card token' do
6
- stub_post('/transactions/payments').
7
- to_return(:status => 200,
8
- :body => lambda { |_request| fixture('token_payments/create.json') })
9
-
10
- payment = build(:token_payment)
11
- response = payment.create
12
-
13
- expect(response).to be_a(Hash)
14
- expect(response.result).to eq('Success')
15
- end
16
-
17
- it 'should return a bad request exception if basic validation fails' do
18
- expect(lambda do
19
- Judopay::TokenPayment.new.create
20
- end).to raise_error(Judopay::ValidationError)
21
- end
22
- end
1
+ require 'spec_helper'
2
+ require_relative '../../lib/judopay/models/token_preauth'
3
+
4
+ describe Judopay::TokenPayment do
5
+ it 'should create a new payment given a valid payment token and card token' do
6
+ stub_post('/transactions/payments').
7
+ to_return(:status => 200,
8
+ :body => lambda { |_request| fixture('token_payments/create.json') })
9
+
10
+ payment = build(:token_payment)
11
+ response = payment.create
12
+
13
+ expect(response).to be_a(Hash)
14
+ expect(response.result).to eq('Success')
15
+ end
16
+
17
+ it 'should return a bad request exception if basic validation fails' do
18
+ expect(lambda do
19
+ Judopay::TokenPayment.new.create
20
+ end).to raise_error(Judopay::ValidationError)
21
+ end
22
+ end
@@ -1,22 +1,22 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/judopay/models/token_preauth'
3
-
4
- describe Judopay::TokenPreauth do
5
- it 'should create a new preauth given a valid payment token and card token' do
6
- stub_post('/transactions/preauths').
7
- to_return(:status => 200,
8
- :body => lambda { |_request| fixture('token_payments/create.json') })
9
-
10
- payment = build(:token_preauth)
11
- response = payment.create
12
-
13
- expect(response).to be_a(Hash)
14
- expect(response.result).to eq('Success')
15
- end
16
-
17
- it 'should return a bad request exception if basic validation fails' do
18
- expect(lambda do
19
- Judopay::TokenPreauth.new.create
20
- end).to raise_error(Judopay::ValidationError)
21
- end
22
- end
1
+ require 'spec_helper'
2
+ require_relative '../../lib/judopay/models/token_preauth'
3
+
4
+ describe Judopay::TokenPreauth do
5
+ it 'should create a new preauth given a valid payment token and card token' do
6
+ stub_post('/transactions/preauths').
7
+ to_return(:status => 200,
8
+ :body => lambda { |_request| fixture('token_payments/create.json') })
9
+
10
+ payment = build(:token_preauth)
11
+ response = payment.create
12
+
13
+ expect(response).to be_a(Hash)
14
+ expect(response.result).to eq('Success')
15
+ end
16
+
17
+ it 'should return a bad request exception if basic validation fails' do
18
+ expect(lambda do
19
+ Judopay::TokenPreauth.new.create
20
+ end).to raise_error(Judopay::ValidationError)
21
+ end
22
+ end
@@ -1,51 +1,51 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/judopay/models/transaction'
3
-
4
- describe Judopay::Transaction do
5
- it 'should list all transactions' do
6
- stub_get('/transactions').
7
- to_return(:status => 200,
8
- :body => lambda { |_request| fixture('transactions/all.json') })
9
-
10
- transactions = Judopay::Transaction.all
11
- expect(transactions).to be_a(Hash)
12
- expect(transactions.results[0].amount).to eq(1.01)
13
- end
14
-
15
- it 'should give details of a single transaction given a valid receipt ID' do
16
- stub_get('/transactions/439539').
17
- to_return(:status => 200,
18
- :body => lambda { |_request| fixture('transactions/find.json') })
19
-
20
- receipt_id = '439539'
21
- transaction = Judopay::Transaction.find(receipt_id)
22
- expect(transaction).to be_a(Hash)
23
- expect(transaction.receipt_id).to eq(receipt_id)
24
- end
25
-
26
- it 'should send paging parameters with a request' do
27
- stub_get('/transactions').
28
- to_return(:status => 200,
29
- :body => lambda { |_request| fixture('transactions/all.json') })
30
-
31
- options = {
32
- :sort => 'time-descending',
33
- :offset => 10,
34
- :page_size => 5,
35
- :dodgy_param => 'banana'
36
- }
37
-
38
- expected_request_options = {
39
- :sort => 'time-descending',
40
- :offset => 10,
41
- :pageSize => 5
42
- }
43
-
44
- Judopay::Transaction.all(options)
45
-
46
- WebMock.should have_requested(
47
- :get,
48
- Judopay.configuration.endpoint_url + '/transactions'
49
- ).with(:query => expected_request_options)
50
- end
51
- end
1
+ require 'spec_helper'
2
+ require_relative '../../lib/judopay/models/transaction'
3
+
4
+ describe Judopay::Transaction do
5
+ it 'should list all transactions' do
6
+ stub_get('/transactions').
7
+ to_return(:status => 200,
8
+ :body => lambda { |_request| fixture('transactions/all.json') })
9
+
10
+ transactions = Judopay::Transaction.all
11
+ expect(transactions).to be_a(Hash)
12
+ expect(transactions.results[0].amount).to eq(1.01)
13
+ end
14
+
15
+ it 'should give details of a single transaction given a valid receipt ID' do
16
+ stub_get('/transactions/439539').
17
+ to_return(:status => 200,
18
+ :body => lambda { |_request| fixture('transactions/find.json') })
19
+
20
+ receipt_id = '439539'
21
+ transaction = Judopay::Transaction.find(receipt_id)
22
+ expect(transaction).to be_a(Hash)
23
+ expect(transaction.receipt_id).to eq(receipt_id)
24
+ end
25
+
26
+ it 'should send paging parameters with a request' do
27
+ stub_get('/transactions').
28
+ to_return(:status => 200,
29
+ :body => lambda { |_request| fixture('transactions/all.json') })
30
+
31
+ options = {
32
+ :sort => 'time-descending',
33
+ :offset => 10,
34
+ :page_size => 5,
35
+ :dodgy_param => 'banana'
36
+ }
37
+
38
+ expected_request_options = {
39
+ :sort => 'time-descending',
40
+ :offset => 10,
41
+ :pageSize => 5
42
+ }
43
+
44
+ Judopay::Transaction.all(options)
45
+
46
+ WebMock.should have_requested(
47
+ :get,
48
+ Judopay.configuration.endpoint_url + '/transactions'
49
+ ).with(:query => expected_request_options)
50
+ end
51
+ end
@@ -1,24 +1,24 @@
1
- require 'spec_helper'
2
- require_relative '../../lib/judopay/models/void'
3
-
4
- describe Judopay::Void do
5
- it 'should create new void with valid details' do
6
- stub_post('/transactions/voids').
7
- to_return(:status => 200,
8
- :body => lambda { |_request| fixture('transactions/void.json') })
9
-
10
- void = build(:void)
11
- response = void.create
12
-
13
- expect(response).to be_a(Hash)
14
- expect(response.result).to eq('Success')
15
- expect(response.type).to eq('VOID')
16
- expect(response.original_amount).to eq('1.02')
17
- end
18
-
19
- it 'should return a bad request exception if basic validation fails' do
20
- expect(lambda do
21
- Judopay::Void.new.create
22
- end).to raise_error(Judopay::ValidationError)
23
- end
24
- end
1
+ require 'spec_helper'
2
+ require_relative '../../lib/judopay/models/void'
3
+
4
+ describe Judopay::Void do
5
+ it 'should create new void with valid details' do
6
+ stub_post('/transactions/voids').
7
+ to_return(:status => 200,
8
+ :body => lambda { |_request| fixture('transactions/void.json') })
9
+
10
+ void = build(:void)
11
+ response = void.create
12
+
13
+ expect(response).to be_a(Hash)
14
+ expect(response.result).to eq('Success')
15
+ expect(response.type).to eq('VOID')
16
+ expect(response.original_amount).to eq('1.02')
17
+ end
18
+
19
+ it 'should return a bad request exception if basic validation fails' do
20
+ expect(lambda do
21
+ Judopay::Void.new.create
22
+ end).to raise_error(Judopay::ValidationError)
23
+ end
24
+ end
@@ -1,16 +1,16 @@
1
- require 'spec_helper'
2
- require_relative '../../../lib/judopay/models/web_payments/payment'
3
-
4
- describe Judopay::WebPayments::Payment do
5
- it 'should create a new web payment request' do
6
- stub_post('/webpayments/payments').
7
- to_return(:status => 200,
8
- :body => lambda { |_request| fixture('web_payments/payments/create.json') })
9
-
10
- payment = build(:web_payment)
11
- response = payment.create
12
-
13
- expect(response).to be_a(Hash)
14
- expect(response.post_url).to eq('https://pay.judopay-sandbox.com/')
15
- end
16
- end
1
+ require 'spec_helper'
2
+ require_relative '../../../lib/judopay/models/web_payments/payment'
3
+
4
+ describe Judopay::WebPayments::Payment do
5
+ it 'should create a new web payment request' do
6
+ stub_post('/webpayments/payments').
7
+ to_return(:status => 200,
8
+ :body => lambda { |_request| fixture('web_payments/payments/create.json') })
9
+
10
+ payment = build(:web_payment)
11
+ response = payment.create
12
+
13
+ expect(response).to be_a(Hash)
14
+ expect(response.post_url).to eq('https://pay.judopay-sandbox.com/')
15
+ end
16
+ end
@@ -1,16 +1,16 @@
1
- require 'spec_helper'
2
- require_relative '../../../lib/judopay/models/web_payments/preauth'
3
-
4
- describe Judopay::WebPayments::Preauth do
5
- it 'should create a new web preauth request' do
6
- stub_post('/webpayments/payments').
7
- to_return(:status => 200,
8
- :body => lambda { |_request| fixture('web_payments/payments/create.json') })
9
-
10
- payment = build(:web_preauth)
11
- response = payment.create
12
-
13
- expect(response).to be_a(Hash)
14
- expect(response.post_url).to eq('https://pay.judopay-sandbox.com/')
15
- end
16
- end
1
+ require 'spec_helper'
2
+ require_relative '../../../lib/judopay/models/web_payments/preauth'
3
+
4
+ describe Judopay::WebPayments::Preauth do
5
+ it 'should create a new web preauth request' do
6
+ stub_post('/webpayments/payments').
7
+ to_return(:status => 200,
8
+ :body => lambda { |_request| fixture('web_payments/payments/create.json') })
9
+
10
+ payment = build(:web_preauth)
11
+ response = payment.create
12
+
13
+ expect(response).to be_a(Hash)
14
+ expect(response.post_url).to eq('https://pay.judopay-sandbox.com/')
15
+ end
16
+ end