mangopay 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +24 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +1 -2
  5. data/LICENSE +20 -0
  6. data/README.md +19 -90
  7. data/bin/mangopay +9 -0
  8. data/lib/generators/mangopay/install_generator.rb +60 -0
  9. data/lib/generators/templates/mangopay.rb +5 -0
  10. data/lib/mangopay.rb +94 -24
  11. data/lib/mangopay/bank_account.rb +21 -0
  12. data/lib/mangopay/client.rb +17 -0
  13. data/lib/mangopay/errors.rb +4 -0
  14. data/lib/mangopay/http_calls.rb +53 -0
  15. data/lib/mangopay/json.rb +21 -0
  16. data/lib/mangopay/legal_user.rb +14 -0
  17. data/lib/mangopay/natural_user.rb +14 -0
  18. data/lib/mangopay/payin.rb +17 -0
  19. data/lib/mangopay/payout.rb +15 -0
  20. data/lib/mangopay/resource.rb +22 -0
  21. data/lib/mangopay/transaction.rb +11 -0
  22. data/lib/mangopay/transfer.rb +4 -55
  23. data/lib/mangopay/user.rb +4 -145
  24. data/lib/mangopay/version.rb +3 -0
  25. data/lib/mangopay/wallet.rb +4 -90
  26. data/mangopay.gemspec +33 -0
  27. data/spec/lib/mangopay/bank_account_spec.rb +26 -0
  28. data/spec/lib/mangopay/client_spec.rb +27 -0
  29. data/spec/lib/mangopay/payin_spec.rb +31 -0
  30. data/spec/lib/mangopay/payout_spec.rb +24 -0
  31. data/spec/lib/mangopay/shared_resources.rb +183 -0
  32. data/spec/lib/mangopay/transaction_spec.rb +14 -0
  33. data/spec/lib/mangopay/transfer_spec.rb +25 -81
  34. data/spec/lib/mangopay/user_spec.rb +37 -103
  35. data/spec/lib/mangopay/wallet_spec.rb +24 -73
  36. data/spec/spec_helper.rb +9 -38
  37. metadata +60 -97
  38. data/CONTRIBUTING.md +0 -51
  39. data/Rakefile +0 -5
  40. data/lib/mangopay/beneficiary.rb +0 -72
  41. data/lib/mangopay/card.rb +0 -42
  42. data/lib/mangopay/contribution.rb +0 -61
  43. data/lib/mangopay/expense.rb +0 -17
  44. data/lib/mangopay/immediate_contribution.rb +0 -58
  45. data/lib/mangopay/operation.rb +0 -16
  46. data/lib/mangopay/recurrent_contribution.rb +0 -62
  47. data/lib/mangopay/ressource.rb +0 -96
  48. data/lib/mangopay/strong_authentication.rb +0 -28
  49. data/lib/mangopay/withdrawal.rb +0 -40
  50. data/lib/mangopay/withdrawal_contribution.rb +0 -32
  51. data/spec/lib/mangopay/beneficiary_spec.rb +0 -124
  52. data/spec/lib/mangopay/card_spec.rb +0 -52
  53. data/spec/lib/mangopay/contribution_spec.rb +0 -65
  54. data/spec/lib/mangopay/expense_spec.rb +0 -10
  55. data/spec/lib/mangopay/immediate_contribution_spec.rb +0 -73
  56. data/spec/lib/mangopay/operation_spec.rb +0 -8
  57. data/spec/lib/mangopay/recurrent_contribution_spec.rb +0 -55
  58. data/spec/lib/mangopay/ressource_spec.rb +0 -5
  59. data/spec/lib/mangopay/strong_authentication_spec.rb +0 -82
  60. data/spec/lib/mangopay/withdrawal_contribution_spec.rb +0 -44
  61. data/spec/lib/mangopay/withdrawal_spec.rb +0 -98
  62. data/spec/support-files/example.pem +0 -49
  63. data/spec/support-files/test_upload.gif +0 -0
  64. data/spec/support-files/test_upload.jpg +0 -0
  65. data/spec/support-files/test_upload.pdf +0 -0
  66. data/spec/support-files/test_upload.png +0 -0
