mangopay 3.25.1 → 3.32.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.
@@ -0,0 +1,30 @@
1
+ describe MangoPay::PayIn::PayByBank::Web, type: :feature do
2
+ include_context 'wallets'
3
+ include_context 'payins'
4
+
5
+ def check_type_and_status(payin)
6
+ expect(payin['Type']).to eq('PAYIN')
7
+ expect(payin['Nature']).to eq('REGULAR')
8
+ expect(payin['PaymentType']).to eq('PAY_BY_BANK')
9
+ expect(payin['ExecutionType']).to eq('WEB')
10
+ expect(payin['Status']).to eq('CREATED')
11
+ end
12
+
13
+ describe 'CREATE' do
14
+ it 'creates a paybybank web payin' do
15
+ created = new_payin_paybybank_web
16
+ expect(created['Id']).not_to be_nil
17
+ check_type_and_status(created)
18
+ end
19
+ end
20
+
21
+ describe 'FETCH' do
22
+ it 'fetches a payin' do
23
+ created = new_payin_paybybank_web
24
+ fetched = MangoPay::PayIn.fetch(created['Id'])
25
+ expect(fetched['Id']).to eq(created['Id'])
26
+ check_type_and_status(created)
27
+ check_type_and_status(fetched)
28
+ end
29
+ end
30
+ end
@@ -32,6 +32,7 @@ describe MangoPay::PayIn::PayPal::Web, type: :feature do
32
32
 
33
33
  describe "FETCH" do
34
34
  it 'FETCHES a payIn with PayPal account email' do
35
+ pending("Expired PayIn id")
35
36
  payin_id = "54088959"
36
37
  buyer_account_email = "paypal-buyer-user@mangopay.com"
37
38
  payin = MangoPay::PayIn.fetch(id = payin_id)
@@ -44,6 +44,7 @@ describe MangoPay::PayIn::PreAuthorized::Direct, type: :feature do
44
44
  describe 'REFUND' do
45
45
  it 'refunds a payin' do
46
46
  payin = new_payin_preauthorized_direct
47
+ sleep(2)
47
48
  refund = MangoPay::PayIn.refund(payin['Id'], {AuthorId: payin['AuthorId']})
48
49
  expect(refund['Id']).not_to be_nil
49
50
  expect(refund['Status']).to eq('SUCCEEDED')
@@ -0,0 +1,30 @@
1
+ describe MangoPay::PayIn::Swish::Web, type: :feature do
2
+ include_context 'wallets'
3
+ include_context 'payins'
4
+
5
+ def check_type_and_status(payin)
6
+ expect(payin['Type']).to eq('PAYIN')
7
+ expect(payin['Nature']).to eq('REGULAR')
8
+ expect(payin['PaymentType']).to eq('SWISH')
9
+ expect(payin['ExecutionType']).to eq('WEB')
10
+ expect(payin['Status']).to eq('CREATED')
11
+ end
12
+
13
+ describe 'CREATE' do
14
+ it 'creates a swish web payin' do
15
+ created = new_payin_swish_web
16
+ expect(created['Id']).not_to be_nil
17
+ check_type_and_status(created)
18
+ end
19
+ end
20
+
21
+ describe 'FETCH' do
22
+ it 'fetches a payin' do
23
+ created = new_payin_swish_web
24
+ fetched = MangoPay::PayIn.fetch(created['Id'])
25
+ expect(fetched['Id']).to eq(created['Id'])
26
+ check_type_and_status(created)
27
+ check_type_and_status(fetched)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ describe MangoPay::PayIn::Twint::Web, type: :feature do
2
+ include_context 'wallets'
3
+ include_context 'payins'
4
+
5
+ def check_type_and_status(payin)
6
+ expect(payin['Type']).to eq('PAYIN')
7
+ expect(payin['Nature']).to eq('REGULAR')
8
+ expect(payin['PaymentType']).to eq('TWINT')
9
+ expect(payin['ExecutionType']).to eq('WEB')
10
+ expect(payin['Status']).to eq('CREATED')
11
+ end
12
+
13
+ describe 'CREATE' do
14
+ it 'creates a twint web payin' do
15
+ created = new_payin_twint_web
16
+ expect(created['Id']).not_to be_nil
17
+ check_type_and_status(created)
18
+ end
19
+ end
20
+
21
+ describe 'FETCH' do
22
+ it 'fetches a payin' do
23
+ created = new_payin_twint_web
24
+ fetched = MangoPay::PayIn.fetch(created['Id'])
25
+ expect(fetched['Id']).to eq(created['Id'])
26
+ check_type_and_status(created)
27
+ check_type_and_status(fetched)
28
+ end
29
+ end
30
+ end
@@ -32,11 +32,13 @@ describe MangoPay::PayOut::BankWire, type: :feature do
32
32
 
