mangopay 3.0.18 → 3.0.19

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 423c179e18019cf3aefcecedd805b3fceb391f4b
4
- data.tar.gz: 281642237df4cc0944592fa18af0188c18e5bc8e
3
+ metadata.gz: b83a705cc7f7ea7dd6954de6b6b0ff58f44c5170
4
+ data.tar.gz: 3d8eaabef7fce1e401810458ec9010366a5832c3
5
5
  SHA512:
6
- metadata.gz: 19a7d3665863f82d12766b1b590304cbfbb16ab3e1f2102ad22a34858e8784f08d5782c8177b93a3cce7610f1ce7e6251cc0a4737c43152bd10eacd9e2250858
7
- data.tar.gz: c8bf7f070bcc27d9179d813d360346fafeeff0452461a5d0328153f3f0af39c6e025a15a3a27f2d1c49de266673403dfe368f258ec4c0e4dd3926a831786ee16
6
+ metadata.gz: 1bf56bfe55dfdec69bd83df86a5fe9be1d758af762d5f2c96674b0dd988242ecd85058493013ee8c584b4648311c3aa610bec1304d8da1856139b2167aacb4b4
7
+ data.tar.gz: 5426a2cbec6a3191a4db3253e52dc54f5b3ba5f0f9c8541be07479285d13db7ad421477ec5ebad2a56fa00062b4907471b465d7783f9936f7d821c7f6eb5d10b
data/README.md CHANGED
@@ -19,17 +19,12 @@ Since [v3.0.17](https://github.com/Mangopay/mangopay2-ruby-sdk/releases/tag/v3.0
19
19
  ## Usage
20
20
 
21
21
  ### Install
22
+ * You can get yourself a [free sandbox account](https://www.mangopay.com/get-started/create-sandbox/) or sign up for a [production account](https://www.mangopay.com/get-started/submit-your-app/create-credentials/) (note that validation of your production account can take a few days, so think about doing it in advance of when you actually want to go live).
23
+
22
24
  * Install the gem by either running ```gem install mangopay```
23
25
  or by adding it to your Gemfile ```gem 'mangopay'```
24
26
 
25
- * The Rails users will be happy to know that there is a new generator script
26
- that will help you configure your access to the Mangopay API version 2.
27
- Simply run ``rails generate mangopay:install CLIENT_ID CLIENT_NAME CLIENT_EMAIL``
28
- where CLIENT_ID is the id you will use to connect to the api
29
- and CLIENT_NAME is a full name that will be use to identify all communications
30
- between you and the Mangopay Team.
31
-
32
- * Otherwise, call ```MangoPay.configure``` in your script as shown in the snippet below.
27
+ * Using the credential info from the signup process above, call ```MangoPay.configure``` in your script as shown in the snippet below.
33
28
 
34
29
  ### Examples
35
30
 
@@ -37,7 +32,7 @@ between you and the Mangopay Team.
37
32
  require 'mangopay'
38
33
 
39
34
 
40
- # configuration (not required if Rails generator fired as above)
35
+ # configuration
41
36
  MangoPay.configure do |c|
42
37
  c.preproduction = true
43
38
  c.client_id = 'YOUR_CLIENT_ID'
@@ -63,7 +58,7 @@ pagination # => {"page"=>1, "per_page"=>8, "total_pages"=>748, "total_items"=>59
63
58
  accounts = MangoPay::BankAccount.fetch(john_id) # => [{...}, ...]: list of accounts data hashes (10 per page by default)
64
59
 
65
60
 
66
- # errors handling
61
+ # error handling
67
62
  begin
68
63
  MangoPay::NaturalUser.create({})
69
64
  rescue MangoPay::ResponseError => ex
@@ -28,6 +28,7 @@ module MangoPay
28
28
  autoload :KycDocument, 'mangopay/kyc_document'
29
29
  autoload :Hook, 'mangopay/hook'
30
30
  autoload :Refund, 'mangopay/refund'
31
+ autoload :Dispute, 'mangopay/dispute'
31
32
  autoload :JSON, 'mangopay/json'
32
33
  autoload :AuthorizationToken, 'mangopay/authorization_token'
33
34
 
@@ -0,0 +1,124 @@
1
+ require 'base64'
2
+
3
+ module MangoPay
4
+
5
+ # See https://docs.mangopay.com/api-references/disputes/disputes/
6
+ class Dispute < Resource
7
+ include HTTPCalls::Fetch
8
+ include HTTPCalls::Update
9
+ class << self
10
+
11
+ def close(dispute_id)
12
+ url = url(dispute_id) + "/close/"
13
+ MangoPay.request(:put, url)
14
+ end
15
+
16
+ # +contested_funds+: Money hash
17
+ # see 'Contest' section @ https://docs.mangopay.com/api-references/disputes/disputes/
18
+ def contest(dispute_id, contested_funds)
19
+ url = url(dispute_id) + "/submit/"
20
+ MangoPay.request(:put, url, {ContestedFunds: contested_funds})
21
+ end
22
+
23
+ def resubmit(dispute_id)
24
+ url = url(dispute_id) + "/submit/"
25
+ MangoPay.request(:put, url)
26
+ end
27
+
28
+ def transactions(dispute_id, filters = {})
29
+ url = url(dispute_id) + "/transactions/"
30
+ MangoPay.request(:get, url, {}, filters)
31
+ end
32
+
33
+ def fetch_for_user(user_id, filters = {})
34
+ url = "#{MangoPay.api_path}/users/#{user_id}/disputes"
35
+ MangoPay.request(:get, url, {}, filters)
36
+ end
37
+
38
+ def fetch_for_wallet(wallet_id, filters = {})
39
+ url = "#{MangoPay.api_path}/wallets/#{wallet_id}/disputes"
40
+ MangoPay.request(:get, url, {}, filters)
41
+ end
42
+
43
+ #####################################################
44
+ # repudiations / settlement transfers
45
+ #####################################################
46
+
47
+ # see https://docs.mangopay.com/api-references/disputes/repudiations/
48
+ def fetch_repudiation(repudiation_id)
49
+ url = "#{MangoPay.api_path}/repudiations/#{repudiation_id}"
50
+ MangoPay.request(:get, url)
51
+ end
52
+
53
+ # +params+: hash; see https://docs.mangopay.com/api-references/disputes/settlement-transfers/
54
+ def create_settlement_transfer(repudiation_id, params)
55
+ url = "#{MangoPay.api_path}/repudiations/#{repudiation_id}/settlementtransfer/"
56
+ MangoPay.request(:post, url, params)
57
+ end
58
+
59
+ #####################################################
60
+ # documents
61
+ #####################################################
62
+
63
+ # +params+: hash; see https://docs.mangopay.com/api-references/disputes/dispute-documents/
64
+ def create_document(dispute_id, params)
65
+ url = url(dispute_id) + "/documents/"
66
+ MangoPay.request(:post, url, params)
67
+ end
68
+
69
+ def fetch_document(document_id)
70
+ url = "#{MangoPay.api_path}/dispute-documents/#{document_id}"
71
+ MangoPay.request(:get, url)
72
+ end
73
+
74
+ # +params+: hash; see 'Edit' section @ https://docs.mangopay.com/api-references/disputes/dispute-documents/
75
+ def update_document(dispute_id, document_id, params)
76
+ url = url(dispute_id) + "/documents/#{document_id}"
77
+ MangoPay.request(:put, url, params)
78
+ end
79
+
80
+ # Fetches list of dispute documents:
81
+ # - for the particular dispute if +dispute_id+ is provided (not nil)
82
+ # - or for all disputes otherwise.
83
+ #
84
+ # Optional +filters+ is a hash accepting following keys:
85
+ # - +page+, +per_page+, +sort+: pagination and sorting params (see MangoPay::HTTPCalls::Fetch::ClassMethods#fetch)
86
+ # - filters such as +Type+ (e.g. 'REFUND_PROOF') and +Status+ (e.g. 'VALIDATED')
87
+ # - +BeforeDate+ (timestamp): filters documents with CreationDate _before_ this date
88
+ # - +AfterDate+ (timestamp): filters documents with CreationDate _after_ this date
89
+ #
90
+ # See https://docs.mangopay.com/api-references/disputes/dispute-documents/
91
+ #
92
+ def fetch_documents(dispute_id = nil, filters = {})
93
+ url = (dispute_id) ? url(dispute_id) + "/documents/" : "#{MangoPay.api_path}/dispute-documents/"
94
+ MangoPay.request(:get, url, {}, filters)
95
+ end
96
+
97
+ # Adds the file page (attachment) to the given document.
98
+ #
99
+ # See https://docs.mangopay.com/api-references/disputes/dispute-document-pages/ :
100
+ # - Document have to be in 'CREATED' Status
101
+ # - You can create as many pages as needed
102
+ # - Change Status to 'VALIDATION_ASKED' to submit dispute documents
103
+ #
104
+ # The file_content_base64 param may be:
105
+ # - Base64 encoded file content
106
+ # - or nil: in this case pass the file path in the next param
107
+ #
108
+ def create_document_page(dispute_id, document_id, file_content_base64, file_path = nil)
109
+ if file_content_base64.nil? && !file_path.nil?
110
+ bts = File.open(file_path, 'rb') { |f| f.read }
111
+ file_content_base64 = Base64.encode64(bts)
112
+ end
113
+ # normally it returns 204 HTTP code on success
114
+ begin
115
+ url = url(dispute_id) + "/documents/#{document_id}/pages"
116
+ MangoPay.request(:post, url, {'File' => file_content_base64})
117
+ rescue ResponseError => ex
118
+ raise ex unless ex.code == '204'
119
+ end
120
+ end
121
+
122
+ end
123
+ end
124
+ end
@@ -1,3 +1,3 @@
1
1
  module MangoPay
2
- VERSION = '3.0.18'
2
+ VERSION = '3.0.19' # disputes
3
3
  end
@@ -16,13 +16,13 @@ describe MangoPay::BankAccount do
16
16
  it 'creates a new GB bank detail' do
17
17
  created = create({
18
18
  Type: 'GB',
19
- AccountNumber: '18329068',
20
- SortCode: '306541',
19
+ AccountNumber: '63956474',
20
+ SortCode: '200000',
21
21
  })
22
22
  expect(created['Id']).not_to be_nil
23
23
  expect(created['Type']).to eq('GB')
24
- expect(created['AccountNumber']).to eq('18329068')
25
- expect(created['SortCode']).to eq('306541')
24
+ expect(created['AccountNumber']).to eq('63956474')
25
+ expect(created['SortCode']).to eq('200000')
26
26
  end
27
27
 
28
28
  it 'creates a new US bank detail' do
@@ -0,0 +1,240 @@
1
+ describe MangoPay::Dispute do
2
+
3
+ # IMPORTANT NOTE!
4
+ #
5
+ # Due to the fact the disputes CANNOT be created on user's side,
6
+ # a special approach in testing is needed.
7
+ # In order to get the tests below pass, a bunch of disputes have
8
+ # to be prepared on the API server side - if they're not, you can
9
+ # just skip these tests, as they won't pass.
10
+ before(:each) do
11
+ @disputes = MangoPay::Dispute.fetch({'page' => 1, 'per_page' => 100})
12
+ end
13
+
14
+ describe 'FETCH' do
15
+ it 'fetches disputes' do
16
+ expect(@disputes).to be_kind_of(Array)
17
+ expect(@disputes).not_to be_empty
18
+ end
19
+ it 'fetches a dispute' do
20
+ id = @disputes.first['Id']
21
+ dispute = MangoPay::Dispute.fetch(id)
22
+ expect(dispute['Id']).to eq(id)
23
+ end
24
+ end
25
+
26
+ describe 'TRANSACTIONS' do
27
+ it 'fetches transactions for dispute' do
28
+ id = @disputes.first['Id']
29
+ transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
30
+ expect(transactions).to be_kind_of(Array)
31
+ expect(transactions).not_to be_empty
32
+ end
33
+ end
34
+
35
+ describe 'FETCH FOR USER AND WALLET' do
36
+ it 'fetches disputes for user' do
37
+ id = @disputes.first['Id']
38
+ transactions = MangoPay::Dispute.transactions(id, {'per_page' => 1})
39
+ user_id = transactions[0]['AuthorId']
40
+ disputes = MangoPay::Dispute.fetch_for_user(user_id, {'per_page' => 1})
41
+ expect(disputes).to be_kind_of(Array)
42
+ expect(disputes).not_to be_empty
43
+ end
44
+ it 'fetches disputes for wallet' do
45
+ dispute = @disputes.find {|disp| disp['InitialTransactionId'] != nil}
46
+ expect(dispute).not_to be_nil, "Cannot test fetching disputes for wallet because there's no disputes with transaction ID in the disputes list."
47
+ payin = MangoPay::PayIn.fetch(dispute['InitialTransactionId'])
48
+ wallet_id = payin['CreditedWalletId']
49
+ disputes = MangoPay::Dispute.fetch_for_wallet(wallet_id, {'per_page' => 1})
50
+ expect(disputes).to be_kind_of(Array)
51
+ expect(disputes).not_to be_empty
52
+ end
53
+ end
54
+
55
+ describe 'UPDATE' do
56
+ it 'updates a dispute' do
57
+ dispute = @disputes.first
58
+ id = dispute['Id']
59
+ new_tag = dispute['Tag'] + '.com'
60
+ changed_dispute = MangoPay::Dispute.update(id, {Tag: new_tag})
61
+ expect(changed_dispute['Tag']).to eq(new_tag)
62
+ end
63
+ end
64
+
65
+ describe 'FETCH REPUDIATION' do
66
+ it 'fetches a repudiation' do
67
+ dispute = @disputes.find {|disp| disp['InitialTransactionId'] != nil}
68
+ expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no disputes with transaction ID in the disputes list."
69
+ transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
70
+ repudiation_id = transactions[0]['Id']
71
+ repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
72
+ expect(repudiation['Id']).to eq(repudiation_id)
73
+ expect(repudiation['Nature']).to eq('REPUDIATION')
74
+ end
75
+ end
76
+
77
+ describe 'CREATE SETTLEMENT TRANSFER' do
78
+ it 'creates settlement transfer' do
79
+ dispute = @disputes.find {|disp| disp['Status'] == 'CLOSED'}
80
+ expect(dispute).not_to be_nil, "Cannot test creating settlement transfer because there's no closed disputes in the disputes list."
81
+ transactions = MangoPay::Dispute.transactions(dispute['Id'], {'per_page' => 1})
82
+ repudiation_id = transactions[0]['Id']
83
+ repudiation = MangoPay::Dispute.fetch_repudiation(repudiation_id)
84
+ params = {
85
+ AuthorId: repudiation['AuthorId'],
86
+ DebitedFunds: {Currency: 'EUR', Amount: 1},
87
+ Fees: {Currency: 'EUR', Amount: 0},
88
+ Tag: 'Custom tag data'
89
+ }
90
+ transfer = MangoPay::Dispute.create_settlement_transfer(repudiation_id, params)
91
+ expect(transfer['Type']).to eq('TRANSFER')
92
+ expect(transfer['Nature']).to eq('SETTLEMENT')
93
+ end
94
+ end
95
+
96
+ describe 'DISPUTE DOCUMENTS API' do
97
+
98
+ def find_dispute
99
+ dispute = @disputes.find {|disp| ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status'])}
100
+ expect(dispute).not_to be_nil, "Cannot test dispute document API because there's no dispute with expected status in the disputes list."
101
+ dispute
102
+ end
103
+
104
+ def create_doc(dispute = nil)
105
+ no_dispute_passed = dispute.nil?
106
+ dispute = find_dispute if no_dispute_passed
107
+ params = { Type: 'DELIVERY_PROOF', Tag: 'Custom tag data' }
108
+ doc = MangoPay::Dispute.create_document(dispute['Id'], params)
109
+ doc['dispute'] = dispute if no_dispute_passed # add it for testing purposes
110
+ doc
111
+ end
112
+
113
+ it 'creates dispute document' do
114
+ doc = create_doc
115
+ expect(doc['Type']).to eq('DELIVERY_PROOF')
116
+ expect(doc['Tag']).to eq('Custom tag data')
117
+ expect(doc['Status']).to eq('CREATED')
118
+ end
119
+
120
+ it 'fetches dispute document' do
121
+ created_doc = create_doc
122
+ fetched_doc = MangoPay::Dispute.fetch_document(created_doc['Id'])
123
+ fields = ['Id', 'Type', 'Tag', 'Status', 'CreationDate', 'RefusedReasonType', 'RefusedReasonMessage']
124
+ fields.each do |field|
125
+ expect(fetched_doc[field]).to eq(created_doc[field])
126
+ end
127
+ end
128
+
129
+ it 'updates dispute document' do
130
+ created_doc = create_doc
131
+ changed_doc = MangoPay::Dispute.update_document(created_doc['dispute']['Id'], created_doc['Id'], {
132
+ Status: 'VALIDATION_ASKED'
133
+ })
134
+ expect(changed_doc['Id']).to eq(created_doc['Id'])
135
+ expect(changed_doc['Status']).to eq('VALIDATION_ASKED')
136
+ end
137
+
138
+ it 'fetches a list of documents' do
139
+ disp = find_dispute
140
+ doc1 = create_doc(disp)
141
+ doc2 = create_doc(disp) # for the same dispute
142
+
143
+ filters = {'per_page' => 2, 'sort' => 'CreationDate:desc'}
144
+
145
+ # fetch last 2 docs for the dispute
146
+ docs = MangoPay::Dispute.fetch_documents(disp['Id'], filters)
147
+ expect(docs).to be_kind_of(Array)
148
+ expect(docs.count).to eq 2 # exactly 2 as pagiantion requested
149
+ # all 2 are at top as lastly created
150
+ # but may share the same CreationDate
151
+ # so the order between them is undetermined
152
+ expect(docs).to include(doc1, doc2)
153
+
154
+ # fetch all docs ever
155
+ docs = MangoPay::Dispute.fetch_documents()
156
+ expect(docs).to be_kind_of(Array)
157
+ expect(docs.count).to be >= 2
158
+
159
+ # fetch last 2 docs ever (sorting by date descending)
160
+ docs = MangoPay::Dispute.fetch_documents(nil, filters)
161
+ expect(docs).to be_kind_of(Array)
162
+ expect(docs.count).to eq 2 # exactly 2 as pagiantion requested
163
+ expect(docs).to include(doc1, doc2)
164
+ end
165
+
166
+ def create_doc_page(file)
167
+ disp = find_dispute
168
+ doc = create_doc(disp)
169
+ MangoPay::Dispute.create_document_page(disp['Id'], doc['Id'], file)
170
+ end
171
+
172
+ it 'create_document_page accepts Base64 encoded file content' do
173
+ fnm = __FILE__.sub('.rb', '.png')
174
+ bts = File.open(fnm, 'rb') { |f| f.read }
175
+ b64 = Base64.encode64(bts)
176
+ ret = create_doc_page(b64)
177
+ expect(ret).to be_nil
178
+ end
179
+
180
+ it 'create_document_page accepts file path' do
181
+ fnm = __FILE__.sub('.rb', '.png')
182
+ disp = find_dispute
183
+ doc = create_doc(disp)
184
+ ret = MangoPay::Dispute.create_document_page(disp['Id'], doc['Id'], nil, fnm)
185
+ expect(ret).to be_nil
186
+ end
187
+
188
+ it 'create_document_page fails when input string is not base64-encoded' do
189
+ file = 'any file content...'
190
+ expect { create_doc_page(file) }.to raise_error { |err|
191
+ expect(err).to be_a MangoPay::ResponseError
192
+ expect(err.code).to eq '400'
193
+ expect(err.type).to eq 'param_error'
194
+ }
195
+ end
196
+ end
197
+
198
+ describe 'CONTEST' do
199
+ it 'contests a dispute' do
200
+ dispute = @disputes.find do |disp|
201
+ ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status']) &&
202
+ ['CONTESTABLE', 'RETRIEVAL'].include?(disp['DisputeType'])
203
+ end
204
+ expect(dispute).not_to be_nil, "Cannot test contesting dispute because there's no available disputes with expected status and type in the disputes list."
205
+ id = dispute['Id']
206
+ contested_funds = dispute['Status'] == 'PENDING_CLIENT_ACTION' ? { Amount: 10, Currency: 'EUR' } : nil;
207
+ changed_dispute = MangoPay::Dispute.contest(id, contested_funds)
208
+ expect(changed_dispute['Id']).to eq(id)
209
+ expect(changed_dispute['Status']).to eq('SUBMITTED')
210
+ end
211
+ end
212
+
213
+ describe 'RESUBMIT' do
214
+ it 'resubmits a dispute' do
215
+ dispute = @disputes.find do |disp|
216
+ ['REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status'])
217
+ end
218
+ expect(dispute).not_to be_nil, "Cannot test resubmiting dispute because there's no available disputes with expected status in the disputes list."
219
+ id = dispute['Id']
220
+ changed_dispute = MangoPay::Dispute.resubmit(id)
221
+ expect(changed_dispute['Id']).to eq(id)
222
+ expect(changed_dispute['Status']).to eq('SUBMITTED')
223
+ end
224
+ end
225
+
226
+ describe 'CLOSE' do
227
+ it 'closes a dispute' do
228
+ dispute = @disputes.find do |disp|
229
+ ['PENDING_CLIENT_ACTION', 'REOPENED_PENDING_CLIENT_ACTION'].include?(disp['Status']) &&
230
+ ['CONTESTABLE', 'RETRIEVAL'].include?(disp['DisputeType'])
231
+ end
232
+ expect(dispute).not_to be_nil, "Cannot test closing dispute because there's no available disputes with expected status in the disputes list."
233
+ id = dispute['Id']
234
+ changed_dispute = MangoPay::Dispute.close(id)
235
+ expect(changed_dispute['Id']).to eq(id)
236
+ expect(changed_dispute['Status']).to eq('CLOSED')
237
+ end
238
+ end
239
+
240
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mangopay
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.18
4
+ version: 3.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geoffroy Lorieux
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-30 00:00:00.000000000 Z
12
+ date: 2015-10-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -77,6 +77,7 @@ files:
77
77
  - lib/mangopay/card.rb
78
78
  - lib/mangopay/card_registration.rb
79
79
  - lib/mangopay/client.rb
80
+ - lib/mangopay/dispute.rb
80
81
  - lib/mangopay/errors.rb
81
82
  - lib/mangopay/event.rb
82
83
  - lib/mangopay/hook.rb
@@ -102,6 +103,8 @@ files:
102
103
  - spec/mangopay/card_registration_spec.rb
103
104
  - spec/mangopay/client_spec.rb
104
105
  - spec/mangopay/configuration_spec.rb
106
+ - spec/mangopay/dispute_spec.png
107
+ - spec/mangopay/dispute_spec.rb
105
108
  - spec/mangopay/event_spec.rb
106
109
  - spec/mangopay/fetch_filters_spec.rb
107
110
  - spec/mangopay/hook_spec.rb
@@ -153,6 +156,8 @@ test_files:
153
156
  - spec/mangopay/card_registration_spec.rb
154
157
  - spec/mangopay/client_spec.rb
155
158
  - spec/mangopay/configuration_spec.rb
159
+ - spec/mangopay/dispute_spec.png
160
+ - spec/mangopay/dispute_spec.rb
156
161
  - spec/mangopay/event_spec.rb
157
162
  - spec/mangopay/fetch_filters_spec.rb
158
163
  - spec/mangopay/hook_spec.rb