mangopay 3.0.25 → 3.0.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +30 -28
  3. data/.rspec +2 -2
  4. data/.travis.yml +13 -4
  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 +228 -225
  12. data/lib/mangopay/authorization_token.rb +88 -88
  13. data/lib/mangopay/bank_account.rb +38 -38
  14. data/lib/mangopay/bankingaliases.rb +29 -0
  15. data/lib/mangopay/bankingaliases_iban.rb +16 -0
  16. data/lib/mangopay/card.rb +8 -8
  17. data/lib/mangopay/card_registration.rb +9 -9
  18. data/lib/mangopay/client.rb +74 -74
  19. data/lib/mangopay/dispute.rb +130 -130
  20. data/lib/mangopay/errors.rb +61 -61
  21. data/lib/mangopay/event.rb +18 -18
  22. data/lib/mangopay/filter_parameters.rb +46 -46
  23. data/lib/mangopay/hook.rb +9 -9
  24. data/lib/mangopay/http_calls.rb +85 -85
  25. data/lib/mangopay/json.rb +14 -14
  26. data/lib/mangopay/kyc_document.rb +70 -70
  27. data/lib/mangopay/legal_user.rb +15 -15
  28. data/lib/mangopay/mandate.rb +32 -32
  29. data/lib/mangopay/natural_user.rb +14 -14
  30. data/lib/mangopay/pay_in.rb +96 -85
  31. data/lib/mangopay/pay_out.rb +14 -14
  32. data/lib/mangopay/pre_authorization.rb +13 -13
  33. data/lib/mangopay/refund.rb +7 -7
  34. data/lib/mangopay/report.rb +17 -17
  35. data/lib/mangopay/resource.rb +21 -21
  36. data/lib/mangopay/transaction.rb +24 -24
  37. data/lib/mangopay/transfer.rb +9 -9
  38. data/lib/mangopay/user.rb +43 -43
  39. data/lib/mangopay/version.rb +3 -3
  40. data/lib/mangopay/wallet.rb +17 -17
  41. data/mangopay.gemspec +30 -30
  42. data/spec/mangopay/authorization_token_spec.rb +70 -70
  43. data/spec/mangopay/bank_account_spec.rb +97 -97
  44. data/spec/mangopay/bankingaliases_spec.rb +29 -0
  45. data/spec/mangopay/card_registration_spec.rb +73 -73
  46. data/spec/mangopay/client_spec.rb +110 -110
  47. data/spec/mangopay/configuration_spec.rb +95 -95
  48. data/spec/mangopay/dispute_spec.rb +262 -262
  49. data/spec/mangopay/event_spec.rb +31 -31
  50. data/spec/mangopay/fetch_filters_spec.rb +63 -63
  51. data/spec/mangopay/hook_spec.rb +37 -37
  52. data/spec/mangopay/idempotency_spec.rb +41 -41
  53. data/spec/mangopay/kyc_document_spec.rb +103 -103
  54. data/spec/mangopay/log_requests_filter_spec.rb +25 -25
  55. data/spec/mangopay/mandate_spec.rb +92 -92
  56. data/spec/mangopay/payin_bankwire_direct_spec.rb +74 -74
  57. data/spec/mangopay/payin_card_direct_spec.rb +68 -68
  58. data/spec/mangopay/payin_card_web_spec.rb +47 -38
  59. data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -37
  60. data/spec/mangopay/payin_directdebit_web_spec.rb +38 -38
  61. data/spec/mangopay/payin_paypal_web_spec.rb +38 -38
  62. data/spec/mangopay/payin_preauthorized_direct_spec.rb +68 -68
  63. data/spec/mangopay/payout_bankwire_spec.rb +54 -54
  64. data/spec/mangopay/preauthorization_spec.rb +42 -42
  65. data/spec/mangopay/refund_spec.rb +21 -21
  66. data/spec/mangopay/report_spec.rb +39 -39
  67. data/spec/mangopay/shared_resources.rb +397 -381
  68. data/spec/mangopay/transaction_spec.rb +54 -54
  69. data/spec/mangopay/transfer_spec.rb +69 -69
  70. data/spec/mangopay/user_spec.rb +137 -137
  71. data/spec/mangopay/wallet_spec.rb +80 -80
  72. data/spec/spec_helper.rb +31 -31
  73. metadata +7 -6
  74. data/lib/mangopay/temp.rb +0 -74
  75. data/spec/mangopay/temp_paymentcard_spec.rb +0 -31
