mangopay 2.0.0

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 (41) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +51 -0
  3. data/Gemfile +3 -0
  4. data/README.md +138 -0
  5. data/Rakefile +5 -0
  6. data/lib/mangopay.rb +45 -0
  7. data/lib/mangopay/beneficiary.rb +72 -0
  8. data/lib/mangopay/card.rb +42 -0
  9. data/lib/mangopay/contribution.rb +61 -0
  10. data/lib/mangopay/expense.rb +17 -0
  11. data/lib/mangopay/immediate_contribution.rb +58 -0
  12. data/lib/mangopay/operation.rb +16 -0
  13. data/lib/mangopay/recurrent_contribution.rb +62 -0
  14. data/lib/mangopay/ressource.rb +96 -0
  15. data/lib/mangopay/strong_authentication.rb +28 -0
  16. data/lib/mangopay/transfer.rb +58 -0
  17. data/lib/mangopay/user.rb +148 -0
  18. data/lib/mangopay/wallet.rb +93 -0
  19. data/lib/mangopay/withdrawal.rb +40 -0
  20. data/lib/mangopay/withdrawal_contribution.rb +32 -0
  21. data/spec/lib/mangopay/beneficiary_spec.rb +124 -0
  22. data/spec/lib/mangopay/card_spec.rb +52 -0
  23. data/spec/lib/mangopay/contribution_spec.rb +65 -0
  24. data/spec/lib/mangopay/expense_spec.rb +10 -0
  25. data/spec/lib/mangopay/immediate_contribution_spec.rb +73 -0
  26. data/spec/lib/mangopay/operation_spec.rb +8 -0
  27. data/spec/lib/mangopay/recurrent_contribution_spec.rb +55 -0
  28. data/spec/lib/mangopay/ressource_spec.rb +5 -0
  29. data/spec/lib/mangopay/strong_authentication_spec.rb +82 -0
  30. data/spec/lib/mangopay/transfer_spec.rb +88 -0
  31. data/spec/lib/mangopay/user_spec.rb +124 -0
  32. data/spec/lib/mangopay/wallet_spec.rb +81 -0
  33. data/spec/lib/mangopay/withdrawal_contribution_spec.rb +44 -0
  34. data/spec/lib/mangopay/withdrawal_spec.rb +98 -0
  35. data/spec/spec_helper.rb +42 -0
  36. data/spec/support-files/example.pem +49 -0
  37. data/spec/support-files/test_upload.gif +0 -0
  38. data/spec/support-files/test_upload.jpg +0 -0
  39. data/spec/support-files/test_upload.pdf +0 -0
  40. data/spec/support-files/test_upload.png +0 -0
  41. metadata +213 -0