data/mangopay.gemspec ADDED
@@ -0,0 +1,33 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'mangopay/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'mangopay'
7
+ s.version = MangoPay::VERSION
8
+ s.summary = "Ruby bindings for the version 2 of the MangoPay API"
9
+ s.description = <<-EOF
10
+ The mangopay Gem makes interacting with MangoPay Services much easier.
11
+ For any questions regarding the use of MangoPay's Services feel free to contact us at http://www.mangopay.com/contact-us/
12
+ You can find more documentation about MangoPay Services at http://www.mangopay.com/
13
+ EOF
14
+ s.authors = ['Geoffroy Lorieux']
15
+ s.email = 'it-support@mangopay.com'
16
+ s.homepage = 'http://www.mangopay.com/'
17
+ s.license = 'MIT'
18
+
19
+ s.required_ruby_version = '>= 1.9.2'
20
+
21
+ s.add_dependency('multi_json', '~> 1.7.7')
22
+
23
+ s.add_development_dependency('rake', '~> 10.1.0')
24
+ s.add_development_dependency('rspec', '~> 2.14.1')
25
+ s.add_development_dependency('capybara', '~> 2.1.0')
26
+ s.add_development_dependency('capybara-webkit', '~> 1.0.0')
27
+ s.add_development_dependency('rails', '~> 4.0.0')
28
+
29
+ s.files = `git ls-files`.split("\n")
30
+ s.test_files = `git ls-files -- spec/*`.split("\n")
31
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
32
+ s.require_paths = ['lib']
33
+ end
@@ -0,0 +1,26 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::BankAccount do
4
+ include_context 'users'
5
+ include_context 'bank_details'
6
+
7
+ describe 'CREATE' do
8
+ it 'creates a new bank detail' do
9
+ expect(new_iban_bank_detail['Id']).not_to be_nil
10
+ end
11
+ end
12
+
13
+ describe 'FETCH' do
14
+
15
+ it 'fetches all the bank details' do
16
+ bank_details = MangoPay::BankAccount.fetch(new_iban_bank_detail['UserId'])
17
+ expect(bank_details).to be_kind_of(Array)
18
+ expect(bank_details[0]['Id']).to eq(new_iban_bank_detail['Id'])
19
+ end
20
+
21
+ it 'fetches one bank detail' do
22
+ bank_detail = MangoPay::BankAccount.fetch(new_iban_bank_detail['UserId'], new_iban_bank_detail['Id'])
23
+ expect(bank_detail['Id']).to eq(new_iban_bank_detail['Id'])
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ require_relative '../../spec_helper'
2
+ require 'securerandom'
3
+
4
+ describe MangoPay::Client do
5
+ include_context 'clients'
6
+
7
+ describe 'CREATE' do
8
+ it 'creates a new client' do
9
+ expect(new_client['ClientId']).to eq(client_id)
10
+ expect(new_client['Email']).not_to be_nil
11
+ expect(new_client['Passphrase']).not_to be_nil
12
+ end
13
+
14
+ it 'refuses the client id' do
15
+ expect(wrong_client['errors']).not_to be_nil
16
+ end
17
+
18
+ it "ClientId_already_exist" do
19
+ existing_client = MangoPay::Client.create({
20
+ 'ClientId' => new_client['ClientId'],
21
+ 'Name' => 'What a nice name'
22
+ })
23
+ expect(existing_client['Type']).to eq('ClientId_already_exist')
24
+ expect(existing_client['Message']).to eq('A partner with this ClientId already exist')
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,31 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::PayIn::Card::Web, type: :feature do
4
+ include_context 'users'
5
+ include_context 'wallets'
6
+ include_context 'cards'
7
+
8
+ describe 'CREATE' do
9
+ it 'creates a card' do
10
+ expect(new_web_card['Id']).not_to be_nil
11
+ expect(new_web_card['Status']).to eq('SUCCEEDED')
12
+ end
13
+ end
14
+
15
+ describe 'FETCH' do
16
+ it 'fetches a payin' do
17
+ payin = MangoPay::PayIn.fetch(new_web_card['Id'])
18
+ expect(payin['Id']).to eq(new_web_card['Id'])
19
+ end
20
+ end
21
+
22
+ describe 'REFUND' do
23
+ it 'refunds a payin' do
24
+ payin_refund = MangoPay::PayIn.refund(new_web_card['Id'], {
25
+ AuthorId: new_web_card['AuthorId']
26
+ })
27
+ expect(payin_refund['Id']).not_to be_nil
28
+ expect(payin_refund['Status']).to eq('SUCCEEDED')
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::PayOut::BankWire, type: :feature do
4
+ include_context 'users'
5
+ include_context 'wallets'
6
+ include_context 'bank_details'
7
+ include_context 'cards'
8
+ include_context 'bank_wires'
9
+
10
+ describe 'CREATE' do
11
+ it 'creates a bank wire payout' do
12
+ expect(new_bank_wire['Id']).not_to be_nil
13
+ expect(new_bank_wire['Status']).to eq('CREATED')
14
+ end
15
+ end
16
+
17
+ describe 'FETCH' do
18
+ it 'fetches a payout' do
19
+ bank_wire = MangoPay::PayOut.fetch(new_bank_wire['Id'])
20
+ expect(bank_wire['Id']).to eq(new_bank_wire['Id'])
21
+ expect(new_bank_wire['Status']).to eq('CREATED')
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,183 @@
1
+ shared_context 'clients' do
2
+
3
+ let(:client_id) {
4
+ SecureRandom.hex(10)
5
+ }
6
+
7
+ let(:wrong_client_id) {
8
+ SecureRandom.hex(20)
9
+ }
10
+
11
+ let(:wrong_client) {
12
+ MangoPay::Client.create({
13
+ 'ClientID' => wrong_client_id,
14
+ 'Name' => 'What a nice name',
15
+ 'Email' => 'clientemail@email.com'
16
+ })
17
+ }
18
+
19
+ let(:new_client) {
20
+ MangoPay::Client.create({
21
+ 'ClientID' => client_id,
22
+ 'Name' => 'What a nice name',
23
+ 'Email' => 'clientemail@email.com'
24
+ })
25
+ }
26
+ end
27
+
28
+ shared_context 'users' do
29
+
30
+ let(:new_natural_user) {
31
+ MangoPay::NaturalUser.create({
32
+ Tag: 'test',
33
+ Email: 'my@email.com',
34
+ FirstName: 'John',
35
+ LastName: 'Doe',
36
+ Address: 'Here',
37
+ Birthday: '',
38
+ Birthplace: 'Paris',
39
+ Nationality: 'FR',
40
+ CountryOfResidence: 'FR',
41
+ Occupation: 'Worker',
42
+ IncomeRange: 1
43
+ })
44
+ }
45
+
46
+ let(:new_legal_user) {
47
+ MangoPay::LegalUser.create({
48
+ Name: 'Super',
49
+ LegalPersonType: 'BUSINESS',
50
+ HeadquartersAddress: 'Here',
51
+ LegalRepresentativeFirstName: 'John',
52
+ LegalRepresentativeLastName: 'Doe',
53
+ LegalRepresentativeAdress: 'Here',
54
+ LegalRepresentativeEmail: 'john@doe.com',
55
+ LegalRepresentativeBirthday: '',
56
+ LegalRepresentativeNationality: 'FR',
57
+ LegalRepresentativeCountryOfResidence: 'FR',
58
+ Statute: '',
59
+ ProofOfRegistration: '',
60
+ ShareholderDeclaration: ''
61
+ })
62
+ }
63
+ end
64
+
65
+ shared_context 'wallets' do
66
+
67
+ let(:new_wallet) {
68
+ MangoPay::Wallet.create({
69
+ Owners: [new_natural_user['Id']],
70
+ Description: 'A test wallet',
71
+ Currency: 'EUR',
72
+ Tag: 'Test Time'
73
+ })
74
+ }
75
+ end
76
+
77
+ shared_context 'bank_details' do
78
+
79
+ let(:new_iban_bank_detail) {
80
+ MangoPay::BankAccount.create(new_natural_user['Id'], {
81
+ Type: 'IBAN',
82
+ OwnerName: 'John',
83
+ OwnerAddress: 'Here',
84
+ IBAN: 'FR76 1790 6000 3200 0833 5232 973',
85
+ BIC: 'AGRIFRPP879',
86
+ Tag: 'Test Time'
87
+ })
88
+ }
89
+ end
90
+
91
+ shared_context 'cards' do
92
+ let(:new_web_card) {
93
+ card = MangoPay::PayIn::Card::Web.create({
94
+ AuthorId: new_natural_user['Id'],
95
+ CreditedUserId: new_wallet['Owners'][0],
96
+ DebitedFunds: { Currency: 'EUR', Amount: 1000 },
97
+ Fees: { Currency: 'EUR', Amount: 0 },
98
+ CreditedWalletId: new_wallet['Id'],
99
+ ReturnURL: MangoPay.configuration.root_url,
100
+ CardType: 'CB_VISA_MASTERCARD',
101
+ Culture: 'FR',
102
+ Tag: 'Test Card'
103
+ })
104
+ visit(card['RedirectURL'])
105
+ fill_in('number', with: '4970100000000154')
106
+ fill_in('cvv', with: '123')
107
+ click_button('paybutton')
108
+ card = MangoPay::PayIn.fetch(card['Id'])
109
+ while card["Status"] == 'CREATED' do
110
+ card = MangoPay::PayIn.fetch(card['Id'])
111
+ end
112
+ card
113
+ }
114
+ end
115
+
116
+ shared_context 'bank_wires' do
117
+ let(:new_bank_wire){
118
+ MangoPay::PayOut::BankWire.create({
119
+ AuthorId: new_web_card['CreditedUserId'],
120
+ DebitedFunds: { Currency: 'EUR', Amount: 500 },
121
+ Fees: { Currency: 'EUR', Amount: 0 },
122
+ DebitedWalletId: new_web_card['CreditedWalletId'],
123
+ BankAccountId: new_iban_bank_detail['Id'],
124
+ Communication: 'This is a test',
125
+ Tag: 'Test Bank Wire'
126
+ })
127
+ }
128
+ end
129
+
130
+ shared_context 'transfer' do
131
+ let(:credited_wallet) {
132
+ MangoPay::Wallet.create({
133
+ Owners: [new_natural_user['Id']],
134
+ Description: 'A test wallet',
135
+ Currency: 'EUR',
136
+ Tag: 'Test Time'
137
+ })
138
+ }
139
+
140
+ let(:debited_wallet) {
141
+ MangoPay::Wallet.create({
142
+ Owners: [new_legal_user['Id']],
143
+ Description: 'A test wallet',
144
+ Currency: 'EUR',
145
+ Tag: 'Test Time'
146
+ })
147
+ }
148
+
149
+ let(:web_card_contribution) {
150
+ card = MangoPay::PayIn::Card::Web.create({
151
+ AuthorId: debited_wallet['Owners'][0],
152
+ CreditedUserId: debited_wallet['Owners'][0],
153
+ DebitedFunds: { Currency: 'EUR', Amount: 1000 },
154
+ Fees: { Currency: 'EUR', Amount: 0 },
155
+ CreditedWalletId: debited_wallet['Id'],
156
+ ReturnURL: MangoPay.configuration.root_url,
157
+ CardType: 'CB_VISA_MASTERCARD',
158
+ Culture: 'FR',
159
+ Tag: 'Test Card'
160
+ })
161
+ visit(card['RedirectURL'])
162
+ fill_in('number', with: '4970100000000154')
163
+ fill_in('cvv', with: '123')
164
+ click_button('paybutton')
165
+ card = MangoPay::PayIn.fetch(card['Id'])
166
+ while card["Status"] == 'CREATED' do
167
+ card = MangoPay::PayIn.fetch(card['Id'])
168
+ end
169
+ card
170
+ }
171
+
172
+ let(:new_transfer) {
173
+ MangoPay::Transfer.create({
174
+ AuthorId: web_card_contribution['CreditedUserId'],
175
+ CreditedUserId: credited_wallet['Owners'][0],
176
+ DebitedFunds: { Currency: 'EUR', Amount: 500},
177
+ Fees: { Currency: 'EUR', Amout: 0},
178
+ DebitedWalletId: web_card_contribution['CreditedWalletId'],
179
+ CreditedWalletId: credited_wallet['Id'],
180
+ Tag: 'Test Transfer'
181
+ })
182
+ }
183
+ end
@@ -0,0 +1,14 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::Transaction do
4
+ include_context 'users'
5
+ include_context 'wallets'
6
+
7
+ describe 'FETCH' do
8
+ it 'fetches the an empty list of transactions' do
9
+ transactions = MangoPay::Transaction.fetch(new_wallet['Id'])
10
+ expect(transactions).to be_kind_of(Array)
11
+ expect(transactions).to be_empty
12
+ end
13
+ end
14
+ end
@@ -1,88 +1,32 @@
1
1
  require_relative '../../spec_helper'
