Skip to content
This repository has been archived by the owner on Mar 27, 2023. It is now read-only.

Commit

Permalink
Updated specs related to redonation notification
Browse files Browse the repository at this point in the history
  • Loading branch information
shivashankar-ror committed Apr 22, 2019
1 parent e2cba78 commit fd1e65a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
10 changes: 8 additions & 2 deletions app/controllers/api/payment/braintree_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ def webhook
end

def one_click
member = Member.find_by_email(params[:user][:email])
@result = client::OneClick.new(unsafe_params, cookies.signed[:payment_methods], member).run

render status: :unprocessable_entity, errors: oneclick_payment_errors unless @result.success?
end

private

def member
if params[:user][:email].present?
Member.find_by_email(params[:user][:email])
elsif unsafe_params[:akid].present?
Member.find_from_request(akid: unsafe_params[:akid], id: cookies.signed[:member_id])
end
end

def oneclick_payment_errors
if @result.class == Braintree::ErrorResult
client::ErrorProcessing.new(@result, locale: locale).process
Expand Down
2 changes: 2 additions & 0 deletions app/lib/payment_processor/braintree/one_click.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def initialize(params, cookied_payment_methods, member = nil)
end

def run
raise PaymentProcessor::Exceptions::CustomerNotFound unless @member.try(:customer)

# TODO: On the second attempt (if the member consents to duplicate donation), post with the same parameters
# but also params[:allow_duplicate] = true
return duplicate_donation_error_response if duplicate_donation && !payment_options.params[:allow_duplicate]
Expand Down
2 changes: 1 addition & 1 deletion app/lib/payment_processor/braintree/one_click_from_uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(params, page:, member: nil, cookied_payment_methods: '')
def process
return false unless one_click?

PaymentProcessor::Braintree::OneClick.new(options, @cookied_payment_methods).run
PaymentProcessor::Braintree::OneClick.new(options, @cookied_payment_methods, member).run
self
end

Expand Down
6 changes: 4 additions & 2 deletions spec/features/express_donations/page_one_click_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
}

VCR.use_cassette('feature_member_express_donation') do
path = api_payment_braintree_one_click_path(donation_page.id)
page.driver.post path, params
Timecop.freeze(Time.now + 15.minutes) do
path = api_payment_braintree_one_click_path(donation_page.id)
page.driver.post path, params
end
end

expect(Action.count).to eq(2)
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/analytics/analytics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
'1999-12-31 21:00:00' => 3
}

Timecop.freeze(start_date) do
Timecop.freeze(start_date).utc do
expect(
subject.total_actions_over_time(period: :hour)
).to include(sample_of_expected_data)
Expand All @@ -118,7 +118,7 @@
'1999-12-31 23:00:00' => 3
}

Timecop.freeze(start_date) do
Timecop.freeze(start_date).utc do
expect(
subject.total_new_members_over_time(period: :hour)
).to include(sample_of_expected_data)
Expand Down

0 comments on commit fd1e65a

Please sign in to comment.