mangopay 3.0.25.pre.alpha.pre.20 → 3.0.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +28 -28
  3. data/.rspec +2 -2
  4. data/.travis.yml +4 -13
  5. data/Gemfile +2 -2
  6. data/LICENSE +20 -20
  7. data/README.md +126 -126
  8. data/bin/mangopay +9 -9
  9. data/lib/generators/mangopay/install_generator.rb +60 -60
  10. data/lib/generators/templates/mangopay.rb.erb +5 -5
  11. data/lib/mangopay.rb +225 -225
  12. data/lib/mangopay/authorization_token.rb +88 -88
  13. data/lib/mangopay/bank_account.rb +38 -38
  14. data/lib/mangopay/card.rb +8 -8
  15. data/lib/mangopay/card_registration.rb +9 -9
  16. data/lib/mangopay/client.rb +74 -74
  17. data/lib/mangopay/dispute.rb +130 -130
  18. data/lib/mangopay/errors.rb +61 -61
  19. data/lib/mangopay/event.rb +18 -18
  20. data/lib/mangopay/filter_parameters.rb +46 -46
  21. data/lib/mangopay/hook.rb +9 -9
  22. data/lib/mangopay/http_calls.rb +85 -85
  23. data/lib/mangopay/json.rb +14 -14
  24. data/lib/mangopay/kyc_document.rb +70 -70
  25. data/lib/mangopay/legal_user.rb +15 -15
  26. data/lib/mangopay/mandate.rb +32 -32
  27. data/lib/mangopay/natural_user.rb +14 -14
  28. data/lib/mangopay/pay_in.rb +85 -85
  29. data/lib/mangopay/pay_out.rb +14 -14
  30. data/lib/mangopay/pre_authorization.rb +13 -13
  31. data/lib/mangopay/refund.rb +7 -7
  32. data/lib/mangopay/report.rb +17 -17
  33. data/lib/mangopay/resource.rb +21 -21
  34. data/lib/mangopay/temp.rb +74 -74
  35. data/lib/mangopay/transaction.rb +24 -24
  36. data/lib/mangopay/transfer.rb +9 -9
  37. data/lib/mangopay/user.rb +43 -43
  38. data/lib/mangopay/version.rb +3 -3
  39. data/lib/mangopay/wallet.rb +17 -17
  40. data/mangopay.gemspec +30 -31
  41. data/spec/mangopay/authorization_token_spec.rb +70 -70
  42. data/spec/mangopay/bank_account_spec.rb +97 -97
  43. data/spec/mangopay/card_registration_spec.rb +73 -73
  44. data/spec/mangopay/client_spec.rb +110 -110
  45. data/spec/mangopay/configuration_spec.rb +95 -95
  46. data/spec/mangopay/dispute_spec.rb +262 -262
  47. data/spec/mangopay/event_spec.rb +31 -31
  48. data/spec/mangopay/fetch_filters_spec.rb +63 -63
  49. data/spec/mangopay/hook_spec.rb +37 -37
  50. data/spec/mangopay/idempotency_spec.rb +41 -41
  51. data/spec/mangopay/kyc_document_spec.rb +103 -103
  52. data/spec/mangopay/log_requests_filter_spec.rb +25 -25
  53. data/spec/mangopay/mandate_spec.rb +92 -92
  54. data/spec/mangopay/payin_bankwire_direct_spec.rb +74 -74
  55. data/spec/mangopay/payin_card_direct_spec.rb +68 -68
  56. data/spec/mangopay/payin_card_web_spec.rb +38 -38
  57. data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -37
  58. data/spec/mangopay/payin_directdebit_web_spec.rb +38 -38
  59. data/spec/mangopay/payin_paypal_web_spec.rb +38 -38
  60. data/spec/mangopay/payin_preauthorized_direct_spec.rb +68 -68
  61. data/spec/mangopay/payout_bankwire_spec.rb +54 -54
  62. data/spec/mangopay/preauthorization_spec.rb +42 -42
  63. data/spec/mangopay/refund_spec.rb +21 -21
  64. data/spec/mangopay/report_spec.rb +39 -39
  65. data/spec/mangopay/shared_resources.rb +381 -381
  66. data/spec/mangopay/temp_paymentcard_spec.rb +31 -31
  67. data/spec/mangopay/transaction_spec.rb +54 -54
  68. data/spec/mangopay/transfer_spec.rb +69 -69
  69. data/spec/mangopay/user_spec.rb +137 -137
  70. data/spec/mangopay/wallet_spec.rb +80 -80
  71. data/spec/spec_helper.rb +31 -31
  72. metadata +5 -5
