Skip to content
Browse files

2.10.0

  • Loading branch information...
1 parent fcaf349 commit 393be089c133bde217abb8ea2a5ccaa1a0dc9305 @braintreeps braintreeps committed Apr 26, 2011
View
2 .gitignore
@@ -2,3 +2,5 @@ bt_rdoc
rdoc
*.gem
tags
+.rvmrc
+
View
6 CHANGELOG.rdoc
@@ -1,3 +1,9 @@
+== 2.10.0
+
+* Added subscription_details to Transaction
+* Added flag to store in vault only when a transaction is successful
+* Added new error code
+
== 2.9.1
* Added a new transaction state, AuthorizationExpired.
View
71 Rakefile
@@ -8,10 +8,6 @@ task :dev_console do
sh "irb -I lib -rubygems -r braintree -r env/development"
end
-task :qa_console do
- sh "irb -I lib -rubygems -r braintree -r env/qa"
-end
-
desc "Run units"
Spec::Rake::SpecTask.new("spec:unit") do |t|
t.spec_files = FileList["spec/unit/**/*_spec.rb"]
@@ -22,29 +18,6 @@ Spec::Rake::SpecTask.new("spec:integration") do |t|
t.spec_files = FileList["spec/integration/**/*_spec.rb"]
end
-desc "run specs after preping the gateway"
-task :cruise do
- begin
- Rake::Task["prep_gateway"].invoke
- Rake::Task["spec:unit"].invoke
- Rake::Task["spec:integration"].invoke
- ensure
- Rake::Task["stop_gateway"].invoke rescue nil
- end
-end
-
-def configure_rdoc_task(t)
- t.main = "README.rdoc"
- t.rdoc_files.include("README.rdoc", "CHANGELOG.rdoc", "LICENSE", "lib/**/*.rb")
- t.title = "Braintree Ruby Documentation"
-end
-
-Rake::RDocTask.new do |t|
- configure_rdoc_task(t)
- t.rdoc_dir = "rdoc"
-end
-
-
require File.dirname(__FILE__) + "/lib/braintree/version.rb"
gem_spec = Gem::Specification.new do |s|
s.name = "braintree"
@@ -66,53 +39,9 @@ end
require File.dirname(__FILE__) + "/lib/braintree/configuration.rb"
-CRUISE_BUILD = "CRUISE_BUILD=#{ENV['CRUISE_BUILD']}"
-GATEWAY_ROOT = File.dirname(__FILE__) + "/../gateway" unless defined?(GATEWAY_ROOT)
-GATEWAY_PORT = Braintree::Configuration.new(:environment => :development).port
-PID_FILE = "/tmp/gateway_server_#{GATEWAY_PORT}.pid"
-
-task :prep_gateway do
- Dir.chdir(GATEWAY_ROOT) do
- sh "rvm system exec rake log:clear"
- sh "git pull"
- sh "env RAILS_ENV=integration #{CRUISE_BUILD} rvm system exec rake db:migrate:reset --trace"
- sh "env RAILS_ENV=integration #{CRUISE_BUILD} rvm system exec ruby script/populate_data"
- Rake::Task[:start_gateway].invoke
- end
-end
-
-task :start_gateway do
- Dir.chdir(GATEWAY_ROOT) do
- spawn_server(PID_FILE, GATEWAY_PORT, "integration")
- end
-end
-
-task :stop_gateway do
- Dir.chdir(GATEWAY_ROOT) do
- shutdown_server(PID_FILE)
- end
-end
-
desc 'Cleans generated files'
task :clean do
rm_f Dir.glob('*.gem').join(" ")
rm_rf "rdoc"
rm_rf "bt_rdoc"
end
-
-def spawn_server(pid_file, port, environment="test")
- require File.dirname(__FILE__) + "/spec/hacks/tcp_socket"
-
- FileUtils.rm(pid_file) if File.exist?(pid_file)
- command = "rvm system exec mongrel_rails start --environment #{environment} --daemon --port #{port} --pid #{pid_file}"
-
- sh command
- puts "== waiting for web server - port: #{port}"
- TCPSocket.wait_for_service :host => "127.0.0.1", :port => port
-end
-
-def shutdown_server(pid_file)
- 10.times { unless File.exists?(pid_file); sleep 1; end }
- puts "\n== killing web server - pid: #{File.read(pid_file).to_i}"
- Process.kill "TERM", File.read(pid_file).to_i
-end
View
9 cruise_config.rb
@@ -1,9 +0,0 @@
-Project.configure do |project|
- project.scheduler.polling_interval = 1.minute
-
- case project.name
- when "client_library_ruby_integration_master"
- project.build_command = "CRUISE_BUILD=#{project.name} GATEWAY_PORT=3010 rake cruise --trace"
- project.triggered_by :gateway_master
- end
-end
View
1 env/development.rb
@@ -3,4 +3,3 @@
Braintree::Configuration.public_key = "integration_public_key"
Braintree::Configuration.private_key = "integration_private_key"
# Braintree::Configuration.logger = Logger.new("/dev/null")
-
View
1 lib/braintree.rb
@@ -52,6 +52,7 @@ module Braintree
require File.dirname(__FILE__) + "/braintree/transaction/address_details"
require File.dirname(__FILE__) + "/braintree/transaction/credit_card_details"
require File.dirname(__FILE__) + "/braintree/transaction/customer_details"
+require File.dirname(__FILE__) + "/braintree/transaction/subscription_details"
require File.dirname(__FILE__) + "/braintree/transaction_gateway"
require File.dirname(__FILE__) + "/braintree/transaction_search"
require File.dirname(__FILE__) + "/braintree/transaction/status_details"
View
3 lib/braintree/error_codes.rb
@@ -7,10 +7,10 @@ module ErrorCodes
module Address
CannotBeBlank = "81801"
CompanyIsTooLong = "81802"
- CountryNameIsNotAccepted = "91803"
CountryCodeAlpha2IsNotAccepted = "91814"
CountryCodeAlpha3IsNotAccepted = "91816"
CountryCodeNumericIsNotAccepted = "91817"
+ CountryNameIsNotAccepted = "91803"
ExtendedAddressIsTooLong = "81804"
FirstNameIsTooLong = "81805"
InconsistentCountry = "91815"
@@ -22,6 +22,7 @@ module Address
RegionIsTooLong = "81810"
StreetAddressIsRequired = "81811"
StreetAddressIsTooLong = "81812"
+ TooManyAddressesPerCustomer = "91818"
end
# See http://www.braintreepaymentsolutions.com/docs/ruby/credit_cards/validations
View
5 lib/braintree/transaction.rb
@@ -42,7 +42,7 @@ module Type # :nodoc:
end
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
+ attr_reader :amount, :created_at, :credit_card_details, :customer_details, :subscription_details, :id
attr_reader :currency_iso_code
attr_reader :custom_fields
attr_reader :cvv_response_code
@@ -155,6 +155,7 @@ def initialize(gateway, attributes) # :nodoc:
set_instance_variables_from_hash(attributes)
@amount = Util.to_big_decimal(amount)
@credit_card_details = CreditCardDetails.new(@credit_card)
+ @subscription_details = SubscriptionDetails.new(@subscription)
@customer_details = CustomerDetails.new(@customer)
@billing_details = AddressDetails.new(@billing)
@shipping_details = AddressDetails.new(@shipping)
@@ -292,7 +293,7 @@ def _new(*args) # :nodoc:
end
def self._attributes # :nodoc:
- [:amount, :created_at, :credit_card_details, :customer_details, :id, :status, :type, :updated_at]
+ [:amount, :created_at, :credit_card_details, :customer_details, :id, :status, :subscription_details, :type, :updated_at]
end
end
end
View
13 lib/braintree/transaction/subscription_details.rb
@@ -0,0 +1,13 @@
+module Braintree
+ class Transaction
+ class SubscriptionDetails # :nodoc:
+ include BaseModule
+
+ attr_reader :billing_period_start_date, :billing_period_end_date
+
+ def initialize(attributes)
+ set_instance_variables_from_hash attributes unless attributes.nil?
+ end
+ end
+ end
+end
View
2 lib/braintree/transaction_gateway.rb
@@ -99,7 +99,7 @@ def self._create_signature # :nodoc:
{
:shipping => AddressGateway._shared_signature
},
- {:options => [:store_in_vault, :submit_for_settlement, :add_billing_address_to_payment_method, :store_shipping_address_in_vault]},
+ {:options => [:store_in_vault, :store_in_vault_on_success, :submit_for_settlement, :add_billing_address_to_payment_method, :store_shipping_address_in_vault]},
{:custom_fields => :_any_key_},
{:descriptor => [:name, :phone]}
]
View
4 lib/braintree/version.rb
@@ -1,8 +1,8 @@
module Braintree
module Version
Major = 2
- Minor = 9
- Tiny = 1
+ Minor = 10
+ Tiny = 0
String = "#{Major}.#{Minor}.#{Tiny}"
end
View
22 spec/integration/braintree/credit_card_spec.rb
@@ -947,6 +947,28 @@
result.transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
result.transaction.credit_card_details.expiration_date.should == "05/2010"
end
+
+ it "allows passing a cvv in addition to the token" do
+ customer = Braintree::Customer.create!(
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2010"
+ }
+ )
+ result = Braintree::CreditCard.sale(customer.credit_cards[0].token,
+ :amount => "100.00",
+ :credit_card => {
+ :cvv => "301"
+ }
+ )
+
+ result.success?.should == true
+ result.transaction.amount.should == BigDecimal.new("100.00")
+ result.transaction.type.should == "sale"
+ result.transaction.customer_details.id.should == customer.id
+ result.transaction.credit_card_details.token.should == customer.credit_cards[0].token
+ result.transaction.cvv_response_code.should == "S"
+ end
end
describe "self.sale!" do
View
14 spec/integration/braintree/subscription_spec.rb
@@ -36,6 +36,20 @@
result.subscription.payment_method_token.should == @credit_card.token
end
+ it "returns a transaction with billing period populated" do
+ result = Braintree::Subscription.create(
+ :payment_method_token => @credit_card.token,
+ :plan_id => SpecHelper::TriallessPlan[:id]
+ )
+
+ result.success?.should == true
+ subscription = result.subscription
+ transaction = subscription.transactions.first
+
+ transaction.subscription_details.billing_period_start_date.should == subscription.billing_period_start_date
+ transaction.subscription_details.billing_period_end_date.should == subscription.billing_period_end_date
+ end
+
it "can set the id" do
new_id = rand(36**9).to_s(36)
result = Braintree::Subscription.create(
View
78 spec/integration/braintree/transaction_spec.rb
@@ -598,6 +598,84 @@
result.errors.for(:transaction).on(:purchase_order_number)[0].code.should == Braintree::ErrorCodes::Transaction::PurchaseOrderNumberIsTooLong
end
end
+
+ context "store_in_vault_on_success" do
+ context "passed as true" do
+ it "stores vault records when transaction succeeds" do
+ result = Braintree::Transaction.create(
+ :type => "sale",
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
+ :customer => {
+ :last_name => "Doe"
+ },
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "12/12",
+ },
+ :options => { :store_in_vault_on_success => true }
+ )
+ result.success?.should == true
+ result.transaction.vault_customer.last_name.should == "Doe"
+ result.transaction.vault_credit_card.masked_number.should == "401288******1881"
+ end
+
+ it "does not store vault records when true and transaction fails" do
+ result = Braintree::Transaction.create(
+ :type => "sale",
+ :amount => Braintree::Test::TransactionAmounts::Decline,
+ :customer => {
+ :last_name => "Doe"
+ },
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "12/12",
+ },
+ :options => { :store_in_vault_on_success => true }
+ )
+ result.success?.should == false
+ result.transaction.vault_customer.should be_nil
+ result.transaction.vault_credit_card.should be_nil
+ end
+ end
+
+ context "passed as false" do
+ it "does not store vault records when transaction succeeds" do
+ result = Braintree::Transaction.create(
+ :type => "sale",
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
+ :customer => {
+ :last_name => "Doe"
+ },
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "12/12",
+ },
+ :options => { :store_in_vault_on_success => false }
+ )
+ result.success?.should == true
+ result.transaction.vault_customer.should be_nil
+ result.transaction.vault_credit_card.should be_nil
+ end
+
+ it "does not store vault records when transaction fails" do
+ result = Braintree::Transaction.create(
+ :type => "sale",
+ :amount => Braintree::Test::TransactionAmounts::Decline,
+ :customer => {
+ :last_name => "Doe"
+ },
+ :credit_card => {
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "12/12",
+ },
+ :options => { :store_in_vault_on_success => false }
+ )
+ result.success?.should == false
+ result.transaction.vault_customer.should be_nil
+ result.transaction.vault_credit_card.should be_nil
+ end
+ end
+ end
end
describe "self.create!" do

0 comments on commit 393be08

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