33
33
  it 'fails if not enough money' do
34
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')
35
+ payout = create_new_payout_bankwire(payin, 10000)
36
+ sleep(2)
37
+ fetched = MangoPay::PayOut::BankWire.get_bankwire(payout['Id'])
38
+ check_type_and_status(payout, true)
39
+ expect(fetched['Status']).to eq('FAILED')
40
+ expect(fetched['ResultCode']).to eq('001001')
41
+ expect(fetched['ResultMessage']).to eq('Unsufficient wallet balance')
40
42
  end
41
43
  end
42
44
 
@@ -0,0 +1,113 @@
1
+ describe MangoPay::Recipient do
2
+ include_context 'recipient'
3
+
4
+ describe 'CREATE' do
5
+ it 'creates a new recipient' do
6
+ recipient = new_recipient
7
+ assert_recipient(recipient)
8
+ expect(recipient['PendingUserAction']).not_to be_nil
9
+ end
10
+ end
11
+
12
+ describe 'GET' do
13
+ it 'fetches a recipient' do
14
+ recipient = new_recipient
15
+ fetched = MangoPay::Recipient.get(recipient['Id'])
16
+ assert_recipient(fetched)
17
+ end
18
+ end
19
+
20
+ describe 'GET User Recipients' do
21
+ it 'fetches a recipient' do
22
+ john = create_new_natural_user_sca_owner
23
+ create_new_recipient(john['Id'])
24
+ fetched = MangoPay::Recipient.get_user_recipients(john['Id'])
25
+ expect(fetched).not_to be_nil
26
+ expect(fetched).to be_kind_of(Array)
27
+ expect(fetched).not_to be_empty
28
+ end
29
+ end
30
+
31
+ describe 'GET Schema' do
32
+ it 'fetches schema for LocalBankTransfer, Individual' do
33
+ schema = MangoPay::Recipient.get_schema('LocalBankTransfer', 'Individual', 'GBP')
34
+ expect(schema).not_to be_nil
35
+ expect(schema['DisplayName']).not_to be_nil
36
+ expect(schema['Currency']).not_to be_nil
37
+ expect(schema['RecipientType']).not_to be_nil
38
+ expect(schema['PayoutMethodType']).not_to be_nil
39
+ expect(schema['RecipientScope']).not_to be_nil
40
+ expect(schema['Tag']).not_to be_nil
41
+ expect(schema['IndividualRecipient']).not_to be_nil
42
+ expect(schema['LocalBankTransfer']).not_to be_nil
43
+ expect(schema['BusinessRecipient']).to be_nil
44
+ expect(schema['InternationalBankTransfer']).to be_nil
45
+ end
46
+
47
+ it 'fetches schema for InternationalBankTransfer, Business' do
48
+ schema = MangoPay::Recipient.get_schema('InternationalBankTransfer', 'Business', 'GBP')
49
+ expect(schema).not_to be_nil
50
+ expect(schema['DisplayName']).not_to be_nil
51
+ expect(schema['Currency']).not_to be_nil
52
+ expect(schema['RecipientType']).not_to be_nil
53
+ expect(schema['PayoutMethodType']).not_to be_nil
54
+ expect(schema['RecipientScope']).not_to be_nil
55
+ expect(schema['Tag']).not_to be_nil
56
+ expect(schema['BusinessRecipient']).not_to be_nil
57
+ expect(schema['InternationalBankTransfer']).not_to be_nil
58
+ expect(schema['IndividualRecipient']).to be_nil
59
+ expect(schema['LocalBankTransfer']).to be_nil
60
+ end
61
+ end
62
+
63
+ describe 'GET Payout Methods' do
64
+ it 'fetches payout methods' do
65
+ payout_methods = MangoPay::Recipient.get_payout_methods('DE', 'EUR')
66
+ expect(payout_methods).not_to be_nil
67
+ expect(payout_methods['AvailablePayoutMethods']).to be_kind_of(Array)
68
+ expect(payout_methods['AvailablePayoutMethods']).not_to be_empty
69
+ end
70
+ end
71
+
72
+ describe 'VALIDATE' do
73
+ it 'validates a recipient' do
74
+ recipient = define_new_recipient
75
+ john = create_new_natural_user_sca_owner
76
+ # it should pass
77
+ MangoPay::Recipient.validate(recipient, john['Id'])
78
+
79
+ # it should throw error
80
+ recipient['Currency'] = nil
81
+ expect { MangoPay::Recipient.validate(recipient, john['Id']) }.to raise_error { |err|
82
+ expect(err).to be_a MangoPay::ResponseError
83
+ expect(err.code).to eq '400'
84
+ expect(err.type).to eq 'param_error'
85
+ }
86
+ end
87
+ end
88
+
89
+ describe 'DEACTIVATE' do
90
+ it 'deactivates a recipient' do
91
+ pending("a recipient needs to be manually activated before running the test")
92
+ john = create_new_natural_user_sca_owner
93
+ recipient = create_new_recipient(john['Id'])
94
+ deactivated = MangoPay::Recipient.deactivate(recipient['Id'])
95
+ fetched = MangoPay::Recipient.get(recipient['Id'])
96
+ expect(deactivated['Status']).to eq('DEACTIVATED')
97
+ expect(fetched['Status']).to eq('DEACTIVATED')
98
+ end
99
+ end
100
+ end
101
+
102
+
103
+ def assert_recipient(recipient)
104
+ expect(recipient).not_to be_nil
105
+ expect(recipient['Status']).not_to be_nil
106
+ expect(recipient['DisplayName']).not_to be_nil
107
+ expect(recipient['PayoutMethodType']).not_to be_nil
108
+ expect(recipient['RecipientType']).not_to be_nil
109
+ expect(recipient['IndividualRecipient']).not_to be_nil
110
+ expect(recipient['LocalBankTransfer']).not_to be_nil
111
+ expect(recipient['RecipientScope']).not_to be_nil
112
+ expect(recipient['UserId']).not_to be_nil
113
+ end
@@ -78,5 +78,145 @@ describe MangoPay::PayIn::RecurringPayments, type: :feature do
78
78
 
