braintree 2.85.0 → 2.86.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0d64ca677afdd3bc219c98009af627b4cbfaaaa
4
- data.tar.gz: a5c8eafe9e54ce75579959bface19399b59ecf8e
3
+ metadata.gz: 7d16d946caac139ce933b07a194e06074d6bf721
4
+ data.tar.gz: 88a89e4cf504034189c75129b1b1e65d2bfeb66d
5
5
  SHA512:
6
- metadata.gz: fc4bed06b88725a62739b7f2c2b014b19b42aaeb55a4ab7eb2d559aeb2c136b6d14ff60c684fbe44f2943a3c3119ec1be4eaba9adfda8a17601d05f63f79d993
7
- data.tar.gz: 93eac87bd236a4923440f96413c19aad8ddf09bbbd7c2ab633bfe6ccd6645d70c737ce643de9204833bf585b2a811308a1f84f3d89c7526f8c9e691410523dd7
6
+ metadata.gz: fab396847ee1626b764b26210c10e7a3eaaf5b2eea6e8e25254ccebd2d4dd92326291a7bc211c8e7073a28c29170176254ea14d99c08a530283d4efe99b07021
7
+ data.tar.gz: 4994c09be6eaf8a57e698248902114cf9671ac64a10d1dd05638a643f94b30904a967fdb1cc06b0ed12d2b4622f5d250a288d79c097a83d5c6e350d6851d5435
@@ -28,7 +28,7 @@ module Braintree
28
28
  def self._generate_signature # :nodoc:
29
29
  [
30
30
  :address_id, :customer_id, :proxy_merchant_id, :merchant_account_id,
31
- :version, :sepa_mandate_acceptance_location, :sepa_mandate_type,
31
+ :version,
32
32
  {:options => [:make_default, :verify_card, :fail_on_duplicate_payment_method]}
33
33
  ]
34
34
  end
@@ -3,7 +3,8 @@ module Braintree
3
3
  class Evidence # :nodoc:
4
4
  include BaseModule
5
5
 
6
- attr_reader :comment,
6
+ attr_reader :category,
7
+ :comment,
7
8
  :created_at,
8
9
  :id,
9
10
  :sent_to_processor_at,
@@ -13,7 +14,7 @@ module Braintree
13
14
 
14
15
  def initialize(attributes)
15
16
  unless attributes.nil?
16
- @tag = attributes.delete(:category)
17
+ @tag = attributes[:category]
17
18
  set_instance_variables_from_hash attributes
18
19
  end
19
20
  @sent_to_processor_at = Date.parse(sent_to_processor_at) unless sent_to_processor_at.nil?
@@ -20,13 +20,23 @@ module Braintree
20
20
  raise NotFoundError, "dispute with id #{dispute_id} not found"
21
21
  end
22
22
 
23
- def add_file_evidence(dispute_id, document_upload_id)
23
+ def add_file_evidence(dispute_id, document_id_or_request)
24
24
  raise ArgumentError, "dispute_id contains invalid characters" unless dispute_id.to_s =~ /\A[\w-]+\z/
25
25
  raise ArgumentError, "dispute_id cannot be blank" if dispute_id.nil? || dispute_id.to_s.strip == ""
26
- raise ArgumentError, "document_upload_id contains invalid characters" unless document_upload_id.to_s =~ /\A[\w-]+\z/
27
- raise ArgumentError, "document_upload_id cannot be blank" if document_upload_id.nil? || dispute_id.to_s.strip == ""
26
+ raise ArgumentError, "document_id_or_request cannot be blank" if document_id_or_request.nil?
28
27
 
