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
@@ -1,19 +1,30 @@
1
1
  module MangoPay
2
-
3
2
  # Provides API methods for the UBO declaration entity.
4
3
  class UboDeclaration < Resource
5
- include HTTPCalls::Fetch
6
-
7
4
  class << self
8
-
9
- def update(id = nil, params = {})
10
- declared_ubo_ids = []
11
- params['DeclaredUBOs'].each do |ubo|
12
- declared_ubo_ids << (ubo.key?('UserId') ? ubo['UserId'] : ubo)
5
+ def url(user_id, id = nil)
6
+ if id
7
+ "#{MangoPay.api_path}/users/#{user_id}/kyc/ubodeclarations/#{id}"
8
+ else
9
+ "#{MangoPay.api_path}/users/#{user_id}/kyc/ubodeclarations"
13
10
  end
14
- params['DeclaredUBOs'] = declared_ubo_ids
15
- MangoPay.request(:put, url(id), params)
11
+ end
12
+
13
+ def create(user_id)
14
+ MangoPay.request(:post, url(user_id))
15
+ end
16
+
17
+ def fetch(user_id, id)
18
+ MangoPay.request(:get, url(user_id, id))
19
+ end
20
+
21
+ def update(user_id, id, params = {})
22
+ request_params = {
23
+ Status: params['Status'],
24
+ Ubos: params['Ubos']
25
+ }
26
+ MangoPay.request(:put, url(user_id, id), request_params)
16
27
  end
17
28
  end
18
29
  end
19
- end
30
+ end
@@ -12,7 +12,7 @@ module MangoPay
12
12
  # Fetches list of wallets belonging to the given +user_id+.
13
13
  # Optional +filters+ is a hash accepting following keys:
14
14
  # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
15
- def wallets(user_id, filters={})
15
+ def wallets(user_id, filters = {})
16
16
  MangoPay.request(:get, url(user_id) + '/wallets', {}, filters)
17
17
  end
18
18
 
@@ -20,14 +20,14 @@ module MangoPay
20
20
  # Optional +filters+ is a hash accepting following keys:
21
21
  # - +page+, +per_page+, +sort+: pagination and sorting params
22
22
  # (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
23
- def bank_accounts(user_id, filters={})
23
+ def bank_accounts(user_id, filters = {})
24
24
  MangoPay.request(:get, url(user_id) + '/bankaccounts', {}, filters)
25
25
  end
26
26
 
27
27
  # Fetches list of cards belonging to the given +user_id+.
28
28
  # Optional +filters+ is a hash accepting following keys:
29
29
  # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
30
- def cards(user_id, filters={})
30
+ def cards(user_id, filters = {})
31
31
  MangoPay.request(:get, url(user_id) + '/cards', {}, filters)
32
32
  end
33
33
 
@@ -35,7 +35,7 @@ module MangoPay
35
35
  # Optional +filters+ is a hash accepting following keys:
36
36
  # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
37
37
  # - other keys specific for transactions filtering (see MangoPay::Transaction#fetch)
38
- def transactions(user_id, filters={})
38
+ def transactions(user_id, filters = {})
39
39
  MangoPay.request(:get, url(user_id) + '/transactions', {}, filters)
40
40
  end
41
41
 
@@ -43,8 +43,26 @@ module MangoPay
43
43
  # Optional +filters+ is a hash accepting following keys:
44
44
  # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
45
45
  # - other keys specific for transactions filtering (see MangoPay::Transaction#fetch)