@@ -1,54 +1,54 @@
1
- describe MangoPay::PayOut::BankWire, type: :feature do
2
- include_context 'bank_accounts'
3
- include_context 'payins'
4
- include_context 'payouts'
5
-
6
- def check_type_and_status(payout, check_status = true)
7
- expect(payout['Type']).to eq('PAYOUT')
8
- expect(payout['Nature']).to eq('REGULAR')
9
- expect(payout['PaymentType']).to eq('BANK_WIRE')
10
-
11
- # linked to correct bank account
12
- expect(payout['BankAccountId']).to eq(new_bank_account['Id'])
13
-
14
- if (check_status)
15
- # not SUCCEEDED yet: waiting for processing
16
- expect(payout['ExecutionDate']).to be_nil
17
- expect(payout['Status']).to eq('CREATED')
18
- expect(payout['ResultCode']).to be_nil
19
- expect(payout['ResultMessage']).to be_nil
20
- end
21
- end
22
-
23
- describe 'CREATE' do
24
-
25
- it 'creates a bank wire payout' do
26
- payin = new_payin_card_direct # this payin is successfull so payout may happen
27
- payout = create_new_payout_bankwire(payin)
28
- expect(payout['Id']).not_to be_nil
29
- check_type_and_status(payout)
30
- expect(payout['DebitedWalletId']).to eq(payin['CreditedWalletId'])
31
- end
32
-
33
- it 'fails if not enough money' do
34
- payin = new_payin_card_web # this payin is NOT processed yet so payout may NOT happen
35
- payout = create_new_payout_bankwire(payin)
36
- check_type_and_status(payout, false)
37
- expect(payout['Status']).to eq('FAILED')
38
- expect(payout['ResultCode']).to eq('001001')
39
- expect(payout['ResultMessage']).to eq('Unsufficient wallet balance')
40
- end
41
- end
42
-
43
- describe 'FETCH' do
44
- it 'fetches a payout' do
45
- created = new_payout_bankwire
46
- fetched = MangoPay::PayOut.fetch(created['Id'])
47
- expect(fetched['Id']).to eq(created['Id'])
48
- expect(fetched['CreationDate']).to eq(created['CreationDate'])
49
- check_type_and_status(created)
50
- check_type_and_status(fetched)
51
- end
52
- end
53
-
54
- end
1
+ describe MangoPay::PayOut::BankWire, type: :feature do
2
+ include_context 'bank_accounts'
3
+ include_context 'payins'
4
+ include_context 'payouts'
5
+
6
+ def check_type_and_status(payout, check_status = true)
7
+ expect(payout['Type']).to eq('PAYOUT')
8
+ expect(payout['Nature']).to eq('REGULAR')
9
+ expect(payout['PaymentType']).to eq('BANK_WIRE')
10
+
11
+ # linked to correct bank account
12
+ expect(payout['BankAccountId']).to eq(new_bank_account['Id'])
13
+
14
+ if (check_status)
15
+ # not SUCCEEDED yet: waiting for processing
16
+ expect(payout['ExecutionDate']).to be_nil
17
+ expect(payout['Status']).to eq('CREATED')
18
+ expect(payout['ResultCode']).to be_nil
19
+ expect(payout['ResultMessage']).to be_nil
20
+ end
21
+ end
22
+
23
+ describe 'CREATE' do
24
+
25
+ it 'creates a bank wire payout' do
26
+ payin = new_payin_card_direct # this payin is successfull so payout may happen
27
+ payout = create_new_payout_bankwire(payin)
28
+ expect(payout['Id']).not_to be_nil
29
+ check_type_and_status(payout)
30
+ expect(payout['DebitedWalletId']).to eq(payin['CreditedWalletId'])
31
+ end
32
+
33
+ it 'fails if not enough money' do
34
+ payin = new_payin_card_web # this payin is NOT processed yet so payout may NOT happen
35
+ payout = create_new_payout_bankwire(payin)
36
+ check_type_and_status(payout, false)
37
+ expect(payout['Status']).to eq('FAILED')
38
+ expect(payout['ResultCode']).to eq('001001')
39
+ expect(payout['ResultMessage']).to eq('Unsufficient wallet balance')
40
+ end
41
+ end
42
+
43
+ describe 'FETCH' do
44
+ it 'fetches a payout' do
45
+ created = new_payout_bankwire
46
+ fetched = MangoPay::PayOut.fetch(created['Id'])
47
+ expect(fetched['Id']).to eq(created['Id'])
48
+ expect(fetched['CreationDate']).to eq(created['CreationDate'])
49
+ check_type_and_status(created)
50
+ check_type_and_status(fetched)
51
+ end
52
+ end
53
+
54
+ end
@@ -1,42 +1,42 @@
1
- describe MangoPay::PreAuthorization do
2
- include_context 'users'
3
- include_context 'payins'
4
-
5
- describe 'CREATE' do
6
- it 'creates a new card pre-authorization' do
7
- cardreg = new_card_registration_completed
8
- created = new_card_preauthorization
9
- expect(created['Id']).not_to be_nil
10
- expect(created['Id'].to_i).to be > 0
11
- expect(created['CardId']).to eq(cardreg['CardId'])
12
- expect(created['AuthorId']).to eq(new_natural_user["Id"])
13
- expect(created['PayInId']).to be_nil
14
- expect(created['Status']).to eq('SUCCEEDED')
15
- expect(created['PaymentStatus']).to eq('WAITING')
16
- expect(created['PaymentType']).to eq('CARD')
17
- expect(created['ExecutionType']).to eq('DIRECT')
18
- end
19
- end
20
-
21
- describe 'UPDATE' do
22
- it 'updates a card pre-authorization' do
23
- created = new_card_preauthorization
24
- updated = MangoPay::PreAuthorization.update(created['Id'] ,{
25
- PaymentStatus: 'CANCELED'
26
- })
27
- expect(updated['PaymentStatus']).to eq('CANCELED')
28
- end
29
- end
30
-
31
- describe 'FETCH' do
32
- it 'fetches a card pre-authorization' do
33
- created = new_card_preauthorization
34
- fetched = MangoPay::PreAuthorization.fetch(created['Id'])
35
- expect(fetched['Id']).to eq(created['Id'])
36
- expect(fetched['CardId']).to eq(created['CardId'])
37
- expect(fetched['AuthorId']).to eq(created['AuthorId'])
38
- expect(fetched['Tag']).to eq(created['Tag'])
39
- end
40
- end
41
-
42
- end
1
+ describe MangoPay::PreAuthorization do
2
+ include_context 'users'
3
+ include_context 'payins'
4
+
5
+ describe 'CREATE' do
6
+ it 'creates a new card pre-authorization' do
7
+ cardreg = new_card_registration_completed
8
+ created = new_card_preauthorization
9
+ expect(created['Id']).not_to be_nil
10
+ expect(created['Id'].to_i).to be > 0
11
+ expect(created['CardId']).to eq(cardreg['CardId'])
12
+ expect(created['AuthorId']).to eq(new_natural_user["Id"])
13
+ expect(created['PayInId']).to be_nil
14
+ expect(created['Status']).to eq('SUCCEEDED')
15
+ expect(created['PaymentStatus']).to eq('WAITING')
16
+ expect(created['PaymentType']).to eq('CARD')
17
+ expect(created['ExecutionType']).to eq('DIRECT')
18
+ end
19
+ end
20
+
21
+ describe 'UPDATE' do
22
+ it 'updates a card pre-authorization' do
23
+ created = new_card_preauthorization
24
+ updated = MangoPay::PreAuthorization.update(created['Id'] ,{
25
+ PaymentStatus: 'CANCELED'
26
+ })
27
+ expect(updated['PaymentStatus']).to eq('CANCELED')
28
+ end
29
+ end
30
+
31
+ describe 'FETCH' do
32
+ it 'fetches a card pre-authorization' do
33
+ created = new_card_preauthorization
34
+ fetched = MangoPay::PreAuthorization.fetch(created['Id'])
35
+ expect(fetched['Id']).to eq(created['Id'])
36
+ expect(fetched['CardId']).to eq(created['CardId'])
37
+ expect(fetched['AuthorId']).to eq(created['AuthorId'])
38
+ expect(fetched['Tag']).to eq(created['Tag'])
39
+ end
40
+ end
41
+
42
+ end
@@ -1,21 +1,21 @@
1
- describe MangoPay::Refund do
2
- include_context 'transfers'
3
-
4
- describe 'FETCH' do
5
- it 'fetches a refund' do
6
- transfer = new_transfer
7
- resource = MangoPay::Transfer.refund(transfer['Id'], { AuthorId: transfer['AuthorId'] })
8
-
9
- refund = MangoPay::Refund.fetch(resource['Id'])
10
-
11
- expect(refund['Id']).not_to be_nil
12
- expect(refund['Status']).to eq('SUCCEEDED')
13
- expect(refund['Type']).to eq('TRANSFER')
14
- expect(refund['Nature']).to eq('REFUND')
15
- expect(refund['InitialTransactionType']).to eq('TRANSFER')
16
- expect(refund['InitialTransactionId']).to eq(transfer['Id'])
17
- expect(refund['DebitedWalletId']).to eq(transfer['CreditedWalletId'])
18
- expect(refund['CreditedWalletId']).to eq(transfer['DebitedWalletId'])
19
- end
20
- end
21
- end
1
+ describe MangoPay::Refund do
2
+ include_context 'transfers'
3
+
4
+ describe 'FETCH' do
5
+ it 'fetches a refund' do
6
+ transfer = new_transfer
7
+ resource = MangoPay::Transfer.refund(transfer['Id'], { AuthorId: transfer['AuthorId'] })
8
+
9
+ refund = MangoPay::Refund.fetch(resource['Id'])
10
+
11
+ expect(refund['Id']).not_to be_nil
12
+ expect(refund['Status']).to eq('SUCCEEDED')
13
+ expect(refund['Type']).to eq('TRANSFER')
14
+ expect(refund['Nature']).to eq('REFUND')
15
+ expect(refund['InitialTransactionType']).to eq('TRANSFER')
16
+ expect(refund['InitialTransactionId']).to eq(transfer['Id'])
17
+ expect(refund['DebitedWalletId']).to eq(transfer['CreditedWalletId'])
18
+ expect(refund['CreditedWalletId']).to eq(transfer['DebitedWalletId'])
19
+ end
20
+ end
21
+ end
@@ -1,39 +1,39 @@
1
- describe MangoPay::Report do
2
-
3
- def create
4
- params = {
5
- Tag: 'custom meta',
6
- CallbackURL: 'http://www.my-site.com/callbackURL/',
7
- DownloadFormat: 'CSV',
8
- Sort: 'CreationDate:DESC',
9
- Preview: false,
10
- Filters: {},
11
- Columns: [ 'Id', 'CreationDate' ]
12
- }
13
- MangoPay::Report.create(params)
14
- end
15
-
16
- describe 'CREATE' do
17
- it 'creates a report' do
18
- created = create
19
- expect(created['Id']).to_not be_nil
20
- end
21
- end
22
-
23
- describe 'FETCH' do
24
-
25
- it 'fetches a report' do
26
- created = create
27
- fetched = MangoPay::Report.fetch(created['Id'])
28
- expect(fetched['Id']).to eq(created['Id'])
29
- end
30
-
31
- it 'fetches all the reports' do
32
- reports = MangoPay::Report.fetch()
33
- expect(reports).to be_kind_of(Array)
34
- expect(reports).not_to be_empty
35
- end
36
-
37
- end
38
-
39
- end
1
+ describe MangoPay::Report do
2
+
3
+ def create
4
+ params = {
5
+ Tag: 'custom meta',
6
+ CallbackURL: 'http://www.my-site.com/callbackURL/',
7
+ DownloadFormat: 'CSV',
8
+ Sort: 'CreationDate:DESC',
9
+ Preview: false,
10
+ Filters: {},
11
+ Columns: [ 'Id', 'CreationDate' ]
12
+ }
13
+ MangoPay::Report.create(params)
14
+ end
15
+
16
+ describe 'CREATE' do
17
+ it 'creates a report' do
18
+ created = create
19
+ expect(created['Id']).to_not be_nil
20
+ end
21
+ end
22
+
23
+ describe 'FETCH' do
24
+
25
+ it 'fetches a report' do
26
+ created = create
27
+ fetched = MangoPay::Report.fetch(created['Id'])
28
+ expect(fetched['Id']).to eq(created['Id'])
29
+ end
30
+
31
+ it 'fetches all the reports' do
32
+ reports = MangoPay::Report.fetch()
33
+ expect(reports).to be_kind_of(Array)
34
+ expect(reports).not_to be_empty
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -1,381 +1,397 @@
1
- ###############################################
2
- shared_context 'users' do
3
- ###############################################
4
-
5
- let(:new_natural_user) { create_new_natural_user }
6
- def define_new_natural_user
7
- {
8
- Tag: 'Test natural user',
9
- Email: 'my@email.com',
10
- FirstName: 'John',
11
- LastName: 'Doe',
12
- Address: {
13
- AddressLine1: 'Le Palais Royal',
14
- AddressLine2: '8 Rue de Montpensier',
15
- City: 'Paris',
16
- Region: '',
17
- PostalCode: '75001',
18
- Country: 'FR'
19
- },
20
- Birthday: 1300186358,
21
- Birthplace: 'Paris',
22
- Nationality: 'FR',
23
- CountryOfResidence: 'FR',
24
- Occupation: 'Worker',
25
- IncomeRange: 1
26
- }
27
- end
28
- def create_new_natural_user
29
- MangoPay::NaturalUser.create(define_new_natural_user)
30
- end
31
-
32
- let(:new_legal_user) {
33
- MangoPay::LegalUser.create({
34
- Name: 'Super',
35
- Email: 'super@email.com',
36
- LegalPersonType: 'BUSINESS',
37
- HeadquartersAddress: {
38
- AddressLine1: '6 Parvis Notre-Dame',
39
- AddressLine2: 'Pl. Jean-Paul II',
40
- City: 'Paris',
41
- Region: '',
42
- PostalCode: '75004',
43
- Country: 'FR'
44
- },
45
- LegalRepresentativeFirstName: 'John',
46
- LegalRepresentativeLastName: 'Doe',
47
- LegalRepresentativeAdress: {
48
- AddressLine1: '38 Rue de Montpensier',
49
- AddressLine2: '',
50
- City: 'Paris',
51
- Region: '',
52
- PostalCode: '75001',
53
- Country: 'FR'
54
- },
55
- LegalRepresentativeEmail: 'john@doe.com',
56
- LegalRepresentativeBirthday: 1300186358,
57
- LegalRepresentativeNationality: 'FR',
58
- LegalRepresentativeCountryOfResidence: 'FR',
59
- Statute: '',
60
- ProofOfRegistration: '',
61
- ShareholderDeclaration: ''
62
- })
63
- }
64
- end
65
-
66
- ###############################################
67
- shared_context 'wallets' do
68
- ###############################################
69
- include_context 'users'
70
-
71
- let(:new_wallet) { create_new_wallet(new_natural_user) }
72
- let(:new_wallet_legal) { create_new_wallet(new_legal_user) }
73
- def create_new_wallet(user)
74
- MangoPay::Wallet.create({
75
- Owners: [user['Id']],
76
- Description: 'A test wallet',
77
- Currency: 'EUR',
78
- Tag: 'Test wallet'
79
- })
80
- end
81
-
82
- def wallets_check_amounts(wlt1, amnt1, wlt2 = nil, amnt2 = nil)
83
- expect(wlt1['Balance']['Amount']).to eq amnt1
84
- expect(wlt2['Balance']['Amount']).to eq amnt2 if wlt2
85
- end
86
-
87
- def wallets_reload_and_check_amounts(wlt1, amnt1, wlt2 = nil, amnt2 = nil)
88
- wlt1 = MangoPay::Wallet::fetch(wlt1['Id'])
89
- wlt2 = MangoPay::Wallet::fetch(wlt2['Id']) if wlt2
90
- wallets_check_amounts(wlt1, amnt1, wlt2, amnt2)
91
- end
92
- end
93
-
94
- ###############################################
95
- shared_context 'bank_accounts' do
96
- ###############################################
97
- include_context 'users'
98
-
99
- let(:new_bank_account) {
100
- MangoPay::BankAccount.create(new_natural_user['Id'], {
101
- Type: 'IBAN',
102
- OwnerName: 'John',
103
- OwnerAddress: {
104
- AddressLine1: 'Le Palais Royal',
105
- AddressLine2: '8 Rue de Montpensier',
106
- City: 'Paris',
107
- Region: '',
108
- PostalCode: '75001',
109
- Country: 'FR'
110
- },
111
- IBAN: 'FR7618829754160173622224154',
112
- BIC: 'CMBRFR2BCME',
113
- Tag: 'Test bank account'
114
- })
115
- }
116
- end
117
-
118
- ###############################################
119
- shared_context 'mandates' do
120
- ###############################################
121
- include_context 'bank_accounts'
122
-
123
- let(:new_mandate) { create_new_mandate() }
124
- def create_new_mandate()
125
- MangoPay::Mandate.create({
126
- BankAccountId: new_bank_account['Id'],
127
- Culture: 'FR',
128
- ReturnURL: MangoPay.configuration.root_url,
129
- Tag: 'Test mandate'
130
- })
131
- end
132
- end
133
-
134
- ###############################################
135
- shared_context 'kyc_documents' do
136
- ###############################################
137
- include_context 'users'
138
-
139
- let(:new_document) { create_new_document(new_natural_user) }
140
- def create_new_document(user)
141
- MangoPay::KycDocument.create(user['Id'], {
142
- Type: 'IDENTITY_PROOF',
143
- Tag: 'Test document'
144
- })
145
- end
146
- end
147
-
148
- ###############################################
149
- shared_context 'payins' do
150
- ###############################################
151
- include_context 'users'
152
- include_context 'wallets'
153
- include_context 'mandates'
154
-
155
- ###############################################
156
- # directdebit/web
157
- ###############################################
158
-
159
- let(:new_payin_directdebit_web) {
160
- MangoPay::PayIn::DirectDebit::Web.create({
161
- AuthorId: new_natural_user['Id'],
162
- CreditedUserId: new_wallet['Owners'][0],
163
- CreditedWalletId: new_wallet['Id'],
164
- DebitedFunds: { Currency: 'EUR', Amount: 1000 },
165
- Fees: { Currency: 'EUR', Amount: 0 },
166
- DirectDebitType: 'GIROPAY',
167
- ReturnURL: MangoPay.configuration.root_url,
168
- Culture: 'FR',
169
- Tag: 'Test PayIn/DirectDebit/Web'
170
- })
171
- }
172
-
173
- ###############################################
174
- # paypal/web
175
- ###############################################
176
-
177
- let(:new_payin_paypal_web) {
178
- MangoPay::PayIn::PayPal::Web.create({
179
- AuthorId: new_natural_user['Id'],
180
- CreditedUserId: new_wallet['Owners'][0],
181
- CreditedWalletId: new_wallet['Id'],
182
- DebitedFunds: { Currency: 'EUR', Amount: 1000 },
183
- Fees: { Currency: 'EUR', Amount: 0 },
184
- ReturnURL: MangoPay.configuration.root_url,
185
- Tag: 'Test PayIn/PayPal/Web'
186
- })
187
- }
188
-
189
- ###############################################
190
- # directdebit/direct
191
- ###############################################
192
-
193
- let(:new_payin_directdebit_direct) {
194
- MangoPay::PayIn::DirectDebit::Direct.create({
195
- AuthorId: new_natural_user['Id'],
196
- CreditedUserId: new_wallet['Owners'][0],
197
- CreditedWalletId: new_wallet['Id'],
198
- DebitedFunds: { Currency: 'EUR', Amount: 1000 },
199
- Fees: { Currency: 'EUR', Amount: 0 },
200
- MandateId: new_mandate['Id'],
201
- ReturnURL: MangoPay.configuration.root_url,
202
- Tag: 'Test PayIn/DirectDebit/Direct'
203
- })
204
- }
205
-
206
- ###############################################
207
- # card/web
208
- ###############################################
209
-
210
- let(:new_payin_card_web) {
211
- MangoPay::PayIn::Card::Web.create({
212
- AuthorId: new_natural_user['Id'],
213
- CreditedUserId: new_wallet['Owners'][0],
214
- CreditedWalletId: new_wallet['Id'],
215
- DebitedFunds: { Currency: 'EUR', Amount: 1000 },
216
- Fees: { Currency: 'EUR', Amount: 0 },
217
- CardType: 'CB_VISA_MASTERCARD',
218
- ReturnURL: MangoPay.configuration.root_url,
219
- Culture: 'FR',
220
- Tag: 'Test PayIn/Card/Web'
221
- })
222
- }
223
-
224
- ###############################################
225
- # card/direct
226
- ###############################################
227
-
228
- let(:new_card_registration) {
229
- MangoPay::CardRegistration.create({
230
- UserId: new_natural_user['Id'],
231
- Currency: 'EUR',
232
- Tag: 'Test Card Registration'
233
- })
234
- }
235
-
236
- let(:new_card_registration_completed) {
237
- # 1st step: create
238
- cardreg = new_card_registration
239
-
240
- # 2nd step: tokenize by payline (fills-in RegistrationData)
241
- data = {
242
- data: cardreg['PreregistrationData'],
243
- accessKeyRef: cardreg['AccessKey'],
244
- cardNumber: 4970100000000154,
245
- cardExpirationDate: 1218,
246
- cardCvx: 123}
247
- res = Net::HTTP.post_form(URI(cardreg['CardRegistrationURL']), data)
248
- raise Exception, [res, res.body] unless (res.is_a?(Net::HTTPOK) && res.body.start_with?('data='))
249
- cardreg['RegistrationData'] = res.body
250
-
251
- # 3rd step: update (fills-in CardId) and return it
252
- MangoPay::CardRegistration.update(cardreg['Id'], {
253
- RegistrationData: cardreg['RegistrationData']
254
- })
255
- }
256
-
257
- let(:new_payin_card_direct) { create_new_payin_card_direct(new_wallet) }
258
- def create_new_payin_card_direct(to_wallet, amnt = 1000)
259
- cardreg = new_card_registration_completed
260
- MangoPay::PayIn::Card::Direct.create({
261
- AuthorId: new_natural_user['Id'],
262
- CreditedUserId: to_wallet['Owners'][0],
263
- CreditedWalletId: to_wallet['Id'],
264
- DebitedFunds: { Currency: 'EUR', Amount: amnt },
265
- Fees: { Currency: 'EUR', Amount: 0 },
266
- CardType: 'CB_VISA_MASTERCARD',
267
- CardId: cardreg['CardId'],
268
- SecureModeReturnURL: 'http://test.com',
269
- Tag: 'Test PayIn/Card/Direct'
270
- })
271
- end
272
-
273
- ###############################################
274
- # card/direct with pre-authorization
275
- ###############################################
276
-
277
- let(:new_card_preauthorization) { create_new_card_preauthorization(new_card_registration_completed) }
278
- def create_new_card_preauthorization(cardreg, amnt = 1000)
279
- MangoPay::PreAuthorization.create({
280
- AuthorId: new_natural_user['Id'],
281
- DebitedFunds: { Currency: 'EUR', Amount: amnt },
282
- CardId: cardreg['CardId'],
283
- SecureMode: 'DEFAULT',
284
- SecureModeReturnURL: 'http://test.com',
285
- Tag: 'Test Card PreAuthorization'
286
- })
287
- end
288
-
289
- let(:new_payin_preauthorized_direct) { create_new_payin_preauthorized_direct(new_wallet) }
290
- def create_new_payin_preauthorized_direct(to_wallet, amnt = 1000)
291
- preauth = new_card_preauthorization
292
- MangoPay::PayIn::PreAuthorized::Direct.create({
293
- AuthorId: new_natural_user['Id'],
294
- CreditedUserId: to_wallet['Owners'][0],
295
- CreditedWalletId: to_wallet['Id'],
296
- DebitedFunds: { Currency: 'EUR', Amount: amnt },
297
- Fees: { Currency: 'EUR', Amount: 0 },
298
- PreauthorizationId: preauth['Id'],
299
- Tag: 'Test PayIn/PreAuthorized/Direct'
300
- })
301
- end
302
-
303
- ###############################################
304
- # bankwire/direct
305
- ###############################################
306
-
307
- let(:new_payin_bankwire_direct) { create_new_payin_bankwire_direct(new_wallet) }
308
- def create_new_payin_bankwire_direct(to_wallet, amnt = 1000)
309
- MangoPay::PayIn::BankWire::Direct.create({
310
- AuthorId: new_natural_user['Id'],
311
- CreditedUserId: to_wallet['Owners'][0],
312
- CreditedWalletId: to_wallet['Id'],
313
- DeclaredDebitedFunds: { Currency: 'EUR', Amount: amnt },
314
- DeclaredFees: { Currency: 'EUR', Amount: 0 },
315
- Tag: 'Test PayIn/BankWire/Direct'
316
- })
317
- end
318
-
319
- end
320
-
321
- ###############################################
322
- shared_context 'payouts' do
323
- ###############################################
324
- include_context 'bank_accounts'
325
-
326
- let(:new_payout_bankwire) { create_new_payout_bankwire(new_payin_card_direct) }
327
- def create_new_payout_bankwire(payin, amnt = 500)
328
- MangoPay::PayOut::BankWire.create({
329
- AuthorId: payin['CreditedUserId'],
330
- DebitedWalletId: payin['CreditedWalletId'],
331
- DebitedFunds: { Currency: 'EUR', Amount: amnt },
332
- Fees: { Currency: 'EUR', Amount: 0 },
333
- BankAccountId: new_bank_account['Id'],
334
- Communication: 'This is a test',
335
- Tag: 'Test PayOut/Bank/Wire'
336
- })
337
- end
338
- end
339
-
340
- ###############################################
341
- shared_context 'transfers' do
342
- ###############################################
343
- include_context 'users'
344
- include_context 'wallets'
345
- include_context 'payins'
346
-
347
- let(:new_transfer) {
348
- wlt1 = new_wallet
349
- wlt2 = new_wallet_legal
350
- create_new_payin_card_direct(wlt1, 1000) # feed wlt1 with money
351
- create_new_transfer(wlt1, wlt2, 500) # transfer wlt1 => wlt2
352
- }
353
- def create_new_transfer(from_wallet, to_wallet, amnt = 500)
354
- MangoPay::Transfer.create({
355
- AuthorId: from_wallet['Owners'][0],
356
- DebitedWalletId: from_wallet['Id'],
357
- CreditedUserId: to_wallet['Owners'][0],
358
- CreditedWalletId: to_wallet['Id'],
359
- DebitedFunds: { Currency: 'EUR', Amount: amnt},
360
- Fees: { Currency: 'EUR', Amount: 0},
361
- Tag: 'Test transfer'
362
- })
363
- end
364
- end
365
-
366
- ###############################################
367
- shared_context 'hooks' do
368
- ###############################################
369
- let(:new_hook) {
370
- hooks = MangoPay::Hook.fetch({'page' => 1, 'per_page' => 1})
371
- if hooks.length == 0
372
- MangoPay::Hook.create({
373
- EventType: 'PAYIN_NORMAL_CREATED',
374
- Url: 'http://test.com',
375
- Tag: 'Test hook'
376
- })
377
- else
378
- hooks[0]
379
- end
380
- }
381
- end
1
+ ###############################################
2
+ shared_context 'users' do
3
+ ###############################################
4
+
5
+ let(:new_natural_user) { create_new_natural_user }
6
+ def define_new_natural_user
7
+ {
8
+ Tag: 'Test natural user',
9
+ Email: 'my@email.com',
10
+ FirstName: 'John',
11
+ LastName: 'Doe',
12
+ Address: {
13
+ AddressLine1: 'Le Palais Royal',
14
+ AddressLine2: '8 Rue de Montpensier',
15
+ City: 'Paris',
16
+ Region: '',
17
+ PostalCode: '75001',
18
+ Country: 'FR'
19
+ },
20
+ Birthday: 1300186358,
21
+ Birthplace: 'Paris',
22
+ Nationality: 'FR',
23
+ CountryOfResidence: 'FR',
24
+ Occupation: 'Worker',
25
+ IncomeRange: 1
26
+ }
27
+ end
28
+ def create_new_natural_user
29
+ MangoPay::NaturalUser.create(define_new_natural_user)
30
+ end
31
+
32
+ let(:new_legal_user) {
33
+ MangoPay::LegalUser.create({
34
+ Name: 'Super',
35
+ Email: 'super@email.com',
36
+ LegalPersonType: 'BUSINESS',
37
+ HeadquartersAddress: {
38
+ AddressLine1: '6 Parvis Notre-Dame',
39
+ AddressLine2: 'Pl. Jean-Paul II',
40
+ City: 'Paris',
41
+ Region: '',
42
+ PostalCode: '75004',
43
+ Country: 'FR'
44
+ },
45
+ LegalRepresentativeFirstName: 'John',
46
+ LegalRepresentativeLastName: 'Doe',
47
+ LegalRepresentativeAdress: {
48
+ AddressLine1: '38 Rue de Montpensier',
49
+ AddressLine2: '',
50
+ City: 'Paris',
51
+ Region: '',
52
+ PostalCode: '75001',
53
+ Country: 'FR'
54
+ },
55
+ LegalRepresentativeEmail: 'john@doe.com',
56
+ LegalRepresentativeBirthday: 1300186358,
57
+ LegalRepresentativeNationality: 'FR',
58
+ LegalRepresentativeCountryOfResidence: 'FR',
59
+ Statute: '',
60
+ ProofOfRegistration: '',
61
+ ShareholderDeclaration: ''
62
+ })
63
+ }
64
+ end
65
+
66
+ ###############################################
67
+ shared_context 'wallets' do
68
+ ###############################################
69
+ include_context 'users'
70
+
71
+ let(:new_wallet) { create_new_wallet(new_natural_user) }
72
+ let(:new_wallet_legal) { create_new_wallet(new_legal_user) }
73
+ def create_new_wallet(user)
74
+ MangoPay::Wallet.create({
75
+ Owners: [user['Id']],
76
+ Description: 'A test wallet',
77
+ Currency: 'EUR',
78
+ Tag: 'Test wallet'
79
+ })
80
+ end
81
+
82
+ def wallets_check_amounts(wlt1, amnt1, wlt2 = nil, amnt2 = nil)
83
+ expect(wlt1['Balance']['Amount']).to eq amnt1
84
+ expect(wlt2['Balance']['Amount']).to eq amnt2 if wlt2
85
+ end
86
+
87
+ def wallets_reload_and_check_amounts(wlt1, amnt1, wlt2 = nil, amnt2 = nil)
88
+ wlt1 = MangoPay::Wallet::fetch(wlt1['Id'])
89
+ wlt2 = MangoPay::Wallet::fetch(wlt2['Id']) if wlt2
90
+ wallets_check_amounts(wlt1, amnt1, wlt2, amnt2)
91
+ end
92
+ end
93
+
94
+ ###############################################
95
+ shared_context 'bank_accounts' do
96
+ ###############################################
97
+ include_context 'users'
98
+
99
+ let(:new_bank_account) {
100
+ MangoPay::BankAccount.create(new_natural_user['Id'], {
101
+ Type: 'IBAN',
102
+ OwnerName: 'John',
103
+ OwnerAddress: {
104
+ AddressLine1: 'Le Palais Royal',
105
+ AddressLine2: '8 Rue de Montpensier',
106
+ City: 'Paris',
107
+ Region: '',
108
+ PostalCode: '75001',
109
+ Country: 'FR'
110
+ },
111
+ IBAN: 'FR7618829754160173622224154',
112
+ BIC: 'CMBRFR2BCME',
113
+ Tag: 'Test bank account'
114
+ })
115
+ }
116
+ end
117
+
118
+ ###############################################
119
+ shared_context 'mandates' do
120
+ ###############################################
121
+ include_context 'bank_accounts'
122
+
123
+ let(:new_mandate) { create_new_mandate() }
124
+ def create_new_mandate()
125
+ MangoPay::Mandate.create({
126
+ BankAccountId: new_bank_account['Id'],
127
+ Culture: 'FR',
128
+ ReturnURL: MangoPay.configuration.root_url,
129
+ Tag: 'Test mandate'
130
+ })
131
+ end
132
+ end
133
+
134
+ ###############################################
135
+ shared_context 'kyc_documents' do
136
+ ###############################################
137
+ include_context 'users'
138
+
139
+ let(:new_document) { create_new_document(new_natural_user) }
140
+ def create_new_document(user)
141
+ MangoPay::KycDocument.create(user['Id'], {
142
+ Type: 'IDENTITY_PROOF',
143
+ Tag: 'Test document'
144
+ })
145
+ end
146
+ end
147
+
148
+ ###############################################
149
+ shared_context 'payins' do
150
+ ###############################################
151
+ include_context 'users'
152
+ include_context 'wallets'
153
+ include_context 'mandates'
154
+
155
+ ###############################################
156
+ # directdebit/web
157
+ ###############################################
158
+
159
+ let(:new_payin_directdebit_web) {
160
+ MangoPay::PayIn::DirectDebit::Web.create({
161
+ AuthorId: new_natural_user['Id'],
162
+ CreditedUserId: new_wallet['Owners'][0],
163
+ CreditedWalletId: new_wallet['Id'],
164
+ DebitedFunds: { Currency: 'EUR', Amount: 1000 },
165
+ Fees: { Currency: 'EUR', Amount: 0 },
166
+ DirectDebitType: 'GIROPAY',
167
+ ReturnURL: MangoPay.configuration.root_url,
168
+ Culture: 'FR',
169
+ Tag: 'Test PayIn/DirectDebit/Web'
170
+ })
171
+ }
172
+
173
+ ###############################################
174
+ # paypal/web
175
+ ###############################################
176
+
177
+ let(:new_payin_paypal_web) {
178
+ MangoPay::PayIn::PayPal::Web.create({
179
+ AuthorId: new_natural_user['Id'],
180
+ CreditedUserId: new_wallet['Owners'][0],
181
+ CreditedWalletId: new_wallet['Id'],
182
+ DebitedFunds: { Currency: 'EUR', Amount: 1000 },
183
+ Fees: { Currency: 'EUR', Amount: 0 },
184
+ ReturnURL: MangoPay.configuration.root_url,
185
+ Tag: 'Test PayIn/PayPal/Web'
186
+ })
187
+ }
188
+
189
+ ###############################################
190
+ # directdebit/direct
191
+ ###############################################
192
+
193
+ let(:new_payin_directdebit_direct) {
194
+ MangoPay::PayIn::DirectDebit::Direct.create({
195
+ AuthorId: new_natural_user['Id'],
196
+ CreditedUserId: new_wallet['Owners'][0],
197
+ CreditedWalletId: new_wallet['Id'],
198
+ DebitedFunds: { Currency: 'EUR', Amount: 1000 },
199
+ Fees: { Currency: 'EUR', Amount: 0 },
200
+ MandateId: new_mandate['Id'],
201
+ ReturnURL: MangoPay.configuration.root_url,
202
+ Tag: 'Test PayIn/DirectDebit/Direct'
203
+ })
204
+ }
205
+
206
+ ###############################################
207
+ # card/web
208
+ ###############################################
209
+
210
+ let(:new_payin_card_web) {
211
+ MangoPay::PayIn::Card::Web.create({
212
+ AuthorId: new_natural_user['Id'],
213
+ CreditedUserId: new_wallet['Owners'][0],
214
+ CreditedWalletId: new_wallet['Id'],
215
+ DebitedFunds: { Currency: 'EUR', Amount: 1000 },
216
+ Fees: { Currency: 'EUR', Amount: 0 },
217
+ CardType: 'CB_VISA_MASTERCARD',
218
+ ReturnURL: MangoPay.configuration.root_url,
219
+ Culture: 'FR',
220
+ Tag: 'Test PayIn/Card/Web'
221
+ })
222
+ }
223
+
224
+ ###############################################
225
+ # card/direct
226
+ ###############################################
227
+
228
+ let(:new_card_registration) {
229
+ MangoPay::CardRegistration.create({
230
+ UserId: new_natural_user['Id'],
231
+ Currency: 'EUR',
232
+ Tag: 'Test Card Registration'
233
+ })
234
+ }
235
+
236
+ let(:new_card_registration_completed) {
237
+ # 1st step: create
238
+ cardreg = new_card_registration
239
+
240
+ # 2nd step: tokenize by payline (fills-in RegistrationData)
241
+ data = {
242
+ data: cardreg['PreregistrationData'],
243
+ accessKeyRef: cardreg['AccessKey'],
244
+ cardNumber: 4970100000000154,
245
+ cardExpirationDate: 1218,
246
+ cardCvx: 123}
247
+ res = Net::HTTP.post_form(URI(cardreg['CardRegistrationURL']), data)
248
+ raise Exception, [res, res.body] unless (res.is_a?(Net::HTTPOK) && res.body.start_with?('data='))
249
+ cardreg['RegistrationData'] = res.body
250
+
251
+ # 3rd step: update (fills-in CardId) and return it
252
+ MangoPay::CardRegistration.update(cardreg['Id'], {
253
+ RegistrationData: cardreg['RegistrationData']
254
+ })
255
+ }
256
+
257
+ let(:new_payin_card_direct) { create_new_payin_card_direct(new_wallet) }
258
+ def create_new_payin_card_direct(to_wallet, amnt = 1000)
259
+ cardreg = new_card_registration_completed
260
+ MangoPay::PayIn::Card::Direct.create({
261
+ AuthorId: new_natural_user['Id'],
262
+ CreditedUserId: to_wallet['Owners'][0],
263
+ CreditedWalletId: to_wallet['Id'],
264
+ DebitedFunds: { Currency: 'EUR', Amount: amnt },
265
+ Fees: { Currency: 'EUR', Amount: 0 },
266
+ CardType: 'CB_VISA_MASTERCARD',
267
+ CardId: cardreg['CardId'],
268
+ SecureModeReturnURL: 'http://test.com',
269
+ Tag: 'Test PayIn/Card/Direct'
270
+ })
271
+ end
272
+
273
+ ###############################################
274
+ # card/direct with pre-authorization
275
+ ###############################################
276
+
277
+ let(:new_card_preauthorization) { create_new_card_preauthorization(new_card_registration_completed) }
278
+ def create_new_card_preauthorization(cardreg, amnt = 1000)
279
+ MangoPay::PreAuthorization.create({
280
+ AuthorId: new_natural_user['Id'],
281
+ DebitedFunds: { Currency: 'EUR', Amount: amnt },
282
+ CardId: cardreg['CardId'],
283
+ SecureMode: 'DEFAULT',
284
+ SecureModeReturnURL: 'http://test.com',
285
+ Tag: 'Test Card PreAuthorization'
286
+ })
287
+ end
288
+
289
+ let(:new_payin_preauthorized_direct) { create_new_payin_preauthorized_direct(new_wallet) }
290
+ def create_new_payin_preauthorized_direct(to_wallet, amnt = 1000)
291
+ preauth = new_card_preauthorization
292
+ MangoPay::PayIn::PreAuthorized::Direct.create({
293
+ AuthorId: new_natural_user['Id'],
294
+ CreditedUserId: to_wallet['Owners'][0],
295
+ CreditedWalletId: to_wallet['Id'],
296
+ DebitedFunds: { Currency: 'EUR', Amount: amnt },
297
+ Fees: { Currency: 'EUR', Amount: 0 },
298
+ PreauthorizationId: preauth['Id'],
299
+ Tag: 'Test PayIn/PreAuthorized/Direct'
300
+ })
301
+ end
302
+
303
+ ###############################################
304
+ # bankwire/direct
305
+ ###############################################
306
+
307
+ let(:new_payin_bankwire_direct) { create_new_payin_bankwire_direct(new_wallet) }
308
+ def create_new_payin_bankwire_direct(to_wallet, amnt = 1000)
309
+ MangoPay::PayIn::BankWire::Direct.create({
310
+ AuthorId: new_natural_user['Id'],
311
+ CreditedUserId: to_wallet['Owners'][0],
312
+ CreditedWalletId: to_wallet['Id'],
313
+ DeclaredDebitedFunds: { Currency: 'EUR', Amount: amnt },
314
+ DeclaredFees: { Currency: 'EUR', Amount: 0 },
315
+ Tag: 'Test PayIn/BankWire/Direct'
316
+ })
317
+ end
318
+
319
+ end
320
+
321
+ ###############################################
322
+ shared_context 'payouts' do
323
+ ###############################################
324
+ include_context 'bank_accounts'
325
+
326
+ let(:new_payout_bankwire) { create_new_payout_bankwire(new_payin_card_direct) }
327
+ def create_new_payout_bankwire(payin, amnt = 500)
328
+ MangoPay::PayOut::BankWire.create({
329
+ AuthorId: payin['CreditedUserId'],
330
+ DebitedWalletId: payin['CreditedWalletId'],
331
+ DebitedFunds: { Currency: 'EUR', Amount: amnt },
332
+ Fees: { Currency: 'EUR', Amount: 0 },
333
+ BankAccountId: new_bank_account['Id'],
334
+ Communication: 'This is a test',
335
+ Tag: 'Test PayOut/Bank/Wire'
336
+ })
337
+ end
338
+ end
339
+
340
+ ###############################################
341
+ shared_context 'transfers' do
342
+ ###############################################
343
+ include_context 'users'
344
+ include_context 'wallets'
345
+ include_context 'payins'
346
+
347
+ let(:new_transfer) {
348
+ wlt1 = new_wallet
349
+ wlt2 = new_wallet_legal
350
+ create_new_payin_card_direct(wlt1, 1000) # feed wlt1 with money
351
+ create_new_transfer(wlt1, wlt2, 500) # transfer wlt1 => wlt2
352
+ }
353
+ def create_new_transfer(from_wallet, to_wallet, amnt = 500)
354
+ MangoPay::Transfer.create({
355
+ AuthorId: from_wallet['Owners'][0],
356
+ DebitedWalletId: from_wallet['Id'],
357
+ CreditedUserId: to_wallet['Owners'][0],
358
+ CreditedWalletId: to_wallet['Id'],
359
+ DebitedFunds: { Currency: 'EUR', Amount: amnt},
360
+ Fees: { Currency: 'EUR', Amount: 0},
361
+ Tag: 'Test transfer'
362
+ })
363
+ end
364
+ end
365
+
366
+ ###############################################
367
+ shared_context 'hooks' do
368
+ ###############################################
369
+ let(:new_hook) {
370
+ hooks = MangoPay::Hook.fetch({'page' => 1, 'per_page' => 1})
371
+ if hooks.length == 0
372
+ MangoPay::Hook.create({
373
+ EventType: 'PAYIN_NORMAL_CREATED',
374
+ Url: 'http://test.com',
375
+ Tag: 'Test hook'
376
+ })
377
+ else
378
+ hooks[0]
379
+ end
380
+ }
381
+ end
382
+
383
+ ###############################################
384
+ shared_context 'bankigaliases' do
385
+ ###############################################
386
+ include_context 'users'
387
+ include_context 'wallets'
388
+
389
+ let(:new_banking_alias) {
390
+ MangoPay::BankingAliasesIBAN.create({
391
+ CreditedUserId: new_natural_user['Id'],
392
+ WalletId: new_wallet['Id'],
393
+ OwnerName: new_natural_user['FirstName'],
394
+ Country: 'LU'
395
+ }, new_wallet['Id'])
396
+ }
397
+ end