mangopay 3.0.11 → 3.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/README.md +26 -0
  4. data/lib/mangopay.rb +97 -105
  5. data/lib/mangopay/bank_account.rb +4 -4
  6. data/lib/mangopay/card.rb +2 -2
  7. data/lib/mangopay/card_registration.rb +3 -3
  8. data/lib/mangopay/client.rb +1 -1
  9. data/lib/mangopay/errors.rb +35 -1
  10. data/lib/mangopay/event.rb +16 -16
  11. data/lib/mangopay/hook.rb +3 -3
  12. data/lib/mangopay/http_calls.rb +1 -1
  13. data/lib/mangopay/json.rb +6 -15
  14. data/lib/mangopay/kyc_document.rb +3 -3
  15. data/lib/mangopay/legal_user.rb +2 -2
  16. data/lib/mangopay/natural_user.rb +2 -2
  17. data/lib/mangopay/pay_in.rb +47 -0
  18. data/lib/mangopay/pay_out.rb +13 -0
  19. data/lib/mangopay/pre_authorization.rb +11 -0
  20. data/lib/mangopay/refund.rb +1 -1
  21. data/lib/mangopay/resource.rb +3 -3
  22. data/lib/mangopay/transaction.rb +1 -1
  23. data/lib/mangopay/transfer.rb +3 -3
  24. data/lib/mangopay/user.rb +3 -3
  25. data/lib/mangopay/version.rb +1 -1
  26. data/lib/mangopay/wallet.rb +5 -5
  27. data/mangopay.gemspec +3 -6
  28. data/spec/{lib/mangopay → mangopay}/authorization_token_spec.rb +70 -72
  29. data/spec/{lib/mangopay → mangopay}/bank_account_spec.rb +0 -2
  30. data/spec/{lib/mangopay → mangopay}/card_registration_spec.rb +0 -2
  31. data/spec/{lib/mangopay → mangopay}/client_spec.rb +2 -4
  32. data/spec/{lib/mangopay → mangopay}/configuration_spec.rb +18 -20
  33. data/spec/{lib/mangopay → mangopay}/event_spec.rb +31 -33
  34. data/spec/{lib/mangopay → mangopay}/fetch_filters_spec.rb +0 -2
  35. data/spec/{lib/mangopay → mangopay}/hook_spec.rb +0 -2
  36. data/spec/{lib/mangopay → mangopay}/kyc_document_spec.rb +58 -60
  37. data/spec/{lib/mangopay → mangopay}/payin_bankwire_direct_spec.rb +0 -2
  38. data/spec/{lib/mangopay → mangopay}/payin_card_direct_spec.rb +0 -2
  39. data/spec/{lib/mangopay → mangopay}/payin_card_web_spec.rb +54 -56
  40. data/spec/{lib/mangopay → mangopay}/payin_preauthorized_direct_spec.rb +0 -2
  41. data/spec/{lib/mangopay → mangopay}/payout_bankwire_spec.rb +54 -56
  42. data/spec/{lib/mangopay → mangopay}/preauthorization_spec.rb +0 -2
  43. data/spec/{lib/mangopay → mangopay}/refund_spec.rb +0 -2
  44. data/spec/{lib/mangopay → mangopay}/shared_resources.rb +0 -4
  45. data/spec/{lib/mangopay → mangopay}/transaction_spec.rb +0 -2
  46. data/spec/{lib/mangopay → mangopay}/transfer_spec.rb +0 -2
  47. data/spec/{lib/mangopay → mangopay}/user_spec.rb +0 -2
  48. data/spec/{lib/mangopay → mangopay}/wallet_spec.rb +87 -89
  49. data/spec/spec_helper.rb +28 -20
  50. metadata +53 -95
  51. data/lib/mangopay/payin.rb +0 -47
  52. data/lib/mangopay/payout.rb +0 -13
  53. data/lib/mangopay/preauthorization.rb +0 -11
@@ -1,5 +1,3 @@
1
- require_relative '../../spec_helper'
2
-
3
1
  describe MangoPay::Client do
4
2
  include_context 'clients'
5
3
 