@@ -0,0 +1,93 @@
1
+ module MangoPay
2
+ class Wallet < MangoPay::Ressource
3
+
4
+ # Create a Wallet
5
+ #
6
+ # * *Args* :
7
+ # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
8
+ # * [Tag]
9
+ # * Owners (an array of user IDs, but only one is supported now)
10
+ # * [Name]
11
+ # * [Description]
12
+ # * [RaisingGoalAmount]
13
+ # * [ContributionLimitDate]
14
+ # * *Returns* :
15
+ # - A wallet object
16
+ #
17
+ def self.create(data)
18
+ post_request('wallets', data)
19
+ end
20
+
21
+ # Get a wallet
22
+ #
23
+ # * *Args* :
24
+ # - +wallet_id+ -> The id of the wallet you want to retrieve
25
+ # * *Returns* :
26
+ # - A wallet object
27
+ #
28
+ def self.details(wallet_id)
29
+ get_request(File.join('wallets', wallet_id.to_s))
30
+ end
31
+
32
+ # Update a wallet
33
+ #
34
+ # * *Args* :
35
+ # - +wallet_id+ -> The id of the wallet you want to update
36
+ # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
37
+ # * [Name]
38
+ # * [Description]
39
+ # * [RaisingGoalAmount]
40
+ # * [SuggestedAmount]
41
+ # * [ExpirationDate] [Tag]
42
+ # * *Returns* :
43
+ # - A wallet object
44
+ #
45
+ def self.update(wallet_id, data)
46
+ put_request(File.join('wallets', wallet_id.to_s), data)
47
+ end
48
+
49
+ # Get the owners of a wallet
50
+ #
51
+ # * *Args* :
52
+ # - +wallet_id+ -> The id of the wallet you want to retrieve the owners from
53
+ # * *Returns* :
54
+ # - An array of users objects
55
+ #
56
+ def self.get_owners(wallet_id)
57
+ get_request(File.join('wallets', wallet_id.to_s, 'users'), 'owners=1')
58
+ end
59
+
60
+ # Get the contributors of a wallet
61
+ #
62
+ # * *Args* :
63
+ # - +wallet_id+ -> The id of the wallet you want to retrieve the contributors from
64
+ # * *Returns* :
65
+ # - An array of users objects
66
+ #
67
+ def self.get_contributors(wallet_id)
68
+ get_request(File.join('wallets', wallet_id.to_s, 'users'), 'contributors=1')
69
+ end
70
+
71
+ # Get the refunded users of a wallet
72
+ #
73
+ # * *Args* :
74
+ # - +wallet_id+ -> The id of the wallet you want to refunded users the owners from
75
+ # * *Returns* :
76
+ # - An array of users objects
77
+ #
78
+ def self.get_refunded(wallet_id)
79
+ get_request(File.join('wallets', wallet_id.to_s, 'users'), 'refunded=1')
80
+ end
81
+
82
+ # Get the operations for a given wallet
83
+ #
84
+ # * *Args* :
85
+ # - +wallet_id+ -> The is of the wallet you want to retrieve operations from
86
+ # * *Returns* :
87
+ # - An array of operations objects
88
+ #
89
+ def self.operations(wallet_id)
90
+ get_request(File.join('wallets', wallet_id.to_s, 'operations'))
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,40 @@
1
+ module MangoPay
2
+ # A withdrawal is a request to get the money from a wallet or a personal account to a bank account.
3
+ class Withdrawal < MangoPay::Ressource
4
+
5
+ # Create a withdrawal
6
+ # Only one amount can be present in the withdrawal request: either AmountWithoutFees or Amount (that is amount with fees).
7
+ # Amount = AmountWithoutFees + ClientFeeAmount
8
+ #
9
+ # * *Args* :
10
+ # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
11
+ # * [Tag]
12
+ # * UserID
13
+ # * WalletID
14
+ # * AmountWithoutFees
15
+ # * Amount
16
+ # * BeneficiaryID
17
+ # * [ClientFeeAmount]
18
+ # * *Returns* :
19
+ # - A withdrawal object
20
+ # * *Raises* :
21
+ # - +2001+ -> Invalid withdrawal amount
22
+ # - +2002+ -> Both parameters are specified: Amount and AmountWithoutFees
23
+ # - +2003+ -> Invalid withdrawal ClientFeeAmount
24
+ #
25
+ def self.create(data)
26
+ post_request('withdrawals', data)
27
+ end
28
+
29
+ # Get a withdrawal
30
+ #
31
+ # * *Args* :
32
+ # - +withdrawal_id+ -> The id of the withdrawal you want to retrieve
33
+ # * *Returns* :
34
+ # - A withdrawal object
35
+ #
36
+ def self.details(withdrawal_id)
37
+ get_request(File.join('withdrawals', withdrawal_id.to_s))
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,32 @@
1
+ module MangoPay
2
+
3
+ class WithdrawalContribution < MangoPay::Ressource
4
+
5
+ # Create a withdrawal contribution
6
+ #
7
+ # * *Args* :
8
+ # - +data+ -> A JSON with the following attributes (Square brackets for optionals):
9
+ # * [Tag]
10
+ # * UserID
11
+ # * WalletID
12
+ # * AmountDeclared
13
+ # * *Returns* :
14
+ # - A withdrawal contribution object
15
+ #
16
+ def self.create(data)
17
+ post_request('contributions-by-withdrawal', data)
18
+ end
19
+
20
+
21
+ # Get a withdrawal contribution
22
+ #
23
+ # * *Args* :
24
+ # - +withdrawal_contribution_id+ -> The id of the withdrawal contribution you want to retrieve
25
+ # * *Returns* :
26
+ # - A withdrawal contribution object
27
+ #
28
+ def self.get(withdrawal_contribution_id)
29
+ get_request(File.join('contributions-by-withdrawal', withdrawal_contribution_id.to_s))
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,124 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::Beneficiary do
4
+
5
+ let(:new_user) {
6
+ MangoPay::User.create({
7
+ 'Tag' => 'test',
8
+ 'Email' => 'my@email.com',
9
+ 'FirstName' => 'John',
10
+ 'LastName' => 'Doe',
11
+ 'CanRegisterMeanOfPayment' => true
12
+ })
13
+ }
14
+
15
+ let(:new_beneficiary) {
16
+ MangoPay::Beneficiary.create({
17
+ 'Tag' => 'test',
18
+ 'UserID' => new_user['ID'],
19
+ 'BankAccountOwnerName' => new_user['FirstName'],
20
+ 'BankAccountOwnerAddress' => '1 bis cite paradis',
21
+ 'BankAccountIBAN' => 'FR76 1790 6000 3200 0833 5232 973',
22
+ 'BankAccountBIC' => 'AGRIFRPP879'
23
+ })
24
+ }
25
+
26
+ let(:new_strong_authentication) {
27
+ MangoPay::Beneficiary.create_strong_authentication(new_beneficiary['ID'], {
28
+ 'Tag' => 'test_beneficiary_strong_authentication'
29
+ })
30
+ }
31
+
32
+ describe "CREATE" do
33
+
34
+ it "create a beneficiary" do
35
+ expect(new_beneficiary['ID']).not_to be_nil
36
+ expect(new_beneficiary['UserID']).to eq(new_user['ID'])
37
+ end
38
+
39
+ it "fails and returns a 2004 error code" do
40
+ fail_beneficiary = MangoPay::Beneficiary.create({
41
+ 'Tag' => 'test',
42
+ 'UserID' => new_user['ID'],
43
+ 'BankAccountOwnerAddress' => '1 bis cite paradis',
44
+ 'BankAccountIBAN' => 'FR76 1790 6000 3200 0833 5232 973',
45
+ 'BankAccountBIC' => 'AGRIFRPP879'
46
+ })
47
+ expect(fail_beneficiary["ErrorCode"]).to eq(2004)
48
+ end
49
+
50
+ it "fails and returns a 2005 error code" do
51
+ fail_beneficiary = MangoPay::Beneficiary.create({
52
+ 'Tag' => 'test',
53
+ 'UserID' => new_user['ID'],
54
+ 'BankAccountOwnerName' => new_user['FirstName'],
55
+ 'BankAccountIBAN' => 'FR76 1790 6000 3200 0833 5232 973',
56
+ 'BankAccountBIC' => 'AGRIFRPP879'
57
+ })
58
+ expect(fail_beneficiary["ErrorCode"]).to eq(2005)
59
+ end
60
+
61
+ it "fail and returns a 2006 error code" do
62
+ fail_beneficiary = MangoPay::Beneficiary.create({
63
+ 'Tag' => 'test',
64
+ 'UserID' => new_user['ID'],
65
+ 'BankAccountOwnerName' => new_user['FirstName'],
66
+ 'BankAccountOwnerAddress' => '1 bis cite paradis',
67
+ 'BankAccountIBAN' => 'FR76 1790 6000 3200 0833 5232 973',
68
+ 'BankAccountBIC' => 'RPPdsakdnsajkdna79'
69
+ })
70
+ expect(fail_beneficiary["ErrorCode"]).to eq(2006)
71
+ end
72
+
73
+ it "fail and returns a 2007 error code" do
74
+ fail_beneficiary = MangoPay::Beneficiary.create({
75
+ 'Tag' => 'test',
76
+ 'UserID' => new_user['ID'],
77
+ 'BankAccountOwnerName' => new_user['FirstName'],
78
+ 'BankAccountOwnerAddress' => '1 bis cite paradis',
79
+ 'BankAccountIBAN' => 'OIJDSAOIJDSAOIDJSAOIJDSA',
80
+ 'BankAccountBIC' => 'AGRIFRPP879'
81
+ })
82
+ expect(fail_beneficiary["ErrorCode"]).to eq(2007)
83
+ end
84
+
85
+ it "fail and returns a 2008 error code" do
86
+ fail_beneficiary = MangoPay::Beneficiary.create({
87
+ 'Tag' => 'test',
88
+ 'UserID' => new_user['ID'],
89
+ 'BankAccountOwnerName' => new_user['FirstName'],
90
+ 'BankAccountOwnerAddress' => '1 bis cite paradis',
91
+ 'BankAccountIBAN' => 'GB87 BARC 2065 8244 9716 55',
92
+ 'BankAccountBIC' => 'CRLYFRPP'
93
+ })
94
+ expect(fail_beneficiary["ErrorCode"]).to eq(2008)
95
+ end
96
+ end
97
+
98
+ describe "GET" do
99
+ it "it gets a beneficiary" do
100
+ beneficiary = MangoPay::Beneficiary.details(new_beneficiary["ID"])
101
+ expect(beneficiary["ID"]).to eq(new_beneficiary['ID'])
102
+ end
103
+ end
104
+
105
+ describe "StrongAuthentication" do
106
+ it "creates the beneficiary strong authentication request" do
107
+ expect(new_strong_authentication).not_to be_nil
108
+ expect(new_strong_authentication['BeneficiaryID']).to eq(new_beneficiary['ID'])
109
+ end
110
+ it "gets the beneficiary strong authentication request" do
111
+ strong_authentication = MangoPay::Beneficiary.get_strong_authentication(new_strong_authentication['BeneficiaryID'])
112
+ expect(strong_authentication['ID']).to eq(new_strong_authentication['ID'])
113
+ end
114
+ it "updated the beneficiary strong authentication request" do
115
+ strong_authentication = MangoPay::Beneficiary.update_strong_authentication(new_strong_authentication['BeneficiaryID'], {
116
+ 'Tag' => 'test_beneficiary_strong_authentication2',
117
+ 'IsDocumentsTransmitted' => true
118
+ })
119
+ expect(strong_authentication['ID']).to eq(new_strong_authentication['ID'])
120
+ expect(strong_authentication['Tag']).to eq('test_beneficiary_strong_authentication2')
121
+ expect(strong_authentication['IsDocumentsTransmitted']).to be_true
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,52 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::Card, :type => :feature do
4
+
5
+ let(:new_user) {
6
+ MangoPay::User.create({
7
+ 'Tag' => 'test',
8
+ 'Email' => 'my@email.com',
9
+ 'FirstName' => 'John',
10
+ 'LastName' => 'Doe',
11
+ 'CanRegisterMeanOfPayment' => true
12
+ })
13
+ }
14
+
15
+ let(:new_card) do
16
+ card = MangoPay::Card.create({
17
+ 'Tag' => 'test-card',
18
+ 'OwnerID' => new_user['ID'],
19
+ 'ReturnURL' => 'http://leetchi.com'
20
+ })
21
+ visit(card['RedirectURL'])
22
+ fill_in('number', :with => '4970100000000154')
23
+ fill_in('cvv', :with => '123')
24
+ click_button('paybutton')
25
+ card = MangoPay::Card.details(card['ID'])
26
+ while (card["CardNumber"] || []).length != 16 do
27
+ card = MangoPay::Card.details(card['ID'])
28
+ end
29
+ card
30
+ end
31
+
32
+ describe "CREATE" do
33
+ it "create a new card and return a redirect url" do
34
+ expect(new_card['RedirectURL']).not_to be_empty
35
+ end
36
+ end
37
+
38
+ describe "GET" do
39
+ it "get the users card" do
40
+ card = MangoPay::Card.details(new_card["ID"])
41
+ expect(card["ID"]).to eq(new_card["ID"])
42
+ end
43
+ end
44
+
45
+ describe "DELETE" do
46
+ it "delete the card" do
47
+ deleted_card = MangoPay::Card.delete(new_card["ID"])
48
+ expect(deleted_card).to eq("\"OK\"")
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,65 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::Contribution, :type => :feature do
4
+
5
+ let(:new_user) {
6
+ MangoPay::User.create({
7
+ 'Tag' => 'test',
8
+ 'Email' => 'my@email.com',
9
+ 'FirstName' => 'John',
10
+ 'LastName' => 'Doe',
11
+ 'CanRegisterMeanOfPayment' => true
12
+ })
13
+ }
14
+
15
+ let(:new_contribution) do
16
+ contribution = MangoPay::Contribution.create({
17
+ 'Tag' => 'test_contribution',
18
+ 'UserID' => new_user['ID'],
19
+ 'WalletID' => 0,
20
+ 'Amount' => 10000,
21
+ 'ReturnURL' => 'https://leetchi.com'
22
+ })
23
+ visit(contribution['PaymentURL'])
24
+ fill_in('number', :with => '4970100000000154')
25
+ fill_in('cvv', :with => '123')
26
+ click_button('paybutton')
27
+ contribution = MangoPay::Contribution.details(contribution['ID'])
28
+ while contribution["IsSucceeded"] == false do
29
+ contribution = MangoPay::Contribution.details(contribution['ID'])
30
+ end
31
+ contribution
32
+ end
33
+
34
+ let(:new_contribution_refund) {
35
+ MangoPay::Contribution.refund({
36
+ 'ContributionID' => new_contribution['ID'],
37
+ 'UserID' => new_user['ID'],
38
+ 'Tag' => 'test_contribution_refund'
39
+ })
40
+ }
41
+
42
+ describe "CREATE" do
43
+ it "creates a contribution" do
44
+ expect(new_contribution['ID']).not_to be_nil
45
+ expect(new_contribution['PaymentURL']).not_to be_nil
46
+ end
47
+ end
48
+
49
+ describe "GET" do
50
+ it "get the contribution" do
51
+ contribution = MangoPay::Contribution.details(new_contribution['ID'])
52
+ expect(contribution['ID']).to eq(new_contribution['ID'])
53
+ end
54
+ end
55
+
56
+ describe "REFUND" do
57
+ it "creates a refund request for the contribution" do
58
+ expect(new_contribution_refund['ID']).not_to be_nil
59
+ end
60
+ it "gets the refund request" do
61
+ contribution_refund = MangoPay::Contribution.get_refund(new_contribution_refund['ID'])
62
+ expect(contribution_refund['ID']).to eq(new_contribution_refund['ID'])
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,10 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::Expense do
4
+
5
+ describe "GET" do
6
+ it "get the expense" do
7
+ card = MangoPay::Expense.get(1)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,73 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::ImmediateContribution, :type => :feature do
4
+
5
+ let(:new_user) {
6
+ MangoPay::User.create({
7
+ 'Tag' => 'test',
8
+ 'Email' => 'my@email.com',
9
+ 'FirstName' => 'John',
10
+ 'LastName' => 'Doe',
11
+ 'CanRegisterMeanOfPayment' => true
12
+ })
13
+ }
14
+
15
+ let(:new_card) do
16
+ card = MangoPay::Card.create({
17
+ 'Tag' => 'test-card',
18
+ 'OwnerID' => new_user['ID'],
19
+ 'ReturnURL' => 'http://leetchi.com'
20
+ })
21
+ visit(card['RedirectURL'])
22
+ fill_in('number', :with => '4970100000000154')
23
+ fill_in('cvv', :with => '123')
24
+ click_button('paybutton')
25
+ card = MangoPay::Card.details(card['ID'])
26
+ while (card["CardNumber"] || []).length != 16 do
27
+ card = MangoPay::Card.details(card['ID'])
28
+ end
29
+ card
30
+ end
31
+
32
+ let(:new_immediate_contribution) do
33
+ c = MangoPay::ImmediateContribution.create({
34
+ 'Tag' => 'test_contribution',
35
+ 'UserID' => new_user['ID'],
36
+ 'PaymentCardID' => new_card['ID'],
37
+ 'WalletID' => 0,
38
+ 'Amount' => 33300
39
+ })
40
+ end
41
+
42
+ let(:new_immediate_contribution_refund) {
43
+ MangoPay::ImmediateContribution.refund({
44
+ 'ContributionID' => new_immediate_contribution['ID'],
45
+ 'UserID' => new_user['ID'],
46
+ 'Tag' => 'test_immediate_contribution_refund'
47
+ })
48
+ }
49
+
50
+ describe "CREATE" do
51
+ it "creates an immediate contribution" do
52
+ expect(new_immediate_contribution['ID']).not_to be_nil
53
+ end
54
+ end
55
+
56
+ describe "GET" do
57
+ it "get the immediate contribution" do
58
+ immediate_contribution = MangoPay::ImmediateContribution.details(new_immediate_contribution['ID'])
59
+ expect(immediate_contribution['ID']).to eq(new_immediate_contribution['ID'])
60
+ end
61
+ end
62
+
63
+ describe "REFUND" do
64
+ it "creates a refund request for the immediate contribution" do
65
+ expect(new_immediate_contribution_refund['ID']).not_to be_nil
66
+ end
67
+ it "gets the refund request" do
68
+ immediate_contribution_refund = MangoPay::ImmediateContribution.get_refund(new_immediate_contribution_refund['ID'])
69
+ expect(immediate_contribution_refund['ID']).to eq(new_immediate_contribution_refund['ID'])
70
+ end
71
+ end
72
+
73
+ end