braintree 2.82.0 → 2.83.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.
- checksums.yaml +4 -4
- data/braintree.gemspec +1 -1
- data/lib/braintree/error_codes.rb +7 -2
- data/lib/braintree/transaction_gateway.rb +1 -1
- data/lib/braintree/transaction_line_item.rb +6 -0
- data/lib/braintree/version.rb +1 -1
- data/lib/braintree/webhook_notification.rb +1 -0
- data/lib/braintree/webhook_notification_gateway.rb +2 -0
- data/lib/braintree/webhook_testing.rb +2 -2
- data/lib/braintree/webhook_testing_gateway.rb +8 -3
- data/spec/integration/braintree/payment_method_spec.rb +59 -5
- data/spec/integration/braintree/transaction_line_item_spec.rb +38 -0
- data/spec/integration/braintree/transaction_spec.rb +113 -4
- data/spec/unit/braintree/webhook_notification_spec.rb +35 -0
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 37cea606be7947a8b853f64c671fdbf463b53a6f
|
|
4
|
+
data.tar.gz: 62c6fa628bcd6bef30444c9bd3949167ba89e994
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7112f55aed9b3218f0112ed9c5a07f82f523eba4ea6553c45495ef93860624b319a59b40b0e832d299b9ffea87bfefa9c69266fb271fb2c24987b07e79b2187
|
|
7
|
+
data.tar.gz: 3e8caab33783ba3d89b048b4208611e2506cf02837d8f35b52723ca34114cd7c76491315f2f14211ef06218ef041b5f68e5ff28fb48ba4fea34c302a538d6bec
|
data/braintree.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
|
9
9
|
s.license = "MIT"
|
|
10
10
|
s.author = "Braintree"
|
|
11
11
|
s.email = "code@getbraintree.com"
|
|
12
|
-
s.homepage = "
|
|
12
|
+
s.homepage = "https://www.braintreepayments.com/"
|
|
13
13
|
s.rubyforge_project = "braintree"
|
|
14
14
|
s.has_rdoc = false
|
|
15
15
|
s.files = Dir.glob ["README.rdoc", "LICENSE", "lib/**/*.{rb,crt}", "spec/**/*", "*.gemspec"]
|
|
@@ -425,7 +425,8 @@ module Braintree
|
|
|
425
425
|
DescriptionIsTooLong = "95803"
|
|
426
426
|
DiscountAmountFormatIsInvalid = "95804"
|
|
427
427
|
DiscountAmountIsTooLarge = "95805"
|
|
428
|
-
DiscountAmountMustBeGreaterThanZero = "95806"
|
|
428
|
+
DiscountAmountMustBeGreaterThanZero = "95806" # Deprecated as the amount may be zero. Use DiscountAmountCannotBeNegative.
|
|
429
|
+
DiscountAmountCannotBeNegative = "95806"
|
|
429
430
|
KindIsInvalid = "95807"
|
|
430
431
|
KindIsRequired = "95808"
|
|
431
432
|
NameIsRequired = "95822"
|
|
@@ -445,7 +446,11 @@ module Braintree
|
|
|
445
446
|
UnitOfMeasureIsTooLong = "95821"
|
|
446
447
|
UnitTaxAmountFormatIsInvalid = "95824"
|
|
447
448
|
UnitTaxAmountIsTooLarge = "95825"
|
|
448
|
-
UnitTaxAmountMustBeGreaterThanZero = "95826"
|
|
449
|
+
UnitTaxAmountMustBeGreaterThanZero = "95826" # Deprecated as the amount may be zero. Use UnitTaxAmountCannotBeNegative.
|
|
450
|
+
UnitTaxAmountCannotBeNegative = "95826"
|
|
451
|
+
TaxAmountFormatIsInvalid = "95827"
|
|
452
|
+
TaxAmountIsTooLarge = "95828"
|
|
453
|
+
TaxAmountCannotBeNegative = "95829"
|
|
449
454
|
end
|
|
450
455
|
|
|
451
456
|
module Merchant
|
|
@@ -149,7 +149,7 @@ module Braintree
|
|
|
149
149
|
:shipping_amount, :discount_amount, :ships_from_postal_code,
|
|
150
150
|
:billing_address_id, :payment_method_nonce, :three_d_secure_token,
|
|
151
151
|
:shared_payment_method_token, :shared_billing_address_id, :shared_customer_id, :shared_shipping_address_id, :shared_payment_method_nonce,
|
|
152
|
-
{:line_items => [:quantity, :name, :description, :kind, :unit_amount, :unit_tax_amount, :total_amount, :discount_amount, :unit_of_measure, :product_code, :commodity_code, :url]},
|
|
152
|
+
{:line_items => [:quantity, :name, :description, :kind, :unit_amount, :unit_tax_amount, :total_amount, :discount_amount, :tax_amount, :unit_of_measure, :product_code, :commodity_code, :url]},
|
|
153
153
|
{:risk_data => [:customer_browser, :customer_ip]},
|
|
154
154
|
{:credit_card => [:token, :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]},
|
|
155
155
|
{:customer => [:id, :company, :email, :fax, :first_name, :last_name, :phone, :website]},
|
|
@@ -9,6 +9,7 @@ module Braintree
|
|
|
9
9
|
attr_reader :unit_tax_amount
|
|
10
10
|
attr_reader :unit_of_measure
|
|
11
11
|
attr_reader :discount_amount
|
|
12
|
+
attr_reader :tax_amount
|
|
12
13
|
attr_reader :total_amount
|
|
13
14
|
attr_reader :product_code
|
|
14
15
|
attr_reader :commodity_code
|
|
@@ -21,6 +22,7 @@ module Braintree
|
|
|
21
22
|
@unit_amount = Util.to_big_decimal(unit_amount)
|
|
22
23
|
@unit_tax_amount = Util.to_big_decimal(unit_tax_amount)
|
|
23
24
|
@discount_amount = Util.to_big_decimal(discount_amount)
|
|
25
|
+
@tax_amount = Util.to_big_decimal(tax_amount)
|
|
24
26
|
@total_amount = Util.to_big_decimal(total_amount)
|
|
25
27
|
end
|
|
26
28
|
|
|
@@ -30,5 +32,9 @@ module Braintree
|
|
|
30
32
|
self.new *args
|
|
31
33
|
end
|
|
32
34
|
end
|
|
35
|
+
|
|
36
|
+
def self.find_all(*args)
|
|
37
|
+
Configuration.gateway.transaction_line_item.find_all(*args)
|
|
38
|
+
end
|
|
33
39
|
end
|
|
34
40
|
end
|
data/lib/braintree/version.rb
CHANGED
|
@@ -7,6 +7,8 @@ module Braintree
|
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
def parse(signature_string, payload)
|
|
10
|
+
raise InvalidSignature, 'signature cannot be nil' if signature_string.nil?
|
|
11
|
+
raise InvalidSignature, 'payload cannot be nil' if payload.nil?
|
|
10
12
|
if payload =~ /[^A-Za-z0-9+=\/\n]/
|
|
11
13
|
raise InvalidSignature, "payload contains illegal characters"
|
|
12
14
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Braintree
|
|
2
2
|
class WebhookTesting # :nodoc:
|
|
3
|
-
def self.sample_notification(kind, id)
|
|
4
|
-
Configuration.gateway.webhook_testing.sample_notification(kind, id)
|
|
3
|
+
def self.sample_notification(kind, id, source_merchant_id=nil)
|
|
4
|
+
Configuration.gateway.webhook_testing.sample_notification(kind, id, source_merchant_id)
|
|
5
5
|
end
|
|
6
6
|
end
|
|
7
7
|
end
|
|
@@ -6,18 +6,23 @@ module Braintree
|
|
|
6
6
|
@config.assert_has_access_token_or_keys
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def sample_notification(kind, id)
|
|
10
|
-
payload = Base64.encode64(_sample_xml(kind, id))
|
|
9
|
+
def sample_notification(kind, id, source_merchant_id=nil)
|
|
10
|
+
payload = Base64.encode64(_sample_xml(kind, id, source_merchant_id))
|
|
11
11
|
signature_string = "#{@config.public_key}|#{Braintree::Digest.hexdigest(@config.private_key, payload)}"
|
|
12
12
|
|
|
13
13
|
return {:bt_signature => signature_string, :bt_payload => payload}
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def _sample_xml(kind, data)
|
|
16
|
+
def _sample_xml(kind, data, source_merchant_id=nil)
|
|
17
|
+
unless source_merchant_id.nil?
|
|
18
|
+
source_merchant_xml = "<source-merchant-id>#{source_merchant_id}</source-merchant-id>"
|
|
19
|
+
end
|
|
20
|
+
|
|
17
21
|
<<-XML
|
|
18
22
|
<notification>
|
|
19
23
|
<timestamp type="datetime">#{Time.now.utc.iso8601}</timestamp>
|
|
20
24
|
<kind>#{kind}</kind>
|
|
25
|
+
#{source_merchant_xml}
|
|
21
26
|
<subject>
|
|
22
27
|
#{_subject_sample_xml(kind, data)}
|
|
23
28
|
</subject>
|
|
@@ -1395,14 +1395,14 @@ describe Braintree::PaymentMethod do
|
|
|
1395
1395
|
|
|
1396
1396
|
context "payment method grant and revoke" do
|
|
1397
1397
|
before(:each) do
|
|
1398
|
-
partner_merchant_gateway = Braintree::Gateway.new(
|
|
1398
|
+
@partner_merchant_gateway = Braintree::Gateway.new(
|
|
1399
1399
|
:merchant_id => "integration_merchant_public_id",
|
|
1400
1400
|
:public_key => "oauth_app_partner_user_public_key",
|
|
1401
1401
|
:private_key => "oauth_app_partner_user_private_key",
|
|
1402
1402
|
:environment => Braintree::Configuration.environment,
|
|
1403
1403
|
:logger => Logger.new("/dev/null")
|
|
1404
1404
|
)
|
|
1405
|
-
customer = partner_merchant_gateway.customer.create(
|
|
1405
|
+
customer = @partner_merchant_gateway.customer.create(
|
|
1406
1406
|
:first_name => "Joe",
|
|
1407
1407
|
:last_name => "Brown",
|
|
1408
1408
|
:company => "ExampleCo",
|
|
@@ -1411,19 +1411,19 @@ describe Braintree::PaymentMethod do
|
|
|
1411
1411
|
:fax => "614.555.5678",
|
|
1412
1412
|
:website => "www.example.com"
|
|
1413
1413
|
).customer
|
|
1414
|
-
@credit_card = partner_merchant_gateway.credit_card.create(
|
|
1414
|
+
@credit_card = @partner_merchant_gateway.credit_card.create(
|
|
1415
1415
|
:customer_id => customer.id,
|
|
1416
1416
|
:cardholder_name => "Adam Davis",
|
|
1417
1417
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
1418
1418
|
:expiration_date => "05/2009"
|
|
1419
1419
|
).credit_card
|
|
1420
1420
|
|
|
1421
|
-
oauth_gateway = Braintree::Gateway.new(
|
|
1421
|
+
@oauth_gateway = Braintree::Gateway.new(
|
|
1422
1422
|
:client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
|
|
1423
1423
|
:client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
|
|
1424
1424
|
:logger => Logger.new("/dev/null")
|
|
1425
1425
|
)
|
|
1426
|
-
access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
|
|
1426
|
+
access_token = Braintree::OAuthTestHelper.create_token(@oauth_gateway, {
|
|
1427
1427
|
:merchant_public_id => "integration_merchant_id",
|
|
1428
1428
|
:scope => "grant_payment_method"
|
|
1429
1429
|
}).credentials.access_token
|
|
@@ -1529,6 +1529,60 @@ describe Braintree::PaymentMethod do
|
|
|
1529
1529
|
)
|
|
1530
1530
|
result.should_not be_success
|
|
1531
1531
|
end
|
|
1532
|
+
|
|
1533
|
+
it "revokes grants upon deletion if :revoke_all_grants is true" do
|
|
1534
|
+
customer_result = @partner_merchant_gateway.customer.create()
|
|
1535
|
+
token = @partner_merchant_gateway.payment_method.create({
|
|
1536
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
|
1537
|
+
:customer_id => customer_result.customer.id
|
|
1538
|
+
}).payment_method.token
|
|
1539
|
+
|
|
1540
|
+
code = Braintree::OAuthTestHelper.create_grant(@oauth_gateway, {
|
|
1541
|
+
:merchant_public_id => "integration_merchant_id",
|
|
1542
|
+
:scope => "grant_payment_method"
|
|
1543
|
+
})
|
|
1544
|
+
access_token_result = @oauth_gateway.oauth.create_token_from_code({
|
|
1545
|
+
:code => code,
|
|
1546
|
+
:scope => "grant_payment_method"
|
|
1547
|
+
}).credentials
|
|
1548
|
+
|
|
1549
|
+
access_token_gateway = Braintree::Gateway.new({
|
|
1550
|
+
:access_token => access_token_result.access_token
|
|
1551
|
+
})
|
|
1552
|
+
|
|
1553
|
+
grant_result = access_token_gateway.payment_method.grant(token, {
|
|
1554
|
+
:allow_vaulting => true,
|
|
1555
|
+
:include_billing_postal_code => true,
|
|
1556
|
+
})
|
|
1557
|
+
|
|
1558
|
+
grant_result.should be_success
|
|
1559
|
+
|
|
1560
|
+
delete_result = @partner_merchant_gateway.payment_method.delete(token, {
|
|
1561
|
+
:revoke_all_grants => true
|
|
1562
|
+
})
|
|
1563
|
+
|
|
1564
|
+
delete_result.should be_success
|
|
1565
|
+
|
|
1566
|
+
new_customer_result = Braintree::Customer.create({
|
|
1567
|
+
:first_name => "Joe",
|
|
1568
|
+
:last_name => "Brown",
|
|
1569
|
+
:company => "ExampleCo",
|
|
1570
|
+
:email => "joe@example.com",
|
|
1571
|
+
:phone => "312.555.1234",
|
|
1572
|
+
:fax => "614.555.5678",
|
|
1573
|
+
:website => "www.example.com"
|
|
1574
|
+
})
|
|
1575
|
+
|
|
1576
|
+
# Revocations don't happen immediately so we add this.
|
|
1577
|
+
sleep(6)
|
|
1578
|
+
|
|
1579
|
+
token_request = Braintree::PaymentMethod.create({
|
|
1580
|
+
:payment_method_nonce => grant_result.payment_method_nonce.nonce,
|
|
1581
|
+
:customer_id => new_customer_result.customer.id
|
|
1582
|
+
})
|
|
1583
|
+
|
|
1584
|
+
token_request.should_not be_success
|
|
1585
|
+
end
|
|
1532
1586
|
end
|
|
1533
1587
|
end
|
|
1534
1588
|
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
|
|
3
|
+
|
|
4
|
+
describe Braintree::TransactionLineItem do
|
|
5
|
+
describe "self.find_all" do
|
|
6
|
+
it "returns line_items for the specified transaction" do
|
|
7
|
+
result = Braintree::Transaction.create(
|
|
8
|
+
:type => "sale",
|
|
9
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
10
|
+
:credit_card => {
|
|
11
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
12
|
+
:expiration_date => "05/2009"
|
|
13
|
+
},
|
|
14
|
+
:line_items => [
|
|
15
|
+
{
|
|
16
|
+
:quantity => "1.0232",
|
|
17
|
+
:name => "Name #1",
|
|
18
|
+
:kind => "debit",
|
|
19
|
+
:unit_amount => "45.1232",
|
|
20
|
+
:total_amount => "45.15",
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
)
|
|
24
|
+
result.success?.should == true
|
|
25
|
+
transaction = result.transaction
|
|
26
|
+
|
|
27
|
+
line_items = Braintree::TransactionLineItem.find_all(transaction.id)
|
|
28
|
+
|
|
29
|
+
line_item = line_items[0]
|
|
30
|
+
line_item.quantity.should == BigDecimal.new("1.0232")
|
|
31
|
+
line_item.name.should == "Name #1"
|
|
32
|
+
line_item.kind.should == "debit"
|
|
33
|
+
line_item.unit_amount.should == BigDecimal.new("45.1232")
|
|
34
|
+
line_item.total_amount.should == BigDecimal.new("45.15")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
@@ -2280,6 +2280,37 @@ describe Braintree::Transaction do
|
|
|
2280
2280
|
line_item.total_amount.should == BigDecimal.new("45.15")
|
|
2281
2281
|
end
|
|
2282
2282
|
|
|
2283
|
+
it "allows creation with single line item with zero amount fields and returns it" do
|
|
2284
|
+
result = Braintree::Transaction.create(
|
|
2285
|
+
:type => "sale",
|
|
2286
|
+
:amount => "45.15",
|
|
2287
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
|
2288
|
+
:line_items => [
|
|
2289
|
+
{
|
|
2290
|
+
:quantity => "1.0232",
|
|
2291
|
+
:name => "Name #1",
|
|
2292
|
+
:kind => "debit",
|
|
2293
|
+
:unit_amount => "45.1232",
|
|
2294
|
+
:total_amount => "45.15",
|
|
2295
|
+
:unit_tax_amount => "0",
|
|
2296
|
+
:discount_amount => "0",
|
|
2297
|
+
:tax_amount => "0",
|
|
2298
|
+
},
|
|
2299
|
+
],
|
|
2300
|
+
)
|
|
2301
|
+
result.success?.should == true
|
|
2302
|
+
result.transaction.line_items.length.should == 1
|
|
2303
|
+
line_item = result.transaction.line_items[0]
|
|
2304
|
+
line_item.quantity.should == BigDecimal.new("1.0232")
|
|
2305
|
+
line_item.name.should == "Name #1"
|
|
2306
|
+
line_item.kind.should == "debit"
|
|
2307
|
+
line_item.unit_amount.should == BigDecimal.new("45.1232")
|
|
2308
|
+
line_item.total_amount.should == BigDecimal.new("45.15")
|
|
2309
|
+
line_item.unit_tax_amount.should == BigDecimal.new("0")
|
|
2310
|
+
line_item.discount_amount.should == BigDecimal.new("0")
|
|
2311
|
+
line_item.tax_amount.should == BigDecimal.new("0")
|
|
2312
|
+
end
|
|
2313
|
+
|
|
2283
2314
|
it "allows creation with single line item and returns it" do
|
|
2284
2315
|
result = Braintree::Transaction.create(
|
|
2285
2316
|
:type => "sale",
|
|
@@ -2295,6 +2326,7 @@ describe Braintree::Transaction do
|
|
|
2295
2326
|
:unit_tax_amount => "1.23",
|
|
2296
2327
|
:unit_of_measure => "gallon",
|
|
2297
2328
|
:discount_amount => "1.02",
|
|
2329
|
+
:tax_amount => "4.50",
|
|
2298
2330
|
:total_amount => "45.15",
|
|
2299
2331
|
:product_code => "23434",
|
|
2300
2332
|
:commodity_code => "9SAASSD8724",
|
|
@@ -2313,6 +2345,7 @@ describe Braintree::Transaction do
|
|
|
2313
2345
|
line_item.unit_tax_amount.should == BigDecimal.new("1.23")
|
|
2314
2346
|
line_item.unit_of_measure.should == "gallon"
|
|
2315
2347
|
line_item.discount_amount.should == BigDecimal.new("1.02")
|
|
2348
|
+
line_item.tax_amount.should == BigDecimal.new("4.50")
|
|
2316
2349
|
line_item.total_amount.should == BigDecimal.new("45.15")
|
|
2317
2350
|
line_item.product_code.should == "23434"
|
|
2318
2351
|
line_item.commodity_code.should == "9SAASSD8724"
|
|
@@ -2332,6 +2365,7 @@ describe Braintree::Transaction do
|
|
|
2332
2365
|
:unit_amount => "45.1232",
|
|
2333
2366
|
:unit_of_measure => "gallon",
|
|
2334
2367
|
:discount_amount => "1.02",
|
|
2368
|
+
:tax_amount => "4.50",
|
|
2335
2369
|
:total_amount => "45.15",
|
|
2336
2370
|
:product_code => "23434",
|
|
2337
2371
|
:commodity_code => "9SAASSD8724",
|
|
@@ -2342,6 +2376,7 @@ describe Braintree::Transaction do
|
|
|
2342
2376
|
:kind => "credit",
|
|
2343
2377
|
:unit_amount => "5",
|
|
2344
2378
|
:unit_of_measure => "gallon",
|
|
2379
|
+
:tax_amount => "1.50",
|
|
2345
2380
|
:total_amount => "10.1",
|
|
2346
2381
|
},
|
|
2347
2382
|
],
|
|
@@ -2355,6 +2390,7 @@ describe Braintree::Transaction do
|
|
|
2355
2390
|
line_item_1.unit_amount.should == BigDecimal.new("45.1232")
|
|
2356
2391
|
line_item_1.unit_of_measure.should == "gallon"
|
|
2357
2392
|
line_item_1.discount_amount.should == BigDecimal.new("1.02")
|
|
2393
|
+
line_item_1.tax_amount.should == BigDecimal.new("4.50")
|
|
2358
2394
|
line_item_1.total_amount.should == BigDecimal.new("45.15")
|
|
2359
2395
|
line_item_1.product_code.should == "23434"
|
|
2360
2396
|
line_item_1.commodity_code.should == "9SAASSD8724"
|
|
@@ -2365,6 +2401,7 @@ describe Braintree::Transaction do
|
|
|
2365
2401
|
line_item_2.unit_amount.should == BigDecimal.new("5")
|
|
2366
2402
|
line_item_2.unit_of_measure.should == "gallon"
|
|
2367
2403
|
line_item_2.total_amount.should == BigDecimal.new("10.1")
|
|
2404
|
+
line_item_2.tax_amount.should == BigDecimal.new("1.50")
|
|
2368
2405
|
line_item_2.discount_amount.should == nil
|
|
2369
2406
|
line_item_2.product_code.should == nil
|
|
2370
2407
|
line_item_2.commodity_code.should == nil
|
|
@@ -2507,7 +2544,7 @@ describe Braintree::Transaction do
|
|
|
2507
2544
|
result.errors.for(:transaction).for(:line_items).for(:index_1).on(:discount_amount)[0].code.should == Braintree::ErrorCodes::TransactionLineItem::DiscountAmountIsTooLarge
|
|
2508
2545
|
end
|
|
2509
2546
|
|
|
2510
|
-
it "handles validation error discount amount
|
|
2547
|
+
it "handles validation error discount amount cannot be negative" do
|
|
2511
2548
|
result = Braintree::Transaction.create(
|
|
2512
2549
|
:type => "sale",
|
|
2513
2550
|
:amount => "35.05",
|
|
@@ -2538,7 +2575,79 @@ describe Braintree::Transaction do
|
|
|
2538
2575
|
],
|
|
2539
2576
|
)
|
|
2540
2577
|
result.success?.should == false
|
|
2541
|
-
result.errors.for(:transaction).for(:line_items).for(:index_1).on(:discount_amount)[0].code.should == Braintree::ErrorCodes::TransactionLineItem::
|
|
2578
|
+
result.errors.for(:transaction).for(:line_items).for(:index_1).on(:discount_amount)[0].code.should == Braintree::ErrorCodes::TransactionLineItem::DiscountAmountCannotBeNegative
|
|
2579
|
+
end
|
|
2580
|
+
|
|
2581
|
+
it "handles validation error tax amount format is invalid" do
|
|
2582
|
+
result = Braintree::Transaction.create(
|
|
2583
|
+
:type => "sale",
|
|
2584
|
+
:amount => "35.05",
|
|
2585
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
|
2586
|
+
:line_items => [
|
|
2587
|
+
{
|
|
2588
|
+
:quantity => "1.2322",
|
|
2589
|
+
:name => "Name #1",
|
|
2590
|
+
:kind => "debit",
|
|
2591
|
+
:unit_amount => "45.1232",
|
|
2592
|
+
:unit_of_measure => "gallon",
|
|
2593
|
+
:discount_amount => "1.02",
|
|
2594
|
+
:tax_amount => "$1.02",
|
|
2595
|
+
:total_amount => "45.15",
|
|
2596
|
+
:product_code => "23434",
|
|
2597
|
+
:commodity_code => "9SAASSD8724",
|
|
2598
|
+
},
|
|
2599
|
+
],
|
|
2600
|
+
)
|
|
2601
|
+
result.success?.should == false
|
|
2602
|
+
result.errors.for(:transaction).for(:line_items).for(:index_0).on(:tax_amount)[0].code.should == Braintree::ErrorCodes::TransactionLineItem::TaxAmountFormatIsInvalid
|
|
2603
|
+
end
|
|
2604
|
+
|
|
2605
|
+
it "handles validation error tax amount is too large" do
|
|
2606
|
+
result = Braintree::Transaction.create(
|
|
2607
|
+
:type => "sale",
|
|
2608
|
+
:amount => "35.05",
|
|
2609
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
|
2610
|
+
:line_items => [
|
|
2611
|
+
{
|
|
2612
|
+
:quantity => "1.2322",
|
|
2613
|
+
:name => "Name #1",
|
|
2614
|
+
:kind => "debit",
|
|
2615
|
+
:unit_amount => "45.1232",
|
|
2616
|
+
:unit_of_measure => "gallon",
|
|
2617
|
+
:discount_amount => "1.02",
|
|
2618
|
+
:tax_amount => "2147483648",
|
|
2619
|
+
:total_amount => "45.15",
|
|
2620
|
+
:product_code => "23434",
|
|
2621
|
+
:commodity_code => "9SAASSD8724",
|
|
2622
|
+
},
|
|
2623
|
+
],
|
|
2624
|
+
)
|
|
2625
|
+
result.success?.should == false
|
|
2626
|
+
result.errors.for(:transaction).for(:line_items).for(:index_0).on(:tax_amount)[0].code.should == Braintree::ErrorCodes::TransactionLineItem::TaxAmountIsTooLarge
|
|
2627
|
+
end
|
|
2628
|
+
|
|
2629
|
+
it "handles validation error tax amount cannot be negative" do
|
|
2630
|
+
result = Braintree::Transaction.create(
|
|
2631
|
+
:type => "sale",
|
|
2632
|
+
:amount => "35.05",
|
|
2633
|
+
:payment_method_nonce => Braintree::Test::Nonce::Transactable,
|
|
2634
|
+
:line_items => [
|
|
2635
|
+
{
|
|
2636
|
+
:quantity => "1.2322",
|
|
2637
|
+
:name => "Name #1",
|
|
2638
|
+
:kind => "debit",
|
|
2639
|
+
:unit_amount => "45.1232",
|
|
2640
|
+
:unit_of_measure => "gallon",
|
|
2641
|
+
:discount_amount => "1.02",
|
|
2642
|
+
:tax_amount => "-2",
|
|
2643
|
+
:total_amount => "45.15",
|
|
2644
|
+
:product_code => "23434",
|
|
2645
|
+
:commodity_code => "9SAASSD8724",
|
|
2646
|
+
},
|
|
2647
|
+
],
|
|
2648
|
+
)
|
|
2649
|
+
result.success?.should == false
|
|
2650
|
+
result.errors.for(:transaction).for(:line_items).for(:index_0).on(:tax_amount)[0].code.should == Braintree::ErrorCodes::TransactionLineItem::TaxAmountCannotBeNegative
|
|
2542
2651
|
end
|
|
2543
2652
|
|
|
2544
2653
|
it "handles validation error kind is invalid" do
|
|
@@ -3185,7 +3294,7 @@ describe Braintree::Transaction do
|
|
|
3185
3294
|
result.errors.for(:transaction).for(:line_items).for(:index_1).on(:unit_tax_amount)[0].code.should == Braintree::ErrorCodes::TransactionLineItem::UnitTaxAmountIsTooLarge
|
|
3186
3295
|
end
|
|
3187
3296
|
|
|
3188
|
-
it "handles validation error unit tax amount
|
|
3297
|
+
it "handles validation error unit tax amount cannot be negative" do
|
|
3189
3298
|
result = Braintree::Transaction.create(
|
|
3190
3299
|
:type => "sale",
|
|
3191
3300
|
:amount => "35.05",
|
|
@@ -3217,7 +3326,7 @@ describe Braintree::Transaction do
|
|
|
3217
3326
|
],
|
|
3218
3327
|
)
|
|
3219
3328
|
result.success?.should == false
|
|
3220
|
-
result.errors.for(:transaction).for(:line_items).for(:index_1).on(:unit_tax_amount)[0].code.should == Braintree::ErrorCodes::TransactionLineItem::
|
|
3329
|
+
result.errors.for(:transaction).for(:line_items).for(:index_1).on(:unit_tax_amount)[0].code.should == Braintree::ErrorCodes::TransactionLineItem::UnitTaxAmountCannotBeNegative
|
|
3221
3330
|
end
|
|
3222
3331
|
|
|
3223
3332
|
it "handles validation errors on line items structure" do
|
|
@@ -58,6 +58,29 @@ describe Braintree::WebhookNotification do
|
|
|
58
58
|
notification.timestamp.should be_within(10).of(Time.now.utc)
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
+
it "builds a sample notification with a source merchant ID" do
|
|
62
|
+
sample_notification = Braintree::WebhookTesting.sample_notification(
|
|
63
|
+
Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
|
|
64
|
+
"my_id",
|
|
65
|
+
"my_source_merchant_id"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
|
|
69
|
+
|
|
70
|
+
notification.source_merchant_id.should == "my_source_merchant_id"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it "doesn't include source merchant IDs if not supplied" do
|
|
74
|
+
sample_notification = Braintree::WebhookTesting.sample_notification(
|
|
75
|
+
Braintree::WebhookNotification::Kind::PartnerMerchantDeclined,
|
|
76
|
+
"my_id"
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
notification = Braintree::WebhookNotification.parse(sample_notification[:bt_signature], sample_notification[:bt_payload])
|
|
80
|
+
|
|
81
|
+
notification.source_merchant_id.should be_nil
|
|
82
|
+
end
|
|
83
|
+
|
|
61
84
|
context "auth" do
|
|
62
85
|
it "builds a sample notification for a status transitioned webhook" do
|
|
63
86
|
sample_notification = Braintree::WebhookTesting.sample_notification(
|
|
@@ -400,6 +423,18 @@ describe Braintree::WebhookNotification do
|
|
|
400
423
|
end
|
|
401
424
|
|
|
402
425
|
describe "parse" do
|
|
426
|
+
it "raises InvalidSignature error when the signature is nil" do
|
|
427
|
+
expect do
|
|
428
|
+
Braintree::WebhookNotification.parse(nil, "payload")
|
|
429
|
+
end.to raise_error(Braintree::InvalidSignature, "signature cannot be nil")
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
it "raises InvalidSignature error when the payload is nil" do
|
|
433
|
+
expect do
|
|
434
|
+
Braintree::WebhookNotification.parse("signature", nil)
|
|
435
|
+
end.to raise_error(Braintree::InvalidSignature, "payload cannot be nil")
|
|
436
|
+
end
|
|
437
|
+
|
|
403
438
|
it "raises InvalidSignature error when the signature is completely invalid" do
|
|
404
439
|
sample_notification = Braintree::WebhookTesting.sample_notification(
|
|
405
440
|
Braintree::WebhookNotification::Kind::SubscriptionWentPastDue,
|
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.
|
|
4
|
+
version: 2.83.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-
|
|
11
|
+
date: 2018-02-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: builder
|
|
@@ -214,6 +214,7 @@ files:
|
|
|
214
214
|
- spec/integration/braintree/subscription_spec.rb
|
|
215
215
|
- spec/integration/braintree/test/transaction_amounts_spec.rb
|
|
216
216
|
- spec/integration/braintree/test_transaction_spec.rb
|
|
217
|
+
- spec/integration/braintree/transaction_line_item_spec.rb
|
|
217
218
|
- spec/integration/braintree/transaction_search_spec.rb
|
|
218
219
|
- spec/integration/braintree/transaction_spec.rb
|
|
219
220
|
- spec/integration/braintree/transparent_redirect_spec.rb
|
|
@@ -275,7 +276,7 @@ files:
|
|
|
275
276
|
- spec/unit/braintree/xml_spec.rb
|
|
276
277
|
- spec/unit/braintree_spec.rb
|
|
277
278
|
- spec/unit/spec_helper.rb
|
|
278
|
-
homepage:
|
|
279
|
+
homepage: https://www.braintreepayments.com/
|
|
279
280
|
licenses:
|
|
280
281
|
- MIT
|
|
281
282
|
metadata: {}
|