29
- params = {document_upload_id: document_upload_id}
28
+ request = document_id_or_request.is_a?(Hash) ? document_id_or_request : { document_id: document_id_or_request }
29
+
30
+ raise ArgumentError, "document_id contains invalid characters" unless request[:document_id].to_s =~ /\A[\w-]+\z/
31
+ raise ArgumentError, "document_id cannot be blank" if request[:document_id].nil? || dispute_id.to_s.strip == ""
32
+ raise ArgumentError, "category must be a string" if request[:category] && !request[:category].is_a?(String)
33
+
34
+ params = {
35
+ evidence: {
36
+ document_upload_id: request[:document_id],
37
+ category: request[:category],
38
+ }
39
+ }
30
40
  response = @config.http.post("#{@config.base_merchant_path}/disputes/#{dispute_id}/evidence", params)
31
41
 
32
42
  if response[:evidence]
@@ -48,15 +58,20 @@ module Braintree
48
58
  request = content_or_request.is_a?(String) ? { content: content_or_request } : content_or_request
49
59
 
50
60
  raise ArgumentError, "content cannot be blank" if request[:content].nil? || request[:content].to_s.strip == ""
51
- raise ArgumentError, "request can only contain the keys [:content, :tag, :sequence_number]" if (request.keys - [:content, :tag, :sequence_number]).any?
61
+ raise ArgumentError, "request can only contain the keys [:content, :category, :sequence_number]" if (request.keys - [:category, :content, :tag, :sequence_number]).any?
52
62
  raise ArgumentError, "sequence_number must be an integer" if request[:sequence_number] && request[:sequence_number].to_s.match(/\D/)
53
63
  raise ArgumentError, "tag must be a string" if request[:tag] && !request[:tag].is_a?(String)
64
+ raise ArgumentError, "category must be a string" if request[:category] && !request[:category].is_a?(String)
65
+
66
+ warn "[DEPRECATED] tag as an option is deprecated. Please use category" if request[:tag]
67
+
68
+ category = request[:category] || request[:tag]
54
69
 
55
70
  params_for_http_post = {
56
71
  evidence: {
57
72
  comments: request[:content]
58
73
  }.tap do |evidence_params|
59
- evidence_params[:category] = request[:tag] if request[:tag]
74
+ evidence_params[:category] = category if category
60
75
  evidence_params[:sequence_number] = request[:sequence_number] if request[:sequence_number]
61
76
  end
62
77
  }
@@ -152,6 +152,23 @@ module Braintree
152
152
  CanOnlyAddEvidenceDocumentToDispute = "95703"
153
153
  CanOnlyAcceptOpenDispute = "95704"
154
154
  CanOnlyFinalizeOpenDispute = "95705"
155
+ CanOnlyCreateEvidenceWithValidCategory = "95706"
156
+ EvidenceContentDateInvalid = "95707"
157
+ EvidenceContentTooLong = "95708"
158
+ EvidenceContentARNTooLong = "95709"
159
+ EvidenceContentPhoneTooLong = "95710"
160
+ EvidenceCategoryTextOnly = "95711"
161
+ EvidenceCategoryDocumentOnly = "95712"
162
+ EvidenceCategoryNotForReasonCode = "95713"
163
+ EvidenceCategoryDuplicate = "95714"
164
+ EvidenceContentEmailInvalid = "95715"
165
+
166
+ DigitalGoodsMissingEvidence = "95720"
167
+ DigitalGoodsMissingDownloadDate = "95721"
168
+ NonDisputedPriorTransactionEvidenceMissingARN = "95722"
169
+ NonDisputedPriorTransactionEvidenceMissingDate = "95723"
170
+ RecurringTransactionEvidenceMissingDate = "95724"
171
+ RecurringTransactionEvidenceMissingARN = "95725"
155
172
  end
156
173
 
157
174
  module DocumentUpload
@@ -27,8 +27,6 @@ module Braintree
27
27
  SuccessfulResult.new(:payment_method => CoinbaseAccount._new(@gateway, response[:coinbase_account]))
28
28
  elsif response[:us_bank_account]
29
29
  SuccessfulResult.new(:payment_method => UsBankAccount._new(@gateway, response[:us_bank_account]))
30
- elsif response[:europe_bank_account]
31
- SuccessfulResult.new(:payment_method => EuropeBankAccount._new(@gateway, response[:europe_bank_account]))
32
30
  elsif response[:apple_pay_card]