@@ -12,8 +10,8 @@ describe MangoPay::Client do
12
10
 
13
11
  it 'refuses the client id' do
14
12
  expect { wrong_client['errors'] }.to raise_error { |err|
15
- err.should be_a MangoPay::ResponseError
16
- err.type.should eq 'param_error'
13
+ expect(err).to be_a MangoPay::ResponseError
14
+ expect(err.type).to eq 'param_error'
17
15
  }
18
16
  end
19
17
 
@@ -1,20 +1,18 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe MangoPay::Configuration do
4
-
5
- it 'fails when calling with wrong client credentials' do
6
- expect {
7
- c = MangoPay.configuration
8
- c.client_id = 'test_asd'
9
- c.client_passphrase = '00000'
10
- MangoPay::User.fetch()
11
- }.to raise_error(MangoPay::ResponseError)
12
- end
13
-
14
- it 'goes ok when calling with correct client credentials' do
15
- reset_mangopay_configuration
16
- users = MangoPay::User.fetch()
17
- expect(users).to be_kind_of(Array)
18
- end
19
-
20
- 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
+ end
@@ -1,33 +1,31 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe MangoPay::Event do
4
-
5
- include_context 'payins'
6
- include_context 'payouts'
7
-
8
- describe 'FETCH' do
9
-
10
- it 'accepts filtering params' do
11
-
12
- # let's have at least 2 events
13
- payin = new_payin_card_direct
14
- payout = create_new_payout_bankwire(payin)
15
-
16
- # get all
17
- events = MangoPay::Event.fetch()
18
- expect(events).to be_kind_of(Array)
19
- expect(events.count).to be >= 2
20
-
21
- # only one per page
22
- events = MangoPay::Event.fetch({'per_page' => 1})
23
- expect(events).to be_kind_of(Array)
24
- expect(events.count).to eq 1
25
-
26
- # filter by date
27
- events = MangoPay::Event.fetch({'AfterDate' => payin['CreationDate'], 'BeforeDate' => payin['CreationDate']})
28
- expect(events).to be_kind_of(Array)
29
- expect(events.count).to be >= 1
30
- expect(events.count {|e| e['ResourceId'] == payin['Id']}).to be >= 1
31
- end
32
- end
33
- end
1
+ describe MangoPay::Event do
2
+
3
+ include_context 'payins'
4
+ include_context 'payouts'
5
+
6
+ describe 'FETCH' do
7
+
8
+ it 'accepts filtering params' do
9
+
10
+ # let's have at least 2 events
11
+ payin = new_payin_card_direct
12
+ create_new_payout_bankwire(payin)
13
+
14
+ # get all
15
+ events = MangoPay::Event.fetch()
16
+ expect(events).to be_kind_of(Array)
17
+ expect(events.count).to be >= 2
18
+
19
+ # only one per page
20
+ events = MangoPay::Event.fetch({'per_page' => 1})
21
+ expect(events).to be_kind_of(Array)
22
+ expect(events.count).to eq 1
23
+
24
+ # filter by date
25
+ events = MangoPay::Event.fetch({'AfterDate' => payin['CreationDate'], 'BeforeDate' => payin['CreationDate']})
26
+ expect(events).to be_kind_of(Array)
27
+ expect(events.count).to be >= 1
28
+ expect(events.count { |e| e['ResourceId'] == payin['Id'] }).to be >= 1
29
+ end
30
+ end
31
+ end
@@ -1,5 +1,3 @@
1
- require_relative '../../spec_helper'
2
-
3
1
  describe 'FETCH WITH FILTERS' do
4
2
  include_context 'users'
5
3
  include_context 'bank_accounts'
@@ -1,5 +1,3 @@
1
- require_relative '../../spec_helper'
2
-
3
1
  describe MangoPay::Hook do
4
2
  include_context 'hooks'
5
3
 
