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

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 -26
  3. data/.rspec +2 -2
  4. data/.travis.yml +13 -0
  5. data/Gemfile +2 -2
  6. data/LICENSE +20 -20
  7. data/README.md +126 -123
  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 -158
  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 -0
  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 -73
  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 -35
  38. data/lib/mangopay/version.rb +3 -3
  39. data/lib/mangopay/wallet.rb +17 -17
  40. data/mangopay.gemspec +31 -30
  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 -18
  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 -0
  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 -0
  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 -365
  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 -122
  70. data/spec/mangopay/wallet_spec.rb +80 -80
  71. data/spec/spec_helper.rb +31 -31
  72. metadata +11 -5
@@ -1,73 +1,73 @@
1
- describe MangoPay::CardRegistration do
2
- include_context 'users'
3
- include_context 'payins'
4
-
5
- describe 'CREATE' do
6
- it 'creates a new card registration' do
7
- created = new_card_registration
8
- expect(created['Id']).not_to be_nil
9
- expect(created['Id'].to_i).to be > 0
10
- expect(created['AccessKey']).not_to be_nil
11
- expect(created['PreregistrationData']).not_to be_nil
12
- expect(created['CardRegistrationURL']).not_to be_nil
13
- expect(created['RegistrationData']).to be_nil
14
- expect(created['CardId']).to be_nil
15
- expect(created['UserId']).to eq(new_natural_user["Id"])
16
- expect(created['Currency']).to eq('EUR')
17
- expect(created['Status']).to eq('CREATED')
18
- end
19
- end
20
-
21
- describe 'UPDATE' do
22
- it 'updates a card registration' do
23
- created = new_card_registration
24
- updated = MangoPay::CardRegistration.update(created['Id'] ,{
25
- RegistrationData: 'test RegistrationData'
26
- })
27
- expect(updated['RegistrationData']).to eq('test RegistrationData')
28
- end
29
- end
30
-
31
- describe 'FETCH' do
32
- it 'fetches a card registration' do
33
- created = new_card_registration
34
- fetched = MangoPay::CardRegistration.fetch(created['Id'])
35
- expect(fetched['Id']).to eq(created['Id'])
36
- expect(fetched['UserId']).to eq(created['UserId'])
37
- expect(fetched['Tag']).to eq(created['Tag'])
38
- end
39
- end
40
-
41
- describe 'TOKENIZATION PROCESS' do
42
- it 'fills-in registration data and links it to a newly created card' do
43
- completed = new_card_registration_completed
44
- reg_data = completed['RegistrationData']
45
- card_id = completed['CardId']
46
-
47
- # reg data filled-in
48
- expect(reg_data).not_to be_nil
49
- expect(reg_data).to be_kind_of String
50
- expect(reg_data).not_to be_empty
51
-
52
- # card id filled-in...
53
- expect(card_id).not_to be_nil
54
- expect(card_id.to_i).to be > 0
55
-
56
- # ...and points to existing (newly created) card
57
- card = MangoPay::Card.fetch(card_id)
58
- expect(card['Id']).to eq card_id
59
-
60
- ################################################################################
61
- # cannot test updating: one can only put a CARD from "VALID" to "INVALID"
62
- # # let's test updating the card too
63
- # expect(card['Validity']).to eq 'UNKNOWN'
64
- # card_updated = MangoPay::Card.update(card_id ,{
65
- # Validity: 'INVALID'
66
- # })
67
- # expect(card_updated['Validity']).to eq 'INVALID'
68
- # expect(MangoPay::Card.fetch(card_id)['Validity']).to eq 'INVALID'
69
- ################################################################################
70
- end
71
- end
72
-
73
- end
1
+ describe MangoPay::CardRegistration do
2
+ include_context 'users'
3
+ include_context 'payins'
4
+
5
+ describe 'CREATE' do
6
+ it 'creates a new card registration' do
7
+ created = new_card_registration
8
+ expect(created['Id']).not_to be_nil
9
+ expect(created['Id'].to_i).to be > 0
10
+ expect(created['AccessKey']).not_to be_nil
11
+ expect(created['PreregistrationData']).not_to be_nil
12
+ expect(created['CardRegistrationURL']).not_to be_nil
13
+ expect(created['RegistrationData']).to be_nil
14
+ expect(created['CardId']).to be_nil
15
+ expect(created['UserId']).to eq(new_natural_user["Id"])
16
+ expect(created['Currency']).to eq('EUR')
17
+ expect(created['Status']).to eq('CREATED')
18
+ end
19
+ end
20
+
21
+ describe 'UPDATE' do
22
+ it 'updates a card registration' do
23
+ created = new_card_registration
24
+ updated = MangoPay::CardRegistration.update(created['Id'] ,{
25
+ RegistrationData: 'test RegistrationData'
26
+ })
27
+ expect(updated['RegistrationData']).to eq('test RegistrationData')
28
+ end
29
+ end
30
+
31
+ describe 'FETCH' do
32
+ it 'fetches a card registration' do
33
+ created = new_card_registration
34
+ fetched = MangoPay::CardRegistration.fetch(created['Id'])
35
+ expect(fetched['Id']).to eq(created['Id'])
36
+ expect(fetched['UserId']).to eq(created['UserId'])
37
+ expect(fetched['Tag']).to eq(created['Tag'])
38
+ end
39
+ end
40
+
41
+ describe 'TOKENIZATION PROCESS' do
42
+ it 'fills-in registration data and links it to a newly created card' do
43
+ completed = new_card_registration_completed
44
+ reg_data = completed['RegistrationData']
45
+ card_id = completed['CardId']
46
+
47
+ # reg data filled-in
48
+ expect(reg_data).not_to be_nil
49
+ expect(reg_data).to be_kind_of String
50
+ expect(reg_data).not_to be_empty
51
+
52
+ # card id filled-in...
53
+ expect(card_id).not_to be_nil
54
+ expect(card_id.to_i).to be > 0
55
+
56
+ # ...and points to existing (newly created) card
57
+ card = MangoPay::Card.fetch(card_id)
58
+ expect(card['Id']).to eq card_id
59
+
60
+ ################################################################################
61
+ # cannot test updating: one can only put a CARD from "VALID" to "INVALID"
62
+ # # let's test updating the card too
63
+ # expect(card['Validity']).to eq 'UNKNOWN'
64
+ # card_updated = MangoPay::Card.update(card_id ,{
65
+ # Validity: 'INVALID'
66
+ # })
67
+ # expect(card_updated['Validity']).to eq 'INVALID'
68
+ # expect(MangoPay::Card.fetch(card_id)['Validity']).to eq 'INVALID'
69
+ ################################################################################
70
+ end
71
+ end
72
+
73
+ end
@@ -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,18 +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
- 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