braintree 2.76.0 → 2.77.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/braintree.rb +12 -0
- data/lib/braintree/apple_pay.rb +29 -0
- data/lib/braintree/apple_pay_card.rb +1 -1
- data/lib/braintree/apple_pay_gateway.rb +37 -0
- data/lib/braintree/apple_pay_options.rb +19 -0
- data/lib/braintree/authorization_adjustment.rb +20 -0
- data/lib/braintree/dispute.rb +78 -9
- data/lib/braintree/dispute/evidence.rb +18 -0
- data/lib/braintree/dispute/history_event.rb +14 -0
- data/lib/braintree/dispute/transaction.rb +18 -0
- data/lib/braintree/dispute_gateway.rb +118 -0
- data/lib/braintree/dispute_search.rb +30 -0
- data/lib/braintree/document_upload.rb +34 -0
- data/lib/braintree/document_upload_gateway.rb +32 -0
- data/lib/braintree/error_codes.rb +17 -0
- data/lib/braintree/facilitated_details.rb +19 -0
- data/lib/braintree/gateway.rb +12 -0
- data/lib/braintree/http.rb +60 -12
- data/lib/braintree/successful_result.rb +1 -1
- data/lib/braintree/test/credit_card.rb +6 -0
- data/lib/braintree/transaction.rb +4 -0
- data/lib/braintree/version.rb +1 -1
- data/lib/braintree/webhook_testing_gateway.rb +196 -19
- data/spec/fixtures/files/bt_logo.png +0 -0
- data/spec/fixtures/files/gif_extension_bt_logo.gif +0 -0
- data/spec/fixtures/files/malformed_pdf.pdf +1 -0
- data/spec/httpsd.pid +1 -1
- data/spec/integration/braintree/apple_pay_spec.rb +92 -0
- data/spec/integration/braintree/coinbase_spec.rb +15 -12
- data/spec/integration/braintree/dispute_search_spec.rb +49 -0
- data/spec/integration/braintree/dispute_spec.rb +216 -0
- data/spec/integration/braintree/document_upload_spec.rb +55 -0
- data/spec/integration/braintree/http_spec.rb +8 -0
- data/spec/integration/braintree/payment_method_spec.rb +5 -16
- data/spec/integration/braintree/transaction_spec.rb +21 -4
- data/spec/spec_helper.rb +3 -2
- data/spec/unit/braintree/apple_pay_card_spec.rb +6 -0
- data/spec/unit/braintree/dispute_search_spec.rb +59 -0
- data/spec/unit/braintree/dispute_spec.rb +331 -8
- data/spec/unit/braintree/document_upload_spec.rb +35 -0
- data/spec/unit/braintree/http_spec.rb +21 -0
- data/spec/unit/braintree/transaction_spec.rb +17 -0
- data/spec/unit/braintree/webhook_notification_spec.rb +74 -51
- metadata +24 -3
@@ -69,6 +69,14 @@ describe Braintree::Http do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
+
it "posts multipart for file uploads" do
|
73
|
+
config = Braintree::Configuration.instantiate
|
74
|
+
file = File.new("#{File.dirname(__FILE__)}/../../fixtures/files/bt_logo.png", "r")
|
75
|
+
response = config.http.post("#{config.base_merchant_path}/document_uploads", {"document_upload[kind]" => "evidence_document"}, file)
|
76
|
+
response[:document_upload][:content_type].should == "image/png"
|
77
|
+
response[:document_upload][:id].should_not be_nil
|
78
|
+
end
|
79
|
+
|
72
80
|
describe "user_agent" do
|
73
81
|
after do
|
74
82
|
Braintree::Configuration.custom_user_agent = nil
|
@@ -1223,29 +1223,18 @@ describe Braintree::PaymentMethod do
|
|
1223
1223
|
end
|
1224
1224
|
|
1225
1225
|
context "coinbase accounts" do
|
1226
|
-
it "
|
1226
|
+
it "cannot create a payment method token with Coinbase" do
|
1227
1227
|
customer = Braintree::Customer.create!
|
1228
|
-
result = Braintree::CreditCard.create(
|
1229
|
-
:customer_id => customer.id,
|
1230
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1231
|
-
:expiration_date => "05/2009",
|
1232
|
-
:options => {:make_default => true}
|
1233
|
-
)
|
1234
|
-
result.should be_success
|
1235
1228
|
|
1236
1229
|
nonce = Braintree::Test::Nonce::Coinbase
|
1237
|
-
|
1230
|
+
result = Braintree::PaymentMethod.create(
|
1238
1231
|
:payment_method_nonce => nonce,
|
1239
1232
|
:customer_id => customer.id
|
1240
|
-
).payment_method.token
|
1241
|
-
|
1242
|
-
updated_result = Braintree::PaymentMethod.update(
|
1243
|
-
original_token,
|
1244
|
-
:options => {:make_default => true}
|
1245
1233
|
)
|
1246
1234
|
|
1247
|
-
|
1248
|
-
|
1235
|
+
result.should_not be_success
|
1236
|
+
|
1237
|
+
result.errors.for(:coinbase_account).first.code.should == Braintree::ErrorCodes::PaymentMethod::PaymentMethodNoLongerSupported
|
1249
1238
|
end
|
1250
1239
|
end
|
1251
1240
|
|
@@ -4329,6 +4329,19 @@ describe Braintree::Transaction do
|
|
4329
4329
|
end
|
4330
4330
|
end
|
4331
4331
|
|
4332
|
+
describe "authorization_adjustments" do
|
4333
|
+
it "includes authorization adjustments on found transactions" do
|
4334
|
+
found_transaction = Braintree::Transaction.find("authadjustmenttransaction")
|
4335
|
+
|
4336
|
+
found_transaction.authorization_adjustments.count.should == 1
|
4337
|
+
|
4338
|
+
authorization_adjustment = found_transaction.authorization_adjustments.first
|
4339
|
+
authorization_adjustment.amount.should == "-20.00"
|
4340
|
+
authorization_adjustment.success.should == true
|
4341
|
+
authorization_adjustment.timestamp.should be_a Time
|
4342
|
+
end
|
4343
|
+
end
|
4344
|
+
|
4332
4345
|
describe "vault_credit_card" do
|
4333
4346
|
it "returns the Braintree::CreditCard if the transaction credit card is stored in the vault" do
|
4334
4347
|
customer = Braintree::Customer.create!(
|
@@ -4700,6 +4713,9 @@ describe Braintree::Transaction do
|
|
4700
4713
|
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
4701
4714
|
:amount => Braintree::Test::TransactionAmounts::Authorize
|
4702
4715
|
)
|
4716
|
+
result.transaction.facilitated_details.merchant_id.should == "integration_merchant_id"
|
4717
|
+
result.transaction.facilitated_details.merchant_name.should == "14ladders"
|
4718
|
+
result.transaction.facilitated_details.payment_method_nonce.should == grant_result.payment_method_nonce.nonce
|
4703
4719
|
result.transaction.facilitator_details.should_not == nil
|
4704
4720
|
result.transaction.facilitator_details.oauth_application_client_id.should == "client_id$#{Braintree::Configuration.environment}$integration_client_id"
|
4705
4721
|
result.transaction.facilitator_details.oauth_application_name.should == "PseudoShop"
|
@@ -4715,9 +4731,7 @@ describe Braintree::Transaction do
|
|
4715
4731
|
)
|
4716
4732
|
|
4717
4733
|
result.transaction.billing_details.postal_code == "95131"
|
4718
|
-
|
4719
|
-
|
4720
|
-
|
4734
|
+
end
|
4721
4735
|
|
4722
4736
|
it "allows transactions to be created with a shared payment method, customer, billing and shipping addresses" do
|
4723
4737
|
result = @granting_gateway.transaction.sale(
|
@@ -4732,11 +4746,14 @@ describe Braintree::Transaction do
|
|
4732
4746
|
result.transaction.billing_details.first_name.should == @address.first_name
|
4733
4747
|
end
|
4734
4748
|
|
4735
|
-
it "
|
4749
|
+
it "facilitated details are returned on transaction created via a shared_payment_method_token" do
|
4736
4750
|
result = @granting_gateway.transaction.sale(
|
4737
4751
|
:shared_payment_method_token => @credit_card.token,
|
4738
4752
|
:amount => Braintree::Test::TransactionAmounts::Authorize
|
4739
4753
|
)
|
4754
|
+
result.transaction.facilitated_details.merchant_id.should == "integration_merchant_id"
|
4755
|
+
result.transaction.facilitated_details.merchant_name.should == "14ladders"
|
4756
|
+
result.transaction.facilitated_details.payment_method_nonce.should == nil
|
4740
4757
|
result.transaction.facilitator_details.should_not == nil
|
4741
4758
|
result.transaction.facilitator_details.oauth_application_client_id.should == "client_id$#{Braintree::Configuration.environment}$integration_client_id"
|
4742
4759
|
result.transaction.facilitator_details.oauth_application_name.should == "PseudoShop"
|
data/spec/spec_helper.rb
CHANGED
@@ -145,8 +145,9 @@ unless defined?(SPEC_HELPER_LOADED)
|
|
145
145
|
def self.simulate_form_post_for_tr(tr_data_string, form_data_hash, url = Braintree::TransparentRedirect.url)
|
146
146
|
response = nil
|
147
147
|
config = Braintree::Configuration.instantiate
|
148
|
-
Net::HTTP.
|
149
|
-
|
148
|
+
http = Net::HTTP.new(config.server, config.port)
|
149
|
+
http.use_ssl = config.ssl?
|
150
|
+
http.start do |http|
|
150
151
|
request = Net::HTTP::Post.new("/" + url.split("/", 4)[3])
|
151
152
|
request.add_field "Content-Type", "application/x-www-form-urlencoded"
|
152
153
|
request.body = Braintree::Util.hash_to_query_string({:tr_data => tr_data_string}.merge(form_data_hash))
|
@@ -1,6 +1,12 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
3
|
describe Braintree::ApplePayCard do
|
4
|
+
describe "bin" do
|
5
|
+
it "returns Apple pay card bin" do
|
6
|
+
Braintree::ApplePayCard._new(:gateway, bin: '411111').bin.should == '411111'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
describe "default?" do
|
5
11
|
it "is true if the Apple pay card is the default payment method for the customer" do
|
6
12
|
Braintree::ApplePayCard._new(:gateway, :default => true).default?.should == true
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Braintree::DisputeSearch do
|
4
|
+
it "overrides previous 'is' with new 'is' for the same field" do
|
5
|
+
search = Braintree::DisputeSearch.new
|
6
|
+
search.id.is "dispute1"
|
7
|
+
search.id.is "dispute2"
|
8
|
+
search.to_hash.should == {:id => {:is => "dispute2"}}
|
9
|
+
end
|
10
|
+
|
11
|
+
it "overrides previous 'in' with new 'in' for the same field" do
|
12
|
+
search = Braintree::DisputeSearch.new
|
13
|
+
search.status.in Braintree::Dispute::Status::Open
|
14
|
+
search.status.in Braintree::Dispute::Status::Won
|
15
|
+
search.to_hash.should == {:status => [Braintree::Dispute::Status::Won]}
|
16
|
+
end
|
17
|
+
|
18
|
+
[
|
19
|
+
:amount_disputed,
|
20
|
+
:amount_won,
|
21
|
+
:case_number,
|
22
|
+
:id,
|
23
|
+
:merchant_account_id,
|
24
|
+
:reason_code,
|
25
|
+
:received_date,
|
26
|
+
:reference_number,
|
27
|
+
:reply_by_date,
|
28
|
+
:transaction_id,
|
29
|
+
].each do |field|
|
30
|
+
it "allows searching on #{field}" do
|
31
|
+
search = Braintree::DisputeSearch.new
|
32
|
+
|
33
|
+
expect do
|
34
|
+
search.send(field).is "hello"
|
35
|
+
end.not_to raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
[
|
40
|
+
:kind,
|
41
|
+
:reason,
|
42
|
+
:status,
|
43
|
+
:transaction_source,
|
44
|
+
].each do |field|
|
45
|
+
it "raises if provided an unknown #{field} value" do
|
46
|
+
search = Braintree::DisputeSearch.new
|
47
|
+
expect do
|
48
|
+
search.send(field).is "unknown value"
|
49
|
+
end.to raise_error(/Invalid argument/)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "raises if no operator is provided" do
|
54
|
+
search = Braintree::DisputeSearch.new
|
55
|
+
expect do
|
56
|
+
search.id "one"
|
57
|
+
end.to raise_error(RuntimeError, "An operator is required")
|
58
|
+
end
|
59
|
+
end
|
@@ -1,15 +1,338 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
3
|
describe Braintree::Dispute do
|
4
|
+
let(:attributes) do
|
5
|
+
{
|
6
|
+
:id => "open_dispute",
|
7
|
+
:amount => "31.00",
|
8
|
+
:amount_disputed => "500.00",
|
9
|
+
:amount_won => "0.00",
|
10
|
+
:created_at => Time.utc(2009, 3, 9, 10, 50, 39),
|
11
|
+
:date_opened => "2009-03-09",
|
12
|
+
:date_won => "2009-04-15",
|
13
|
+
:original_dispute_id => "original_dispute_id",
|
14
|
+
:received_date => "2009-03-09",
|
15
|
+
:reply_by_date => nil,
|
16
|
+
:updated_at => Time.utc(2009, 3, 9, 10, 50, 39),
|
17
|
+
:evidence => [
|
18
|
+
{
|
19
|
+
comment: nil,
|
20
|
+
created_at: Time.utc(2009, 3, 10, 12, 5, 20),
|
21
|
+
id: "evidence1",
|
22
|
+
sent_to_processor_at: nil,
|
23
|
+
url: "url_of_file_evidence",
|
24
|
+
},
|
25
|
+
{
|
26
|
+
comment: "text evidence",
|
27
|
+
created_at: Time.utc(2009, 3, 10, 12, 5, 21),
|
28
|
+
id: "evidence2",
|
29
|
+
sent_to_processor_at: "2009-03-13",
|
30
|
+
url: nil,
|
31
|
+
}
|
32
|
+
],
|
33
|
+
:status_history => [
|
34
|
+
{
|
35
|
+
:effective_date => "2009-03-09",
|
36
|
+
:status => "open",
|
37
|
+
:timestamp => Time.utc(2009, 3, 9, 10, 50, 39),
|
38
|
+
}
|
39
|
+
],
|
40
|
+
:transaction => {
|
41
|
+
:amount => "31.00",
|
42
|
+
:id => "open_disputed_transaction",
|
43
|
+
:created_at => Time.utc(2009, 2, 9, 12, 59, 59),
|
44
|
+
:order_id => nil,
|
45
|
+
:purchase_order_number => "po",
|
46
|
+
:payment_instrument_subtype => "Visa",
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
[
|
52
|
+
:accept,
|
53
|
+
:finalize,
|
54
|
+
:find
|
55
|
+
].each do |method_name|
|
56
|
+
describe "self.#{method_name}" do
|
57
|
+
it "raises an exception if the id is blank" do
|
58
|
+
expect do
|
59
|
+
Braintree::Dispute.public_send(method_name, " ")
|
60
|
+
end.to raise_error(ArgumentError)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "raises an exception if the id is nil" do
|
64
|
+
expect do
|
65
|
+
Braintree::Dispute.public_send(method_name, nil)
|
66
|
+
end.to raise_error(ArgumentError)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "does not raise an exception if the id is a fixnum" do
|
70
|
+
Braintree::Http.stub(:new).and_return double.as_null_object
|
71
|
+
Braintree::Dispute.stub(:_new).and_return nil
|
72
|
+
Braintree::ErrorResult.stub(:new).and_return nil
|
73
|
+
|
74
|
+
expect do
|
75
|
+
Braintree::Dispute.public_send(method_name, 8675309)
|
76
|
+
end.to_not raise_error
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "self.add_file_evidence" do
|
82
|
+
it "raises an exception if the dispute_id is blank" do
|
83
|
+
expect do
|
84
|
+
Braintree::Dispute.add_file_evidence(" ", "doc_upload_id")
|
85
|
+
end.to raise_error(ArgumentError)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "raises an exception if the dispute_id is nil" do
|
89
|
+
expect do
|
90
|
+
Braintree::Dispute.add_file_evidence(nil, "doc_upload_id")
|
91
|
+
end.to raise_error(ArgumentError)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "raises an exception if the dispute_id contains invalid characters" do
|
95
|
+
expect do
|
96
|
+
Braintree::Dispute.add_file_evidence("@#$%", "doc_upload_id")
|
97
|
+
end.to raise_error(ArgumentError)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "does not raise an exception if the dispute_id is a fixnum" do
|
101
|
+
Braintree::Http.stub(:new).and_return double.as_null_object
|
102
|
+
Braintree::Dispute.stub(:_new).and_return nil
|
103
|
+
expect do
|
104
|
+
Braintree::Dispute.add_file_evidence(8675309, "doc_upload_id")
|
105
|
+
end.to_not raise_error
|
106
|
+
end
|
107
|
+
|
108
|
+
it "raises an exception if the document_upload_id is blank" do
|
109
|
+
expect do
|
110
|
+
Braintree::Dispute.add_file_evidence("dispute_id", " ")
|
111
|
+
end.to raise_error(ArgumentError)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "raises an exception if the document_upload_id is nil" do
|
115
|
+
expect do
|
116
|
+
Braintree::Dispute.add_file_evidence("dispute_id", nil)
|
117
|
+
end.to raise_error(ArgumentError)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "raises an exception if the document_upload_id contains invalid characters" do
|
121
|
+
expect do
|
122
|
+
Braintree::Dispute.add_file_evidence("dispute_id", "@#$%")
|
123
|
+
end.to raise_error(ArgumentError)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "does not raise an exception if the document_upload_id is a fixnum" do
|
127
|
+
Braintree::Http.stub(:new).and_return double.as_null_object
|
128
|
+
Braintree::Dispute.stub(:_new).and_return nil
|
129
|
+
expect do
|
130
|
+
Braintree::Dispute.add_file_evidence("dispute_id", 8675309)
|
131
|
+
end.to_not raise_error
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "self.add_text_evidence" do
|
136
|
+
it "raises an exception if the id is blank" do
|
137
|
+
expect do
|
138
|
+
Braintree::Dispute.add_text_evidence(" ", "text evidence")
|
139
|
+
end.to raise_error(ArgumentError)
|
140
|
+
end
|
141
|
+
|
142
|
+
it "raises an exception if the id is nil" do
|
143
|
+
expect do
|
144
|
+
Braintree::Dispute.add_text_evidence(nil, "text evidence")
|
145
|
+
end.to raise_error(ArgumentError)
|
146
|
+
end
|
147
|
+
|
148
|
+
it "raises an exception if the id contains invalid characters" do
|
149
|
+
expect do
|
150
|
+
Braintree::Dispute.add_text_evidence("@#$%", "text evidence")
|
151
|
+
end.to raise_error(ArgumentError)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "does not raise an exception if the id is a fixnum" do
|
155
|
+
Braintree::Http.stub(:new).and_return double.as_null_object
|
156
|
+
Braintree::Dispute.stub(:_new).and_return nil
|
157
|
+
expect do
|
158
|
+
Braintree::Dispute.add_text_evidence(8675309, "text evidence")
|
159
|
+
end.to_not raise_error
|
160
|
+
end
|
161
|
+
|
162
|
+
it "raises an exception if the content is blank" do
|
163
|
+
expect do
|
164
|
+
Braintree::Dispute.add_text_evidence("dispute_id", " ")
|
165
|
+
end.to raise_error(ArgumentError)
|
166
|
+
end
|
167
|
+
|
168
|
+
it "raises an exception if the content is nil" do
|
169
|
+
expect do
|
170
|
+
Braintree::Dispute.add_text_evidence("dispute_id", nil)
|
171
|
+
end.to raise_error(ArgumentError)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "self.remove_evidence" do
|
176
|
+
it "raises an exception if the dispute_id is blank" do
|
177
|
+
expect do
|
178
|
+
Braintree::Dispute.remove_evidence(" ")
|
179
|
+
end.to raise_error(ArgumentError)
|
180
|
+
end
|
181
|
+
|
182
|
+
it "raises an exception if the dispute_id is nil" do
|
183
|
+
expect do
|
184
|
+
Braintree::Dispute.remove_evidence(nil)
|
185
|
+
end.to raise_error(ArgumentError)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "raises an exception if the content is blank" do
|
189
|
+
expect do
|
190
|
+
Braintree::Dispute.remove_evidence("dispute_id", " ")
|
191
|
+
end.to raise_error(ArgumentError)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "raises an exception if the content is nil" do
|
195
|
+
expect do
|
196
|
+
Braintree::Dispute.remove_evidence("dispute_id", nil)
|
197
|
+
end.to raise_error(ArgumentError)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "raises an exception if the dispute_id contains invalid characters" do
|
201
|
+
expect do
|
202
|
+
Braintree::Dispute.remove_evidence("@#$%", "evidence_id")
|
203
|
+
end.to raise_error(ArgumentError)
|
204
|
+
end
|
205
|
+
|
206
|
+
it "raises an exception if the evidence_id contains invalid characters" do
|
207
|
+
expect do
|
208
|
+
Braintree::Dispute.remove_evidence("dispute_id", "@#$%")
|
209
|
+
end.to raise_error(ArgumentError)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
4
213
|
describe "initialize" do
|
5
|
-
it "
|
6
|
-
dispute = Braintree::Dispute._new(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
214
|
+
it "converts string amount_dispute and amount_won" do
|
215
|
+
dispute = Braintree::Dispute._new(attributes)
|
216
|
+
|
217
|
+
dispute.amount_disputed.should == 500.0
|
218
|
+
dispute.amount_won.should == 0.0
|
219
|
+
end
|
220
|
+
|
221
|
+
[
|
222
|
+
:reply_by_date,
|
223
|
+
:amount,
|
224
|
+
:date_opened,
|
225
|
+
:date_won,
|
226
|
+
:status_history,
|
227
|
+
].each do |field|
|
228
|
+
it "handles nil #{field}" do
|
229
|
+
attributes.delete(field)
|
230
|
+
|
231
|
+
dispute = Braintree::Dispute._new(attributes)
|
232
|
+
|
233
|
+
dispute.send(field).should == nil
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
it "converts date_opened, date_won, reply_by_date, received_date from String to Date" do
|
238
|
+
dispute = Braintree::Dispute._new(attributes.merge(:reply_by_date => "2009-03-14"))
|
239
|
+
|
240
|
+
dispute.date_opened.should == Date.new(2009, 3, 9)
|
241
|
+
dispute.date_won.should == Date.new(2009, 4, 15)
|
242
|
+
dispute.received_date.should == Date.new(2009, 3, 9)
|
243
|
+
dispute.reply_by_date.should == Date.new(2009, 3, 14)
|
244
|
+
end
|
245
|
+
|
246
|
+
it "converts transaction hash into a Dispute::TransactionDetails object first" do
|
247
|
+
dispute = Braintree::Dispute._new(attributes)
|
248
|
+
|
249
|
+
dispute.transaction_details.id.should == "open_disputed_transaction"
|
250
|
+
dispute.transaction_details.amount.should == 31.00
|
251
|
+
end
|
252
|
+
|
253
|
+
it "converts transaction hash into a Dispute::Transaction object" do
|
254
|
+
dispute = Braintree::Dispute._new(attributes)
|
255
|
+
|
256
|
+
dispute.transaction.amount.should == 31.00
|
257
|
+
dispute.transaction.id.should == "open_disputed_transaction"
|
258
|
+
dispute.transaction.order_id.should == nil
|
259
|
+
dispute.transaction.purchase_order_number.should == "po"
|
260
|
+
dispute.transaction.payment_instrument_subtype.should == "Visa"
|
261
|
+
end
|
262
|
+
|
263
|
+
it "converts status_history hash into an array of Dispute::HistoryEvent objects" do
|
264
|
+
dispute = Braintree::Dispute._new(attributes)
|
265
|
+
|
266
|
+
dispute.status_history.length.should == 1
|
267
|
+
status_history_1 = dispute.status_history.first
|
268
|
+
status_history_1.status.should == Braintree::Dispute::Status::Open
|
269
|
+
status_history_1.timestamp.should == Time.utc(2009, 3, 9, 10, 50, 39)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "converts evidence hash into an array of Dispute::Evidence objects" do
|
273
|
+
dispute = Braintree::Dispute._new(attributes)
|
274
|
+
|
275
|
+
dispute.evidence.length.should ==2
|
276
|
+
evidence1 = dispute.evidence.first
|
277
|
+
evidence1.comment.should == nil
|
278
|
+
evidence1.created_at.should == Time.utc(2009, 3, 10, 12, 5, 20)
|
279
|
+
evidence1.id.should == "evidence1"
|
280
|
+
evidence1.sent_to_processor_at.should == nil
|
281
|
+
evidence1.url.should == "url_of_file_evidence"
|
282
|
+
|
283
|
+
evidence2 = dispute.evidence.last
|
284
|
+
evidence2.comment.should == "text evidence"
|
285
|
+
evidence2.created_at.should == Time.utc(2009, 3, 10, 12, 5, 21)
|
286
|
+
evidence2.id.should == "evidence2"
|
287
|
+
evidence2.sent_to_processor_at.should == Date.new(2009, 3, 13)
|
288
|
+
evidence2.url.should == nil
|
289
|
+
end
|
290
|
+
|
291
|
+
it "handles nil evidence" do
|
292
|
+
attributes.delete(:evidence)
|
293
|
+
|
294
|
+
dispute = Braintree::Dispute._new(attributes)
|
295
|
+
|
296
|
+
dispute.evidence.should == nil
|
297
|
+
end
|
298
|
+
|
299
|
+
it "sets the older webhook fields for backwards compatibility" do
|
300
|
+
dispute = Braintree::Dispute._new(attributes)
|
301
|
+
|
302
|
+
dispute.amount.should == 31.00
|
303
|
+
dispute.date_opened.should == Date.new(2009, 3, 9)
|
304
|
+
dispute.date_won.should == Date.new(2009, 4, 15)
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
describe "==" do
|
309
|
+
it "returns true when given a dispute with the same id" do
|
310
|
+
first = Braintree::Dispute._new(attributes)
|
311
|
+
second = Braintree::Dispute._new(attributes)
|
312
|
+
|
313
|
+
first.should == second
|
314
|
+
second.should == first
|
315
|
+
end
|
316
|
+
|
317
|
+
it "returns false when given a dispute with a different id" do
|
318
|
+
first = Braintree::Dispute._new(attributes)
|
319
|
+
second = Braintree::Dispute._new(attributes.merge(:id => "1234"))
|
320
|
+
|
321
|
+
first.should_not == second
|
322
|
+
second.should_not == first
|
323
|
+
end
|
324
|
+
|
325
|
+
it "returns false when not given a dispute" do
|
326
|
+
dispute = Braintree::Dispute._new(attributes)
|
327
|
+
dispute.should_not == "not a dispute"
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
describe "new" do
|
332
|
+
it "is protected" do
|
333
|
+
expect do
|
334
|
+
Braintree::Dispute.new
|
335
|
+
end.to raise_error(NoMethodError, /protected method .new/)
|
13
336
|
end
|
14
337
|
end
|
15
338
|
end
|