@@ -1,60 +1,58 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe MangoPay::KycDocument do
4
- include_context 'kyc_documents'
5
-
6
- describe 'CREATE' do
7
- it 'creates a document' do
8
- expect(new_document['Id']).to_not be_nil
9
- expect(new_document['Type']).to eq('IDENTITY_PROOF')
10
- expect(new_document['Status']).to eq('CREATED')
11
- expect(new_document['RefusedReasonType']).to be_nil
12
- expect(new_document['RefusedReasonMessage']).to be_nil
13
- end
14
- end
15
-
16
- describe 'UPDATE' do
17
- it 'updates a document' do
18
- updated_document = MangoPay::KycDocument.update(new_natural_user['Id'], new_document['Id'], {
19
- Status: 'VALIDATION_ASKED'
20
- })
21
- expect(updated_document['Id']).to eq(new_document['Id'])
22
- expect(updated_document['Status']).to eq('VALIDATION_ASKED')
23
- end
24
- end
25
-
26
- describe 'FETCH' do
27
- it 'fetches a document' do
28
- document = MangoPay::KycDocument.fetch(new_natural_user['Id'], new_document['Id'])
29
- expect(document['Id']).to eq(new_document['Id'])
30
- end
31
- end
32
-
33
- describe 'CREATE PAGE' do
34
-
35
- def create_page(file)
36
- MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], file)
37
- end
38
-
39
- it 'accepts File instance' do
40
- file = File.open(__FILE__)
41
- ret = create_page(file)
42
- expect(ret).to be_nil
43
- end
44
-
45
- it 'accepts base64-encoded string' do
46
- file = Base64.encode64('any file content...')
47
- ret = create_page(file)
48
- expect(ret).to be_nil
49
- end
50
-
51
- it 'fails when input string is not base64-encoded' do
52
- file = 'any file content...'
53
- expect { create_page(file) }.to raise_error { |err|
54
- err.should be_a MangoPay::ResponseError
55
- err.code.should eq '400'
56
- err.type.should eq 'param_error'
57
- }
58
- end
59
- end
60
- end
1
+ describe MangoPay::KycDocument do
2
+ include_context 'kyc_documents'
3
+
4
+ describe 'CREATE' do
5
+ it 'creates a document' do
6
+ expect(new_document['Id']).to_not be_nil
7
+ expect(new_document['Type']).to eq('IDENTITY_PROOF')
8
+ expect(new_document['Status']).to eq('CREATED')
9
+ expect(new_document['RefusedReasonType']).to be_nil
10
+ expect(new_document['RefusedReasonMessage']).to be_nil
11
+ end
12
+ end
13
+
14
+ describe 'UPDATE' do
15
+ it 'updates a document' do
16
+ updated_document = MangoPay::KycDocument.update(new_natural_user['Id'], new_document['Id'], {
17
+ Status: 'VALIDATION_ASKED'
18
+ })
19
+ expect(updated_document['Id']).to eq(new_document['Id'])
20
+ expect(updated_document['Status']).to eq('VALIDATION_ASKED')
21
+ end
22
+ end
23
+
24
+ describe 'FETCH' do
25
+ it 'fetches a document' do
26
+ document = MangoPay::KycDocument.fetch(new_natural_user['Id'], new_document['Id'])
27
+ expect(document['Id']).to eq(new_document['Id'])
28
+ end
29
+ end
30
+
31
+ describe 'CREATE PAGE' do
32
+
33
+ def create_page(file)
34
+ MangoPay::KycDocument.create_page(new_natural_user['Id'], new_document['Id'], file)
35
+ end
36
+
37
+ it 'accepts File instance' do
38
+ file = File.open(__FILE__)
39
+ ret = create_page(file)
40
+ expect(ret).to be_nil
41
+ end
42
+
43
+ it 'accepts base64-encoded string' do
44
+ file = Base64.encode64('any file content...')
45
+ ret = create_page(file)
46
+ expect(ret).to be_nil
47
+ end
48
+
49
+ it 'fails when input string is not base64-encoded' do
50
+ file = 'any file content...'
51
+ expect { create_page(file) }.to raise_error { |err|
52
+ expect(err).to be_a MangoPay::ResponseError
53
+ expect(err.code).to eq '400'
54
+ expect(err.type).to eq 'param_error'
55
+ }
56
+ end
57
+ end
58
+ end
@@ -1,5 +1,3 @@
1
- require_relative '../../spec_helper'
2
-
3
1
  describe MangoPay::PayIn::BankWire::Direct, type: :feature do