79
79
  expect(update).not_to be_nil
80
80
  end
81
+
82
+ it 'creates a recurring paypal payment CIT' do
83
+ wallet = new_wallet
84
+ recurring = MangoPay::PayIn::RecurringPayments::Recurring.create(
85
+ AuthorId: new_natural_user['Id'],
86
+ CreditedUserId: wallet['Owners'][0],
87
+ CreditedWalletId: wallet['Id'],
88
+ FirstTransactionDebitedFunds: {Currency: 'EUR', Amount: 1000},
89
+ FirstTransactionFees: {Currency: 'EUR', Amount: 0},
90
+ Billing: {
91
+ Address: {
92
+ AddressLine1: 'AddressLine1',
93
+ AddressLine2: 'AddressLine2',
94
+ City: 'City',
95
+ Region: 'Region',
96
+ PostalCode: 'PostalCode',
97
+ Country: 'FR'
98
+ },
99
+ FirstName: 'Joe',
100
+ LastName: 'Blogs'
101
+ },
102
+ Shipping: {
103
+ Address: {
104
+ AddressLine1: 'AddressLine1',
105
+ AddressLine2: 'AddressLine2',
106
+ City: 'City',
107
+ Region: 'Region',
108
+ PostalCode: 'PostalCode',
109
+ Country: 'FR'
110
+ },
111
+ FirstName: 'Joe',
112
+ LastName: 'Blogs'
113
+ },
114
+ PaymentType: 'PAYPAL'
115
+ )
116
+ expect(recurring).not_to be_nil
117
+ expect(recurring['Status']).not_to be_nil
118
+ expect(recurring['Id']).not_to be_nil
119
+
120
+ cit = MangoPay::PayIn::RecurringPayments::PayPalCIT.create(
121
+ {
122
+ "ReturnURL": "http://example.com",
123
+ "CancelURL": "http://example.net",
124
+ "LineItems": [
125
+ {
126
+ "Name": "Running shoes",
127
+ "Quantity": 1,
128
+ "UnitAmount": 1000,
129
+ "TaxAmount": 0,
130
+ "Description": "ID of Seller 1",
131
+ "Category": "PHYSICAL_GOODS"
132
+ }
133
+ ],
134
+ "Tag": "Created using the Mangopay API Postman collection",
135
+ "RecurringPayinRegistrationId": recurring['Id'],
136
+ "ShippingPreference": "SET_PROVIDED_ADDRESS",
137
+ "Reference": "abcd-efgh-ijkl",
138
+ "StatementDescriptor": "Example123"
139
+ }
140
+ )
141
+
142
+ expect(cit).not_to be_nil
143
+ expect(cit['Status']).to eq('CREATED')
144
+ expect(cit['PaymentType']).to eq('PAYPAL')
145
+ expect(cit['ExecutionType']).to eq('WEB')
146
+ end
147
+
148
+ it 'creates a recurring paypal payment MIT' do
149
+ wallet = new_wallet
150
+ recurring = MangoPay::PayIn::RecurringPayments::Recurring.create(
151
+ AuthorId: new_natural_user['Id'],
152
+ CreditedUserId: wallet['Owners'][0],
153
+ CreditedWalletId: wallet['Id'],
154
+ FirstTransactionDebitedFunds: {Currency: 'EUR', Amount: 1000},
155
+ FirstTransactionFees: {Currency: 'EUR', Amount: 0},
156
+ Billing: {
157
+ Address: {
158
+ AddressLine1: 'AddressLine1',
159
+ AddressLine2: 'AddressLine2',
160
+ City: 'City',
161
+ Region: 'Region',
162
+ PostalCode: 'PostalCode',
163
+ Country: 'FR'
164
+ },
165
+ FirstName: 'Joe',
166
+ LastName: 'Blogs'
167
+ },
168
+ Shipping: {
169
+ Address: {
170
+ AddressLine1: 'AddressLine1',
171
+ AddressLine2: 'AddressLine2',
172
+ City: 'City',
173
+ Region: 'Region',
174
+ PostalCode: 'PostalCode',
175
+ Country: 'FR'
176
+ },
177
+ FirstName: 'Joe',
178
+ LastName: 'Blogs'
179
+ },
180
+ PaymentType: 'PAYPAL'
181
+ )
182
+ expect(recurring).not_to be_nil
183
+ expect(recurring['Status']).not_to be_nil
184
+ expect(recurring['Id']).not_to be_nil
185
+
186
+ cit = MangoPay::PayIn::RecurringPayments::PayPalMIT.create(
187
+ {
188
+ "ReturnURL": "http://example.com",
189
+ "CancelURL": "http://example.net",
190
+ "LineItems": [
191
+ {
192
+ "Name": "Running shoes",
193
+ "Quantity": 1,
194
+ "UnitAmount": 1000,
195
+ "TaxAmount": 0,
196
+ "Description": "ID of Seller 1",
197
+ "Category": "PHYSICAL_GOODS"
198
+ }
199
+ ],
200
+ "Tag": "Created using the Mangopay API Postman collection",
201
+ "RecurringPayinRegistrationId": recurring['Id'],
202
+ "ShippingPreference": "SET_PROVIDED_ADDRESS",
203
+ "Reference": "abcd-efgh-ijkl",
204
+ "StatementDescriptor": "Example123",
205
+ "DebitedFunds": {
206
+ "Currency": "EUR",
207
+ "Amount": 1000
208
+ },
209
+ "Fees": {
210
+ "Currency": "EUR",
211
+ "Amount": 0
212
+ }
213
+ }
214
+ )
215
+
216
+ expect(cit).not_to be_nil
217
+ expect(cit['Status']).to eq('CREATED')
218
+ expect(cit['PaymentType']).to eq('PAYPAL')
219
+ expect(cit['ExecutionType']).to eq('WEB')
220
+ end
81
221
  end
82
222
  end