46
- def emoney(user_id, filters={})
47
- MangoPay.request(:get, url(user_id) + '/emoney', {}, filters)
46
+ def emoney(user_id, year, month = nil, filters = {})
47
+ if month
48
+ MangoPay.request(:get, url(user_id) + "/emoney/#{year}/#{month}", {}, filters)
49
+ else
50
+ MangoPay.request(:get, url(user_id) + "/emoney/#{year}", {}, filters)
51
+ end
52
+ end
53
+
54
+ # Fetches list of kyc documents belonging to the given +user_id+.
55
+ # Optional +filters+ is a hash accepting following keys:
56
+ # - +page+, +per_page+, +sort+, +BeforeDate+, +AfterDate+, +Status+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
57
+ def kyc_documents(user_id, filters = {})
58
+ MangoPay.request(:get, url(user_id) + '/KYC/documents', {}, filters)
59
+ end
60
+
61
+ # Fetches list of pre-authorizations belonging to the given +user_id+.
62
+ # Optional +filters+ is a hash accepting the following keys:
63
+ # - +page+, +per_page+, +sort+, +Status+, +ResultCode+, +PaymentStatus+: pagination and sorting/filtering params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
64
+ def pre_authorizations(user_id, filters = {})
65
+ MangoPay.request(:get, url(user_id) + '/preauthorizations', {}, filters)
48
66
  end
49
67
  end
50
68
  end
@@ -1,3 +1,3 @@
1
1
  module MangoPay
2
- VERSION = '3.0.30'
2
+ VERSION = '3.0.34'
3
3
  end
@@ -94,4 +94,12 @@ describe MangoPay::BankAccount do
94
94
  expect(fetched['Active']).to eq(false)
95
95
  end
96
96
  end
97
+
98
+ describe 'FETCH Transaction' do
99
+ it "fetches a bank account's transactions" do
100
+ bank_account = new_bank_account
101
+ transactions = MangoPay::BankAccount.transactions(bank_account['Id'])
102
+ expect(transactions).to be_an(Array)
103
+ end
104
+ end
97
105
  end
@@ -85,4 +85,11 @@ describe MangoPay::CardRegistration do
85
85
  end
86
86
  end
87
87
 
88
+ describe 'FETCH Transactions' do
89
+ it "retrieves list of card's transactions" do
90
+ card_id = new_card_registration_completed['CardId']
91
+ transactions = MangoPay::Card.transactions(card_id)
92
+ expect(transactions).to be_an(Array)
93
+ end
94
+ end
88
95
  end
@@ -7,6 +7,13 @@ describe MangoPay::Client do
7
7
  end
8
8
  end
9
9
 
10
+ describe 'FETCH' do
11
+ it "fetches the client headquarter's phone number" do
12
+ client = MangoPay::Client.fetch
13
+ expect(client['HeadquartersPhoneNumber']).to_not be_nil
14
+ end
15
+ end
16
+
10
17
  describe 'UPDATE' do
11
18
  it 'updates the current client details' do
12
19
  clnt = MangoPay::Client.fetch
@@ -14,22 +21,26 @@ describe MangoPay::Client do
14
21
  after = before == '#aaaaaa' ? '#bbbbbb' : '#aaaaaa' # change the color
15
22
  clnt['PrimaryThemeColour'] = after
16
23
  clnt['HeadquartersAddress'] = {
17
- AddressLine1: 'Rue Dandelion, n. 17',
18
- City: 'Lyon',
19
- Country: 'FR',
20
- PostalCode: '150770'
24
+ AddressLine1: 'Rue Dandelion, n. 17',
25
+ City: 'Lyon',
26
+ Country: 'FR',
27
+ PostalCode: '150770'
21
28
  }
29
+ clnt['TechEmails'] = ['support@mangopay.com']
30
+ phoneNumber = rand(99999999).to_s
31
+ clnt['HeadquartersPhoneNumber'] = phoneNumber
22
32
 
23
33
  updated = MangoPay::Client.update(clnt)
24
34
  expect(updated['ClientId']).to eq(MangoPay.configuration.client_id)
25
35
  expect(updated['PrimaryThemeColour']).to eq(after)
36
+ expect(updated['HeadquartersPhoneNumber']).to eq(phoneNumber)
26
37
  end
27
38
  end
28
39
 
29
40
  describe 'UPLOAD LOGO' do
30
41
  it 'accepts Base64 encoded file content' do
