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

Adds preliminary support for Klarna #1059

Closed
wants to merge 48 commits into from
Closed

Adds preliminary support for Klarna #1059

wants to merge 48 commits into from

Conversation

edward
Copy link
Contributor

@edward edward commented Mar 4, 2014

@bslobodin @louiskearns Here’s my first draft for Klarna support.

Plan:

  • Klarna ActionView helper with knowns and existing Shopify API
  • Add support in ActionView helper that knows how to produce the fields that Klarna needs given cart items
  • Get confirmation on what we should do when we have more than one tax rate for a single cart line item on the Shopify side as Klarna only supports a single tax rate
  • Test change to PaymentProvider-related stuff for change around requires_cart_items
  • Add tests in Shopify that make a taxed line item and assert that it produces the Klarna-ok object
  • Add a transformer in Shopify that turns a Cart::LineItem into an object compatible with what the Klarna gateway wants
  • Add support/tests in Shopify for passing in cart items with the data that Klarna needs*
  • Get confirmation on what testing and production service_url is
  • Confirm that merchant_terms_uri, merchant_checkout_uri, merchant_base_uri, merchant_confirmation_uri can all be the same URL to the cancel page
  • Confirm that it’s cool to do locale-guessing from just the shop country
  • Test via a remote/integration test that this thing works for real with test credentials
  • Get real, non-staging endpoints
  • Figure out how return-url and notification-url works
  • Add missing shipping-line information

*Cart item data that Klarna needs: 'type', 'reference', 'quantity', 'unit_price', 'tax_rate'

@edward
Copy link
Contributor Author

edward commented Mar 4, 2014

Test failed due to a missing SSH key in Circle CI. Related issue logged here: https://github.com/Shopify/ops/issues/569

@bslobodin
Copy link
Contributor

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.

@edward
Copy link
Contributor Author

edward commented Mar 4, 2014

@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'
Copy link
Contributor

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

@edward
Copy link
Contributor Author

edward commented Mar 24, 2014

@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
Copy link
Contributor Author

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?

Copy link
Contributor Author

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.)

Copy link
Contributor

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.

@edward
Copy link
Contributor Author

edward commented Apr 16, 2014

@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)
Copy link
Contributor

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??

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@edward
Copy link
Contributor Author

edward commented Apr 28, 2014

@bslobodin @odorcicd

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:

  • guessing the locale from the billing address country may cause an exception, but only under truly exceptional circumstances – Klarna shouldn’t even appear as an option if the buyer hasn’t specified one of the countries that the locale-guessing method is aware of
  • Klarna has confirmed to be throwing away information other than the shipping address email and shipping address postal code – beyond pushing Klarna not to do this, there’s not much we can do on the AM side to correct this UX oddity

Anything else that I’ve missed before I squash and bump?


private

def street_address
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@odorcicd
Copy link
Contributor

@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]
Copy link
Contributor

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?

@edward
Copy link
Contributor Author

edward commented Apr 28, 2014

@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:

image

@odorcicd
Copy link
Contributor

@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]

Copy link
Contributor

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',
Copy link
Contributor

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'
Copy link
Contributor Author

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?

Copy link
Contributor

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)

Copy link
Contributor Author

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
.

@edward
Copy link
Contributor Author

edward commented Apr 29, 2014

Squash-merged into master

@edward edward closed this Apr 29, 2014
@edward edward deleted the klarna branch June 16, 2014 13:35
@edward
Copy link
Contributor Author

edward commented Jun 16, 2014

@ntalbott Ok, deleted

@patrickdet
Copy link

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?
/cc @edward

@edward
Copy link
Contributor Author

edward commented Oct 1, 2014

@patrickdet “It’s complicated”

Shopify and Klarna are still talking about how we’re going to integrate. I forget what happened to the PR.

@beranPro
Copy link

anything new on this PR ?
Are there any plans to integrate Klarna ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants