mangopay 3.0.30 → 3.0.34

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +6 -1
  3. data/CHANGELOG.md +35 -0
  4. data/README.md +5 -5
  5. data/lib/generators/mangopay/install_generator.rb +1 -1
  6. data/lib/generators/templates/mangopay.rb.erb +1 -1
  7. data/lib/mangopay.rb +19 -9
  8. data/lib/mangopay/authorization_token.rb +2 -2
  9. data/lib/mangopay/bank_account.rb +11 -0
  10. data/lib/mangopay/card.rb +15 -0
  11. data/lib/mangopay/filter_parameters.rb +6 -1
  12. data/lib/mangopay/http_calls.rb +7 -7
  13. data/lib/mangopay/legal_user.rb +0 -8
  14. data/lib/mangopay/mandate.rb +10 -0
  15. data/lib/mangopay/pay_in.rb +31 -0
  16. data/lib/mangopay/pay_out.rb +11 -0
  17. data/lib/mangopay/refund.rb +11 -0
  18. data/lib/mangopay/transfer.rb +11 -0
  19. data/lib/mangopay/ubo.rb +26 -0
  20. data/lib/mangopay/ubo_declaration.rb +22 -11
  21. data/lib/mangopay/user.rb +24 -6
  22. data/lib/mangopay/version.rb +1 -1
  23. data/spec/mangopay/bank_account_spec.rb +8 -0
  24. data/spec/mangopay/card_registration_spec.rb +7 -0
  25. data/spec/mangopay/client_spec.rb +17 -6
  26. data/spec/mangopay/configuration_spec.rb +53 -1
  27. data/spec/mangopay/event_spec.rb +12 -10
  28. data/spec/mangopay/mandate_spec.rb +7 -0
  29. data/spec/mangopay/payin_applepay_direct_spec.rb +20 -0
  30. data/spec/mangopay/payin_bankwire_external_instruction_spec.rb +43 -4
  31. data/spec/mangopay/payin_card_web_spec.rb +17 -0
  32. data/spec/mangopay/payin_paypal_web_spec.rb +13 -1
  33. data/spec/mangopay/payout_bankwire_spec.rb +8 -0
  34. data/spec/mangopay/preauthorization_spec.rb +9 -0
  35. data/spec/mangopay/refund_spec.rb +13 -0
  36. data/spec/mangopay/shared_resources.rb +346 -240
  37. data/spec/mangopay/transfer_spec.rb +8 -0
  38. data/spec/mangopay/ubo_declaration_spec.rb +13 -17
  39. data/spec/mangopay/ubo_spec.rb +39 -0
  40. data/spec/mangopay/user_spec.rb +51 -16
  41. data/spec/spec_helper.rb +1 -1
  42. metadata +9 -3
@@ -51,4 +51,12 @@ describe MangoPay::PayOut::BankWire, type: :feature do
51
51
  end
52
52
  end
53
53
 
54
+ describe 'GET Refunds' do
55
+ it "fetches the pay-out's refunds" do
56
+ payout = new_payout_bankwire
57
+ refunds = MangoPay::PayOut.refunds(payout['Id'])
58
+ expect(refunds).to be_an(Array)
59
+ end
60
+ end
61
+
54
62
  end
@@ -39,4 +39,13 @@ describe MangoPay::PreAuthorization do
39
39
  end
40
40
  end
41
41
 
42
+ describe 'FETCH FOR CARD' do
43
+ it "fetches a card's pre-authorizations" do
44
+ created = new_card_preauthorization
45
+ fetched = MangoPay::Card.get_pre_authorizations(created['CardId'])
46
+
47
+ expect(fetched).to be_an(Array)
48
+ end
49
+ end
50
+
42
51
  end
@@ -18,4 +18,17 @@ describe MangoPay::Refund do
18
18
  expect(refund['CreditedWalletId']).to eq(transfer['DebitedWalletId'])
19
19
  end
20
20
  end
