Skip to content

Commit

Permalink
i18n added
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshumishra31 committed Apr 13, 2018
1 parent d8b5dcc commit 98157af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/models/spree/payment_method/gift_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def can_capture?(payment)

def authorize(amount_in_cents, gift_card, gateway_options = {})
order = Spree::Order.find_by(number: get_order_number(gateway_options))
if gift_card.nil? || !gift_card.enabled || order.email != gift_card.email || order.line_items.map(&:product).any? { |p| p.is_gift_card? }
return ActiveMerchant::Billing::Response.new(false, Spree.t('gift_card_payment_method.cannot_buy_from_gift_card'), {}, {}) if order_with_gift_card?(order)
if gift_card.nil? || !gift_card.enabled || order.email != gift_card.email
ActiveMerchant::Billing::Response.new(false, Spree.t('gift_card_payment_method.unable_to_find'), {}, {})
else
action = -> (gift_card) do
Expand All @@ -44,7 +45,8 @@ def void(auth_code, gateway_options = {})

def purchase(amount_in_cents, gift_card, gateway_options = {})
order = Spree::Order.find_by(number: get_order_number(gateway_options))
if gift_card.nil? || !gift_card.enabled || order.email != gift_card.email || order.line_items.map(&:product).any? { |p| p.is_gift_card? }
return ActiveMerchant::Billing::Response.new(false, Spree.t('gift_card_payment_method.cannot_buy_from_gift_card'), {}, {}) if order_with_gift_card?(order)
if gift_card.nil? || !gift_card.enabled || order.email != gift_card.email
ActiveMerchant::Billing::Response.new(false, Spree.t('gift_card_payment_method.unable_to_find'), {}, {})
else
action = -> (gift_card) do
Expand All @@ -69,6 +71,10 @@ def source_required?

private

def order_with_gift_card?(order)
order.line_items.map(&:product).any? { |p| p.is_gift_card? }
end

def handle_action_call(gift_card, action, action_name, auth_code = nil)
gift_card.with_lock do
if response = action.call(gift_card)
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ en:
unable_to_find_for_action: "Could not find gift card for auth code: %{auth_code} for action: %{action}"
unable_to_void: "Unable to void code: %{auth_code}"
unable_to_credit: "Unable to credit code: %{auth_code}"
cannot_buy_from_gift_card: "Cannot buy gift card from gift card."
gift_card_redeemed: 'Gift card has been redeemed successfully.'
gift_card_settings: 'Gift Card Settings'
gift_card_user: 'Gift Card User'
Expand Down

0 comments on commit 98157af

Please sign in to comment.