Skip to content
Browse files

1.1.2

  • Loading branch information...
1 parent 49a29fd commit 189741358cd1d4c2feffb386849816e119acc66d @braintreeps braintreeps committed Mar 19, 2010
View
10 CHANGELOG.rdoc
@@ -1,3 +1,13 @@
+== 1.1.2
+
+* allow passing expiration_month and expiration_year separately
+* updated Customer.find to raise an ArgumentError if given an invalid id
+* added error code for transaction amounts that are too large
+* include Enumerable in Braintree::Errors to iterate over all validation errors
+* added processor_authorization_code attr_reader to Braintree::Transaction
+* added cvv_response_code attr_reader to Braintree::Transaction
+* added deep_errors method to Braintree::ValidationErrorCollection to get errors at every level of nesting
+
== 1.1.1
* Added explicit require for date to fix missing initialize (thanks jherdman[http://github.com/jherdman])
View
17 Rakefile
@@ -22,22 +22,11 @@ Spec::Rake::SpecTask.new("spec:integration") do |t|
t.spec_files = FileList["spec/integration/**/*_spec.rb"]
end
-desc "run integration keeping the gateway server and sphinx running"
-task :start_servers_and_run_integration_specs do
- begin
- Rake::Task["start_gateway"].invoke
- Rake::Task["start_sphinx"].invoke
- Rake::Task["spec:integration"].invoke
- ensure
- Rake::Task["stop_gateway"].invoke
- Rake::Task["stop_sphinx"].invoke
- end
-end
-
-desc "run integration tests after preping the gateway (including git clone and db reset), what the build needs to run"
-task :run_integration_specs_for_cruise do
+desc "run specs after preping the gateway"
+task :run_specs_for_cruise do
begin
Rake::Task["prep_gateway"].invoke
+ Rake::Task["spec:unit"].invoke
Rake::Task["spec:integration"].invoke
ensure
Rake::Task["stop_gateway"].invoke
View
10 cruise_config.rb
@@ -2,16 +2,8 @@
project.scheduler.polling_interval = 1.minute
case project.name
- when /client_library_ruby_unit/
- project.build_command = "rake spec:unit --trace"
when "client_library_ruby_integration_master"
- project.build_command = "CRUISE_BUILD=#{project.name} GATEWAY_PORT=3010 SPHINX_PORT=3322 rake run_integration_specs_for_cruise --trace"
- project.triggered_by :gateway_master
- when "client_library_ruby_integration_release_1"
- project.build_command = "CRUISE_BUILD=#{project.name} GATEWAY_PORT=3020 SPHINX_PORT=3332 rake run_integration_specs_for_cruise --trace"
- project.triggered_by :gateway_release_1
- when "client_library_ruby_integration_release_1_to_master"
- project.build_command = "CRUISE_BUILD=#{project.name} GATEWAY_PORT=3030 SPHINX_PORT=3342 rake run_integration_specs_for_cruise --trace"
+ project.build_command = "CRUISE_BUILD=#{project.name} GATEWAY_PORT=3010 SPHINX_PORT=3322 rake run_specs_for_cruise --trace"
project.triggered_by :gateway_master
end
end
View
4 lib/braintree/credit_card.rb
@@ -192,7 +192,7 @@ def self._attributes # :nodoc:
def self._create_signature # :nodoc:
[
- :customer_id, :cardholder_name, :cvv, :number, :expiration_date, :token,
+ :customer_id, :cardholder_name, :cvv, :number, :expiration_date, :expiration_month, :expiration_year, :token,
{:options => [:verify_card]},
{:billing_address => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :region, :postal_code, :street_address]}
]
@@ -226,7 +226,7 @@ def self._do_update(http_verb, url, params) # :nodoc:
def self._update_signature # :nodoc:
[
- :cardholder_name, :cvv, :number, :expiration_date, :token,
+ :cardholder_name, :cvv, :number, :expiration_date, :expiration_month, :expiration_year, :token,
{:options => [:verify_card]},
{:billing_address => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :region, :postal_code, :street_address]}
]
View
2 lib/braintree/customer.rb
@@ -79,6 +79,8 @@ def self.delete(customer_id)
end
def self.find(customer_id)
+ raise ArgumentError, "customer_id should be a string" unless customer_id.is_a?(String)
+ raise ArgumentError, "customer_id cannot be blank" if customer_id.to_s == ""
response = Http.get("/customers/#{customer_id}")
new(response[:customer])
rescue NotFoundError
View
1 lib/braintree/error_codes.rb
@@ -79,6 +79,7 @@ module Transaction
AmountCannotBeNegative = "81501"
AmountIsRequired = "81502"
AmountIsInvalid = "81503"
+ AmountIsTooLarge = "81528"
CannotBeVoided = "91504"
CannotRefundCredit = "91505"
CannotRefundUnlessSettled = "91506"
View
6 lib/braintree/errors.rb
@@ -1,10 +1,16 @@
module Braintree
# Provides access to errors from an ErrorResult.
class Errors
+ include Enumerable
+
def initialize(data = {}) # :nodoc:
@errors = ValidationErrorCollection.new(data.merge(:errors => []))
end
+ def each(&block)
+ @errors.deep_errors.each(&block)
+ end
+
# Accesses validation errors for the given +scope+.
def for(scope)
@errors.for(scope)
View
7 lib/braintree/transaction.rb
@@ -127,9 +127,12 @@ module Type # :nodoc:
attr_reader :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code
attr_reader :amount, :created_at, :credit_card_details, :customer_details, :id, :status
attr_reader :custom_fields
+ attr_reader :cvv_response_code
attr_reader :order_id
attr_reader :billing_details, :shipping_details
attr_reader :status_history
+ # The authorization code from the processor.
+ attr_reader :processor_authorization_code
# The response code from the processor.
attr_reader :processor_response_code
# The response text from the processor.
@@ -245,7 +248,7 @@ def inspect # :nodoc:
nice_attributes = order.map do |attr|
if attr == :amount
self.amount ? "amount: #{self.amount.to_s("F").inspect}" : "amount: nil"
- else
+ else
"#{attr}: #{send(attr).inspect}"
end
end
@@ -381,7 +384,7 @@ def self._basic_search(query, options) # :nodoc:
def self._create_signature # :nodoc:
[
:amount, :customer_id, :order_id, :payment_method_token, :type,
- {:credit_card => [:token, :cvv, :expiration_date, :number]},
+ {:credit_card => [:token, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]},
{:customer => [:id, :company, :email, :fax, :first_name, :last_name, :phone, :website]},
{:billing => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :postal_code, :region, :street_address]},
{:shipping => [:first_name, :last_name, :company, :country_name, :extended_address, :locality, :postal_code, :region, :street_address]},
View
6 lib/braintree/validation_error_collection.rb
@@ -35,7 +35,11 @@ def [](index)
@errors[index]
end
- def deep_size # :nodoc:
+ def deep_errors
+ ([@errors] + @nested.values.map { |error_collection| error_collection.deep_errors }).flatten
+ end
+
+ def deep_size
size + @nested.values.inject(0) { |count, error_collection| count + error_collection.deep_size }
end
View
2 lib/braintree/version.rb
@@ -2,7 +2,7 @@ module Braintree
module Version
Major = 1
Minor = 1
- Tiny = 1
+ Tiny = 2
String = "#{Major}.#{Minor}.#{Tiny}"
end
View
34 spec/integration/braintree/credit_card_spec.rb
@@ -25,6 +25,21 @@
credit_card.expiration_date.should == "05/2009"
end
+ it "can provide expiration month and year separately" do
+ customer = Braintree::Customer.create!
+ result = Braintree::CreditCard.create(
+ :customer_id => customer.id,
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_month => "05",
+ :expiration_year => "2012"
+ )
+ result.success?.should == true
+ credit_card = result.credit_card
+ credit_card.expiration_month.should == "05"
+ credit_card.expiration_year.should == "2012"
+ credit_card.expiration_date.should == "05/2012"
+ end
+
it "can specify the desired token" do
token = "token_#{rand(1_000_000)}"
customer = Braintree::Customer.create!
@@ -254,6 +269,25 @@
updated_credit_card.cardholder_name.should == "New Holder"
end
+ it "can pass expiration_month and expiration_year" do
+ customer = Braintree::Customer.create!
+ credit_card = Braintree::CreditCard.create!(
+ :customer_id => customer.id,
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2012"
+ )
+ update_result = Braintree::CreditCard.update(credit_card.token,
+ :number => Braintree::Test::CreditCardNumbers::MasterCard,
+ :expiration_month => "07",
+ :expiration_year => "2011"
+ )
+ update_result.success?.should == true
+ update_result.credit_card.should == credit_card
+ update_result.credit_card.expiration_month.should == "07"
+ update_result.credit_card.expiration_year.should == "2011"
+ update_result.credit_card.expiration_date.should == "07/2011"
+ end
+
it "verifies the update if options[verify_card]=true" do
customer = Braintree::Customer.create!
credit_card = Braintree::CreditCard.create!(
View
30 spec/integration/braintree/customer_spec.rb
@@ -61,6 +61,18 @@
result.success?.should == true
end
+ it "supports utf-8" do
+ first_name = "Jos\303\251"
+ last_name = "Mu\303\261oz"
+ result = Braintree::Customer.create(:first_name => first_name, :last_name => last_name)
+ result.success?.should == true
+ result.customer.first_name.should == first_name
+ result.customer.last_name.should == last_name
+ found_customer = Braintree::Customer.find(result.customer.id)
+ found_customer.first_name.should == first_name
+ found_customer.last_name.should == last_name
+ end
+
it "returns an error response if invalid" do
result = Braintree::Customer.create(
:email => "@invalid.com"
@@ -477,6 +489,24 @@
customer.last_name.should == "Cool"
end
+ it "works for a blank customer" do
+ created_customer = Braintree::Customer.create!
+ found_customer = Braintree::Customer.find(created_customer.id)
+ found_customer.id.should == created_customer.id
+ end
+
+ it "raises an ArgumentError if customer_id is not a string" do
+ expect do
+ Braintree::Customer.find(Object.new)
+ end.to raise_error(ArgumentError, "customer_id should be a string")
+ end
+
+ it "raises an ArgumentError if customer_id is blank" do
+ expect do
+ Braintree::Customer.find("")
+ end.to raise_error(ArgumentError, "customer_id cannot be blank")
+ end
+
it "raises a NotFoundError exception if customer cannot be found" do
expect do
Braintree::Customer.find("invalid-id")
View
35 spec/integration/braintree/transaction_spec.rb
@@ -15,6 +15,7 @@
result.transaction.id.should =~ /^\w{6}$/
result.transaction.type.should == "sale"
result.transaction.amount.should == BigDecimal.new(Braintree::Test::TransactionAmounts::Authorize)
+ result.transaction.processor_authorization_code.should_not be_nil
result.transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
result.transaction.credit_card_details.expiration_date.should == "05/2009"
@@ -38,6 +39,32 @@
result.transaction.processor_response_text.should == "Do Not Honor"
end
+ it "accepts credit card expiration month and expiration year" do
+ result = Braintree::Transaction.create(
+ :type => "sale",
+ :amount => Braintree::Test::TransactionAmounts::Decline,
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_month => "05",
+ :expiration_year => "2011"
+ }
+ )
+ result.success?.should == true
+ result.transaction.credit_card_details.expiration_month.should == "05"
+ result.transaction.credit_card_details.expiration_year.should == "2011"
+ result.transaction.credit_card_details.expiration_date.should == "05/2011"
+ end
+
+ it "returns some error if customer_id is invalid" do
+ result = Braintree::Transaction.create(
+ :type => "sale",
+ :amount => Braintree::Test::TransactionAmounts::Decline,
+ :customer_id => 123456789
+ )
+ result.success?.should == false
+ result.errors.for(:transaction).on(:customer_id)[0].code.should == "91510"
+ end
+
it "can create custom fields" do
result = Braintree::Transaction.create(
:type => "sale",
@@ -192,7 +219,7 @@
transaction.credit_card_details.expiration_date.should == "05/2009"
end
- it "raises a ValidationsFailed if invalid" do
+ it "raises a validationsfailed if invalid" do
expect do
Braintree::Transaction.create!(
:type => "sale",
@@ -282,6 +309,7 @@
transaction.avs_error_response_code.should == nil
transaction.avs_postal_code_response_code.should == "M"
transaction.avs_street_address_response_code.should == "M"
+ transaction.cvv_response_code.should == "M"
transaction.customer_details.first_name.should == "Dan"
transaction.customer_details.last_name.should == "Smith"
transaction.customer_details.company.should == "Braintree Payment Solutions"
@@ -745,15 +773,16 @@
transaction.amount.should == BigDecimal.new("100.00")
transaction.order_id.should == "123"
transaction.processor_response_code.should == "1000"
- transaction.created_at.between?(Time.now - 5, Time.now).should == true
- transaction.updated_at.between?(Time.now - 5, Time.now).should == true
+ transaction.created_at.between?(Time.now - 60, Time.now).should == true
+ transaction.updated_at.between?(Time.now - 60, Time.now).should == true
transaction.credit_card_details.bin.should == "510510"
transaction.credit_card_details.last_4.should == "5100"
transaction.credit_card_details.masked_number.should == "510510******5100"
transaction.credit_card_details.card_type.should == "MasterCard"
transaction.avs_error_response_code.should == nil
transaction.avs_postal_code_response_code.should == "M"
transaction.avs_street_address_response_code.should == "M"
+ transaction.cvv_response_code.should == "M"
transaction.customer_details.first_name.should == "Dan"
transaction.customer_details.last_name.should == "Smith"
transaction.customer_details.company.should == "Braintree Payment Solutions"
View
1 spec/integration/spec_helper.rb
@@ -7,7 +7,6 @@
Spec::Runner.configure do |config|
CLIENT_LIB_ROOT = File.expand_path(File.dirname(__FILE__) + "/../..")
GATEWAY_ROOT = File.expand_path("#{CLIENT_LIB_ROOT}/../gateway")
- GATEWAY_SERVER_PORT = 3000
GATEWAY_PID_FILE = "/tmp/gateway_server_#{Braintree::Configuration.port}.pid"
SPHINX_PID_FILE = "#{GATEWAY_ROOT}/log/searchd.integration.pid"
View
16 spec/unit/braintree/configuration_spec.rb
@@ -25,7 +25,8 @@
describe "self.base_merchant_url" do
it "returns the expected url for the development env" do
Braintree::Configuration.environment = :development
- Braintree::Configuration.base_merchant_url.should == "http://localhost:3000/merchants/integration_merchant_id"
+ port = Braintree::Configuration.port
+ Braintree::Configuration.base_merchant_url.should == "http://localhost:#{port}/merchants/integration_merchant_id"
end
it "returns the expected url for the sandbox env" do
@@ -129,9 +130,18 @@
Braintree::Configuration.port.should == 443
end
- it "is 3000 for development" do
+ it "is 3000 or GATEWAY_PORT environment variable for development" do
Braintree::Configuration.environment = :development
- Braintree::Configuration.port.should == 3000
+ old_gateway_port = ENV['GATEWAY_PORT']
+ begin
+ ENV['GATEWAY_PORT'] = nil
+ Braintree::Configuration.port.should == 3000
+
+ ENV['GATEWAY_PORT'] = '1234'
+ Braintree::Configuration.port.should == '1234'
+ ensure
+ ENV['GATEWAY_PORT'] = old_gateway_port
+ end
end
end
View
3 spec/unit/braintree/credit_card_spec.rb
@@ -19,7 +19,8 @@
describe "self.create_credit_card_url" do
it "returns the url" do
- Braintree::CreditCard.create_credit_card_url.should == "http://localhost:3000/merchants/integration_merchant_id/payment_methods/all/create_via_transparent_redirect_request"
+ port = Braintree::Configuration.port
+ Braintree::CreditCard.create_credit_card_url.should == "http://localhost:#{port}/merchants/integration_merchant_id/payment_methods/all/create_via_transparent_redirect_request"
end
end
View
17 spec/unit/braintree/errors_spec.rb
@@ -54,6 +54,23 @@
end
end
+ describe "each" do
+ it "yields errors at all levels" do
+ errors = Braintree::Errors.new(
+ :level1 => {
+ :errors => [{:code => "1", :attribute => "attr", :message => "message"}],
+ :level2 => {
+ :errors => [
+ {:code => "2", :attribute => "attr2", :message => "message2"},
+ {:code => "3", :attribute => "attr3", :message => "message3"}
+ ],
+ }
+ }
+ )
+ errors.map { |e| e.code }.sort.should == %w[1 2 3]
+ end
+ end
+
describe "size" do
it "returns the number of validation errors at the first level if only has one level" do
errors = Braintree::Errors.new(
View
3 spec/unit/braintree/transaction_spec.rb
@@ -19,7 +19,8 @@
describe "self.create_transaction_url" do
it "returns the url" do
- Braintree::Transaction.create_transaction_url.should == "http://localhost:3000/merchants/integration_merchant_id/transactions/all/create_via_transparent_redirect_request"
+ port = Braintree::Configuration.port
+ Braintree::Transaction.create_transaction_url.should == "http://localhost:#{port}/merchants/integration_merchant_id/transactions/all/create_via_transparent_redirect_request"
end
end
View
20 spec/unit/braintree/validation_error_collection_spec.rb
@@ -125,4 +125,24 @@
end
end
+ describe "deep_errors" do
+ it "returns errors from all levels" do
+ errors = Braintree::ValidationErrorCollection.new(
+ :errors => [
+ { :attribute => "one", :code => 1, :message => "bad juju" },
+ { :attribute => "two", :code => 2, :message => "bad juju" }],
+ :nested => {
+ :errors => [{ :attribute => "three", :code => 3, :message => "badder juju"}],
+ :nested_again => {
+ :errors => [{ :attribute => "four", :code => 4, :message => "badder juju"}]
+ }
+ },
+ :same_level => {
+ :errors => [{ :attribute => "five", :code => 5, :message => "badder juju"}],
+ }
+ )
+ errors.deep_errors.map { |e| e.code }.sort.should == [1, 2, 3, 4, 5]
+ end
+ end
+
end

0 comments on commit 1897413

Please sign in to comment.
Something went wrong with that request. Please try again.