21
+
22
+ #describe 'FETCH for Repudiation' do
23
+ # it "fetches a repudiation's refunds" do
24
+ # disputes = MangoPay::Dispute.fetch
25
+ # dispute = disputes.find do |dispute|
26
+ # dispute['DisputeType'] == 'NOT_CONTESTABLE'\
27
+ # && !dispute['InitialTransactionId'].nil?
28
+ # end
29
+ # repudiation_id = MangoPay::Dispute.transactions(dispute['Id'])[0]['Id']
30
+ # refunds = MangoPay::Refund.of_repudiation(repudiation_id)
31
+ # expect(refunds).to be_an(Array)
32
+ # end
33
+ # end
21
34
  end
@@ -1,82 +1,86 @@
1
1
  ###############################################
2
2
  shared_context 'users' do
3
- ###############################################
3
+ ###############################################
4
4
 
5
5
  let(:new_natural_user) { create_new_natural_user }
6
+
6
7
  def define_new_natural_user
7
8
  {
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
9
+ Tag: 'Test natural user',
10
+ Email: 'my@email.com',
11
+ FirstName: 'John',
12
+ LastName: 'Doe',
13
+ Address: {
14
+ AddressLine1: 'Le Palais Royal',
15
+ AddressLine2: '8 Rue de Montpensier',
16
+ City: 'Paris',
17
+ Region: '',
18
+ PostalCode: '75001',
19
+ Country: 'FR'
20
+ },
21
+ Birthday: 1_300_186_358,
22
+ Birthplace: 'Paris',
23
+ Nationality: 'FR',
24
+ CountryOfResidence: 'FR',
25
+ Occupation: 'Worker',
26
+ IncomeRange: 1
26
27
  }
27
28
  end
29
+
28
30
  def create_new_natural_user
29
31
  MangoPay::NaturalUser.create(define_new_natural_user)
30
32
  end
31
33
 
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
- }
34
+ let(:new_legal_user) do
35
+ MangoPay::LegalUser.create(
36
+ Name: 'Super',
37
+ Email: 'super@email.com',
38
+ LegalPersonType: 'BUSINESS',
39
+ HeadquartersAddress: {
40
+ AddressLine1: '6 Parvis Notre-Dame',
41
+ AddressLine2: 'Pl. Jean-Paul II',
42
+ City: 'Paris',
43
+ Region: 'FR',
44
+ PostalCode: '75004',
45
+ Country: 'FR'
46
+ },
47
+ LegalRepresentativeFirstName: 'John',
48
+ LegalRepresentativeLastName: 'Doe',
49
+ LegalRepresentativeAdress: {
50
+ AddressLine1: '38 Rue de Montpensier',
51
+ AddressLine2: '',
52
+ City: 'Paris',
53
+ Region: '',
54
+ PostalCode: '75001',
55
+ Country: 'FR'
56
+ },
57
+ LegalRepresentativeEmail: 'john@doe.com',
58
+ LegalRepresentativeBirthday: 1_300_186_358,
59
+ LegalRepresentativeNationality: 'FR',
60
+ LegalRepresentativeCountryOfResidence: 'FR',
61
+ CompanyNumber: 'LU123456789',
62
+ Statute: '',
63
+ ProofOfRegistration: '',
64
+ ShareholderDeclaration: ''
65
+ )
66
+ end
64
67
  end
65
68
 
66
69
  ###############################################
67
70
  shared_context 'wallets' do
68
- ###############################################
71
+ ###############################################
69
72
  include_context 'users'
70
73
 
71
74
  let(:new_wallet) { create_new_wallet(new_natural_user) }
72
75
  let(:new_wallet_legal) { create_new_wallet(new_legal_user) }
76
+
73
77
  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
- })
78
+ MangoPay::Wallet.create(
79
+ Owners: [user['Id']],
80
+ Description: 'A test wallet',
81
+ Currency: 'EUR',
82
+ Tag: 'Test wallet'
83
+ )
80
84
  end
81
85
 
82
86
  def wallets_check_amounts(wlt1, amnt1, wlt2 = nil, amnt2 = nil)
@@ -85,69 +89,93 @@ shared_context 'wallets' do
85
89
  end
86
90
 
87
91
  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
92
+ wlt1 = MangoPay::Wallet.fetch(wlt1['Id'])
93
+ wlt2 = MangoPay::Wallet.fetch(wlt2['Id']) if wlt2
90
94
  wallets_check_amounts(wlt1, amnt1, wlt2, amnt2)
91
95
  end
92
96
  end
93
97
 