2
2
 
3
- describe MangoPay::Transfer, :type => :feature do
4
-
5
- let(:new_payer) {
6
- user = MangoPay::User.create({
7
- 'Tag' => 'test',
8
- 'Email' => 'my@email.com',
9
- 'FirstName' => 'John',
10
- 'LastName' => 'Doe',
11
- 'CanRegisterMeanOfPayment' => true
12
- })
13
- contribution = MangoPay::Contribution.create({
14
- 'Tag' => 'test_contribution',
15
- 'UserID' => user['ID'],
16
- 'WalletID' => 0,
17
- 'Amount' => 10000,
18
- 'ReturnURL' => 'https://leetchi.com',
19
- 'BankAccountBIC' => 'AGRIFRPP879'
20
- })
21
- visit(contribution['PaymentURL'])
22
- fill_in('number', :with => '4970100000000154')
23
- fill_in('cvv', :with => '123')
24
- click_button('paybutton')
25
- contribution = MangoPay::Contribution.details(contribution['ID'])
26
- while contribution["IsSucceeded"] == false do
27
- contribution = MangoPay::Contribution.details(contribution['ID'])
28
- end
29
- user
30
- }
31
-
32
- let(:new_beneficiary) {
33
- user = MangoPay::User.create({
34
- 'Tag' => 'test',
35
- 'Email' => 'my@email.com',
36
- 'FirstName' => 'John',
37
- 'LastName' => 'Doe',
38
- 'CanRegisterMeanOfPayment' => true
39
- })
40
- MangoPay::Wallet.create({
41
- 'Name' => 'test',
42
- 'Owners' => [ user['ID'] ],
43
- 'RaisingGoalAmount' => 12000
44
- })
45
- user
46
- }
47
-
48
- let(:new_transfert) {
49
- MangoPay::Transfer.create({
50
- 'Tag' => 'test transfer',
51
- 'PayerID' => new_payer['ID'],
52
- 'BeneficiaryID' => new_beneficiary['ID'],
53
- 'Amount' => 1000,
54
- 'PayerWalletID' => 0,
55
- 'BeneficiaryWalletID' => MangoPay::User.get_wallets(new_beneficiary['ID'])[0]['ID']
56
- })
57
- }
58
-
59
- let(:new_transfer_refund) {
60
- MangoPay::Transfer.refund({
61
- 'TransferID' => new_transfert['ID'],
62
- 'UserID' => new_transfert['BeneficiaryID']
63
- })
64
- }
65
-
66
- describe "CREATE" do
67
- it "create a transfer" do
68
- expect(new_transfert['ID']).not_to be_nil
69
- end
3
+ describe MangoPay::Transfer, type: :feature do
4
+ include_context 'users'
5
+ include_context 'wallets'
6
+ include_context 'transfer'
7
+
8
+ describe 'CREATE' do
9
+ it 'creates a new Transfer' do
10
+ expect(new_transfer['Id']).not_to be_nil
11
+ expect(new_transfer['Status']).to eq('SUCCEEDED')
70
12
  end
