Permalink
Browse files

Do not default starting_at date to Date.tomorrow for recurring modify…

… action. It is not a required parameter for modify action. Add tests to verify the same
  • Loading branch information...
1 parent 6571c65 commit e1b68bc2d832fd8c5c4c7437745720cdd6be71a6 @supritasrinivas supritasrinivas committed Apr 13, 2012
Showing with 95 additions and 2 deletions.
  1. +7 −2 lib/active_merchant/billing/gateways/payflow.rb
  2. +88 −0 test/unit/gateways/payflow_test.rb
@@ -207,8 +207,13 @@ def build_recurring_request(action, money, options)
xml.tag! 'OptionalTrans', TRANSACTIONS[initial_tx[:type]]
xml.tag! 'OptionalTransAmt', amount(initial_tx[:amount]) unless initial_tx[:amount].blank?
end
-
- xml.tag! 'Start', format_rp_date(options[:starting_at] || Date.today + 1 )
+
+ if action == :add
+ xml.tag! 'Start', format_rp_date(options[:starting_at] || Date.today + 1 )
+ else
+ xml.tag! 'Start', format_rp_date(options[:starting_at]) unless options[:starting_at].nil?
+ end
+
xml.tag! 'EMail', options[:email] unless options[:email].nil?
billing_address = options[:billing_address] || options[:address]
@@ -165,6 +165,18 @@ def test_initial_purchase_missing_amount
end
end
+ def test_recurring_add_action_missing_parameters
+ assert_raises ArgumentError do
+ response = @gateway.recurring(@amount, @credit_card)
+ end
+ end
+
+ def test_recurring_modify_action_missing_parameters
+ assert_raises ArgumentError do
+ response = @gateway.recurring(@amount, nil)
+ end
+ end
+
def test_successful_recurring_action
@gateway.stubs(:ssl_post).returns(successful_recurring_response)
@@ -176,6 +188,56 @@ def test_successful_recurring_action
assert response.test?
assert_equal "R7960E739F80", response.authorization
end
+
+ def test_successful_recurring_modify_action
+ @gateway.stubs(:ssl_post).returns(successful_recurring_response)
+
+ response = @gateway.recurring(@amount, nil, :profile_id => "RT0000000009", :periodicity => :monthly)
+
+ assert_instance_of PayflowResponse, response
+ assert_success response
+ assert_equal 'RT0000000009', response.profile_id
+ assert response.test?
+ assert_equal "R7960E739F80", response.authorization
+ end
+
+ def test_successful_recurring_modify_action_with_retry_num_days
+ @gateway.stubs(:ssl_post).returns(successful_recurring_response)
+
+ response = @gateway.recurring(@amount, nil, :profile_id => "RT0000000009", :retry_num_days => 3, :periodicity => :monthly)
+
+ assert_instance_of PayflowResponse, response
+ assert_success response
+ assert_equal 'RT0000000009', response.profile_id
+ assert response.test?
+ assert_equal "R7960E739F80", response.authorization
+ end
+
+ def test_falied_recurring_modify_action_with_starting_at_in_the_past
+ @gateway.stubs(:ssl_post).returns(start_date_error_recurring_response)
+
+ response = @gateway.recurring(@amount, nil, :profile_id => "RT0000000009", :starting_at => Date.yesterday, :periodicity => :monthly)
+
+ assert_instance_of PayflowResponse, response
+ assert_success response
+ assert_equal 'RT0000000009', response.profile_id
+ assert_equal 'Field format error: START or NEXTPAYMENTDATE older than last payment date', response.message
+ assert response.test?
+ assert_equal "R7960E739F80", response.authorization
+ end
+
+ def test_falied_recurring_modify_action_with_starting_at_missing_and_changed_periodicity
+ @gateway.stubs(:ssl_post).returns(start_date_missing_recurring_response)
+
+ response = @gateway.recurring(@amount, nil, :profile_id => "RT0000000009", :periodicity => :yearly)
+
+ assert_instance_of PayflowResponse, response
+ assert_success response
+ assert_equal 'RT0000000009', response.profile_id
+ assert_equal 'Field format error: START field missing', response.message
+ assert response.test?
+ assert_equal "R7960E739F80", response.authorization
+ end
def test_recurring_profile_payment_history_inquiry
@gateway.stubs(:ssl_post).returns(successful_payment_history_recurring_response)
@@ -240,6 +302,32 @@ def successful_recurring_response
XML
end
+ def start_date_error_recurring_response
+ <<-XML
+ <ResponseData>
+ <Result>0</Result>
+ <Message>Field format error: START or NEXTPAYMENTDATE older than last payment date</Message>
+ <Partner>paypal</Partner>
+ <RPRef>R7960E739F80</RPRef>
+ <Vendor>ActiveMerchant</Vendor>
+ <ProfileId>RT0000000009</ProfileId>
+ </ResponseData>
+ XML
+ end
+
+ def start_date_missing_recurring_response
+ <<-XML
+ <ResponseData>
+ <Result>0</Result>
+ <Message>Field format error: START field missing</Message>
+ <Partner>paypal</Partner>
+ <RPRef>R7960E739F80</RPRef>
+ <Vendor>ActiveMerchant</Vendor>
+ <ProfileId>RT0000000009</ProfileId>
+ </ResponseData>
+ XML
+ end
+
def successful_payment_history_recurring_response
<<-XML
<ResponseData>

0 comments on commit e1b68bc

Please sign in to comment.