98
+ shared_context 'ubo' do
99
+ def new_ubo(user, ubo_declaration)
100
+ ubo = {
101
+ FirstName: 'John',
102
+ LastName: 'Doe',
103
+ Address: {
104
+ AddressLine1: '6 Parvis Notre-Dame',
105
+ AddressLine2: 'Pl. Jean-Paul II',
106
+ City: 'Paris',
107
+ Region: '',
108
+ PostalCode: '75004',
109
+ Country: 'FR'
110
+ },
111
+ Nationality: 'FR',
112
+ Birthday: 1_300_186_358,
113
+ Birthplace: {
114
+ City: 'Paris',
115
+ Country: 'FR'
116
+ }
117
+ }
118
+ MangoPay::Ubo.create(user['Id'], ubo_declaration['Id'], ubo)
119
+ end
120
+ end
121
+
94
122
  ###############################################
95
123
  shared_context 'bank_accounts' do
96
- ###############################################
124
+ ###############################################
97
125
  include_context 'users'
98
126
 
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
- }
127
+ let(:new_bank_account) do
128
+ MangoPay::BankAccount.create(new_natural_user['Id'],
129
+ Type: 'IBAN',
130
+ OwnerName: 'John',
131
+ OwnerAddress: {
132
+ AddressLine1: 'Le Palais Royal',
133
+ AddressLine2: '8 Rue de Montpensier',
134
+ City: 'Paris',
135
+ Region: '',
136
+ PostalCode: '75001',
137
+ Country: 'FR'
138
+ },
139
+ IBAN: 'FR7618829754160173622224154',
140
+ BIC: 'CMBRFR2BCME',
141
+ Tag: 'Test bank account')
142
+ end
116
143
  end
117
144
 
118
145
  ###############################################
119
146
  shared_context 'mandates' do
120
- ###############################################
147
+ ###############################################
121
148
  include_context 'bank_accounts'
122
149
 
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
- })
150
+ let(:new_mandate) { create_new_mandate }
151
+
152
+ def create_new_mandate
153
+ MangoPay::Mandate.create(
154
+ BankAccountId: new_bank_account['Id'],
155
+ Culture: 'FR',
156
+ ReturnURL: MangoPay.configuration.root_url,
157
+ Tag: 'Test mandate'
158
+ )
131
159
  end
132
160
  end
133
161
 
134
162
  ###############################################
135
163
  shared_context 'kyc_documents' do
136
- ###############################################
164
+ ###############################################
137
165
  include_context 'users'
138
166
 
139
167
  let(:new_document) { create_new_document(new_natural_user) }
168
+
140
169
  def create_new_document(user)
141
- MangoPay::KycDocument.create(user['Id'], {
142
- Type: 'IDENTITY_PROOF',
143
- Tag: 'Test document'
144
- })
170
+ MangoPay::KycDocument.create(user['Id'],
171
+ Type: 'IDENTITY_PROOF',
172
+ Tag: 'Test document')
145
173
  end
146
174
  end
147
175
 
148
176
  ###############################################
149
177
  shared_context 'payins' do
150
- ###############################################
178
+ ###############################################
151
179
  include_context 'users'
152
180
  include_context 'wallets'
153
181
  include_context 'mandates'
@@ -156,118 +184,192 @@ shared_context 'payins' do
156
184
  # directdebit/web
157
185
  ###############################################
158
186
 
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
- }
187
+ let(:new_payin_directdebit_web) do
188
+ MangoPay::PayIn::DirectDebit::Web.create(
189
+ AuthorId: new_natural_user['Id'],
190
+ CreditedUserId: new_wallet['Owners'][0],
191
+ CreditedWalletId: new_wallet['Id'],
192
+ DebitedFunds: {Currency: 'EUR', Amount: 1000},
193
+ Fees: {Currency: 'EUR', Amount: 0},
194
+ DirectDebitType: 'GIROPAY',
195
+ ReturnURL: MangoPay.configuration.root_url,
196
+ Culture: 'FR',
197
+ Tag: 'Test PayIn/DirectDebit/Web'
198
+ )
199
+ end
172
200
 
173
201
  ###############################################
174
202
  # paypal/web
175
203
  ###############################################
