Permalink
Browse files

Customer can confirm a transparent redirect

  • Loading branch information...
1 parent cc1df68 commit 962ec8122ac69bc05105c6390e90a6ff1bda7778 @jferris jferris committed Dec 9, 2011
Showing with 36 additions and 0 deletions.
  1. +4 −0 lib/ashmont/customer.rb
  2. +32 −0 spec/ashmont/customer_spec.rb
View
@@ -77,6 +77,10 @@ def country_name
credit_card.billing_address.country_name if credit_card
end
+ def confirm(query_string)
+ handle_result Braintree::TransparentRedirect.confirm(query_string)
+ end
+
private
def create_or_update(attributes)
@@ -235,4 +235,36 @@
Ashmont::Customer.new("xyz").send(billing_address_attribute).should == "expected"
end
end
+
+ it "confirms a transparent redirect query string" do
+ token = "xyz"
+ query_string = "abcmagic"
+ remote_customer = stub("customer", :credit_cards => [], :id => token)
+ confirm_result = stub("result", :success? => true, :customer => remote_customer)
+ Braintree::TransparentRedirect.stubs(:confirm => confirm_result)
+
+ customer = Ashmont::Customer.new
+ customer.confirm(query_string).should be_true
+
+ Braintree::TransparentRedirect.should have_received(:confirm).with(query_string)
+ customer.token.should == token
+ end
+
+ it "adds errors for an invalid transparent redirect query string" do
+ error_messages = "error messages"
+ errors = "errors"
+ verification = "failure"
+ confirm_result = stub("result",
+ :success? => false,
+ :errors => error_messages,
+ :credit_card_verification => verification)
+ Braintree::TransparentRedirect.stubs(:confirm => confirm_result)
+ Ashmont::Errors.stubs(:new => errors)
+
+ customer = Ashmont::Customer.new
+ customer.confirm("abc").should be_false
+
+ Ashmont::Errors.should have_received(:new).with(verification, error_messages)
+ customer.errors.should == errors
+ end
end

0 comments on commit 962ec81

Please sign in to comment.