Permalink
Browse files

Add 'retain' option to the Samurai gateway store method, allowing

yet-to-be-used payment methods to be stored for longer than 24-48 hours
  • Loading branch information...
1 parent c86d95f commit 2acaf5f13048009b9a6c477dd4d56bcd3d5621c3 @brentmc79 brentmc79 committed Mar 6, 2012
@@ -76,6 +76,7 @@ def store(creditcard, options = {})
:zip => address[:zip],
:sandbox => test?
})
+ result.retain if options[:retain] && result.is_sensitive_data_valid && result.payment_method_token
Response.new(result.is_sensitive_data_valid,
message_from_result(result),
@@ -50,6 +50,10 @@ def test_successful_auth_and_void
assert_success @gateway.void(authorize.authorization)
end
+ def test_successful_store_and_retain
+ assert_success @gateway.store(@credit_card, :retain => true)
+ end
+
def test_invalid_login
assert_raise(ArgumentError) do
SamuraiGateway.new( :login => '', :password => '' )
@@ -134,6 +134,42 @@ def test_successful_store
assert_success response
end
+ def test_successful_retain
+ card_to_store = valid_credit_card
+ payment_method = successful_create_payment_method_response
+ Samurai::PaymentMethod.expects(:create).
+ with(card_to_store).
+ returns(payment_method)
+ payment_method.expects(:retain)
+ response = @gateway.store(@successful_credit_card, :retain => true)
+ assert_instance_of Response, response
+ assert_success response
+ end
+
+ def test_no_retain_on_failed_store
+ card_to_store = valid_credit_card
+ payment_method = successful_create_payment_method_response
+ payment_method.is_sensitive_data_valid = false
+ payment_method.payment_method_token = nil
+ Samurai::PaymentMethod.expects(:create).
+ with(card_to_store).
+ returns(payment_method)
+ payment_method.expects(:retain).never
+ response = @gateway.store(@successful_credit_card, :retain => true)
+ end
+
+ def test_no_retain_options
+ card_to_store = valid_credit_card
+ payment_method = successful_create_payment_method_response
+ Samurai::PaymentMethod.expects(:create).
+ with(card_to_store).
+ returns(payment_method).
+ twice
+ payment_method.expects(:retain).never
+ response = @gateway.store(@successful_credit_card, :retain => false)
+ response = @gateway.store(@successful_credit_card)
+ end
+
def test_passing_optional_processor_options
Samurai::Processor.expects(:purchase).
with(@successful_payment_method_token, @amount, {:billing_reference => 'billing_reference'}).
@@ -159,6 +195,22 @@ def test_successful_avs_and_cvv
private
+ def valid_credit_card
+ {
+ :card_number => "4242424242424242",
+ :expiry_month => "09",
+ :expiry_year => (Time.now.year + 1).to_s,
+ :cvv => "123",
+ :first_name => "Longbob",
+ :last_name => "Longsen",
+ :address_1 => nil,
+ :address_2 => nil,
+ :city => nil,
+ :zip => nil,
+ :sandbox => true
+ }
+ end
+
def successful_purchase_response
successful_response("Purchase")
end

0 comments on commit 2acaf5f

Please sign in to comment.