176
204
 
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
- ###############################################
205
+ let(:new_payin_paypal_web) do
206
+ MangoPay::PayIn::PayPal::Web.create(
207
+ AuthorId: new_natural_user['Id'],
208
+ CreditedUserId: new_wallet['Owners'][0],
209
+ CreditedWalletId: new_wallet['Id'],
210
+ DebitedFunds: {Currency: 'EUR', Amount: 1000},
211
+ Fees: {Currency: 'EUR', Amount: 0},
212
+ ReturnURL: MangoPay.configuration.root_url,
213
+ Culture: "FR",
214
+ Tag: 'Test PayIn/PayPal/Web'
215
+ )
216
+ end
217
+
218
+ ###############################################
219
+ # applepay/direct
220
+ ###############################################
221
+
222
+ let(:new_payin_applepay_direct) do
223
+ MangoPay::PayIn::ApplePay::Direct.create(
224
+ AuthorId: new_natural_user['Id'],
225
+ CreditedUserId: new_wallet['Owners'][0],
226
+ CreditedWalletId: new_wallet['Id'],
227
+ DebitedFunds: {Currency: 'EUR', Amount: 199},
228
+ Fees: {Currency: 'EUR', Amount: 1},
229
+ PaymentType: 'APPLEPAY',
230
+ PaymentData: {
231
+ TransactionId: '061EB32181A2D9CA42AD16031B476EEBAA62A9A095AD660E2759FBA52B51A61',
232
+ Network: 'VISA',
233
+ TokenData: "{\"version\":\"EC_v1\",\"data\":\"w4HMBVqNC9ghPP4zncTA\\/0oQAsduERfsx78oxgniynNjZLANTL6+0koEtkQnW\\/K38Zew8qV1GLp+fLHo+qCBpiKCIwlz3eoFBTbZU+8pYcjaeIYBX9SOxcwxXsNGrGLk+kBUqnpiSIPaAG1E+WPT8R1kjOCnGvtdombvricwRTQkGjtovPfzZo8LzD3ZQJnHMsWJ8QYDLyr\\/ZN9gtLAtsBAMvwManwiaG3pOIWpyeOQOb01YcEVO16EZBjaY4x4C\\/oyFLWDuKGvhbJwZqWh1d1o9JT29QVmvy3Oq2JEjq3c3NutYut4rwDEP4owqI40Nb7mP2ebmdNgnYyWfPmkRfDCRHIWtbMC35IPg5313B1dgXZ2BmyZRXD5p+mr67vAk7iFfjEpu3GieFqwZrTl3\\/pI5V8Sxe3SIYKgT5Hr7ow==\",\"signature\":\"MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCAMIID5jCCA4ugAwIBAgIIaGD2mdnMpw8wCgYIKoZIzj0EAwIwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3Jp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WZ+Y1UENj53pwv4CMDIt1UQhsKMFd2xd8zg7kGf9F3wsIW2WT8ZyaYISb1T4en0bmcubCYkhYQaZDwmSHQAAMYIBizCCAYcCAQEwgYYwejEuMCwGA1UEAwwlQXBwbGUgQXBwbGljYXRpb24gSW50ZWdyYXRpb24gQ0EgLSBHMzEmMCQGA1UECwwdQXBwbGUgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkxEzARBgNVBAoMCkFwcGxlIEluYy4xCzAJBgNVBAYTAlVTAghoYPaZ2cynDzANBglghkgBZQMEAgEFAKCBlTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3DQEJBTEPFw0xOTA1MjMxMTA1MDdaMCoGCSqGSIb3DQEJNDEdMBswDQYJYIZIAWUDBAIBBQChCgYIKoZIzj0EAwIwLwYJKoZIhvcNAQkEMSIEIIvfGVQYBeOilcB7GNI8m8+FBVZ28QfA6BIXaggBja2PMAoGCCqGSM49BAMCBEYwRAIgU01yYfjlx9bvGeC5CU2RS5KBEG+15HH9tz\\/sg3qmQ14CID4F4ZJwAz+tXAUcAIzoMpYSnM8YBlnGJSTSp+LhspenAAAAAAAA\",\"header\":{\"ephemeralPublicKey\":\"MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE0rs3wRpirXjPbFDQfPRdfEzRIZDWm0qn7Y0HB0PNzV1DDKfpYrnhRb4GEhBF\\/oEXBOe452PxbCnN1qAlqcSUWw==\",\"publicKeyHash\":\"saPRAqS7TZ4bAYwzBj8ezDDC55ZolyH1FL+Xc8fd93o=\",\"transactionId\":\"b061eb32181a2d9ca42ad16031b476eebaa62a9a095ad660e2759fba52b51a61\"}}"
234
+ },
235
+ StatementDescriptor: "php",
236
+ ReturnURL: MangoPay.configuration.root_url,
237
+ Tag: 'Test PayIn/ApplePay/Direct'
238
+ )
239
+ end
240
+
241
+ ###############################################
242
+ # CANNOT BE TESTED AS WE CAN'T MOCK TOKEN GENERATION
243
+ # googlepay/direct
244
+ ###############################################
245
+ let(:new_payin_googlepay_direct) do
246
+ MangoPay::PayIn::GooglePay::Direct.create(
247
+ AuthorId: new_natural_user['Id'],
248
+ CreditedUserId: new_wallet['Owners'][0],
249
+ CreditedWalletId: new_wallet['Id'],
250
+ DebitedFunds: {Currency: 'EUR', Amount: 199},
251
+ Fees: {Currency: 'EUR', Amount: 1},
252
+ PaymentData: {
253
+ TransactionId: '061EB32181A2D9CA42AD16031B476EEBAA62A9A095AD660E2759FBA52B51A61',
254
+ Network: 'VISA',
255
+ TokenData: "tokenData"
256
+ },
257
+ StatementDescriptor: "ruby",
258
+ ReturnURL: MangoPay.configuration.root_url,
259
+ Tag: 'Test PayIn/GooglePay/Direct',
260
+ Billing: {
261
+ Address: {
262
+ AddressLine1: 'AddressLine1',
263
+ AddressLine2: 'AddressLine2',
264
+ City: 'City',
265
+ Region: 'Region',
266
+ PostalCode: 'PostalCode',
267
+ CountryIso: 'FR'
268
+ }
269
+ }
270
+ )
271
+ end
272
+
273
+
274
+ ###############################################
190
275
  # directdebit/direct
