mangopay 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,8 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::Operation do
4
+
5
+ it "gets the operation" do
6
+ operation = MangoPay::Operation.get(1)
7
+ end
8
+ end
@@ -0,0 +1,55 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::RecurrentContribution 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_recurrent_contribution) {
16
+ MangoPay::RecurrentContribution.create({
17
+ 'Tag' => 'test-recurrent-contribution',
18
+ 'UserID' => new_user['ID'],
19
+ 'WalletID' => 0,
20
+ 'Amount' => 4200,
21
+ 'StartDate' => '1388534400',
22
+ 'FrequencyCode' => 'TwiceMonthly',
23
+ 'NumberOfExecutions' => 10,
24
+ 'ReturnURL' => 'http://leetchi.com'
25
+ })
26
+ }
27
+
28
+ describe "CREATE" do
29
+ it "create a new recurrent contribution and return a PaymentURL" do
30
+ expect(new_recurrent_contribution['PaymentURL']).not_to be_empty
31
+ end
32
+ end
33
+
34
+ describe "GET" do
35
+ it "get a recurrent contribution" do
36
+ recurrent_contribution = MangoPay::RecurrentContribution.get(new_recurrent_contribution["ID"])
37
+ expect(recurrent_contribution["ID"]).to eq(new_recurrent_contribution["ID"])
38
+ end
39
+ end
40
+
41
+ describe "UPDATE" do
42
+ it "updates a recurrent contribution" do
43
+ recurrent_contribution = MangoPay::RecurrentContribution.update(new_recurrent_contribution["ID"], { :IsEnabled => false })
44
+ expect(recurrent_contribution["IsEnabled"]).to be_false
45
+ end
46
+ end
47
+
48
+ describe "GET_EXECUTIONS" do
49
+ it "get a list of the recurrent contribution executions" do
50
+ recurrent_contribution_executions = MangoPay::RecurrentContribution.get_executions(new_recurrent_contribution["ID"])
51
+ expect(recurrent_contribution_executions).to be_a_kind_of(Array)
52
+ expect(recurrent_contribution_executions).to be_empty
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,5 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::Ressource do
4
+ pending "It should test the ressource"
5
+ end
@@ -0,0 +1,82 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::StrongAuthentication 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_beneficiary_authentication) {
27
+ MangoPay::Beneficiary.create_strong_authentication(new_beneficiary['ID'], {
28
+ 'Tag' => 'test_beneficiary_strong_authentication'
29
+ })
30
+ }
31
+
32
+ let(:new_strong_user_authentication) {
33
+ MangoPay::User.create_strong_authentication(new_user['ID'], {
34
+ 'Tag' => 'test_user_strong_authentication'
35
+ })
36
+ }
37
+
38
+ describe "GET" do
39
+ it "get the pending strong authentication requests" do
40
+ strong_authentication = MangoPay::StrongAuthentication.get
41
+ expect(strong_authentication).to be_kind_of(Array)
42
+ end
43
+ end
44
+
45
+ describe "UPLOAD BENEFICIARY" do
46
+ it "uploads a PDF file to complete a beneficiary strong authentication request" do
47
+ document_upload = MangoPay::StrongAuthentication.upload(new_strong_beneficiary_authentication['UrlRequest'], 'spec/support-files/test_upload.pdf')
48
+ expect(document_upload).to be_true
49
+ end
50
+ it "uploads a JPG file to complete a beneficiary strong authentication request" do
51
+ document_upload = MangoPay::StrongAuthentication.upload(new_strong_beneficiary_authentication['UrlRequest'], 'spec/support-files/test_upload.jpg')
52
+ expect(document_upload).to be_true
53
+ end
54
+ it "uploads a PNG file to complete a beneficiary strong authentication request" do
55
+ document_upload = MangoPay::StrongAuthentication.upload(new_strong_beneficiary_authentication['UrlRequest'], 'spec/support-files/test_upload.png')
56
+ expect(document_upload).to be_true
57
+ end
58
+ it "uploads a GIF file to complete a beneficiary strong authentication request" do
59
+ document_upload = MangoPay::StrongAuthentication.upload(new_strong_beneficiary_authentication['UrlRequest'], 'spec/support-files/test_upload.gif')
60
+ expect(document_upload).to be_true
61
+ end
62
+ end
63
+
64
+ describe "UPLOAD USER" do
65
+ it "uploads a PDF file to complete a user strong authentication request" do
66
+ document_upload = MangoPay::StrongAuthentication.upload(new_strong_user_authentication['UrlRequest'], 'spec/support-files/test_upload.pdf')
67
+ expect(document_upload).to be_true
68
+ end
69
+ it "uploads a JPG file to complete a user strong authentication request" do
70
+ document_upload = MangoPay::StrongAuthentication.upload(new_strong_user_authentication['UrlRequest'], 'spec/support-files/test_upload.jpg')
71
+ expect(document_upload).to be_true
72
+ end
73
+ it "uploads a PNG file to complete a user strong authentication request" do
74
+ document_upload = MangoPay::StrongAuthentication.upload(new_strong_user_authentication['UrlRequest'], 'spec/support-files/test_upload.png')
75
+ expect(document_upload).to be_true
76
+ end
77
+ it "uploads a GIF file to complete a user strong authentication request" do
78
+ document_upload = MangoPay::StrongAuthentication.upload(new_strong_user_authentication['UrlRequest'], 'spec/support-files/test_upload.gif')
79
+ expect(document_upload).to be_true
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,88 @@
1
+ require_relative '../../spec_helper'
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
70
+ end
71
+
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
77
+ 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
87
+ end
88
+ end
@@ -0,0 +1,124 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::User 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_wallet) {
16
+ MangoPay::Wallet.create({
17
+ 'Name' => 'test',
18
+ 'Owners' => [ new_user['ID'] ],
19
+ 'RaisingGoalAmount' => 12000
20
+ })
21
+ }
22
+
23
+ let(:new_strong_authentication) {
24
+ MangoPay::User.create_strong_authentication(new_user['ID'], {
25
+ 'Tag' => 'test_strong_auth'
26
+ })
27
+ }
28
+
29
+ describe "CREATE" do
30
+ it "create a user" do
31
+ expect(new_user["FirstName"]).to eq('John')
32
+ expect(new_user["LastName"]).to eq('Doe')
33
+ expect(new_user["Email"]).to eq('my@email.com')
34
+ expect(new_user["CanRegisterMeanOfPayment"]).to be_true
35
+ expect(new_user["ID"]).not_to be_nil
36
+ end
37
+ end
38
+
39
+ describe "GET" do
40
+ it "gets the user infos" do
41
+ user = MangoPay::User.details(new_user["ID"])
42
+
43
+ expect(user["FirstName"]).to eq(new_user["FirstName"])
44
+ expect(user["LastName"]).to eq(new_user["LastName"])
45
+ expect(user["Email"]).to eq(new_user["Email"])
46
+ expect(user["ID"]).to eq(new_user["ID"])
47
+ end
48
+ end
49
+
50
+ describe "UPDATE" do
51
+ it "update the user infos" do
52
+ user = MangoPay::User.update(new_user["ID"], {
53
+ 'Tag' => 'test-update',
54
+ 'Email' => 'mynew@email.com',
55
+ 'FirstName' => 'Jack',
56
+ 'LastName' => 'Black',
57
+ 'CanRegisterMeanOfPayment' => false
58
+ })
59
+ expect(user["FirstName"]).to eq('Jack')
60
+ expect(user["LastName"]).to eq('Black')
61
+ expect(user["Email"]).to eq('mynew@email.com')
62
+ expect(user["CanRegisterMeanOfPayment"]).to be_false
63
+ expect(user["ID"]).to eq(new_user["ID"])
64
+ end
65
+ end
66
+
67
+ describe "GET_WALLETS" do
68
+ it "get an empty list of wallets" do
69
+ wallets = MangoPay::User.get_wallets(new_user["ID"])
70
+ expect(wallets).to be_empty
71
+ end
72
+ it "gets a new wallet for the user" do
73
+ new_wallet
74
+ wallets = MangoPay::User.get_wallets(new_user['ID'])
75
+ expect(wallets).not_to be_empty
76
+ expect(wallets[0]["Owners"][0]).to eq(new_user['ID'])
77
+ end
78
+ end
79
+
80
+ describe "CARDS" do
81
+ it "gets the user cards" do
82
+ cards = MangoPay::User.cards(new_user["ID"])
83
+ expect(cards).to be_empty
84
+ end
85
+ end
86
+
87
+ describe "OPERATIONS" do
88
+ it "gets all the users operations" do
89
+ operations = MangoPay::User.operations(new_user['ID'])
90
+ expect(operations).to be_empty
91
+ end
92
+ it "gets all the users personal operation" do
93
+ personal_operations = MangoPay::User.personal_operations(new_user['ID'])
94
+ expect(personal_operations).to be_empty
95
+ end
96
+ end
97
+
98
+ describe "STRONG_AUTHENTICATION" do
99
+ it "creates a new strong authentication request" do
100
+ expect(new_strong_authentication['ID']).not_to be_nil
101
+ end
102
+ it "gets the user strong authentication request" do
103
+ strong_authentication = MangoPay::User.get_strong_authentication(new_strong_authentication['UserID'])
104
+ expect(strong_authentication['ID']).to eq(new_strong_authentication['ID'])
105
+ end
106
+ it "updates the user strong authentication request" do
107
+ strong_authentication = MangoPay::User.update_strong_authentication(new_strong_authentication['UserID'], {
108
+ 'Tag' => 'test_strong_authentication2',
109
+ 'IsDocumentsTransmitted' => true
110
+ })
111
+ expect(strong_authentication['ID']).to eq(new_strong_authentication['ID'])
112
+ expect(strong_authentication['UserID']).to eq(new_strong_authentication['UserID'])
113
+ expect(strong_authentication['Tag']).to eq('test_strong_authentication2')
114
+ expect(strong_authentication['IsDocumentsTransmitted']).to be_true
115
+ end
116
+ end
117
+
118
+ describe "EXPENSE_SITES" do
119
+ it "get the expense sites for the given user" do
120
+ expense_sites = MangoPay::User.expense_sites(new_user['ID'], new_wallet['ID'])
121
+ expect(expense_sites).to be_kind_of(Array)
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,81 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ describe MangoPay::Wallet 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
+ let(:new_wallet) {
15
+ MangoPay::Wallet.create({
16
+ 'Name' => 'test',
17
+ 'Owners' => [ new_user['ID'] ],
18
+ 'RaisingGoalAmount' => 12000
19
+ })
20
+ }
21
+
22
+ describe "CREATE" do
23
+ it "should create a new wallet" do
24
+ expect(new_wallet["ID"]).not_to be_nil
25
+ expect(new_wallet["Name"]).to eq('test')
26
+ expect(new_wallet["RaisingGoalAmount"]).to eq(12000)
27
+ expect(new_wallet["CollectedAmount"]).to eq(0)
28
+ expect(new_wallet["SpentAmount"]).to eq(0)
29
+ end
30
+ end
31
+
32
+ describe "GET" do
33
+ it "get the wallet" do
34
+ wallet = MangoPay::Wallet.details(new_wallet["ID"])
35
+ expect(wallet['ID']).to eq(new_wallet['ID'])
36
+ expect(wallet['Name']).to eq(new_wallet['Name'])
37
+ expect(wallet['Owners']).to eq(new_wallet['Owners'])
38
+ expect(wallet['RaisingGoalAmount']).to eq(new_wallet['RaisingGoalAmount'])
39
+ end
40
+ end
41
+
42
+ describe "UPDATE" do
43
+ it "update the wallet" do
44
+ wallet = MangoPay::Wallet.update(new_wallet["ID"], {
45
+ 'Name' => 'test_update',
46
+ 'RaisingGoalAmount' => 5000
47
+ })
48
+ expect(wallet['ID']).to eq(wallet['ID'])
49
+ expect(wallet['Name']).to eq('test_update')
50
+ expect(wallet['RaisingGoalAmount']).to eq(5000)
51
+ end
52
+ end
53
+
54
+ describe "GET_OWNERS" do
55
+ it "get the wallet's owners" do
56
+ wallet = MangoPay::Wallet.get_owners(new_wallet["ID"])
57
+ expect(wallet[0]['ID']).to eq(new_user['ID'])
58
+ end
59
+ end
60
+
61
+ describe "GET_CONTRIBUTORS" do
62
+ it "get the wallet's contributors" do
63
+ wallet = MangoPay::Wallet.get_contributors(new_wallet["ID"])
64
+ expect(wallet[0]['ID']).to eq(new_user['ID'])
65
+ end
66
+ end
67
+
68
+ describe "GET_REFUNDED" do
69
+ it "get the wallet's refunded" do
70
+ wallet = MangoPay::Wallet.get_refunded(new_wallet["ID"])
71
+ expect(wallet[0]['ID']).to eq(new_user['ID'])
72
+ end
73
+ end
74
+
75
+ describe "OPERATIONS" do
76
+ it "gets the wallet operations" do
77
+ operations = MangoPay::Wallet.operations(new_wallet['ID'])
78
+ expect(operations).to be_kind_of(Array)
79
+ end
80
+ end
81
+ end