31
42
  fnm = __FILE__.sub('.rb', '.png')
32
- bts = File.open(fnm, 'rb') { |f| f.read }
43
+ bts = File.open(fnm, 'rb') {|f| f.read}
33
44
  b64 = Base64.encode64(bts)
34
45
  ret = MangoPay::Client.upload_logo(b64)
35
46
  expect(ret).to be_nil
@@ -43,7 +54,7 @@ describe MangoPay::Client do
43
54
 
44
55
  it 'fails when input string is not base64-encoded' do
45
56
  file = 'any file content...'
46
- expect { MangoPay::Client.upload_logo(file) }.to raise_error { |err|
57
+ expect {MangoPay::Client.upload_logo(file)}.to raise_error {|err|
47
58
  expect(err).to be_a MangoPay::ResponseError
48
59
  expect(err.code).to eq '400'
49
60
  expect(err.type).to eq 'param_error'
@@ -4,7 +4,7 @@ describe MangoPay::Configuration do
4
4
  expect {
5
5
  c = MangoPay.configuration
6
6
  c.client_id = 'test_asd'
7
- c.client_passphrase = '00000'
7
+ c.client_apiKey = '00000'
8
8
  MangoPay::User.fetch()
9
9
  }.to raise_error(MangoPay::ResponseError)
10
10
  end
@@ -15,6 +15,58 @@ describe MangoPay::Configuration do
15
15
  expect(users).to be_kind_of(Array)
16
16
  end
17
17
 
18
+ describe 'logger' do
19
+ around(:each) do |example|
20
+ c = MangoPay.configuration
21
+ c.logger = logger
22
+ c.log_file = log_file
23
+ example.run
24
+ c.logger = nil
25
+ c.log_file = nil
26
+ MangoPay.instance_variable_set(:@logger, nil)
27
+ end
28
+
29
+ context 'when the logger is set' do
30
+ let(:logger) { Logger.new(STDOUT) }
31
+
32
+ context 'when the log_file is set' do
33
+ let(:log_file) { File.join(MangoPay.configuration.temp_dir, 'mangopay.log.tmp') }
34
+
35
+ it 'initializes the logger using the logger option' do
36
+ expect(MangoPay.send(:logger).instance_variable_get(:@logdev).dev).to(eq(STDOUT))
37
+ end
38
+ end
39
+
40
+ context 'when the log_file is not set' do
41
+ let(:log_file) { nil }
42
+
43
+ it 'initializes the logger using the logger option' do
44
+ expect(MangoPay.send(:logger).instance_variable_get(:@logdev).dev).to(eq(STDOUT))
45
+ end
46
+ end
47
+ end
48
+
49
+ context 'when the logger is not set' do
50
+ let(:logger) { nil }
51
+
52
+ context 'when the log_file is set' do
53
+ let(:log_file) { File.join(MangoPay.configuration.temp_dir, 'mangopay.log.tmp') }
54
+
55
+ it 'initializes the logger using the log file' do
56
+ expect(MangoPay.send(:logger).instance_variable_get(:@logdev).dev).to(be_an_instance_of(File))
57
+ end
58
+ end
59
+
60
+ context 'when the log_file is not set' do
61
+ let(:log_file) { nil }
62
+
63
+ it 'raises an error' do
64
+ expect{ MangoPay.send(:logger) }.to raise_error NotImplementedError
65
+ end
66
+ end
67
+ end
68
+ end
69
+
18
70
  context 'with multithreading' do
19
71
  after :all do
20
72
  reset_mangopay_configuration
@@ -11,21 +11,23 @@ describe MangoPay::Event do
11
11
  payin = new_payin_card_direct
12
12
  create_new_payout_bankwire(payin)
13
13
 
14
- # get all # TODO: Uncomment this test once Events are fixed on the server
15
- # events = MangoPay::Event.fetch()
16
- # expect(events).to be_kind_of(Array)
17
- # expect(events.count).to be >= 2
14
+ # get all #
15
+ events = MangoPay::Event.fetch
16
+ expect(events).to be_kind_of(Array)
17
+ expect(events.count).to be >= 2
18
18
 
19
- # only one per page # TODO: Uncomment this test once Events are fixed on the server
20
- # events = MangoPay::Event.fetch({'per_page' => 1})
21
- # expect(events).to be_kind_of(Array)
22
- # expect(events.count).to eq 1
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
23
 
24
24
  # filter by date
25
- events = MangoPay::Event.fetch({'AfterDate' => payin['CreationDate'], 'BeforeDate' => payin['CreationDate']})
25
+ eventDate = events[0]["Date"]
26
+ resourceId=events[0]["ResourceId"]
27
+ events = MangoPay::Event.fetch({'AfterDate' => eventDate - 1, 'BeforeDate' => eventDate + 1})
26
28
  expect(events).to be_kind_of(Array)
27
29
  expect(events.count).to be >= 1
28
- expect(events.count { |e| e['ResourceId'] == payin['Id'] }).to be >= 1
30
+ expect(events.count {|e| e['ResourceId'] == resourceId}).to be >= 1
29
31
  end
30
32
  end
31
33
  end
@@ -89,4 +89,11 @@ describe MangoPay::Mandate do
89
89
  end
90
90
  end
91
91
 
92
+ describe 'FETCH Transactions' do
93
+ it "fetches a mandate's transactions" do
94
+ mandate = new_mandate
95
+ transactions = MangoPay::Mandate.transactions(mandate['Id'])
96
+ expect(transactions).to be_an(Array)
97
+ end
98
+ end
92
99
  end
@@ -0,0 +1,20 @@
1
+ describe MangoPay::PayIn::ApplePay::Direct, 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('APPLEPAY')
8
+ expect(payin['ExecutionType']).to eq('DIRECT')
9
+ expect(payin['Status']).to eq('SUCCEEDED')
10
+ end
11
+
12
+ describe 'CREATE' do
13
+ it 'creates a applepay direct payin' do
14
+ created = new_payin_applepay_direct
15
+ expect(created['Id']).not_to be_nil
16
+ check_type_and_status(created)
17
+ end
18
+ end
19
+ end
20
+
@@ -1,7 +1,8 @@
1
1
  describe MangoPay::PayIn::BankWire::ExternalInstruction, type: :feature do
2
2
  include_context 'wallets'
3
3
  include_context 'payins'
4
-
4
+
5
+
5
6
  def check_type_and_status(payin)
6
7
  expect(payin['Type']).to eq('PAYIN')
7
8
  expect(payin['Nature']).to eq('REGULAR')
@@ -11,18 +12,56 @@ describe MangoPay::PayIn::BankWire::ExternalInstruction, type: :feature do
11
12
 
12
13
  describe 'FETCH' do
13
14
  it 'fetches a payin' do
15
+ backupConfig = MangoPay.configuration.clone
14
16
  MangoPay.configure do |c|
15
17
  c.preproduction = true
16
18
  c.client_id = 'sdk-unit-tests'
17
- c.root_url = 'https://api-test.mangopay.com'
18
- c.client_passphrase = '9RMGpwVUwFLK0SurxObJ2yaadDcO0zeKFKxWmthjB93SQjFzy0'
19
+ c.root_url = 'https://api.sandbox.mangopay.com'
20
+ c.client_apiKey = 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
19
21
  c.http_timeout = 10000
20
22
  end
21
23
 
22
- id = "2826947"
24
+ id = "66142029"
23
25
  payIn = MangoPay::PayIn.fetch(id)
24
26
  expect(payIn['Id']).to eq(id)
25
27
  check_type_and_status(payIn)
28
+ MangoPay.configuration = backupConfig
29
+ end
30
+
31
+ it 'fetches a bankwire external instruction with iban' do
32
+ backupConfig = MangoPay.configuration.clone
33
+ MangoPay.configure do |c|
34
+ c.preproduction = true
35
+ c.client_id = 'sdk-unit-tests'
36
+ c.root_url = 'https://api.sandbox.mangopay.com'
37
+ c.client_apiKey = 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
38
+ c.http_timeout = 10000
39
+ end
40
+
41
+ payInId = "74980101"
42
+ payIn = MangoPay::PayIn.fetch(payInId)
43
+ expect(payIn).to_not be(nil)
44
+ expect(payIn['Id']).to eq(payInId)
45
+ check_type_and_status(payIn)
46
+ MangoPay.configuration = backupConfig
47
+ end
48
+
49
+ it 'fetches a bankwire external instruction with account number' do
50
+ backupConfig = MangoPay.configuration.clone
51
+ MangoPay.configure do |c|
52
+ c.preproduction = true
53
+ c.client_id = 'sdk-unit-tests'
54
+ c.root_url = 'https://api.sandbox.mangopay.com'
55
+ c.client_apiKey = 'cqFfFrWfCcb7UadHNxx2C9Lo6Djw8ZduLi7J9USTmu8bhxxpju'
56
+ c.http_timeout = 10000
57
+ end
58
+
59
+ payInId = "74981216"
60
+ payIn = MangoPay::PayIn.fetch(payInId)
61
+ expect(payIn).to_not be(nil)
62
+ expect(payIn['Id']).to eq(payInId)
63
+ check_type_and_status(payIn)
64
+ MangoPay.configuration = backupConfig
26
65
  end
27
66
  end
28
67
 
@@ -22,6 +22,15 @@ describe MangoPay::PayIn::Card::Web, type: :feature do
22
22
  end
23
23
  end
24
24
 
25
+ describe 'CREATE with PaylineV2' do
26
+ it 'creates a card web payin with payline v2' do
27
+ created = new_payin_card_web_payline
28
+ expect(created['Id']).not_to be_nil
29
+ expect(created['RedirectURL']).to include('https://www.maysite.com/payline_template/')
30
+ check_type_and_status(created)
31
+ end
32
+ end
33
+
25
34
  describe 'EXTENDED' do
26
35
  context 'when resource not exists' do
27
36
  it 'fetches extended information' do
@@ -44,4 +53,12 @@ describe MangoPay::PayIn::Card::Web, type: :feature do
44
53
  end
45
54
  end
46
55
 
56
+ describe 'FETCH Refunds' do
57
+ it "fetches the pay-in's refunds" do
58
+ payin = new_payin_card_web
59
+ refunds = MangoPay::PayIn.refunds(payin['Id'])
60
+ expect(refunds).to be_an(Array)
61
+ end
62
+ end
63
+
47
64
  end
@@ -13,7 +13,7 @@ describe MangoPay::PayIn::PayPal::Web, type: :feature do
13
13
  expect(payin['ResultMessage']).to be_nil
14
14
  expect(payin['ExecutionDate']).to be_nil
15
15
  end
16
-
16
+
17
17
  describe 'CREATE' do
18
18
  it 'creates a paypal web payin' do
19
19
  created = new_payin_paypal_web
@@ -22,6 +22,18 @@ describe MangoPay::PayIn::PayPal::Web, type: :feature do
22
22
  end
23
23
  end
24
24
 
25
+ describe "FETCH" do
26
+ it 'FETCHES a payIn with PayPal account email' do
27
+ payin_id = "54088959"
28
+ buyer_account_email = "paypal-buyer-user@mangopay.com"
29
+ payin = MangoPay::PayIn.fetch(id = payin_id)
30
+
31
+ expect(payin).not_to be_nil
32
+ expect(payin["PaypalBuyerAccountEmail"]).not_to be_nil
33
+ expect(payin["PaypalBuyerAccountEmail"]).to eq(buyer_account_email)
34
+ end
35
+ end
36
+
25
37
  describe 'FETCH' do
26
38
  it 'fetches a payin' do
27
39
  created = new_payin_paypal_web