191
276
  ###############################################
192
277
 
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
-
278
+ let(:new_payin_directdebit_direct) do
279
+ MangoPay::PayIn::DirectDebit::Direct.create(
280
+ AuthorId: new_natural_user['Id'],
281
+ CreditedUserId: new_wallet['Owners'][0],
282
+ CreditedWalletId: new_wallet['Id'],
283
+ DebitedFunds: {Currency: 'EUR', Amount: 1000},
284
+ Fees: {Currency: 'EUR', Amount: 0},
285
+ MandateId: new_mandate['Id'],
286
+ ReturnURL: MangoPay.configuration.root_url,
287
+ Tag: 'Test PayIn/DirectDebit/Direct'
288
+ )
289
+ end
290
+
206
291
  ###############################################
207
292
  # card/web
208
293
  ###############################################
209
294
 
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
- }
295
+ let(:new_payin_card_web) do
296
+ MangoPay::PayIn::Card::Web.create(
297
+ AuthorId: new_natural_user['Id'],
298
+ CreditedUserId: new_wallet['Owners'][0],
299
+ CreditedWalletId: new_wallet['Id'],
300
+ DebitedFunds: {Currency: 'EUR', Amount: 1000},
301
+ Fees: {Currency: 'EUR', Amount: 0},
302
+ CardType: 'CB_VISA_MASTERCARD',
303
+ ReturnURL: MangoPay.configuration.root_url,
304
+ Culture: 'FR',
305
+ Tag: 'Test PayIn/Card/Web'
306
+ )
307
+ end
308
+
309
+ let(:new_payin_card_web_payline) do
310
+ MangoPay::PayIn::Card::Web.create(
311
+ AuthorId: new_natural_user['Id'],
312
+ CreditedUserId: new_wallet['Owners'][0],
313
+ CreditedWalletId: new_wallet['Id'],
314
+ DebitedFunds: {Currency: 'EUR', Amount: 1000},
315
+ Fees: {Currency: 'EUR', Amount: 0},
316
+ CardType: 'CB_VISA_MASTERCARD',
317
+ ReturnURL: MangoPay.configuration.root_url,
318
+ Culture: 'FR',
319
+ Tag: 'Test PayIn/Card/Web',
320
+ TemplateURLOptions: {PAYLINEV2: "https://www.maysite.com/payline_template/"}
321
+ )
322
+ end
223
323
 