33
31
  SuccessfulResult.new(:payment_method => ApplePayCard._new(@gateway, response[:apple_pay_card]))
34
32
  elsif response[:android_pay_card]
@@ -7,6 +7,7 @@ module Braintree
7
7
  attr_reader :customer_id
8
8
  attr_reader :email
9
9
  attr_reader :image_url
10
+ attr_reader :payer_id
10
11
  attr_reader :subscriptions
11
12
  attr_reader :token
12
13
  attr_reader :updated_at
@@ -1,7 +1,7 @@
1
1
  module Braintree
2
2
  module Version
3
3
  Major = 2
4
- Minor = 85
4
+ Minor = 86
5
5
  Tiny = 0
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
@@ -188,19 +188,18 @@ describe Braintree::ClientToken do
188
188
  end
189
189
 
190
190
  context "SEPA" do
191
- it "includes the SEPA options for a SEPA merchant" do
191
+ it "raises error for passing in sepa related params" do
192
192
  with_altpay_merchant do
193
193
  result = Braintree::Customer.create
194
194
  customer_id = result.customer.id
195
195
 
196
- raw_client_token = Braintree::ClientToken.generate(
197
- :customer_id => customer_id,
198
- :sepa_mandate_acceptance_location => "Hamburg, Germany",
199
- :sepa_mandate_type => Braintree::EuropeBankAccount::MandateType::Business
200
- )
201
- client_token = decode_client_token(raw_client_token)
202
-
203
- client_token["authorizationFingerprint"].should include("sepa_mandate_type=business")
196
+ expect do
197
+ Braintree::ClientToken.generate(
198
+ :customer_id => customer_id,
199
+ :sepa_mandate_acceptance_location => "Hamburg, Germany",
200
+ :sepa_mandate_type => Braintree::EuropeBankAccount::MandateType::Business
201
+ )
202
+ end.to raise_error(ArgumentError, "invalid keys: sepa_mandate_acceptance_location, sepa_mandate_type")
204
203
  end
205
204
  end
206
205
  end
@@ -3,6 +3,12 @@ require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
3
3
  require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
4
4
 
5
5
  describe Braintree::Dispute do
6
+ let(:document_upload) do
7
+ file = File.new("#{File.dirname(__FILE__)}/../../fixtures/files/bt_logo.png", "r")
8
+ response = Braintree::DocumentUpload.create({:kind => Braintree::DocumentUpload::Kind::EvidenceDocument, :file => file})
9
+ document_upload = response.document_upload
10
+ end
11
+
6
12
  let(:transaction) do
