Permalink
Browse files

1.2.1

  • Loading branch information...
1 parent 168d742 commit 8229c6f87edb3e5c033a840ba0d3669d7cb37bac @braintreeps braintreeps committed Apr 13, 2010
View
@@ -1,3 +1,10 @@
+== 1.2.1
+
+* Added ValidationErrorCollection#shallow_errors to get all of the ValidationErrors at a given level in the error hierarchy
+* Added the ability to make a credit card the default card for a customer
+* Added constants for transaction statuses
+* Updated Quick Start in README.rdoc to show a workflow with error checking
+
== 1.2.0
* Added Subscription search
View
@@ -17,15 +17,25 @@ The Braintree gem provides integration access to the Braintree Gateway.
Braintree::Configuration.public_key = "a_public_key"
Braintree::Configuration.private_key = "a_private_key"
- transaction = Braintree::Transaction.sale!(
- :amount => "100.00",
+ result = Braintree::Transaction.sale(
+ :amount => "1000.00",
:credit_card => {
:number => "5105105105105100",
:expiration_date => "05/12"
}
)
- puts "Transaction ID: #{transaction.id}"
- puts "Status: #{transaction.status}"
+
+ if result.success?
+ if result.transaction.status == Braintree::Transaction::Status::Authorized
+ puts "sucess!: #{result.transaction.id}"
+ else
+ puts "Error processing transaction:"
+ puts " code: #{result.transaction.processor_response_code}"
+ puts " text: #{result.transaction.processor_response_text}"
+ end
+ else
+ p result.errors
+ end
== Bang Methods
@@ -224,7 +224,7 @@ def self._do_update(http_verb, url, params) # :nodoc:
def self._update_signature # :nodoc:
[
:cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number, :token,
- {:options => [:verify_card]},
+ {:options => [:make_default, :verify_card]},
{:billing_address => [:company, :country_name, :extended_address, :first_name, :last_name, :locality, :postal_code, :region, :street_address]}
]
end
@@ -119,6 +119,19 @@ module Braintree
class Transaction
include BaseModule
+ module Status
+ Authorizing = 'authorizing'
+ Authorized = 'authorized'
+ GatewayRejected = 'gateway_rejected'
+ Failed = 'failed'
+ ProcessorDeclined = 'processor_declined'
+ Settled = 'settled'
+ SettlementFailed = 'settlement_failed'
+ SubmittedForSettlement = 'submitted_for_settlement'
+ Unknown = 'unknown'
+ Voided = 'voided'
+ end
+
module Type # :nodoc:
Credit = "credit" # :nodoc:
Sale = "sale" # :nodoc:
@@ -35,6 +35,8 @@ def [](index)
@errors[index]
end
+ # Returns an array of ValidationError objects at this level and all nested levels in the error
+ # hierarchy
def deep_errors
([@errors] + @nested.values.map { |error_collection| error_collection.deep_errors }).flatten
end
@@ -63,6 +65,11 @@ def on(attribute)
@errors.select { |error| error.attribute == attribute.to_s }
end
+ # Returns an array of ValidationError objects at the given level in the error hierarchy
+ def shallow_errors
+ @errors.dup
+ end
+
# The number of errors at this level. This does not include nested errors.
def size
@errors.size
View
@@ -2,7 +2,7 @@ module Braintree
module Version
Major = 1
Minor = 2
- Tiny = 0
+ Tiny = 1
String = "#{Major}.#{Minor}.#{Tiny}"
end
@@ -67,7 +67,7 @@
:options => {:verify_card => true}
)
result.success?.should == false
- result.credit_card_verification.status.should == "processor_declined"
+ result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
result.credit_card_verification.processor_response_code.should == "2000"
result.credit_card_verification.processor_response_text.should == "Do Not Honor"
result.credit_card_verification.cvv_response_code.should == "I"
@@ -116,6 +116,28 @@
result.success?.should == false
result.errors.for(:credit_card).on(:expiration_date)[0].message.should == "Expiration date is invalid."
end
+
+ it "can set the default flag" do
+ customer = Braintree::Customer.create!
+ card1 = Braintree::CreditCard.create(
+ :customer_id => customer.id,
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2009"
+ ).credit_card
+ card1.should be_default
+
+ card2 = Braintree::CreditCard.create(
+ :customer_id => customer.id,
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2009",
+ :options => {
+ :make_default => true
+ }
+ ).credit_card
+ card2.should be_default
+
+ Braintree::CreditCard.find(card1.token).should_not be_default
+ end
end
describe "self.create!" do
@@ -221,6 +243,39 @@
credit_card.customer_id.should == customer.id
end
+ it "create card as default" do
+ customer = Braintree::Customer.create!(
+ :credit_card => {
+ :cardholder_name => "Old Cardholder Name",
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2012"
+ }
+ )
+ card1 = customer.credit_cards[0]
+
+ params = {
+ :credit_card => {
+ :cardholder_name => "Card Holder",
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2012",
+ :options => {:make_default => true}
+ }
+ }
+ tr_data_params = {
+ :credit_card => {
+ :customer_id => customer.id
+ }
+ }
+ tr_data = Braintree::TransparentRedirect.create_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
+ query_string_response = SpecHelper.simulate_form_post_for_tr(Braintree::CreditCard.create_credit_card_url, tr_data, params)
+ result = Braintree::CreditCard.create_from_transparent_redirect(query_string_response)
+ result.success?.should == true
+ card2 = result.credit_card
+
+ Braintree::CreditCard.find(card1.token).should_not be_default
+ card2.should be_default
+ end
+
it "returns xml with nested errors if validation errors" do
customer = Braintree::Customer.create.customer
params = {
@@ -307,7 +362,7 @@
:options => {:verify_card => true}
)
update_result.success?.should == false
- update_result.credit_card_verification.status.should == "processor_declined"
+ update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
end
it "can update the billing address" do
@@ -373,6 +428,28 @@
update_result.success?.should == false
update_result.errors.for(:credit_card).on(:number)[0].message.should == "Credit card number must be 12-19 digits."
end
+
+ it "can update the default" do
+ customer = Braintree::Customer.create!
+ card1 = Braintree::CreditCard.create(
+ :customer_id => customer.id,
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2009"
+ ).credit_card
+ card2 = Braintree::CreditCard.create(
+ :customer_id => customer.id,
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2009"
+ ).credit_card
+
+ card1.should be_default
+ card2.should_not be_default
+
+ Braintree::CreditCard.update(card2.token, :options => {:make_default => true})
+
+ Braintree::CreditCard.find(card1.token).should_not be_default
+ Braintree::CreditCard.find(card2.token).should be_default
+ end
end
describe "self.update!" do
@@ -451,6 +528,41 @@
credit_card.expiration_date.should == "05/2014"
credit_card.token.should == new_token
end
+
+ it "updates the default credit card" do
+ customer = Braintree::Customer.create!(
+ :credit_card => {
+ :cardholder_name => "Old Cardholder Name",
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2012"
+ }
+ )
+ card1 = customer.credit_cards[0]
+
+ card2 = Braintree::CreditCard.create(
+ :customer_id => customer.id,
+ :number => Braintree::Test::CreditCardNumbers::Visa,
+ :expiration_date => "05/2009"
+ ).credit_card
+
+ card1.should be_default
+ card2.should_not be_default
+
+ params = {
+ :credit_card => {
+ :options => {:make_default => true}
+ }
+ }
+ tr_data_params = {
+ :payment_method_token => card2.token
+ }
+ tr_data = Braintree::TransparentRedirect.update_credit_card_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
+ query_string_response = SpecHelper.simulate_form_post_for_tr(Braintree::CreditCard.update_credit_card_url, tr_data, params)
+ result = Braintree::CreditCard.update_from_transparent_redirect(query_string_response)
+
+ Braintree::CreditCard.find(card1.token).should_not be_default
+ Braintree::CreditCard.find(card2.token).should be_default
+ end
end
describe "credit" do
@@ -744,7 +856,7 @@
:options => {:verify_card => true}
)
update_result.success?.should == false
- update_result.credit_card_verification.status.should == "processor_declined"
+ update_result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
end
it "can update the billing address" do
@@ -110,7 +110,7 @@
}
)
result.success?.should == false
- result.credit_card_verification.status.should == "processor_declined"
+ result.credit_card_verification.status.should == Braintree::Transaction::Status::ProcessorDeclined
end
it "can create a customer, payment method, and billing address at the same time" do
@@ -10,7 +10,7 @@
:expiration_date => "12/2012"
}
)
- transaction.status.should == "authorized"
+ transaction.status.should == Braintree::Transaction::Status::Authorized
end
end
@@ -23,7 +23,7 @@
:expiration_date => "12/2012"
}
)
- transaction.status.should == "processor_declined"
+ transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
end
end
end
Oops, something went wrong.

0 comments on commit 8229c6f

Please sign in to comment.