@@ -1,110 +1,110 @@
1
- describe MangoPay::Client do
2
-
3
- describe 'FETCH' do
4
- it 'fetches the current client details' do
5
- clnt = MangoPay::Client.fetch
6
- expect(clnt['ClientId']).to eq(MangoPay.configuration.client_id)
7
- end
8
- end
9
-
10
- describe 'UPDATE' do
11
- it 'updates the current client details' do
12
- clnt = MangoPay::Client.fetch
13
- before = clnt['PrimaryThemeColour']
14
- after = before == '#aaaaaa' ? '#bbbbbb' : '#aaaaaa' # change the color
15
- clnt['PrimaryThemeColour'] = after
16
-
17
- updated = MangoPay::Client.update(clnt)
18
- expect(updated['ClientId']).to eq(MangoPay.configuration.client_id)
19
- expect(updated['PrimaryThemeColour']).to eq(after)
20
- end
21
- end
22
-
23
- describe 'UPLOAD LOGO' do
24
- it 'accepts Base64 encoded file content' do
25
- fnm = __FILE__.sub('.rb', '.png')
26
- bts = File.open(fnm, 'rb') { |f| f.read }
27
- b64 = Base64.encode64(bts)
28
- ret = MangoPay::Client.upload_logo(b64)
29
- expect(ret).to be_nil
30
- end
31
-
32
- it 'accepts file path' do
33
- fnm = __FILE__.sub('.rb', '.png')
34
- ret = MangoPay::Client.upload_logo(nil, fnm)
35
- expect(ret).to be_nil
36
- end
37
-
38
- it 'fails when input string is not base64-encoded' do
39
- file = 'any file content...'
40
- expect { MangoPay::Client.upload_logo(file) }.to raise_error { |err|
41
- expect(err).to be_a MangoPay::ResponseError
42
- expect(err.code).to eq '400'
43
- expect(err.type).to eq 'param_error'
44
- }
45
- end
46
- end
47
-
48
- describe 'fetch_wallets' do
49
- it 'fetches all client wallets' do
50
- wlts = MangoPay::Client.fetch_wallets
51
- expect(wlts).to be_kind_of(Array)
52
- expect(wlts).not_to be_empty
53
- end
54
-
55
- it 'fetches all client fees wallets' do
56
- wlts = MangoPay::Client.fetch_wallets('fees')
57
- expect(wlts).to be_kind_of(Array)
58
- expect(wlts).not_to be_empty
59
- expect((wlts.map {|m| m['FundsType']}).uniq).to eq(['FEES'])
60
- end
61
-
62
- it 'fetches all client credit wallets' do
63
- wlts = MangoPay::Client.fetch_wallets('credit')
64
- expect(wlts).to be_kind_of(Array)
65
- expect(wlts).not_to be_empty
66
- expect((wlts.map {|m| m['FundsType']}).uniq).to eq(['CREDIT'])
67
- end
68
- end
69
-
70
- describe 'fetch_wallet' do
71
- it 'fetches one of client wallets by funds type (fees) and currency' do
72
- wlt = MangoPay::Client.fetch_wallet('fees', 'EUR')
73
- expect(wlt).to be_kind_of(Hash)
74
- expect(wlt['FundsType']).to eq('FEES')
75
- expect(wlt['Currency']).to eq('EUR')
76
- end
77
-
78
- it 'fetches one of client wallets by funds type (credit) and currency' do
79
- wlt = MangoPay::Client.fetch_wallet('credit', 'EUR')
80
- expect(wlt).to be_kind_of(Hash)
81
- expect(wlt['FundsType']).to eq('CREDIT')
82
- expect(wlt['Currency']).to eq('EUR')
83
- end
84
- end
85
-
86
- describe 'fetch_wallets_transactions' do
87
- it 'fetches transactions for all client wallets' do
88
- trns = MangoPay::Client.fetch_wallets_transactions
89
- expect(trns).to be_kind_of(Array)
90
- expect(trns).not_to be_empty
91
- end
92
- end
93
-
94
- describe 'fetch_wallets_transactions' do
95
- it 'fetches transactions of one of client wallets by funds type (fees) and currency' do
96
- trns = MangoPay::Client.fetch_wallet_transactions('fees', 'EUR')
97
- expect(trns).to be_kind_of(Array)
98
- expect(trns).not_to be_empty
99
- expect((trns.map {|m| m['DebitedWalletId']}).uniq).to eq(['FEES_EUR'])
100
- end
101
-
102
- it 'fetches transactions of one of client wallets by funds type (credit) and currency' do
103
- trns = MangoPay::Client.fetch_wallet_transactions('credit', 'EUR')
104
- expect(trns).to be_kind_of(Array)
105
- expect(trns).not_to be_empty
106
- expect((trns.map {|m| m['DebitedWalletId']}).uniq).to eq(['CREDIT_EUR'])
107
- end
108
- end
109
-
110
- end
1
+ describe MangoPay::Client do
2
+
3
+ describe 'FETCH' do
4
+ it 'fetches the current client details' do
5
+ clnt = MangoPay::Client.fetch
6
+ expect(clnt['ClientId']).to eq(MangoPay.configuration.client_id)
7
+ end
8
+ end
9
+
10
+ describe 'UPDATE' do
11
+ it 'updates the current client details' do
12
+ clnt = MangoPay::Client.fetch
13
+ before = clnt['PrimaryThemeColour']
14
+ after = before == '#aaaaaa' ? '#bbbbbb' : '#aaaaaa' # change the color
15
+ clnt['PrimaryThemeColour'] = after
16
+
17
+ updated = MangoPay::Client.update(clnt)
18
+ expect(updated['ClientId']).to eq(MangoPay.configuration.client_id)
19
+ expect(updated['PrimaryThemeColour']).to eq(after)
20
+ end
21
+ end
22
+
23
+ describe 'UPLOAD LOGO' do
24
+ it 'accepts Base64 encoded file content' do
25
+ fnm = __FILE__.sub('.rb', '.png')
26
+ bts = File.open(fnm, 'rb') { |f| f.read }
27
+ b64 = Base64.encode64(bts)
28
+ ret = MangoPay::Client.upload_logo(b64)
29
+ expect(ret).to be_nil
30
+ end
31
+
32
+ it 'accepts file path' do
33
+ fnm = __FILE__.sub('.rb', '.png')
34
+ ret = MangoPay::Client.upload_logo(nil, fnm)
35
+ expect(ret).to be_nil
36
+ end
37
+
38
+ it 'fails when input string is not base64-encoded' do
39
+ file = 'any file content...'
40
+ expect { MangoPay::Client.upload_logo(file) }.to raise_error { |err|
41
+ expect(err).to be_a MangoPay::ResponseError
42
+ expect(err.code).to eq '400'
43
+ expect(err.type).to eq 'param_error'
44
+ }
45
+ end
46
+ end
47
+
48
+ describe 'fetch_wallets' do
49
+ it 'fetches all client wallets' do
50
+ wlts = MangoPay::Client.fetch_wallets
51
+ expect(wlts).to be_kind_of(Array)
52
+ expect(wlts).not_to be_empty
53
+ end
54
+
55
+ it 'fetches all client fees wallets' do
56
+ wlts = MangoPay::Client.fetch_wallets('fees')
57
+ expect(wlts).to be_kind_of(Array)
58
+ expect(wlts).not_to be_empty
59
+ expect((wlts.map {|m| m['FundsType']}).uniq).to eq(['FEES'])
60
+ end
61
+
62
+ it 'fetches all client credit wallets' do
63
+ wlts = MangoPay::Client.fetch_wallets('credit')
64
+ expect(wlts).to be_kind_of(Array)
65
+ expect(wlts).not_to be_empty
66
+ expect((wlts.map {|m| m['FundsType']}).uniq).to eq(['CREDIT'])
67
+ end
68
+ end
69
+
70
+ describe 'fetch_wallet' do
71
+ it 'fetches one of client wallets by funds type (fees) and currency' do
72
+ wlt = MangoPay::Client.fetch_wallet('fees', 'EUR')
73
+ expect(wlt).to be_kind_of(Hash)
74
+ expect(wlt['FundsType']).to eq('FEES')
75
+ expect(wlt['Currency']).to eq('EUR')
76
+ end
77
+
78
+ it 'fetches one of client wallets by funds type (credit) and currency' do
79
+ wlt = MangoPay::Client.fetch_wallet('credit', 'EUR')
80
+ expect(wlt).to be_kind_of(Hash)
81
+ expect(wlt['FundsType']).to eq('CREDIT')
82
+ expect(wlt['Currency']).to eq('EUR')
83
+ end
84
+ end
85
+
86
+ describe 'fetch_wallets_transactions' do
87
+ it 'fetches transactions for all client wallets' do
88
+ trns = MangoPay::Client.fetch_wallets_transactions
89
+ expect(trns).to be_kind_of(Array)
90
+ expect(trns).not_to be_empty
91
+ end
92
+ end
93
+
94
+ describe 'fetch_wallets_transactions' do
95
+ it 'fetches transactions of one of client wallets by funds type (fees) and currency' do
96
+ trns = MangoPay::Client.fetch_wallet_transactions('fees', 'EUR')
97
+ expect(trns).to be_kind_of(Array)
98
+ expect(trns).not_to be_empty
99
+ expect((trns.map {|m| m['DebitedWalletId']}).uniq).to eq(['FEES_EUR'])
100
+ end
101
+
102
+ it 'fetches transactions of one of client wallets by funds type (credit) and currency' do
103
+ trns = MangoPay::Client.fetch_wallet_transactions('credit', 'EUR')
104
+ expect(trns).to be_kind_of(Array)
105
+ expect(trns).not_to be_empty
106
+ expect((trns.map {|m| m['DebitedWalletId']}).uniq).to eq(['CREDIT_EUR'])
107
+ end
108
+ end
109
+
110
+ end
@@ -1,95 +1,95 @@
1
- describe MangoPay::Configuration do
2
-
3
- it 'fails when calling with wrong client credentials' do
4
- expect {
5
- c = MangoPay.configuration
6
- c.client_id = 'test_asd'
7
- c.client_passphrase = '00000'
8
- MangoPay::User.fetch()
9
- }.to raise_error(MangoPay::ResponseError)
10
- end
11
-
12
- it 'goes ok when calling with correct client credentials' do
13
- reset_mangopay_configuration
14
- users = MangoPay::User.fetch()
15
- expect(users).to be_kind_of(Array)
16
- end
17
-
18
- context 'with multithreading' do
19
- after :all do
20
- reset_mangopay_configuration
21
- end
22
-
23
- before :all do
24
- MangoPay.configuration.client_id = 'default'
25
-
26
- thread_a = Thread.new do
27
- @default_client_id = MangoPay.configuration.client_id
28
-
29
- MangoPay.configuration.client_id = 'a'
30
-
31
- # Test #configuration= & #configuration
32
- config = MangoPay::Configuration.new
33
- config.client_id = 'a'
34
- MangoPay.configuration = config
35
- @before_client_id = MangoPay.configuration.client_id
36
-
37
- # Test multithreading
38
- sleep 1 # Waits for thread B to do its business
39
- @after_client_id = MangoPay.configuration.client_id
40
-
41
- # Test #configure
42
- MangoPay.configure do |c|
43
- c.client_id = 'configured'
44
- end
45
- @configured_client_id = MangoPay.configuration.client_id
46
-
47
- # Test #with_config
48
- @before_with_config_client_id = MangoPay.configuration.client_id
49
- config = MangoPay::Configuration.new
50
- config.client_id = 'with_config'
51
- MangoPay.with_configuration(config) do
52
- @with_config_client_id = MangoPay.configuration.client_id
53
- end
54
- @after_with_config_client_id = MangoPay.configuration.client_id
55
- end
56
-
57
- thread_b = Thread.new do
58
- # Thread A does its business
59
- sleep 0.5
60
- @thread_b_default_client_id = MangoPay.configuration.client_id
61
-
62
- # Will it impact the configuration in thread A ?
63
- MangoPay.configuration.client_id = 'b'
64
- end
65
-
66
- # Wait for both threads to complete
67
- thread_a.join
68
- thread_b.join
69
- end
70
-
71
- it '#configuration & #configuration=' do
72
- expect(@before_client_id).to eq('a')
73
- end
74
-
75
- it '#configure' do
76
- expect(@configured_client_id).to eq('configured')
77
- end
78
-
79
- it '#with_configuration' do
80
- expect(@with_config_client_id).to eq('with_config')
81
- expect(@after_with_config_client_id).to eq(@before_with_config_client_id)
82
- end
83
-
84
- context "since configurations are thread-local," do
85
- it 'threads get the last configuration set as default config.' do
86
- expect(@default_client_id).to eq('default')
87
- expect(@thread_b_default_client_id).to eq('a')
88
- end
89
-
90
- it "configurations are isolated from other threads' activity." do
91
- expect(@after_client_id).to eq('a')
92
- end
93
- end
94
- end
95
- end
1
+ describe MangoPay::Configuration do
2
+
3
+ it 'fails when calling with wrong client credentials' do
4
+ expect {
5
+ c = MangoPay.configuration
6
+ c.client_id = 'test_asd'
7
+ c.client_passphrase = '00000'
8
+ MangoPay::User.fetch()
9
+ }.to raise_error(MangoPay::ResponseError)
10
+ end
11
+
12
+ it 'goes ok when calling with correct client credentials' do
13
+ reset_mangopay_configuration
14
+ users = MangoPay::User.fetch()
15
+ expect(users).to be_kind_of(Array)
16
+ end
17
+
18
+ context 'with multithreading' do
19
+ after :all do
20
+ reset_mangopay_configuration
21
+ end
22
+
23
+ before :all do
24
+ MangoPay.configuration.client_id = 'default'
25
+
26
+ thread_a = Thread.new do
27
+ @default_client_id = MangoPay.configuration.client_id
28
+
29
+ MangoPay.configuration.client_id = 'a'
30
+
31
+ # Test #configuration= & #configuration
32
+ config = MangoPay::Configuration.new
33
+ config.client_id = 'a'
34
+ MangoPay.configuration = config
35
+ @before_client_id = MangoPay.configuration.client_id
36
+
37
+ # Test multithreading
38
+ sleep 1 # Waits for thread B to do its business
39
+ @after_client_id = MangoPay.configuration.client_id
40
+
41
+ # Test #configure
42
+ MangoPay.configure do |c|
43
+ c.client_id = 'configured'
44
+ end
45
+ @configured_client_id = MangoPay.configuration.client_id
46
+
47
+ # Test #with_config
48
+ @before_with_config_client_id = MangoPay.configuration.client_id
49
+ config = MangoPay::Configuration.new
50
+ config.client_id = 'with_config'
51
+ MangoPay.with_configuration(config) do
52
+ @with_config_client_id = MangoPay.configuration.client_id
53
+ end
54
+ @after_with_config_client_id = MangoPay.configuration.client_id
55
+ end
56
+
57
+ thread_b = Thread.new do
58
+ # Thread A does its business
59
+ sleep 0.5
60
+ @thread_b_default_client_id = MangoPay.configuration.client_id
61
+
62
+ # Will it impact the configuration in thread A ?
63
+ MangoPay.configuration.client_id = 'b'
64
+ end
65
+
66
+ # Wait for both threads to complete
67
+ thread_a.join
68
+ thread_b.join
69
+ end
70
+
71
+ it '#configuration & #configuration=' do
72
+ expect(@before_client_id).to eq('a')
73
+ end
74
+
75
+ it '#configure' do
76
+ expect(@configured_client_id).to eq('configured')
77
+ end
78
+
79
+ it '#with_configuration' do
80
+ expect(@with_config_client_id).to eq('with_config')
81
+ expect(@after_with_config_client_id).to eq(@before_with_config_client_id)
82
+ end
83
+
84
+ context "since configurations are thread-local," do
85
+ it 'threads get the last configuration set as default config.' do
86
+ expect(@default_client_id).to eq('default')
87
+ expect(@thread_b_default_client_id).to eq('a')
88
+ end
89
+
90
+ it "configurations are isolated from other threads' activity." do
91
+ expect(@after_client_id).to eq('a')
92
+ end
93
+ end
94
+ end
95
+ end
@@ -1,262 +1,262 @@
1
- describe MangoPay::Dispute do
2
-
3
- =begin
4
- comment out all Dispute related unit tests please
5
- these require manual actions on our side
6
- and it's infact not suitable like that
7
-
8
- # IMPORTANT NOTE!
9
- #
10
- # Due to the fact the disputes CANNOT be created on user's side,
11
- # a special approach in testing is needed.
12
- # In order to get the tests below pass, a bunch of disputes have
13
- # to be prepared on the API server side - if they're not, you can
14
- # just skip these tests, as they won't pass.
15
- before(:each) do
16
- @disputes = MangoPay::Dispute.fetch({'page' => 1, 'per_page' => 100})
17
- end
18
-
19
- describe 'FETCH' do
20
- it 'fetches disputes' do
21
- expect(@disputes).to be_kind_of(Array)
22
- expect(@disputes).not_to be_empty
23
- end
24
- it 'fetches a dispute' do
25
- id = @disputes.first['Id']
26
- dispute = MangoPay::Dispute.fetch(id)
27
- expect(dispute['Id']).to eq(id)
28
- end
29
- end
30
-
31
- describe 'TRANSACTIONS' do
32
- it 'fetches transactions for dispute' do
33
- dispute = @disputes.find { |d| d['DisputeType'] == 'NOT_CONTESTABLE' }
34
- id = dispute['Id']
35
- transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
36
- expect(transactions).to be_kind_of(Array)
37
- expect(transactions).not_to be_empty
38
- end
39
- end
40
-
41
- describe 'FETCH FOR USER AND WALLET' do
42
- it 'fetches disputes for user' do
43
- dispute = @disputes.find { |d| d['DisputeType'] == 'NOT_CONTESTABLE' }
44
- id = dispute['Id']
45
- transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
46
- user_id = transactions[0]['AuthorId']
47
- disputes = MangoPay::Dispute.fetch_for_user(user_id, {'per_page' => 1})
48
- expect(disputes).to be_kind_of(Array)
49
- expect(disputes).not_to be_empty
50
- end
51
- it 'fetches disputes for wallet' do
52
- dispute = @disputes.find {|disp| disp['InitialTransactionId'] != nil}
53
- expect(dispute).not_to be_nil, "Cannot test fetching disputes for wallet because there's no disputes with transaction ID in the disputes list."
54
- payin = MangoPay::PayIn.fetch(dispute['InitialTransactionId'])
55
- wallet_id = payin['CreditedWalletId']
56
- disputes = MangoPay::Dispute.fetch_for_wallet(wallet_id, {'per_page' => 1})
57
- expect(disputes).to be_kind_of(Array)
58
- expect(disputes).not_to be_empty
59
- end
60
- end
61
-
62
- describe 'UPDATE' do
63
- it 'updates a dispute' do
64
- dispute = @disputes.first
65
- id = dispute['Id']
66
- new_tag = dispute['Tag'] + '.com'
67
- changed_dispute = MangoPay::Dispute.update(id, {Tag: new_tag})
68
- expect(changed_dispute['Tag']).to eq(new_tag)
69
- end
70
- end
71
-
72
- describe 'FETCH REPUDIATION' do
73
- it 'fetches a repudiation' do
74
- dispute = @disputes.find {|disp| disp['InitialTransactionId'] != nil && disp['DisputeType'] == 'NOT_CONTESTABLE'}
75
- expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no not contestable disputes with transaction ID in the disputes list."
76
- transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
77
- repudiation_id = transactions[0]['Id']
78
- repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
79
- expect(repudiation['Id']).to eq(repudiation_id)
80
- expect(repudiation['Nature']).to eq('REPUDIATION')
81
- end
82
- end
83
-
84
- describe 'CREATE AND FETCH SETTLEMENT TRANSFER' do
85
- it 'creates and fetches settlement transfer' do
86
- dispute = @disputes.find {|disp| disp['Status'] == 'CLOSED' && disp['DisputeType'] == 'NOT_CONTESTABLE'}
87
- expect(dispute).not_to be_nil, "Cannot test creating settlement transfer because there's no closed, not contestable disputes in the disputes list."
88
- transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
89
- repudiation_id = transactions[0]['Id']
90
- repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
91
- params = {
92
- AuthorId: repudiation['AuthorId'],
93
- DebitedFunds: {Currency: 'EUR', Amount: 1},
94
- Fees: {Currency: 'EUR', Amount: 0},
95
- Tag: 'Custom tag data'
96
- }
97
-
98
- transfer = MangoPay::Dispute.create_settlement_transfer(repudiation_id, params)
99
- expect(transfer['Type']).to eq('TRANSFER')
100
- expect(transfer['Nature']).to eq('SETTLEMENT')
101
-
102
- fetched_transfer = MangoPay::Dispute.fetch_settlement_transfer(transfer['Id'])
103
- expect(fetched_transfer['Id']).to eq(transfer['Id'])
104
- expect(fetched_transfer['CreationDate']).to eq(transfer['CreationDate'])
105
- end
106
- end
107
-
108
- describe 'DISPUTE DOCUMENTS API' do
109
-
110
- def find_dispute
111
- dispute = @disputes.find {|disp| ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status'])}
112
- expect(dispute).not_to be_nil, "Cannot test dispute document API because there's no dispute with expected status in the disputes list."
113
- dispute
114
- end
115
-
116
- def create_doc(dispute = nil)
117
- no_dispute_passed = dispute.nil?
118
- dispute = find_dispute if no_dispute_passed
119
- params = { Type: 'DELIVERY_PROOF', Tag: 'Custom tag data' }
120
- doc = MangoPay::Dispute.create_document(dispute['Id'], params)
121
- doc['dispute'] = dispute if no_dispute_passed # add it for testing purposes
122
- doc
123
- end
124
-
125
- it 'creates dispute document' do
126
- doc = create_doc
127
- expect(doc['Type']).to eq('DELIVERY_PROOF')
128
- expect(doc['Tag']).to eq('Custom tag data')
129
- expect(doc['Status']).to eq('CREATED')
130
- end
131
-
132
- it 'fetches dispute document' do
133
- created_doc = create_doc
134
- fetched_doc = MangoPay::Dispute.fetch_document(created_doc['Id'])
135
- fields = ['Id', 'Type', 'Tag', 'Status', 'CreationDate', 'RefusedReasonType', 'RefusedReasonMessage']
136
- fields.each do |field|
137
- expect(fetched_doc[field]).to eq(created_doc[field])
138
- end
139
- end
140
-
141
- it 'updates dispute document' do
142
- created_doc = create_doc
143
- changed_doc = MangoPay::Dispute.update_document(created_doc['dispute']['Id'], created_doc['Id'], {
144
- Status: 'VALIDATION_ASKED'
145
- })
146
- expect(changed_doc['Id']).to eq(created_doc['Id'])
147
- expect(changed_doc['Status']).to eq('VALIDATION_ASKED')
148
- end
149
-
150
- it 'fetches a list of documents' do
151
- disp = @disputes.find {|disp| disp['Status'] == 'SUBMITTED'}
152
- disp = test_contest_dispute if disp == nil
153
- expect(disp).not_to be_nil, "Cannot test fetching dispute documents because there's no dispute with expected status in the disputes list."
154
-
155
- doc1 = create_doc(disp)
156
- doc2 = create_doc(disp) # for the same dispute
157
-
158
- filters = {'per_page' => 2, 'sort' => 'CreationDate:desc'}
159
-
160
- # fetch last 2 docs for the dispute
161
- docs = MangoPay::Dispute.fetch_documents(disp['Id'], filters)
162
- expect(docs).to be_kind_of(Array)
163
- expect(docs.count).to eq 2 # exactly 2 as pagiantion requested
164
- # all 2 are at top as lastly created
165
- # but may share the same CreationDate
166
- # so the order between them is undetermined
167
- expect(docs).to include(doc1, doc2)
168
-
169
- # fetch all docs ever
170
- docs = MangoPay::Dispute.fetch_documents()
171
- expect(docs).to be_kind_of(Array)
172
- expect(docs.count).to be >= 2
173
-
174
- # fetch last 2 docs ever (sorting by date descending)
175
- docs = MangoPay::Dispute.fetch_documents(nil, filters)
176
- expect(docs).to be_kind_of(Array)
177
- expect(docs.count).to eq 2 # exactly 2 as pagiantion requested
178
- expect(docs).to include(doc1, doc2)
179
- end
180
-
181
- def create_doc_page(file)
182
- disp = find_dispute
183
- doc = create_doc(disp)
184
- MangoPay::Dispute.create_document_page(disp['Id'], doc['Id'], file)
185
- end
186
-
187
- it 'create_document_page accepts Base64 encoded file content' do
188
- fnm = __FILE__.sub('.rb', '.png')
189
- bts = File.open(fnm, 'rb') { |f| f.read }
190
- b64 = Base64.encode64(bts)
191
- ret = create_doc_page(b64)
192
- expect(ret).to be_nil
193
- end
194
-
195
- it 'create_document_page accepts file path' do
196
- fnm = __FILE__.sub('.rb', '.png')
197
- disp = find_dispute
198
- doc = create_doc(disp)
199
- ret = MangoPay::Dispute.create_document_page(disp['Id'], doc['Id'], nil, fnm)
200
- expect(ret).to be_nil
201
- end
202
-
203
- it 'create_document_page fails when input string is not base64-encoded' do
204
- file = 'any file content...'
205
- expect { create_doc_page(file) }.to raise_error { |err|
206
- expect(err).to be_a MangoPay::ResponseError
207
- expect(err.code).to eq '400'
208
- expect(err.type).to eq 'param_error'
209
- }
210
- end
211
- end
212
-
213
- def test_contest_dispute
214
- dispute = @disputes.find do |disp|
215
- ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status']) &&
216
- ['CONTESTABLE', 'RETRIEVAL'].include?(disp['DisputeType'])
217
- end
218
- expect(dispute).not_to be_nil, "Cannot test contesting dispute because there's no available disputes with expected status and type in the disputes list."
219
- id = dispute['Id']
220
- contested_funds = dispute['Status'] == 'PENDING_CLIENT_ACTION' ? { Amount: 10, Currency: 'EUR' } : nil;
221
- changed_dispute = MangoPay::Dispute.contest(id, contested_funds)
222
- expect(changed_dispute['Id']).to eq(id)
223
- expect(changed_dispute['Status']).to eq('SUBMITTED')
224
- changed_dispute
225
- end
226
-
227
- describe 'CONTEST' do
228
- it 'contests a dispute' do
229
- test_contest_dispute
230
- end
231
- end
232
-
233
- describe 'RESUBMIT' do
234
- it 'resubmits a dispute' do
235
- dispute = @disputes.find do |disp|
236
- ['REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status'])
237
- end
238
- expect(dispute).not_to be_nil, "Cannot test resubmiting dispute because there's no available disputes with expected status in the disputes list."
239
- id = dispute['Id']
240
- changed_dispute = MangoPay::Dispute.resubmit(id)
241
- expect(changed_dispute['Id']).to eq(id)
242
- expect(changed_dispute['Status']).to eq('SUBMITTED')
243
- end
244
- end
245
-
246
- describe 'CLOSE' do
247
- it 'closes a dispute' do
248
- dispute = @disputes.find do |disp|
249
- ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status']) &&
250
- ['CONTESTABLE', 'RETRIEVAL'].include?(disp['DisputeType'])
251
- end
252
- expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no available disputes with expected status in the disputes list."
253
- id = dispute['Id']
254
- changed_dispute = MangoPay::Dispute.close(id)
255
- expect(changed_dispute['Id']).to eq(id)
256
- expect(changed_dispute['Status']).to eq('CLOSED')
257
- end
258
- end
259
-
260
- =end
261
-
262
- end
1
+ describe MangoPay::Dispute do
2
+
3
+ =begin
4
+ comment out all Dispute related unit tests please
5
+ these require manual actions on our side
6
+ and it's infact not suitable like that
7
+
8
+ # IMPORTANT NOTE!
9
+ #
10
+ # Due to the fact the disputes CANNOT be created on user's side,
11
+ # a special approach in testing is needed.
12
+ # In order to get the tests below pass, a bunch of disputes have
13
+ # to be prepared on the API server side - if they're not, you can
14
+ # just skip these tests, as they won't pass.
15
+ before(:each) do
16
+ @disputes = MangoPay::Dispute.fetch({'page' => 1, 'per_page' => 100})
17
+ end
18
+
19
+ describe 'FETCH' do
20
+ it 'fetches disputes' do
21
+ expect(@disputes).to be_kind_of(Array)
22
+ expect(@disputes).not_to be_empty
23
+ end
24
+ it 'fetches a dispute' do
25
+ id = @disputes.first['Id']
26
+ dispute = MangoPay::Dispute.fetch(id)
27
+ expect(dispute['Id']).to eq(id)
28
+ end
29
+ end
30
+
31
+ describe 'TRANSACTIONS' do
32
+ it 'fetches transactions for dispute' do
33
+ dispute = @disputes.find { |d| d['DisputeType'] == 'NOT_CONTESTABLE' }
34
+ id = dispute['Id']
35
+ transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
36
+ expect(transactions).to be_kind_of(Array)
37
+ expect(transactions).not_to be_empty
38
+ end
39
+ end
40
+
41
+ describe 'FETCH FOR USER AND WALLET' do
42
+ it 'fetches disputes for user' do
43
+ dispute = @disputes.find { |d| d['DisputeType'] == 'NOT_CONTESTABLE' }
44
+ id = dispute['Id']
45
+ transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
46
+ user_id = transactions[0]['AuthorId']
47
+ disputes = MangoPay::Dispute.fetch_for_user(user_id, {'per_page' => 1})
48
+ expect(disputes).to be_kind_of(Array)
49
+ expect(disputes).not_to be_empty
50
+ end
51
+ it 'fetches disputes for wallet' do
52
+ dispute = @disputes.find {|disp| disp['InitialTransactionId'] != nil}
53
+ expect(dispute).not_to be_nil, "Cannot test fetching disputes for wallet because there's no disputes with transaction ID in the disputes list."
54
+ payin = MangoPay::PayIn.fetch(dispute['InitialTransactionId'])
55
+ wallet_id = payin['CreditedWalletId']
56
+ disputes = MangoPay::Dispute.fetch_for_wallet(wallet_id, {'per_page' => 1})
57
+ expect(disputes).to be_kind_of(Array)
58
+ expect(disputes).not_to be_empty
59
+ end
60
+ end
61
+
62
+ describe 'UPDATE' do
63
+ it 'updates a dispute' do
64
+ dispute = @disputes.first
65
+ id = dispute['Id']
66
+ new_tag = dispute['Tag'] + '.com'
67
+ changed_dispute = MangoPay::Dispute.update(id, {Tag: new_tag})
68
+ expect(changed_dispute['Tag']).to eq(new_tag)
69
+ end
70
+ end
71
+
72
+ describe 'FETCH REPUDIATION' do
73
+ it 'fetches a repudiation' do
74
+ dispute = @disputes.find {|disp| disp['InitialTransactionId'] != nil && disp['DisputeType'] == 'NOT_CONTESTABLE'}
75
+ expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no not contestable disputes with transaction ID in the disputes list."
76
+ transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
77
+ repudiation_id = transactions[0]['Id']
78
+ repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
79
+ expect(repudiation['Id']).to eq(repudiation_id)
80
+ expect(repudiation['Nature']).to eq('REPUDIATION')
81
+ end
82
+ end
83
+
84
+ describe 'CREATE AND FETCH SETTLEMENT TRANSFER' do
85
+ it 'creates and fetches settlement transfer' do
86
+ dispute = @disputes.find {|disp| disp['Status'] == 'CLOSED' && disp['DisputeType'] == 'NOT_CONTESTABLE'}
87
+ expect(dispute).not_to be_nil, "Cannot test creating settlement transfer because there's no closed, not contestable disputes in the disputes list."
88
+ transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
89
+ repudiation_id = transactions[0]['Id']
90
+ repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
91
+ params = {
92
+ AuthorId: repudiation['AuthorId'],
93
+ DebitedFunds: {Currency: 'EUR', Amount: 1},
94
+ Fees: {Currency: 'EUR', Amount: 0},
95
+ Tag: 'Custom tag data'
96
+ }
97
+
98
+ transfer = MangoPay::Dispute.create_settlement_transfer(repudiation_id, params)
99
+ expect(transfer['Type']).to eq('TRANSFER')
100
+ expect(transfer['Nature']).to eq('SETTLEMENT')
101
+
102
+ fetched_transfer = MangoPay::Dispute.fetch_settlement_transfer(transfer['Id'])
103
+ expect(fetched_transfer['Id']).to eq(transfer['Id'])
104
+ expect(fetched_transfer['CreationDate']).to eq(transfer['CreationDate'])
105
+ end
106
+ end
107
+
108
+ describe 'DISPUTE DOCUMENTS API' do
109
+
110
+ def find_dispute
111
+ dispute = @disputes.find {|disp| ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status'])}
112
+ expect(dispute).not_to be_nil, "Cannot test dispute document API because there's no dispute with expected status in the disputes list."
113
+ dispute
114
+ end
115
+
116
+ def create_doc(dispute = nil)
117
+ no_dispute_passed = dispute.nil?
118
+ dispute = find_dispute if no_dispute_passed
119
+ params = { Type: 'DELIVERY_PROOF', Tag: 'Custom tag data' }
120
+ doc = MangoPay::Dispute.create_document(dispute['Id'], params)
121
+ doc['dispute'] = dispute if no_dispute_passed # add it for testing purposes
122
+ doc
123
+ end
124
+
125
+ it 'creates dispute document' do
126
+ doc = create_doc
127
+ expect(doc['Type']).to eq('DELIVERY_PROOF')
128
+ expect(doc['Tag']).to eq('Custom tag data')
129
+ expect(doc['Status']).to eq('CREATED')
130
+ end
131
+
132
+ it 'fetches dispute document' do
133
+ created_doc = create_doc
134
+ fetched_doc = MangoPay::Dispute.fetch_document(created_doc['Id'])
135
+ fields = ['Id', 'Type', 'Tag', 'Status', 'CreationDate', 'RefusedReasonType', 'RefusedReasonMessage']
136
+ fields.each do |field|
137
+ expect(fetched_doc[field]).to eq(created_doc[field])
138
+ end
139
+ end
140
+
141
+ it 'updates dispute document' do
142
+ created_doc = create_doc
143
+ changed_doc = MangoPay::Dispute.update_document(created_doc['dispute']['Id'], created_doc['Id'], {
144
+ Status: 'VALIDATION_ASKED'
145
+ })
146
+ expect(changed_doc['Id']).to eq(created_doc['Id'])
147
+ expect(changed_doc['Status']).to eq('VALIDATION_ASKED')
148
+ end
149
+
150
+ it 'fetches a list of documents' do
151
+ disp = @disputes.find {|disp| disp['Status'] == 'SUBMITTED'}
152
+ disp = test_contest_dispute if disp == nil
153
+ expect(disp).not_to be_nil, "Cannot test fetching dispute documents because there's no dispute with expected status in the disputes list."
154
+
155
+ doc1 = create_doc(disp)
156
+ doc2 = create_doc(disp) # for the same dispute
157
+
158
+ filters = {'per_page' => 2, 'sort' => 'CreationDate:desc'}
159
+
160
+ # fetch last 2 docs for the dispute
161
+ docs = MangoPay::Dispute.fetch_documents(disp['Id'], filters)
162
+ expect(docs).to be_kind_of(Array)
163
+ expect(docs.count).to eq 2 # exactly 2 as pagiantion requested
164
+ # all 2 are at top as lastly created
165
+ # but may share the same CreationDate
166
+ # so the order between them is undetermined
167
+ expect(docs).to include(doc1, doc2)
168
+
169
+ # fetch all docs ever
170
+ docs = MangoPay::Dispute.fetch_documents()
171
+ expect(docs).to be_kind_of(Array)
172
+ expect(docs.count).to be >= 2
173
+
174
+ # fetch last 2 docs ever (sorting by date descending)
175
+ docs = MangoPay::Dispute.fetch_documents(nil, filters)
176
+ expect(docs).to be_kind_of(Array)
177
+ expect(docs.count).to eq 2 # exactly 2 as pagiantion requested
178
+ expect(docs).to include(doc1, doc2)
179
+ end
180
+
181
+ def create_doc_page(file)
182
+ disp = find_dispute
183
+ doc = create_doc(disp)
184
+ MangoPay::Dispute.create_document_page(disp['Id'], doc['Id'], file)
185
+ end
186
+
187
+ it 'create_document_page accepts Base64 encoded file content' do
188
+ fnm = __FILE__.sub('.rb', '.png')
189
+ bts = File.open(fnm, 'rb') { |f| f.read }
190
+ b64 = Base64.encode64(bts)
191
+ ret = create_doc_page(b64)
192
+ expect(ret).to be_nil
193
+ end
194
+
195
+ it 'create_document_page accepts file path' do
196
+ fnm = __FILE__.sub('.rb', '.png')
197
+ disp = find_dispute
198
+ doc = create_doc(disp)
199
+ ret = MangoPay::Dispute.create_document_page(disp['Id'], doc['Id'], nil, fnm)
200
+ expect(ret).to be_nil
201
+ end
202
+
203
+ it 'create_document_page fails when input string is not base64-encoded' do
204
+ file = 'any file content...'
205
+ expect { create_doc_page(file) }.to raise_error { |err|
206
+ expect(err).to be_a MangoPay::ResponseError
207
+ expect(err.code).to eq '400'
208
+ expect(err.type).to eq 'param_error'
209
+ }
210
+ end
211
+ end
212
+
213
+ def test_contest_dispute
214
+ dispute = @disputes.find do |disp|
215
+ ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status']) &&
216
+ ['CONTESTABLE', 'RETRIEVAL'].include?(disp['DisputeType'])
217
+ end
218
+ expect(dispute).not_to be_nil, "Cannot test contesting dispute because there's no available disputes with expected status and type in the disputes list."
219
+ id = dispute['Id']
220
+ contested_funds = dispute['Status'] == 'PENDING_CLIENT_ACTION' ? { Amount: 10, Currency: 'EUR' } : nil;
221
+ changed_dispute = MangoPay::Dispute.contest(id, contested_funds)
222
+ expect(changed_dispute['Id']).to eq(id)
223
+ expect(changed_dispute['Status']).to eq('SUBMITTED')
224
+ changed_dispute
225
+ end
226
+
227
+ describe 'CONTEST' do
228
+ it 'contests a dispute' do
229
+ test_contest_dispute
230
+ end
231
+ end
232
+
233
+ describe 'RESUBMIT' do
234
+ it 'resubmits a dispute' do
235
+ dispute = @disputes.find do |disp|
236
+ ['REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status'])
237
+ end
238
+ expect(dispute).not_to be_nil, "Cannot test resubmiting dispute because there's no available disputes with expected status in the disputes list."
239
+ id = dispute['Id']
240
+ changed_dispute = MangoPay::Dispute.resubmit(id)
241
+ expect(changed_dispute['Id']).to eq(id)
242
+ expect(changed_dispute['Status']).to eq('SUBMITTED')
243
+ end
244
+ end
245
+
246
+ describe 'CLOSE' do
247
+ it 'closes a dispute' do
248
+ dispute = @disputes.find do |disp|
249
+ ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status']) &&
250
+ ['CONTESTABLE', 'RETRIEVAL'].include?(disp['DisputeType'])
251
+ end
252
+ expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no available disputes with expected status in the disputes list."
253
+ id = dispute['Id']
254
+ changed_dispute = MangoPay::Dispute.close(id)
255
+ expect(changed_dispute['Id']).to eq(id)
256
+ expect(changed_dispute['Status']).to eq('CLOSED')
257
+ end
258
+ end
259
+
260
+ =end
261
+
262
+ end