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
Adds preliminary support for Klarna #1059
Conversation
Test failed due to a missing SSH key in Circle CI. Related issue logged here: https://github.com/Shopify/ops/issues/569 |
AM is actually using Travis (https://travis-ci.org/Shopify/active_merchant). Yes, someone added a Circle project as well, but it was never fully set up AFAICT. |
@bslobodin Ah, yeah, I see that now. I’m going to have the generated tests be skipped for now. |
module Klarna | ||
|
||
mattr_accessor :service_url | ||
self.service_url = 'https://hpp-staging-eu.herokuapp.com/api/v1/checkout' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add support for both staging and live? This looks like just a test url
@bslobodin @odorcicd Could you please take a look at what’s been done so far? |
end | ||
|
||
# Acknowledge the transaction to Klarna. This method has to be called after a new | ||
# apc arrives. Klarna will verify that all the information we received are correct and will return a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@odorcicd @bslobodin What’s an apc in this context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This is part of the generated stuff that AM made for me.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea what it actually stands for, but it's a callback we get from the gateway with the status of the payment and acknowledge
needs to check if it can be trusted before further processing takes place, i.e. order update.
@bslobodin @odorcicd I think this guy is pretty much done. Can you please take a look? |
merchant_checkout_uri | ||
merchant_base_uri | ||
merchant_confirmation_uri).each do |required_field| | ||
raise ArgumentError, "Missing required field #{required_field}" unless fields.has_key?(required_field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps unless fields[required_field].present?
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like has_key?
is more readable here and tells a better story – I care about whether a key is set at all.
Conversely, fields[required_field].present?
is more about whether the value of that hash key is nil
or not, which isn’t exactly the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me required
suggests that it should be raising when values are nil or empty as well.
I think we’re good here, but I just wanted to ping you before I squash, bump the version number, and release a new version of ActiveMerchant. The remaining unresolved issues are:
Anything else that I’ve missed before I squash and bump? |
|
||
private | ||
|
||
def street_address |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
@edward still find it weird that Klarna would blow up if there's someone making a purchase from outside one of those countries. This means any merchant using Klarna can't have any international customers? |
self.currency = options[:currency] | ||
self.credential2 = options[:credential2] | ||
self.credential3 = options[:credential3] | ||
self.credential4 = options[:credential4] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These used to be aligned?
@odorcicd the Klarna gateway page will currently blow up if they are somehow sent a customer with a billing address country that is not in their supported list. Here’s a picture of the error: |
@edward do they also blowup if the billing information put in is a US address, for example? |
|
||
def test_basic_helper_fields | ||
assert_field 'purchase_currency', @options[:currency] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line?
'merchant_confirmation_uri' => 'http://some-webstore.se?URI=confirmation' | ||
} | ||
|
||
cart_items =[{:type => 'physical', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after =
.
assert_field 'cart_item-0_name', item[:name].to_s | ||
assert_field 'cart_item-0_quantity', item[:quantity].to_s | ||
assert_field 'cart_item-0_unit_price', item[:unit_price].to_s | ||
assert_field 'cart_item-0_tax_rate', '1000' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something feels wrong about this calculated amount. Is the formula correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, yea, the rate should be %ge? If you set the below, the rate should be 10%
or 0.1
, depending on how it needs to be expressed to Klarna.
:unit_price => Money.new(9.00),
:tax_amount => Money.new(0.90)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rate as expressed to Klarna should be a percentage multiplied by 100
and converted to an integer.
Am I missing something?
—
Edward https://www.google.ca/search?q=edward+ocampo-gooding at Shopify
On Tue, Apr 29, 2014 at 11:21 AM, Boris Slobodin
notifications@github.comwrote:
In test/unit/integrations/helpers/klarna_helper_test.rb:
- def test_merchant_digest
- @Helper = valid_helper
- assert_field 'merchant_digest', "/fUAJJiWEluzrwL1AX8pptGFYP3T1gWIv+tafLnARzY="
- end
- def test_line_item
- item = example_line_item
- @helper.line_item(item)
- assert_field 'cart_item-0_type', item[:type].to_s
- assert_field 'cart_item-0_reference', item[:reference].to_s
- assert_field 'cart_item-0_name', item[:name].to_s
- assert_field 'cart_item-0_quantity', item[:quantity].to_s
- assert_field 'cart_item-0_unit_price', item[:unit_price].to_s
- assert_field 'cart_item-0_tax_rate', '1000'
Hm, yea, the rate should be %ge? If you set the below, the rate should be
10% or 0.1, depending on how it needs to be expressed to Klarna.:unit_price => Money.new(9.00),
:tax_amount => Money.new(0.90)—
Reply to this email directly or view it on GitHubhttps://github.com//pull/1059/files#r12098609
.
Squash-merged into master |
@ntalbott Ok, deleted |
Whatever happened to this Klarna patch? It's nowhere to be found but in this pull-request. Did you decide to drop support for Klarna? |
@patrickdet “It’s complicated” Shopify and Klarna are still talking about how we’re going to integrate. I forget what happened to the PR. |
anything new on this PR ? |
@bslobodin @louiskearns Here’s my first draft for Klarna support.
Plan:
PaymentProvider
-related stuff for change aroundrequires_cart_items
*Cart item data that Klarna needs: 'type', 'reference', 'quantity', 'unit_price', 'tax_rate'