braintree 2.11.0 → 2.12.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/braintree.rb +5 -4
- data/lib/braintree/add_on.rb +5 -0
- data/lib/braintree/add_on_gateway.rb +16 -0
- data/lib/braintree/discount.rb +5 -0
- data/lib/braintree/discount_gateway.rb +16 -0
- data/lib/braintree/error_codes.rb +7 -0
- data/lib/braintree/gateway.rb +12 -0
- data/lib/braintree/modification.rb +11 -1
- data/lib/braintree/plan.rb +44 -0
- data/lib/braintree/plan_gateway.rb +16 -0
- data/lib/braintree/subscription.rb +1 -0
- data/lib/braintree/transaction.rb +8 -0
- data/lib/braintree/transaction_gateway.rb +9 -0
- data/lib/braintree/version.rb +1 -1
- data/spec/integration/braintree/add_on_spec.rb +34 -0
- data/spec/integration/braintree/discount_spec.rb +34 -0
- data/spec/integration/braintree/plan_spec.rb +52 -0
- data/spec/integration/braintree/settlement_batch_summary_spec.rb +2 -2
- data/spec/integration/braintree/subscription_spec.rb +1 -0
- data/spec/integration/braintree/transaction_spec.rb +113 -0
- data/spec/integration/spec_helper.rb +5 -0
- data/spec/spec_helper.rb +4 -0
- data/spec/unit/braintree/modification_spec.rb +7 -0
- data/spec/unit/braintree/transaction_spec.rb +8 -0
- metadata +14 -6
data/lib/braintree.rb
CHANGED
@@ -14,14 +14,13 @@ require "zlib"
|
|
14
14
|
|
15
15
|
require "builder"
|
16
16
|
|
17
|
-
module Braintree
|
18
|
-
end
|
19
|
-
|
20
17
|
require File.dirname(__FILE__) + "/braintree/exceptions"
|
18
|
+
|
21
19
|
require File.dirname(__FILE__) + "/braintree/base_module"
|
22
20
|
require File.dirname(__FILE__) + "/braintree/modification"
|
23
21
|
|
24
22
|
require File.dirname(__FILE__) + "/braintree/add_on"
|
23
|
+
require File.dirname(__FILE__) + "/braintree/add_on_gateway"
|
25
24
|
require File.dirname(__FILE__) + "/braintree/address/country_names"
|
26
25
|
require File.dirname(__FILE__) + "/braintree/address"
|
27
26
|
require File.dirname(__FILE__) + "/braintree/address_gateway"
|
@@ -36,11 +35,14 @@ require File.dirname(__FILE__) + "/braintree/customer_search"
|
|
36
35
|
require File.dirname(__FILE__) + "/braintree/descriptor"
|
37
36
|
require File.dirname(__FILE__) + "/braintree/digest"
|
38
37
|
require File.dirname(__FILE__) + "/braintree/discount"
|
38
|
+
require File.dirname(__FILE__) + "/braintree/discount_gateway"
|
39
39
|
require File.dirname(__FILE__) + "/braintree/error_codes"
|
40
40
|
require File.dirname(__FILE__) + "/braintree/error_result"
|
41
41
|
require File.dirname(__FILE__) + "/braintree/errors"
|
42
42
|
require File.dirname(__FILE__) + "/braintree/gateway"
|
43
43
|
require File.dirname(__FILE__) + "/braintree/http"
|
44
|
+
require File.dirname(__FILE__) + "/braintree/plan"
|
45
|
+
require File.dirname(__FILE__) + "/braintree/plan_gateway"
|
44
46
|
require File.dirname(__FILE__) + "/braintree/settlement_batch_summary"
|
45
47
|
require File.dirname(__FILE__) + "/braintree/settlement_batch_summary_gateway"
|
46
48
|
require File.dirname(__FILE__) + "/braintree/resource_collection"
|
@@ -69,4 +71,3 @@ require File.dirname(__FILE__) + "/braintree/xml/generator"
|
|
69
71
|
require File.dirname(__FILE__) + "/braintree/xml/libxml"
|
70
72
|
require File.dirname(__FILE__) + "/braintree/xml/rexml"
|
71
73
|
require File.dirname(__FILE__) + "/braintree/xml/parser"
|
72
|
-
|
data/lib/braintree/add_on.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Braintree
|
2
|
+
class AddOnGateway # :nodoc
|
3
|
+
def initialize(gateway)
|
4
|
+
@gateway = gateway
|
5
|
+
@config = gateway.config
|
6
|
+
end
|
7
|
+
|
8
|
+
def all
|
9
|
+
response = @config.http.get "/add_ons"
|
10
|
+
attributes_collection = response[:add_ons]
|
11
|
+
attributes_collection.map do |attributes|
|
12
|
+
AddOn._new(attributes)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/braintree/discount.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Braintree
|
2
|
+
class DiscountGateway # :nodoc
|
3
|
+
def initialize(gateway)
|
4
|
+
@gateway = gateway
|
5
|
+
@config = gateway.config
|
6
|
+
end
|
7
|
+
|
8
|
+
def all
|
9
|
+
response = @config.http.get "/discounts"
|
10
|
+
attributes_collection = response[:discounts]
|
11
|
+
attributes_collection.map do |attributes|
|
12
|
+
Discount._new(attributes)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -158,6 +158,10 @@ module Braintree
|
|
158
158
|
AmountMustBeGreaterThanZero = "81531"
|
159
159
|
BillingAddressConflict = "91530"
|
160
160
|
CannotBeVoided = "91504"
|
161
|
+
CannotCloneCredit = "91543"
|
162
|
+
CannotCloneTransactionWithVaultCreditCard = "91540"
|
163
|
+
CannotCloneUnsuccessfulTransaction = "91542"
|
164
|
+
CannotCloneVoiceAuthorizations = "91541"
|
161
165
|
CannotRefundCredit = "91505"
|
162
166
|
CannotRefundUnlessSettled = "91506"
|
163
167
|
CannotRefundWithSuspendedMerchantAccount = "91538"
|
@@ -180,6 +184,8 @@ module Braintree
|
|
180
184
|
PaymentMethodTokenIsInvalid = "91518"
|
181
185
|
ProcessorAuthorizationCodeCannotBeSet = "91519"
|
182
186
|
ProcessorAuthorizationCodeIsInvalid = "81520"
|
187
|
+
ProcessorDoesNotSupportCredits = "91546"
|
188
|
+
ProcessorDoesNotSupportVoiceAuthorizations = "91545"
|
183
189
|
PurchaseOrderNumberIsTooLong = "91537"
|
184
190
|
RefundAmountIsTooLarge = "91521"
|
185
191
|
SettlementAmountIsTooLarge = "91522"
|
@@ -194,6 +200,7 @@ module Braintree
|
|
194
200
|
UnsupportedVoiceAuthorization = "91539"
|
195
201
|
|
196
202
|
module Options
|
203
|
+
SubmitForSettlementIsRequiredForCloning = "91544"
|
197
204
|
VaultIsDisabled = "91525"
|
198
205
|
end
|
199
206
|
end
|
data/lib/braintree/gateway.rb
CHANGED
@@ -12,6 +12,10 @@ module Braintree
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def add_on
|
16
|
+
AddOnGateway.new(self)
|
17
|
+
end
|
18
|
+
|
15
19
|
def address
|
16
20
|
AddressGateway.new(self)
|
17
21
|
end
|
@@ -24,6 +28,14 @@ module Braintree
|
|
24
28
|
CustomerGateway.new(self)
|
25
29
|
end
|
26
30
|
|
31
|
+
def discount
|
32
|
+
DiscountGateway.new(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
def plan
|
36
|
+
PlanGateway.new(self)
|
37
|
+
end
|
38
|
+
|
27
39
|
def settlement_batch_summary
|
28
40
|
SettlementBatchSummaryGateway.new(self)
|
29
41
|
end
|
@@ -2,7 +2,17 @@ module Braintree
|
|
2
2
|
class Modification # :nodoc:
|
3
3
|
include BaseModule
|
4
4
|
|
5
|
-
attr_reader :amount
|
5
|
+
attr_reader :amount
|
6
|
+
attr_reader :created_at
|
7
|
+
attr_reader :description
|
8
|
+
attr_reader :id
|
9
|
+
attr_reader :kind
|
10
|
+
attr_reader :merchant_id
|
11
|
+
attr_reader :name
|
12
|
+
attr_reader :never_expires
|
13
|
+
attr_reader :number_of_billing_cycles
|
14
|
+
attr_reader :quantity
|
15
|
+
attr_reader :updated_at
|
6
16
|
|
7
17
|
class << self
|
8
18
|
protected :new
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Braintree
|
2
|
+
# See http://www.braintreepayments.com/docs/ruby
|
3
|
+
class Plan
|
4
|
+
include BaseModule
|
5
|
+
|
6
|
+
attr_reader :id
|
7
|
+
attr_reader :merchant_id
|
8
|
+
attr_reader :billing_day_of_month
|
9
|
+
attr_reader :billing_frequency
|
10
|
+
attr_reader :currency_iso_code
|
11
|
+
attr_reader :description
|
12
|
+
attr_reader :discounts
|
13
|
+
attr_reader :name
|
14
|
+
attr_reader :number_of_billing_cycles
|
15
|
+
attr_reader :price
|
16
|
+
attr_reader :trial_duration
|
17
|
+
attr_reader :trial_duration_unit
|
18
|
+
attr_reader :trial_period
|
19
|
+
attr_reader :created_at
|
20
|
+
attr_reader :updated_at
|
21
|
+
attr_reader :add_ons
|
22
|
+
|
23
|
+
# See http://www.braintreepayments.com/docs/ruby/plans/all
|
24
|
+
def self.all
|
25
|
+
Configuration.gateway.plan.all
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(gateway, attributes) # :nodoc:
|
29
|
+
@gateway = gateway
|
30
|
+
set_instance_variables_from_hash(attributes)
|
31
|
+
add_ons.map! { |attrs| AddOn._new(attrs) }
|
32
|
+
discounts.map! { |attrs| Discount._new(attrs) }
|
33
|
+
@price = Util.to_big_decimal(price)
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
protected :new
|
38
|
+
end
|
39
|
+
|
40
|
+
def self._new(*args)
|
41
|
+
self.new *args
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Braintree
|
2
|
+
class PlanGateway # :nodoc:
|
3
|
+
def initialize(gateway)
|
4
|
+
@gateway = gateway
|
5
|
+
@config = gateway.config
|
6
|
+
end
|
7
|
+
|
8
|
+
def all
|
9
|
+
response = @config.http.get "/plans"
|
10
|
+
attributes_collection = response[:plans]
|
11
|
+
attributes_collection.map do |attributes|
|
12
|
+
Plan._new(@gateway, attributes)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -28,6 +28,7 @@ module Braintree
|
|
28
28
|
attr_reader :number_of_billing_cycles, :billing_day_of_month
|
29
29
|
attr_reader :add_ons, :discounts
|
30
30
|
attr_reader :descriptor
|
31
|
+
attr_reader :current_billing_cycle
|
31
32
|
|
32
33
|
# See http://www.braintreepayments.com/docs/ruby/subscriptions/cancel
|
33
34
|
def self.cancel(subscription_id)
|
@@ -81,6 +81,14 @@ module Braintree
|
|
81
81
|
return_object_or_raise(:transaction) { create(attributes) }
|
82
82
|
end
|
83
83
|
|
84
|
+
def self.clone_transaction(transaction_id, attributes)
|
85
|
+
Configuration.gateway.transaction.clone_transaction(transaction_id, attributes)
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.clone_transaction!(transaction_id, attributes)
|
89
|
+
return_object_or_raise(:transaction) { clone_transaction(transaction_id, attributes) }
|
90
|
+
end
|
91
|
+
|
84
92
|
# Deprecated. Use Braintree::TransparentRedirect.confirm
|
85
93
|
#
|
86
94
|
# See http://www.braintreepayments.com/docs/ruby/transactions/create_tr
|
@@ -10,6 +10,11 @@ module Braintree
|
|
10
10
|
_do_create "/transactions", :transaction => attributes
|
11
11
|
end
|
12
12
|
|
13
|
+
def clone_transaction(transaction_id, attributes)
|
14
|
+
Util.verify_keys(TransactionGateway._clone_signature, attributes)
|
15
|
+
_do_create "/transactions/#{transaction_id}/clone", :transaction_clone => attributes
|
16
|
+
end
|
17
|
+
|
13
18
|
# Deprecated
|
14
19
|
def create_from_transparent_redirect(query_string)
|
15
20
|
params = @gateway.transparent_redirect.parse_and_validate_query_string query_string
|
@@ -87,6 +92,10 @@ module Braintree
|
|
87
92
|
end
|
88
93
|
end
|
89
94
|
|
95
|
+
def self._clone_signature # :nodoc:
|
96
|
+
[:amount, {:options => [:submit_for_settlement]}]
|
97
|
+
end
|
98
|
+
|
90
99
|
def self._create_signature # :nodoc:
|
91
100
|
[
|
92
101
|
:amount, :customer_id, :merchant_account_id, :order_id, :payment_method_token,
|
data/lib/braintree/version.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Braintree::AddOn do
|
4
|
+
describe "self.all" do
|
5
|
+
it "gets all add_ons" do
|
6
|
+
id = rand(36**8).to_s(36)
|
7
|
+
|
8
|
+
expected = {
|
9
|
+
:amount => "100.00",
|
10
|
+
:description => "some description",
|
11
|
+
:id => id,
|
12
|
+
:kind => "add_on",
|
13
|
+
:name => "ruby_add_on",
|
14
|
+
:never_expires => false,
|
15
|
+
:number_of_billing_cycles => 1
|
16
|
+
}
|
17
|
+
|
18
|
+
create_modification_for_tests(expected)
|
19
|
+
|
20
|
+
add_ons = Braintree::AddOn.all
|
21
|
+
add_on = add_ons.select { |add_on| add_on.id == id }.first
|
22
|
+
|
23
|
+
add_on.should_not be_nil
|
24
|
+
add_on.amount.should == BigDecimal.new(expected[:amount])
|
25
|
+
add_on.created_at.should_not be_nil
|
26
|
+
add_on.description.should == expected[:description]
|
27
|
+
add_on.kind.should == expected[:kind]
|
28
|
+
add_on.name.should == expected[:name]
|
29
|
+
add_on.never_expires.should == expected[:never_expires]
|
30
|
+
add_on.number_of_billing_cycles.should == expected[:number_of_billing_cycles]
|
31
|
+
add_on.updated_at.should_not be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Braintree::Discount do
|
4
|
+
describe "self.all" do
|
5
|
+
it "gets all discounts" do
|
6
|
+
id = rand(36**8).to_s(36)
|
7
|
+
|
8
|
+
expected = {
|
9
|
+
:amount => "100.00",
|
10
|
+
:description => "some description",
|
11
|
+
:id => id,
|
12
|
+
:kind => "discount",
|
13
|
+
:name => "ruby_discount",
|
14
|
+
:never_expires => false,
|
15
|
+
:number_of_billing_cycles => 1
|
16
|
+
}
|
17
|
+
|
18
|
+
create_modification_for_tests(expected)
|
19
|
+
|
20
|
+
discounts = Braintree::Discount.all
|
21
|
+
discount = discounts.select { |discount| discount.id == id }.first
|
22
|
+
|
23
|
+
discount.should_not be_nil
|
24
|
+
discount.amount.should == BigDecimal.new(expected[:amount])
|
25
|
+
discount.created_at.should_not be_nil
|
26
|
+
discount.description.should == expected[:description]
|
27
|
+
discount.kind.should == expected[:kind]
|
28
|
+
discount.name.should == expected[:name]
|
29
|
+
discount.never_expires.should == expected[:never_expires]
|
30
|
+
discount.number_of_billing_cycles.should == expected[:number_of_billing_cycles]
|
31
|
+
discount.updated_at.should_not be_nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
describe Braintree::Plan do
|
4
|
+
|
5
|
+
describe "self.all" do
|
6
|
+
it "gets all plans" do
|
7
|
+
plan_token = "test_plan_#{rand(36**8).to_s(36)}"
|
8
|
+
attributes = {
|
9
|
+
:id => plan_token,
|
10
|
+
:billing_day_of_month => 1,
|
11
|
+
:billing_frequency => 1,
|
12
|
+
:currency_iso_code => "USD",
|
13
|
+
:description => "some description",
|
14
|
+
:name => "ruby_test plan",
|
15
|
+
:number_of_billing_cycles => 1,
|
16
|
+
:price => "1.00",
|
17
|
+
:trial_duration => 3,
|
18
|
+
:trial_duration_unit => "day",
|
19
|
+
:trial_period => true,
|
20
|
+
}
|
21
|
+
create_plan_for_tests(attributes)
|
22
|
+
|
23
|
+
add_on_name = "ruby_add_on"
|
24
|
+
discount_name = "ruby_discount"
|
25
|
+
create_modification_for_tests({ :kind => "add_on", :plan_id => plan_token, :amount => "1.00", :name => add_on_name })
|
26
|
+
create_modification_for_tests({ :kind => "discount", :plan_id => plan_token, :amount => "1.00", :name => discount_name })
|
27
|
+
|
28
|
+
plans = Braintree::Plan.all
|
29
|
+
plan = plans.select { |plan| plan.id == plan_token }.first
|
30
|
+
plan.should_not be_nil
|
31
|
+
plan.id.should == attributes[:id]
|
32
|
+
plan.billing_day_of_month.should == attributes[:billing_day_of_month]
|
33
|
+
plan.billing_frequency.should == attributes[:billing_frequency]
|
34
|
+
plan.currency_iso_code.should == attributes[:currency_iso_code]
|
35
|
+
plan.description.should == attributes[:description]
|
36
|
+
plan.name.should == attributes[:name]
|
37
|
+
plan.number_of_billing_cycles.should == attributes[:number_of_billing_cycles]
|
38
|
+
plan.price.should == Braintree::Util.to_big_decimal("1.00")
|
39
|
+
plan.trial_duration.should == attributes[:trial_duration]
|
40
|
+
plan.trial_duration_unit.should == attributes[:trial_duration_unit]
|
41
|
+
plan.trial_period.should == attributes[:trial_period]
|
42
|
+
plan.created_at.should_not be_nil
|
43
|
+
plan.updated_at.should_not be_nil
|
44
|
+
plan.add_ons.first.name.should == add_on_name
|
45
|
+
plan.discounts.first.name.should == discount_name
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def create_plan_for_tests(attributes)
|
50
|
+
Braintree::Configuration.gateway.config.http.post "/plans/create_plan_for_tests", :plan => attributes
|
51
|
+
end
|
52
|
+
end
|
@@ -27,7 +27,7 @@ describe Braintree::SettlementBatchSummary do
|
|
27
27
|
)
|
28
28
|
SpecHelper.settle_transaction transaction.id
|
29
29
|
|
30
|
-
result = Braintree::SettlementBatchSummary.generate(
|
30
|
+
result = Braintree::SettlementBatchSummary.generate(now_in_eastern)
|
31
31
|
result.should be_success
|
32
32
|
amex_records = result.settlement_batch_summary.records.select {|row| row[:card_type] == Braintree::CreditCard::CardType::AmEx }
|
33
33
|
amex_records.first[:count].to_i.should >= 1
|
@@ -49,7 +49,7 @@ describe Braintree::SettlementBatchSummary do
|
|
49
49
|
)
|
50
50
|
SpecHelper.settle_transaction transaction.id
|
51
51
|
|
52
|
-
result = Braintree::SettlementBatchSummary.generate(
|
52
|
+
result = Braintree::SettlementBatchSummary.generate(now_in_eastern, 'store_me')
|
53
53
|
result.should be_success
|
54
54
|
|
55
55
|
amex_records = result.settlement_batch_summary.records.select {|row| row[:store_me] == "1" }
|
@@ -591,6 +591,7 @@ describe Braintree::Subscription do
|
|
591
591
|
subscription.paid_through_date.should match(date_format)
|
592
592
|
|
593
593
|
subscription.failure_count.should == 0
|
594
|
+
subscription.current_billing_cycle.should == 1
|
594
595
|
subscription.next_bill_amount.should == "12.34"
|
595
596
|
subscription.next_billing_period_amount.should == "12.34"
|
596
597
|
subscription.payment_method_token.should == @credit_card.token
|
@@ -1,6 +1,119 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
3
|
describe Braintree::Transaction do
|
4
|
+
describe "self.clone_transaction" do
|
5
|
+
it "creates a new transaction from the card of the transaction to clone" do
|
6
|
+
result = Braintree::Transaction.sale(
|
7
|
+
:amount => "112.44",
|
8
|
+
:customer => {
|
9
|
+
:last_name => "Adama",
|
10
|
+
},
|
11
|
+
:credit_card => {
|
12
|
+
:number => "5105105105105100",
|
13
|
+
:expiration_date => "05/2012"
|
14
|
+
},
|
15
|
+
:billing => {
|
16
|
+
:country_name => "Botswana",
|
17
|
+
:country_code_alpha2 => "BW",
|
18
|
+
:country_code_alpha3 => "BWA",
|
19
|
+
:country_code_numeric => "072"
|
20
|
+
},
|
21
|
+
:shipping => {
|
22
|
+
:country_name => "Bhutan",
|
23
|
+
:country_code_alpha2 => "BT",
|
24
|
+
:country_code_alpha3 => "BTN",
|
25
|
+
:country_code_numeric => "064"
|
26
|
+
}
|
27
|
+
)
|
28
|
+
result.success?.should == true
|
29
|
+
|
30
|
+
clone_result = Braintree::Transaction.clone_transaction(result.transaction.id, :amount => "112.44", :options => {
|
31
|
+
:submit_for_settlement => false
|
32
|
+
})
|
33
|
+
clone_result.success?.should == true
|
34
|
+
|
35
|
+
transaction = clone_result.transaction
|
36
|
+
|
37
|
+
transaction.id.should_not == result.transaction.id
|
38
|
+
transaction.amount.should == BigDecimal.new("112.44")
|
39
|
+
|
40
|
+
transaction.billing_details.country_name.should == "Botswana"
|
41
|
+
transaction.billing_details.country_code_alpha2.should == "BW"
|
42
|
+
transaction.billing_details.country_code_alpha3.should == "BWA"
|
43
|
+
transaction.billing_details.country_code_numeric.should == "072"
|
44
|
+
|
45
|
+
transaction.shipping_details.country_name.should == "Bhutan"
|
46
|
+
transaction.shipping_details.country_code_alpha2.should == "BT"
|
47
|
+
transaction.shipping_details.country_code_alpha3.should == "BTN"
|
48
|
+
transaction.shipping_details.country_code_numeric.should == "064"
|
49
|
+
|
50
|
+
transaction.credit_card_details.masked_number.should == "510510******5100"
|
51
|
+
transaction.credit_card_details.expiration_date.should == "05/2012"
|
52
|
+
|
53
|
+
transaction.customer_details.last_name.should == "Adama"
|
54
|
+
transaction.status.should == Braintree::Transaction::Status::Authorized
|
55
|
+
end
|
56
|
+
|
57
|
+
it "submit for settlement option" do
|
58
|
+
result = Braintree::Transaction.sale(
|
59
|
+
:amount => "112.44",
|
60
|
+
:credit_card => {
|
61
|
+
:number => "5105105105105100",
|
62
|
+
:expiration_date => "05/2012"
|
63
|
+
}
|
64
|
+
)
|
65
|
+
|
66
|
+
result.success?.should be_true
|
67
|
+
|
68
|
+
clone_result = Braintree::Transaction.clone_transaction(result.transaction.id, :amount => "112.44", :options => {:submit_for_settlement => true})
|
69
|
+
clone_result.success?.should == true
|
70
|
+
|
71
|
+
clone_result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
|
72
|
+
end
|
73
|
+
|
74
|
+
it "handles validation errors" do
|
75
|
+
transaction = Braintree::Transaction.credit!(
|
76
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
77
|
+
:credit_card => {
|
78
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
79
|
+
:expiration_date => "05/2009"
|
80
|
+
}
|
81
|
+
)
|
82
|
+
result = Braintree::Transaction.clone_transaction(transaction.id, :amount => "112.44")
|
83
|
+
result.success?.should be_false
|
84
|
+
|
85
|
+
result.errors.for(:transaction).on(:base).first.code.should == Braintree::ErrorCodes::Transaction::CannotCloneCredit
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "self.clone_transaction!" do
|
90
|
+
it "returns the transaction if valid" do
|
91
|
+
transaction = Braintree::Transaction.sale!(
|
92
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
93
|
+
:credit_card => {
|
94
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
95
|
+
:expiration_date => "05/2009"
|
96
|
+
}
|
97
|
+
)
|
98
|
+
clone_transaction = Braintree::Transaction.clone_transaction!(transaction.id, :amount => "112.44", :options => {:submit_for_settlement => false})
|
99
|
+
clone_transaction.id.should_not == transaction.id
|
100
|
+
end
|
101
|
+
|
102
|
+
it "raises a validationsfailed if invalid" do
|
103
|
+
transaction = Braintree::Transaction.sale!(
|
104
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
105
|
+
:credit_card => {
|
106
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
107
|
+
:expiration_date => "05/2009"
|
108
|
+
}
|
109
|
+
)
|
110
|
+
expect do
|
111
|
+
clone_transaction = Braintree::Transaction.clone_transaction!(transaction.id, :amount => "im not a number")
|
112
|
+
clone_transaction.id.should_not == transaction.id
|
113
|
+
end.to raise_error(Braintree::ValidationsFailed)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
4
117
|
describe "self.create" do
|
5
118
|
it "returns a successful result if successful" do
|
6
119
|
result = Braintree::Transaction.create(
|
@@ -17,4 +17,9 @@ unless defined?(INTEGRATION_SPEC_HELPER_LOADED)
|
|
17
17
|
10.times { unless File.exists?(web_server_pid_file); sleep 1; end }
|
18
18
|
Process.kill "INT", File.read(web_server_pid_file).to_i
|
19
19
|
end
|
20
|
+
|
21
|
+
def create_modification_for_tests(attributes)
|
22
|
+
config = Braintree::Configuration.gateway.config
|
23
|
+
config.http.post "/modifications/create_modification_for_tests", :modification => attributes
|
24
|
+
end
|
20
25
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
2
|
|
3
3
|
describe Braintree::Transaction do
|
4
|
+
describe "self.clone_transaction" do
|
5
|
+
it "raises an exception if hash includes an invalid key" do
|
6
|
+
expect do
|
7
|
+
Braintree::Transaction.clone_transaction("an_id", :amount => "10.00", :invalid_key => "foo")
|
8
|
+
end.to raise_error(ArgumentError, "invalid keys: invalid_key")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
4
12
|
describe "self.create" do
|
5
13
|
it "raises an exception if hash includes an invalid key" do
|
6
14
|
expect do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: braintree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 63
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
8
|
+
- 12
|
9
9
|
- 0
|
10
|
-
version: 2.
|
10
|
+
version: 2.12.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Braintree
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-06 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -46,6 +46,7 @@ files:
|
|
46
46
|
- README.rdoc
|
47
47
|
- LICENSE
|
48
48
|
- lib/braintree/add_on.rb
|
49
|
+
- lib/braintree/add_on_gateway.rb
|
49
50
|
- lib/braintree/address/country_names.rb
|
50
51
|
- lib/braintree/address.rb
|
51
52
|
- lib/braintree/address_gateway.rb
|
@@ -61,6 +62,7 @@ files:
|
|
61
62
|
- lib/braintree/descriptor.rb
|
62
63
|
- lib/braintree/digest.rb
|
63
64
|
- lib/braintree/discount.rb
|
65
|
+
- lib/braintree/discount_gateway.rb
|
64
66
|
- lib/braintree/error_codes.rb
|
65
67
|
- lib/braintree/error_result.rb
|
66
68
|
- lib/braintree/errors.rb
|
@@ -68,6 +70,8 @@ files:
|
|
68
70
|
- lib/braintree/gateway.rb
|
69
71
|
- lib/braintree/http.rb
|
70
72
|
- lib/braintree/modification.rb
|
73
|
+
- lib/braintree/plan.rb
|
74
|
+
- lib/braintree/plan_gateway.rb
|
71
75
|
- lib/braintree/resource_collection.rb
|
72
76
|
- lib/braintree/settlement_batch.rb
|
73
77
|
- lib/braintree/settlement_batch_summary.rb
|
@@ -99,13 +103,16 @@ files:
|
|
99
103
|
- lib/braintree/xml.rb
|
100
104
|
- lib/braintree.rb
|
101
105
|
- spec/hacks/tcp_socket.rb
|
106
|
+
- spec/integration/braintree/add_on_spec.rb
|
102
107
|
- spec/integration/braintree/address_spec.rb
|
103
108
|
- spec/integration/braintree/advanced_search_spec.rb
|
104
109
|
- spec/integration/braintree/credit_card_spec.rb
|
105
110
|
- spec/integration/braintree/customer_search_spec.rb
|
106
111
|
- spec/integration/braintree/customer_spec.rb
|
112
|
+
- spec/integration/braintree/discount_spec.rb
|
107
113
|
- spec/integration/braintree/error_codes_spec.rb
|
108
114
|
- spec/integration/braintree/http_spec.rb
|
115
|
+
- spec/integration/braintree/plan_spec.rb
|
109
116
|
- spec/integration/braintree/settlement_batch_summary_spec.rb
|
110
117
|
- spec/integration/braintree/subscription_spec.rb
|
111
118
|
- spec/integration/braintree/test/transaction_amounts_spec.rb
|
@@ -125,6 +132,7 @@ files:
|
|
125
132
|
- spec/unit/braintree/error_result_spec.rb
|
126
133
|
- spec/unit/braintree/errors_spec.rb
|
127
134
|
- spec/unit/braintree/http_spec.rb
|
135
|
+
- spec/unit/braintree/modification_spec.rb
|
128
136
|
- spec/unit/braintree/resource_collection_spec.rb
|
129
137
|
- spec/unit/braintree/subscription_search_spec.rb
|
130
138
|
- spec/unit/braintree/subscription_spec.rb
|
@@ -176,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
184
|
requirements: []
|
177
185
|
|
178
186
|
rubyforge_project: braintree
|
179
|
-
rubygems_version: 1.
|
187
|
+
rubygems_version: 1.6.2
|
180
188
|
signing_key:
|
181
189
|
specification_version: 3
|
182
190
|
summary: Braintree Gateway Ruby Client Library
|