13
+ end
71
14
 
72
- describe "GET" do
73
- it "gets the transfer" do
74
- transfert = MangoPay::Transfer.details(new_transfert['ID'])
75
- expect(transfert['ID']).to eq(new_transfert['ID'])
76
- end
15
+ describe 'FETCH' do
16
+ it 'fetches a Transfer' do
17
+ transfer = MangoPay::Transfer.fetch(new_transfer['Id'])
18
+ expect(transfer['Id']).to eq(new_transfer['Id'])
19
+ expect(new_transfer['Status']).to eq('SUCCEEDED')
77
20
  end
78
-
79
- describe "REFUND" do
80
- it "create a refund for the transfer" do
81
- expect(new_transfer_refund['ID']).not_to be_nil
82
- end
83
- it "gets a the transfer refund" do
84
- transfer_refund = MangoPay::Transfer.get_refund(new_transfer_refund['ID'])
85
- expect(transfer_refund['ID']).to eq(new_transfer_refund['ID'])
86
- end
21
+ end
22
+
23
+ describe 'REFUND' do
24
+ it 'refunds a transfer' do
25
+ transfer_refund = MangoPay::Transfer.refund(new_transfer['Id'], {
26
+ AuthorId: new_transfer['AuthorId']
27
+ })
28
+ expect(transfer_refund['Id']).not_to be_nil
29
+ expect(transfer_refund['Status']).to eq('SUCCEEDED')
87
30
  end
31
+ end
88
32
  end