7
13
  result = Braintree::Transaction.sale(
8
14
  :amount => '10.00',
@@ -46,16 +52,11 @@ describe Braintree::Dispute do
46
52
  end
47
53
 
48
54
  describe "self.add_file_evidence" do
49
- let(:document_upload) do
50
- file = File.new("#{File.dirname(__FILE__)}/../../fixtures/files/bt_logo.png", "r")
51
- response = Braintree::DocumentUpload.create({:kind => Braintree::DocumentUpload::Kind::EvidenceDocument, :file => file})
52
- document_upload = response.document_upload
53
- end
54
-
55
- it "creates text evidence for the dispute" do
55
+ it "creates file evidence for the dispute" do
56
56
  result = Braintree::Dispute.add_file_evidence(dispute.id, document_upload.id)
57
57
 
58
58
  result.success?.should == true
59
+ result.evidence.category.should be_nil
59
60
  result.evidence.comment.should be_nil
60
61
  result.evidence.created_at.between?(Time.now - 10, Time.now).should == true
61
62
  result.evidence.id.should =~ /^\w{16,}$/
@@ -87,6 +88,14 @@ describe Braintree::Dispute do
87
88
  expected_evidence.comment.should be_nil
88
89
  expected_evidence.url.should include("bt_logo.png")
89
90
  end
91
+
92
+ it "creates file evidence with a category when provided" do
93
+ result = Braintree::Dispute.add_file_evidence(dispute.id, {category: "GENERAL", document_id: document_upload.id})
94
+
95
+ result.success?.should == true
96
+ result.evidence.category.should == "GENERAL"
97
+ result.evidence.url.should include("bt_logo.png")
98
+ end
90
99
  end
91
100
 
92
101
  describe "self.add_text_evidence" do
@@ -94,6 +103,7 @@ describe Braintree::Dispute do
94
103
  result = Braintree::Dispute.add_text_evidence(dispute.id, "text evidence")
95
104
 
96
105
  result.success?.should == true
106
+ result.evidence.category.should == nil
97
107
  result.evidence.comment.should == "text evidence"
98
108
  result.evidence.created_at.between?(Time.now - 10, Time.now).should == true
99
109
  result.evidence.id.should =~ /^\w{16,}$/
@@ -131,6 +141,7 @@ describe Braintree::Dispute do
131
141
  result = Braintree::Dispute.add_text_evidence(dispute.id, { content: "123456789", tag: "REFUND_ID", sequence_number: 7 })
132
142
 
133
143
  result.success?.should == true
144
+ result.evidence.category.should == "REFUND_ID"
134
145
  result.evidence.comment.should == "123456789"
135
146
  result.evidence.created_at.between?(Time.now - 10, Time.now).should == true
136
147
  result.evidence.id.should =~ /^\w{16,}$/
@@ -227,4 +238,66 @@ describe Braintree::Dispute do
227
238
  result.errors.for(:dispute)[0].message.should == "Evidence can only be removed from disputes that are in an Open state"
228
239
  end
229
240
  end
241
+
242
+ context "categorized evidence" do
243
+ it "fails to create file evidence for an unsupported category" do
244
+ result = Braintree::Dispute.add_file_evidence(dispute.id, {category: "NOTREALCATEGORY", document_id: document_upload.id})
245
+
246
+ result.success?.should == false
247
+ result.errors.for(:dispute)[0].code.should == Braintree::ErrorCodes::Dispute::CanOnlyCreateEvidenceWithValidCategory
248
+ end
249
+
250
+ it "fails to create text evidence for an unsupported category" do
251
+ result = Braintree::Dispute.add_text_evidence(dispute.id, {category: "NOTREALCATEGORY", content: "evidence"})
252
+
253
+ result.success?.should == false
254
+ result.errors.for(:dispute)[0].code.should == Braintree::ErrorCodes::Dispute::CanOnlyCreateEvidenceWithValidCategory
255
+ end
256
+
257
+ it "fails to create text evidence for a file only category MERCHANT_WEBSITE_OR_APP_ACCESS" do
258
+ result = Braintree::Dispute.add_text_evidence(dispute.id, {category: "MERCHANT_WEBSITE_OR_APP_ACCESS", content: "evidence"})
259
+
260
+ result.success?.should == false
261
+ result.errors.for(:dispute)[0].code.should == Braintree::ErrorCodes::Dispute::EvidenceCategoryDocumentOnly
262
+ end
263
+
264
+ it "fails to create file evidence for a text only category DEVICE_ID" do
265
+ result = Braintree::Dispute.add_file_evidence(dispute.id, {category: "DEVICE_ID", document_id: document_upload.id})
266
+
267
+ result.success?.should == false
268
+ result.errors.for(:dispute)[0].code.should == Braintree::ErrorCodes::Dispute::EvidenceCategoryTextOnly
269
+ end
270
+
271
+ it "fails to create evidence with an invalid date time format" do
272
+ result = Braintree::Dispute.add_text_evidence(dispute.id, {category: "DOWNLOAD_DATE_TIME", content: "baddate"})
273
+
274
+ result.success?.should == false
275
+ result.errors.for(:dispute)[0].code.should == Braintree::ErrorCodes::Dispute::EvidenceContentDateInvalid
276
+ end
277
+
278
+ it "successfully creates text evidence with an valid date time format" do
279
+ result = Braintree::Dispute.add_text_evidence(dispute.id, {category: "DOWNLOAD_DATE_TIME", content: "2018-10-20T18:00:00-0500"})
280
+
281
+ result.success?.should == true
282
+ end
283
+
284
+ it "fails to finalize a dispute with digital goods missing" do
285
+ Braintree::Dispute.add_text_evidence(dispute.id, {category: "DEVICE_ID", content: "iphone_id"})
286
+ result = Braintree::Dispute.finalize(dispute.id)
287
+
288
+ result.success?.should == false
289
+ error_codes = result.errors.for(:dispute).map(&:code)
290
+
291
+ error_codes.should include(Braintree::ErrorCodes::Dispute::DigitalGoodsMissingDownloadDate)
292
+ error_codes.should include(Braintree::ErrorCodes::Dispute::DigitalGoodsMissingEvidence)
293
+ end
294
+
295
+ it "fails to finalize a dispute with partial non-disputed transaction information provided" do
296
+ Braintree::Dispute.add_text_evidence(dispute.id, {category: "PRIOR_NON_DISPUTED_TRANSACTION_ARN", content: "123"})
297
+ result = Braintree::Dispute.finalize(dispute.id)
298
+
299
+ result.success?.should == false
300
+ result.errors.for(:dispute)[0].code.should == Braintree::ErrorCodes::Dispute::NonDisputedPriorTransactionEvidenceMissingDate
301
+ end
302
+ end
230
303
  end
@@ -200,6 +200,18 @@ describe Braintree::PaymentMethod do
200
200
  venmo_account.customer_id.should == customer.id
201
201
  end
202
202
 
203
+ it "raise server error when we attempt to create europe bank account payment method" do
204
+ customer = Braintree::Customer.create.customer
205
+ token = SecureRandom.hex(16)
206
+ expect do
207
+ Braintree::PaymentMethod.create(
208
+ :payment_method_nonce => Braintree::Test::Nonce::Europe,
209
+ :customer_id => customer.id,
210
+ :token => token
211
+ )
212
+ end.to raise_error(Braintree::ServerError)
213
+ end
214
+
203
215
  it "allows passing the make_default option alongside the nonce" do
204
216
  customer = Braintree::Customer.create!
205
217
  result = Braintree::CreditCard.create(
@@ -534,10 +546,12 @@ describe Braintree::PaymentMethod do
534
546
  result.should be_success
535
547
  result.payment_method.should be_a(Braintree::PayPalAccount)
536
548
  result.payment_method.image_url.should_not be_nil
549
+ result.payment_method.payer_id.should_not be_nil
537
550
  token = result.payment_method.token
538
551
 
539
552
  found_paypal_account = Braintree::PayPalAccount.find(token)
540
553
  found_paypal_account.should_not be_nil
554
+ found_paypal_account.payer_id.should_not be_nil
541
555
  end
542
556
 
543
557
  it "creates a billing agreement payment method from a refresh token" do
@@ -550,11 +564,13 @@ describe Braintree::PaymentMethod do
550
564
  result.should be_success
551
565
  result.payment_method.should be_a(Braintree::PayPalAccount)
552
566
  result.payment_method.billing_agreement_id.should eq("B_FAKE_ID")
567
+ result.payment_method.payer_id.should_not be_nil
553
568
  token = result.payment_method.token
554
569
 
555
570
  found_paypal_account = Braintree::PayPalAccount.find(token)
556
571
  found_paypal_account.should_not be_nil
557
572
  found_paypal_account.billing_agreement_id.should eq("B_FAKE_ID")
573
+ found_paypal_account.payer_id.should_not be_nil
558
574
  end
559
575
 
560
576
  it "creates a billing agreement payment method from a refresh token without upgrading" do
@@ -130,6 +130,29 @@ describe Braintree::Dispute do
130
130
  Braintree::Dispute.add_file_evidence("dispute_id", 8675309)
131
131
  end.to_not raise_error
132
132
  end
133
+
134
+ describe "with optional params" do
135
+ it "does not raise an exception if the optional parameters are valid" do
136
+ Braintree::Http.stub(:new).and_return double.as_null_object
137
+ expect do
138
+ Braintree::Dispute.add_file_evidence("dispute_id", { category: "GENERAL", document_id: "document_id" })
139
+ end.to_not raise_error
140
+ end
141
+
142
+ it "raises an exception if the optional params contain invalid keys" do
143
+ expect do
144
+ Braintree::Dispute.add_file_evidence("dispute_id", { random_param: "" })
145
+ end.to raise_error(ArgumentError)
146
+ end
147
+
148
+ it "raises an exception if the param tag is not a string" do
149
+ Braintree::Http.stub(:new).and_return double.as_null_object
150
+
151
+ expect do
152
+ Braintree::Dispute.add_file_evidence("dispute_id", { category: 3, document_id: "document_id" })
153
+ end.to raise_error(ArgumentError)
154
+ end
155
+ end
133
156
  end
134
157
 
135
158
  describe "self.add_text_evidence" do
@@ -173,26 +196,40 @@ describe Braintree::Dispute do
173
196
 
174
197
  describe "with optional params" do
175
198
  it "does not raise an exception if the optional parameters are valid" do
199
+ Braintree::Http.stub(:new).and_return double.as_null_object
176
200
  expect do
177
- Braintree::Dispute.add_text_evidence("dispute_id", nil, { tag: "", sequence_number: 3 })
178
- end.to raise_error
201
+ Braintree::Dispute.add_text_evidence("dispute_id", { content: "a", tag: "", sequence_number: 3 })
202
+ end.to_not raise_error
203
+ end
204
+
205
+ it "does not raise an exception if the category parameter is provided" do
206
+ Braintree::Http.stub(:new).and_return double.as_null_object
207
+ expect do
208
+ Braintree::Dispute.add_text_evidence("dispute_id", { content: "a", category: "", sequence_number: 3 })
209
+ end.to_not raise_error
179
210
  end
180
211
 
181
212
  it "raises an exception if the optional params contain invalid keys" do
182
213
  expect do
183
- Braintree::Dispute.add_text_evidence("dispute_id", nil, { random_param: "" })
214
+ Braintree::Dispute.add_text_evidence("dispute_id", { random_param: "" })
184
215
  end.to raise_error(ArgumentError)
185
216
  end
186
217
 
187
218
  it "raises an exception if sequence_number is provided and not an integer" do
188
219
  expect do
189
- Braintree::Dispute.add_text_evidence("dispute_id", nil, { sequence_number: "abc" })
220
+ Braintree::Dispute.add_text_evidence("dispute_id", { sequence_number: "abc" })
190
221
  end.to raise_error(ArgumentError)
191
222
  end
192
223
 
193
224
  it "raises an exception if the param tag is not a string" do
194
225
  expect do
195
- Braintree::Dispute.add_text_evidence("dispute_id", nil, { tag: 3 })
226
+ Braintree::Dispute.add_text_evidence("dispute_id", { tag: 3 })
227
+ end.to raise_error(ArgumentError)
228
+ end
229
+
230
+ it "raises an exception if the param category is not a string" do
231
+ expect do
232
+ Braintree::Dispute.add_text_evidence("dispute_id", { category: 3 })
196
233
  end.to raise_error(ArgumentError)
197
234
  end
198
235
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braintree
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.85.0
4
+ version: 2.86.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Braintree
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-15 00:00:00.000000000 Z
11
+ date: 2018-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: builder
@@ -185,7 +185,6 @@ files:
185
185
  - spec/fixtures/files/gif_extension_bt_logo.gif
186
186
  - spec/fixtures/files/malformed_pdf.pdf
187
187
  - spec/hacks/tcp_socket.rb
188
- - spec/httpsd.pid
189
188
  - spec/integration/braintree/add_on_spec.rb
190
189
  - spec/integration/braintree/address_spec.rb
191
190
  - spec/integration/braintree/advanced_search_spec.rb
data/spec/httpsd.pid DELETED
@@ -1 +0,0 @@
1
- 2671