224
324
  ###############################################
225
325
  # card/direct
226
326
  ###############################################
227
327
 
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
- }
328
+ let(:new_card_registration) do
329
+ MangoPay::CardRegistration.create(
330
+ UserId: new_natural_user['Id'],
331
+ Currency: 'EUR',
332
+ Tag: 'Test Card Registration'
333
+ )
334
+ end
235
335
 
236
- let(:new_card_registration_completed) {
336
+ let(:new_card_registration_completed) do
237
337
  # 1st step: create
238
338
  cardreg = new_card_registration
239
339
 
240
340
  # 2nd step: tokenize by payline (fills-in RegistrationData)
241
341
  data = {
242
- data: cardreg['PreregistrationData'],
243
- accessKeyRef: cardreg['AccessKey'],
244
- cardNumber: 4970100000000154,
245
- cardExpirationDate: 1218,
246
- cardCvx: 123}
342
+ data: cardreg['PreregistrationData'],
343
+ accessKeyRef: cardreg['AccessKey'],
344
+ cardNumber: 4970100000000154,
345
+ cardExpirationDate: 1226,
346
+ cardCvx: 123}
347
+
247
348
  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='))
349
+ raise Exception, [res, res.body] unless res.is_a?(Net::HTTPOK) && res.body.start_with?('data=')
350
+
249
351
  cardreg['RegistrationData'] = res.body
250
352
 
251
353
  # 3rd step: update (fills-in CardId) and return it
252
- MangoPay::CardRegistration.update(cardreg['Id'], {
253
- RegistrationData: cardreg['RegistrationData']
254
- })
255
- }
354
+ MangoPay::CardRegistration.update(cardreg['Id'],
355
+ RegistrationData: cardreg['RegistrationData'])
356
+ end
256
357
 
257
358
  let(:new_payin_card_direct) { create_new_payin_card_direct(new_wallet) }
359
+
258
360
  def create_new_payin_card_direct(to_wallet, amnt = 1000)
259
361
  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
- })
362
+ MangoPay::PayIn::Card::Direct.create(
363
+ AuthorId: new_natural_user['Id'],
364
+ CreditedUserId: to_wallet['Owners'][0],
365
+ CreditedWalletId: to_wallet['Id'],
366
+ DebitedFunds: {Currency: 'EUR', Amount: amnt},
367
+ Fees: {Currency: 'EUR', Amount: 0},
368
+ CardType: 'CB_VISA_MASTERCARD',
369
+ CardId: cardreg['CardId'],
370
+ SecureModeReturnURL: 'http://test.com',
371
+ Tag: 'Test PayIn/Card/Direct'
372
+ )
271
373
  end
272
374
 
273
375
  ###############################################
@@ -275,29 +377,31 @@ shared_context 'payins' do
275
377
  ###############################################
276
378
 
277
379
  let(:new_card_preauthorization) { create_new_card_preauthorization(new_card_registration_completed) }
380
+
278
381
  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
- })
382
+ MangoPay::PreAuthorization.create(
383
+ AuthorId: new_natural_user['Id'],
384
+ DebitedFunds: {Currency: 'EUR', Amount: amnt},
385
+ CardId: cardreg['CardId'],
386
+ SecureMode: 'DEFAULT',
387
+ SecureModeReturnURL: 'http://test.com',
388
+ Tag: 'Test Card PreAuthorization'
389
+ )
287
390
  end
288
391
 
289
392
  let(:new_payin_preauthorized_direct) { create_new_payin_preauthorized_direct(new_wallet) }
393
+
290
394
  def create_new_payin_preauthorized_direct(to_wallet, amnt = 1000)
291
395
  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
- })
396
+ MangoPay::PayIn::PreAuthorized::Direct.create(
397
+ AuthorId: new_natural_user['Id'],
398
+ CreditedUserId: to_wallet['Owners'][0],
399
+ CreditedWalletId: to_wallet['Id'],
400
+ DebitedFunds: {Currency: 'EUR', Amount: amnt},
401
+ Fees: {Currency: 'EUR', Amount: 0},
402
+ PreauthorizationId: preauth['Id'],
403
+ Tag: 'Test PayIn/PreAuthorized/Direct'
404
+ )
301
405
  end
