Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix payments on Klarna #23

Merged
merged 3 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def self.prepended(base)
scope :klarna_credit, ->{ where(source_type: 'Spree::KlarnaCreditPayment') }
scope :risky, -> do
joins("JOIN spree_klarna_credit_payments ON spree_payments.source_id = spree_klarna_credit_payments.id")
.where("avs_response IN (?) OR (cvv_response_code IS NOT NULL and cvv_response_code != 'M') OR state = 'failed' OR (fraud_status = 'REJECTED' AND source_type = 'Spree::KlarnaCreditPayment')", Spree::Payment::RISKY_AVS_CODES)
.where("avs_response IN (?) OR (cvv_response_code IS NOT NULL and cvv_response_code != 'M') OR state = 'failed' OR (fraud_status = 'REJECTED' AND source_type = 'Spree::KlarnaCreditPayment')", ::Spree::Payment::RISKY_AVS_CODES)
end

scope :klarna_risky, -> do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def unit_price
end

def total_amount
(shipment.total * 100).to_i
(shipment.cost * 100).to_i
end

def total_tax_amount
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<% if @payment_method.persisted? && (@payment_method.preferred_api_key.blank? || @payment_method.preferred_api_secret.blank?)
missing_preferece = [
(Spree.t('api_key') if @payment_method.preferred_api_key.blank?),
(Spree.t('api_secret') if @payment_method.preferred_api_secret.blank?),
].compact.to_sentence(locale: I18n.locale)
%>
<% if @payment_method.type == "Spree::Gateway::KlarnaCredit" %>
<% if @payment_method.persisted? && (@payment_method.preferred_api_key.blank? || @payment_method.preferred_api_secret.blank?)
missing_preferece = [
(Spree.t('api_key') if @payment_method.preferred_api_key.blank?),
(Spree.t('api_secret') if @payment_method.preferred_api_secret.blank?),
].compact.to_sentence(locale: I18n.locale)
%>
<div class="errorExplanation align-center">
<span class="fa fa-exclamation-circle"></span>
<%= Spree.t('klarna.specify_credentials', missing_preferece: missing_preferece) %>
<%= Spree.t('klarna.specify_credentials', missing_preferece: missing_preferece) %>
</div>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
json.partial!('spree/api/payments/source_views/check', payment_source: payment_source)

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def validate_klarna_credentials

klarna_response = Klarna.client(:credit).create_session({})

if klarna_response.code == 401
if klarna_response.http_response.code == '401'
flash[:error] = I18n.t('spree.klarna.invalid_api_credentials')
else
flash[:notice] = I18n.t('spree.klarna.valid_api_credentials')
Expand Down