Skip to content

Commit

Permalink
Stripe integration: don't display missing payment info if payments ha…
Browse files Browse the repository at this point in the history
…ve just been set up
  • Loading branch information
valdis committed Sep 21, 2017
1 parent 0629eaa commit 4172486
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
8 changes: 4 additions & 4 deletions app/controllers/application_controller.rb
Expand Up @@ -353,7 +353,7 @@ def fetch_community_plan_expiration_status
# Before filter for payments, shows notification if user is not ready for payments
def warn_about_missing_payment_info
if @current_user
has_paid_listings = PaypalHelper.open_listings_with_payment_process?(@current_community.id, @current_user.id)
has_paid_listings = PaymentHelper.open_listings_with_payment_process?(@current_community.id, @current_user.id)
paypal_community = PaypalHelper.community_ready_for_payments?(@current_community.id)
stripe_community = StripeHelper.community_ready_for_payments?(@current_community.id)
paypal_ready = PaypalHelper.account_prepared_for_user?(@current_user.id, @current_community.id)
Expand All @@ -367,10 +367,10 @@ def warn_about_missing_payment_info
accept_payments << :stripe
end

payment_settings_link = view_context.link_to(t("paypal_accounts.from_your_payment_settings_link_text"),
person_payment_settings_path(@current_user), target: "_blank")

if has_paid_listings && accept_payments.blank?
payment_settings_link = view_context.link_to(t("paypal_accounts.from_your_payment_settings_link_text"),
person_payment_settings_path(@current_user), target: "_blank")

flash.now[:warning] = t("stripe_accounts.missing_payment", settings_link: payment_settings_link).html_safe
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/payment_settings_controller.rb
Expand Up @@ -5,6 +5,7 @@ class PaymentSettingsController < ApplicationController

before_action :ensure_payments_enabled
before_action :load_stripe_account
skip_before_action :warn_about_missing_payment_info, only: [:update]

def index
more_locals = {}
Expand Down Expand Up @@ -51,6 +52,7 @@ def update
stripe_send_verification
end

warn_about_missing_payment_info
index
end

Expand Down
23 changes: 23 additions & 0 deletions app/view_utils/payment_helper.rb
@@ -0,0 +1,23 @@
module PaymentHelper

module_function

def open_listings_with_payment_process?(community_id, user_id)
processes = TransactionService::API::Api.processes.get(community_id: community_id)[:data]
payment_process_ids = processes.reject { |p| p[:process] == :none }.map { |p| p[:id] }

if payment_process_ids.empty?
false
else
listing_count = Listing
.where(
community_id: community_id,
author_id: user_id,
open: true,
transaction_process_id: payment_process_ids)
.count

listing_count > 0
end
end
end
21 changes: 1 addition & 20 deletions app/view_utils/paypal_helper.rb
Expand Up @@ -85,26 +85,7 @@ def paypal_provisioned?(community_id)
def open_listings_with_missing_payment_info?(user_id, community_id)
paypal_active?(community_id) &&
!user_and_community_ready_for_payments?(user_id, community_id) &&
open_listings_with_payment_process?(community_id, user_id)
end

def open_listings_with_payment_process?(community_id, user_id)
processes = TransactionService::API::Api.processes.get(community_id: community_id)[:data]
payment_process_ids = processes.reject { |p| p[:process] == :none }.map { |p| p[:id] }

if payment_process_ids.empty?
false
else
listing_count = Listing
.where(
community_id: community_id,
author_id: user_id,
open: true,
transaction_process_id: payment_process_ids)
.count

listing_count > 0
end
PaymentHelper.open_listings_with_payment_process?(community_id, user_id)
end

def accounts_api
Expand Down
2 changes: 1 addition & 1 deletion app/view_utils/stripe_helper.rb
Expand Up @@ -57,7 +57,7 @@ def publishable_key(community_id)
def open_listings_with_missing_payment_info?(user_id, community_id)
stripe_active?(community_id) &&
!user_and_community_ready_for_payments?(user_id, community_id) &&
PaypalHelper.open_listings_with_payment_process?(community_id, user_id)
PaymentHelper.open_listings_with_payment_process?(community_id, user_id)
end

# We are not using FeatureFlagHelper.feature_enabled?(:stripe) here,
Expand Down

0 comments on commit 4172486

Please sign in to comment.