302
406
 
303
407
  ###############################################
@@ -305,93 +409,95 @@ shared_context 'payins' do
305
409
  ###############################################
306
410
 
307
411
  let(:new_payin_bankwire_direct) { create_new_payin_bankwire_direct(new_wallet) }
412
+
308
413
  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
- })
414
+ MangoPay::PayIn::BankWire::Direct.create(
415
+ AuthorId: new_natural_user['Id'],
416
+ CreditedUserId: to_wallet['Owners'][0],
417
+ CreditedWalletId: to_wallet['Id'],
418
+ DeclaredDebitedFunds: {Currency: 'EUR', Amount: amnt},
419
+ DeclaredFees: {Currency: 'EUR', Amount: 0},
420
+ Tag: 'Test PayIn/BankWire/Direct'
421
+ )
317
422
  end
318
-
319
423
  end
320
424
 
321
425
  ###############################################
322
426
  shared_context 'payouts' do
323
- ###############################################
427
+ ###############################################
324
428
  include_context 'bank_accounts'
325
429
 
326
430
  let(:new_payout_bankwire) { create_new_payout_bankwire(new_payin_card_direct) }
431
+
327
432
  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
- })
433
+ MangoPay::PayOut::BankWire.create(
434
+ AuthorId: payin['CreditedUserId'],
435
+ DebitedWalletId: payin['CreditedWalletId'],
436
+ DebitedFunds: {Currency: 'EUR', Amount: amnt},
437
+ Fees: {Currency: 'EUR', Amount: 0},
438
+ BankAccountId: new_bank_account['Id'],
439
+ Communication: 'This is a test',
440
+ Tag: 'Test PayOut/Bank/Wire'
441
+ )
337
442
  end
338
443
  end
339
444
 
340
445
  ###############################################
341
446
  shared_context 'transfers' do
342
- ###############################################
447
+ ###############################################
343
448
  include_context 'users'
344
449
  include_context 'wallets'
345
450
  include_context 'payins'
346
451
 
347
- let(:new_transfer) {
452
+ let(:new_transfer) do
348
453
  wlt1 = new_wallet
349
454
  wlt2 = new_wallet_legal
350
455
  create_new_payin_card_direct(wlt1, 1000) # feed wlt1 with money
351
456
  create_new_transfer(wlt1, wlt2, 500) # transfer wlt1 => wlt2
352
- }
457
+ end
458
+
353
459
  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
- })
460
+ MangoPay::Transfer.create(
461
+ AuthorId: from_wallet['Owners'][0],
462
+ DebitedWalletId: from_wallet['Id'],
463
+ CreditedUserId: to_wallet['Owners'][0],
464
+ CreditedWalletId: to_wallet['Id'],
465
+ DebitedFunds: {Currency: 'EUR', Amount: amnt},
466
+ Fees: {Currency: 'EUR', Amount: 0},
467
+ Tag: 'Test transfer'
468
+ )
363
469
  end
364
470
  end
365
471
 
366
472
  ###############################################
367
473
  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
- })
474
+ ###############################################
475
+ let(:new_hook) do
476
+ hooks = MangoPay::Hook.fetch('page' => 1, 'per_page' => 1)
477
+ if hooks.empty?
478
+ MangoPay::Hook.create(
479
+ EventType: 'PAYIN_NORMAL_CREATED',
480
+ Url: 'http://test.com',
481
+ Tag: 'Test hook'
482
+ )
377
483
  else
378
484
  hooks[0]
379
485
  end
380
- }
486
+ end
381
487
  end
382
488
 
383
489
  ###############################################
384
490
  shared_context 'bankigaliases' do
385
- ###############################################
491
+ ###############################################
386
492
  include_context 'users'
387
493
  include_context 'wallets'
388
494
 
389
- let(:new_banking_alias) {
495
+ let(:new_banking_alias) do
390
496
  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
- }
497
+ CreditedUserId: new_natural_user['Id'],
498
+ WalletId: new_wallet['Id'],
499
+ OwnerName: new_natural_user['FirstName'],
500
+ Country: 'LU'
501
+ }, new_wallet['Id'])
502
+ end
397
503
  end