4
2
  include_context 'wallets'
5
3
  include_context 'payins'
@@ -1,5 +1,3 @@
1
- require_relative '../../spec_helper'
2
-
3
1
  describe MangoPay::PayIn::Card::Direct, type: :feature do
4
2
  include_context 'wallets'
5
3
  include_context 'payins'
@@ -1,56 +1,54 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe MangoPay::PayIn::Card::Web, type: :feature do
4
- include_context 'payins'
5
-
6
- def check_type_and_status(payin)
7
- expect(payin['Type']).to eq('PAYIN')
8
- expect(payin['Nature']).to eq('REGULAR')
9
- expect(payin['PaymentType']).to eq('CARD')
10
- expect(payin['ExecutionType']).to eq('WEB')
11
-
12
- # not SUCCEEDED yet: waiting for processing
13
- expect(payin['Status']).to eq('CREATED')
14
- expect(payin['ResultCode']).to be_nil
15
- expect(payin['ResultMessage']).to be_nil
16
- expect(payin['ExecutionDate']).to be_nil
17
- end
18
-
19
- describe 'CREATE' do
20
- it 'creates a card web payin' do
21
- created = new_payin_card_web
22
- expect(created['Id']).not_to be_nil
23
- check_type_and_status(created)
24
- end
25
- end
26
-
27
- describe 'FETCH' do
28
- it 'fetches a payin' do
29
- created = new_payin_card_web
30
- fetched = MangoPay::PayIn.fetch(created['Id'])
31
- expect(fetched['Id']).to eq(created['Id'])
32
- expect(fetched['CreationDate']).to eq(created['CreationDate'])
33
- expect(fetched['CreditedFunds']).to eq(created['CreditedFunds'])
34
- expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId'])
35
- check_type_and_status(created)
36
- check_type_and_status(fetched)
37
- end
38
- end
39
-
40
- describe 'REFUND' do
41
- it 'refunds a payin' do
42
- payin = new_payin_card_web
43
- refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
44
- expect(refund['Id']).not_to be_nil
45
- expect(refund['Type']).to eq('PAYOUT')
46
- expect(refund['Nature']).to eq('REFUND')
47
- expect(refund['InitialTransactionType']).to eq('PAYIN')
48
- expect(refund['InitialTransactionId']).to eq(payin['Id'])
49
- expect(refund['DebitedWalletId']).to eq(payin['CreditedWalletId'])
50
- expect(refund['Status']).to eq('FAILED')
51
- expect(refund['ResultCode']).to eq('001001')
52
- expect(refund['ResultMessage']).to eq('Unsufficient wallet balance')
53
- end
54
- end
55
-
56
- end
1
+ describe MangoPay::PayIn::Card::Web, type: :feature do
2
+ include_context 'payins'
3
+
4
+ def check_type_and_status(payin)
5
+ expect(payin['Type']).to eq('PAYIN')
6
+ expect(payin['Nature']).to eq('REGULAR')
7
+ expect(payin['PaymentType']).to eq('CARD')
8
+ expect(payin['ExecutionType']).to eq('WEB')
9
+
10
+ # not SUCCEEDED yet: waiting for processing
11
+ expect(payin['Status']).to eq('CREATED')
12
+ expect(payin['ResultCode']).to be_nil
13
+ expect(payin['ResultMessage']).to be_nil
14
+ expect(payin['ExecutionDate']).to be_nil
15
+ end
16
+
17
+ describe 'CREATE' do
18
+ it 'creates a card web payin' do
19
+ created = new_payin_card_web
20
+ expect(created['Id']).not_to be_nil
21
+ check_type_and_status(created)
22
+ end
23
+ end
24
+
25
+ describe 'FETCH' do
26
+ it 'fetches a payin' do
27
+ created = new_payin_card_web
28
+ fetched = MangoPay::PayIn.fetch(created['Id'])
29
+ expect(fetched['Id']).to eq(created['Id'])
30
+ expect(fetched['CreationDate']).to eq(created['CreationDate'])
31
+ expect(fetched['CreditedFunds']).to eq(created['CreditedFunds'])
32
+ expect(fetched['CreditedWalletId']).to eq(created['CreditedWalletId'])
33
+ check_type_and_status(created)
34
+ check_type_and_status(fetched)
35
+ end
36
+ end
37
+
38
+ describe 'REFUND' do
39
+ it 'refunds a payin' do
40
+ payin = new_payin_card_web
41
+ refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
42
+ expect(refund['Id']).not_to be_nil
43
+ expect(refund['Type']).to eq('PAYOUT')
44
+ expect(refund['Nature']).to eq('REFUND')
45
+ expect(refund['InitialTransactionType']).to eq('PAYIN')
46
+ expect(refund['InitialTransactionId']).to eq(payin['Id'])
47
+ expect(refund['DebitedWalletId']).to eq(payin['CreditedWalletId'])
48
+ expect(refund['Status']).to eq('FAILED')
49
+ expect(refund['ResultCode']).to eq('001001')
50
+ expect(refund['ResultMessage']).to eq('Unsufficient wallet balance')
51
+ end
52
+ end
53
+
54
+ end
@@ -1,5 +1,3 @@
1
- require_relative '../../spec_helper'
2
-
3
1
  describe MangoPay::PayIn::PreAuthorized::Direct, type: :feature do
4
2
  include_context 'wallets'
5
3
  include_context 'payins'
@@ -1,56 +1,54 @@
1
- require_relative '../../spec_helper'
2
-
3
- describe MangoPay::PayOut::BankWire, type: :feature do
4
- include_context 'bank_accounts'
5
- include_context 'payins'
6
- include_context 'payouts'
7
-
8
- def check_type_and_status(payout, check_status = true)
9
- expect(payout['Type']).to eq('PAYOUT')
10
- expect(payout['Nature']).to eq('REGULAR')
11
- expect(payout['PaymentType']).to eq('BANK_WIRE')
12
- expect(payout['ExecutionDate']).to be_nil
13
-
14
- # linked to correct bank account
15
- expect(payout['BankAccountId']).to eq(new_bank_account['Id'])
16
-
17
- if (check_status)
18
- # not SUCCEEDED yet: waiting for processing
19
- expect(payout['Status']).to eq('CREATED')
20
- expect(payout['ResultCode']).to be_nil
21
- expect(payout['ResultMessage']).to be_nil
22
- end
23
- end
24
-
25
- describe 'CREATE' do
26
-
27
- it 'creates a bank wire payout' do
28
- payin = new_payin_card_direct # this payin is successfull so payout may happen
29
- payout = create_new_payout_bankwire(payin)
30
- expect(payout['Id']).not_to be_nil
31
- check_type_and_status(payout)
32
- expect(payout['DebitedWalletId']).to eq(payin['CreditedWalletId'])
33
- end
34
-
35
- it 'fails if not enough money' do
36
- payin = new_payin_card_web # this payin is NOT processed yet so payout may NOT happen
37
- payout = create_new_payout_bankwire(payin)
38
- check_type_and_status(payout, false)
39
- expect(payout['Status']).to eq('FAILED')
40
- expect(payout['ResultCode']).to eq('001001')
41
- expect(payout['ResultMessage']).to eq('Unsufficient wallet balance')
42
- end
43
- end
44
-
45
- describe 'FETCH' do
46
- it 'fetches a payout' do
47
- created = new_payout_bankwire
48
- fetched = MangoPay::PayOut.fetch(created['Id'])
49
- expect(fetched['Id']).to eq(created['Id'])
50
- expect(fetched['CreationDate']).to eq(created['CreationDate'])
51
- check_type_and_status(created)
52
- check_type_and_status(fetched)
53
- end
54
- end
55
-
56
- 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
+ expect(payout['ExecutionDate']).to be_nil
11
+
12
+ # linked to correct bank account
13
+ expect(payout['BankAccountId']).to eq(new_bank_account['Id'])
14
+
15
+ if (check_status)
16
+ # not SUCCEEDED yet: waiting for processing
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