workarea-klarna 1.0.0 → 1.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b329672c7677a15dd2c837beac7585af2d605687b4b08d330e334227d687006
4
- data.tar.gz: 5bf7f652fbe885802606eb15307c4660eb78c50012e1e05032e1ad7c0e856373
3
+ metadata.gz: e17b49cdfa065638bbb4f8888d123947759b86a69943fe5f44de06a53bea9b4a
4
+ data.tar.gz: 8ebf705cd2f857c1e60327bbef2db98fe1370a5805c68174cea2d7454757df5d
5
5
  SHA512:
6
- metadata.gz: 0271d39ec81381a10988b829b408f3fb9bf870c0654262b843329d0262365c4f3dc0f3133b57ceffaedfb1a8ab2fd907acc7869d533ca78527a7d9a518e9fbda
7
- data.tar.gz: f77a15b2f8f09f748f04d2bd32259c4721af1382060b682a2266e73b280578c22308e1223d26baf98bfe9028942eca19654211dbce11fefc318bc189093510c7
6
+ metadata.gz: 68a20b6f8e5c7b950ce72512f82eaff39d06eed6762905f3c7bb5fe0b16bfe5156062d27bf22b16c78eb9cd0d2075a0145b5d807d956ea00cabb5ecc01d11d78
7
+ data.tar.gz: eeaa6d9753cba65d3d96dcaccfab52d17b4402b00e2a0270f9b67cf8510ea2217f234ca757562c01ca247e8c7fb69dd160877114c29c0f584743234918db4996
@@ -1,3 +1,23 @@
1
+ Workarea Klarna 1.1.0.beta1 (2020-12-08)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * bump version for beta release
5
+
6
+
7
+ Matt Duffy
8
+
9
+ * add pushing to weblinc gem server
10
+
11
+
12
+ Matt Duffy
13
+
14
+ * Add On-Site Messaging support
15
+
16
+
17
+ Matt Duffy
18
+
19
+
20
+
1
21
  Workarea Klarna 1.0.0 (2020-10-14)
2
22
  --------------------------------------------------------------------------------
3
23
 
data/README.md CHANGED
@@ -8,6 +8,7 @@ Overview
8
8
  * Adds Klarna tender type.
9
9
  * Dynamically provides payment options in checkout based on customer's eligible payment options determined by geographic location.
10
10
  * Supports authorizations, captures, cancellations, and refunds.
11
+ * Enables On-Site Messaging through admin configuration.
11
12
 
12
13
  Getting Started
13
14
  --------------------------------------------------------------------------------
@@ -68,6 +69,22 @@ You must provide credentials for each region you would like to support. The plug
68
69
 
69
70
  You can get more specific information from the [Klarna Developer](https://developers.klarna.com/) portal.
70
71
 
72
+ ## On-Site Messaging
73
+
74
+ Klarna allows you to strategically place information about Klarna payments on your website through On-Site Messaging. The workarea-klarna plugin simplifies the installation process by including the required script tag and some common placements when an admin user configures on-site messaging in the admin.
75
+
76
+ ### Enabling
77
+
78
+ Workarea provides two configuration fields in the admin under the "Klarna" section to allow the use of messaging. The first field is the on-site messaging client ID. To obtain an ID, [go through the activation process](https://developers.klarna.com/documentation/on-site-messaging/integration/platform-activation/) on your Klarna merchant portal. This will provide a code sample of the script tag that Workarea will automatically generate. Copy the client ID from that code sample and set it within the Workarea configuration page, select the region that corresponds to the region of your merchant portal (North America, Europe, or Oceania), and you're done!
79
+
80
+ ### Automated Placements
81
+
82
+ Once you provide the client ID, Workarea will automatically enable two placements on your site. The first is the "info-page" placement, which is used to generate the page at **yoursite.com/klarna** and a link to that page will be added to the footer navigation. The second placement is on product detail pages, where a message will display under the add to cart button advertising Klarna as a payment option. The price within this message will update if/when the price of the product changes as a user selects product options.
83
+
84
+ ### Custom Placements
85
+
86
+ To add more placements to your site, you can utilize the various system and content pages by adding a HTML content block and copying the placement code from your [Klarna merchant portal placements page](https://developers.klarna.com/documentation/on-site-messaging/integration/installation/#adding-placements).
87
+
71
88
  Workarea Platform Documentation
72
89
  --------------------------------------------------------------------------------
73
90
 
data/Rakefile CHANGED
@@ -32,6 +32,8 @@ require 'workarea/klarna/version'
32
32
 
33
33
  desc "Release version #{Workarea::Klarna::VERSION} of the gem"
34
34
  task :release do
35
+ host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
36
+
35
37
  Rake::Task['workarea:changelog'].execute
36
38
  system 'git add CHANGELOG.md'
37
39
  system 'git commit -m "Update CHANGELOG"'
@@ -41,6 +43,7 @@ task :release do
41
43
 
42
44
  system "gem build workarea-klarna.gemspec"
43
45
  system "gem push workarea-klarna-#{Workarea::Klarna::VERSION}.gem"
46
+ system "gem push workarea-klarna-#{Workarea::Klarna::VERSION}.gem --host #{host}"
44
47
  system "rm workarea-klarna-#{Workarea::Klarna::VERSION}.gem"
45
48
  end
46
49
 
@@ -0,0 +1,22 @@
1
+ /**
2
+ * @namespace WORKAREA.klarnaPlacementRefresh
3
+ */
4
+ WORKAREA.registerModule('klarnaPlacementRefresh', (function () {
5
+ 'use strict';
6
+
7
+ /**
8
+ * @method
9
+ * @name init
10
+ * @memberof WORKAREA.klarnaPlacementRefresh
11
+ */
12
+ var init = function () {
13
+ var $placements = $('[data-klarna-placement-refresh]');
14
+
15
+ if (_.isEmpty($placements)) { return; }
16
+
17
+ window.KlarnaOnsiteService = window.KlarnaOnsiteService || [];
18
+ window.KlarnaOnsiteService.push({ eventName: 'refresh-placements' });
19
+ };
20
+
21
+ return { init: init };
22
+ }()));
@@ -0,0 +1,7 @@
1
+ module Workarea
2
+ decorate Storefront::PagesController, with: :klarna do
3
+ def klarna
4
+ head :not_found unless Klarna.on_site_messaging?
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ module Workarea
2
+ module Storefront
3
+ module KlarnaHelper
4
+ def klarna_on_site_messaging_javacript_tag
5
+ return unless Workarea::Klarna.on_site_messaging?
6
+
7
+ javascript_include_tag(
8
+ klarna_on_site_messaging_url,
9
+ async: true,
10
+ data: {
11
+ client_id: Workarea::Klarna.on_site_messaging_client_id,
12
+ klarna_on_site_messaging: ''
13
+ }
14
+ )
15
+ end
16
+
17
+ def klarna_on_site_messaging_url
18
+ region = Workarea.config.klarna_on_site_messaging_region
19
+ subdomains = [
20
+ Workarea.config.klarna_on_site_messaging_subdomains[region],
21
+ ('playground' if Workarea.config.klarna_playground)
22
+ ]
23
+
24
+ "https://#{subdomains.compact.join('.')}.klarnaservices.com/lib.js"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,2 @@
1
+ - if Workarea::Klarna.on_site_messaging?
2
+ %li.page-footer__help-item= link_to t('workarea.storefront.orders.klarna'), klarna_path, class: 'page-footer__help-link'
@@ -0,0 +1 @@
1
+ = klarna_on_site_messaging_javacript_tag
@@ -0,0 +1,3 @@
1
+ <!-- Placement v2 -->
2
+ %klarna-placement{ data: { key: 'info-page', locale: 'en-US' } }
3
+ <!-- end Placement -->
@@ -0,0 +1,3 @@
1
+ <!-- Placement v2 -->
2
+ %klarna-placement{ data: { key: 'credit-promotion-auto-size', locale: 'en-US', purchase_amount: (product.sell_min_price&.cents || 0), klarna_placement_refresh: request.xhr? } }
3
+ <!-- end Placement -->
@@ -3,12 +3,28 @@ Workarea::Plugin.append_partials(
3
3
  'workarea/storefront/klarna/sdk'
4
4
  )
5
5
 
6
+ Workarea::Plugin.append_partials(
7
+ 'storefront.body_top',
8
+ 'workarea/storefront/klarna/on_site_messaging'
9
+ )
10
+
6
11
  Workarea::Plugin.append_partials(
7
12
  'storefront.payment_method',
8
13
  'workarea/storefront/checkouts/klarna_payments'
9
14
  )
10
15
 
16
+ Workarea::Plugin.append_partials(
17
+ 'storefront.product_details',
18
+ 'workarea/storefront/products/klarna_placement'
19
+ )
20
+
21
+ Workarea::Plugin.append_partials(
22
+ 'storefront.footer_help',
23
+ 'workarea/storefront/klarna/footer_link'
24
+ )
25
+
11
26
  Workarea::Plugin.append_javascripts(
12
27
  'storefront.modules',
13
- 'workarea/storefront/klarna/modules/klarna_widget'
28
+ 'workarea/storefront/klarna/modules/klarna_widget',
29
+ 'workarea/storefront/klarna/modules/klarna_placement_refresh'
14
30
  )
@@ -12,7 +12,7 @@ Workarea.configure do |config|
12
12
  # This controls whether requests go to the live or sandbox API endpoints.
13
13
  config.klarna_playground = !Rails.env.production?
14
14
 
15
- # Continents supported by KLarna and keys used to generate paths to
15
+ # Continents supported by Klarna and keys used to generate paths to
16
16
  # credentials via environment variables and/or rails credentials. Also used
17
17
  # to get the keys for the subdomain configuration.
18
18
  config.klarna_continent_keys = {
@@ -29,4 +29,12 @@ Workarea.configure do |config|
29
29
  'OC' => 'api-oc',
30
30
  'AUS' => 'api-oc'
31
31
  }
32
+
33
+ # Subdomains to use for On-Site Messaging
34
+ config.klarna_on_site_messaging_subdomains = {
35
+ 'EUR' => 'eu-library',
36
+ 'NA' => 'na-library',
37
+ 'OC' => 'oc-library',
38
+ 'AUS' => 'oc-library'
39
+ }
32
40
  end
@@ -24,20 +24,42 @@ Workarea::Configuration.define_fields do
24
24
  field 'Europe Username',
25
25
  type: :string,
26
26
  id: 'klarna_eur_username',
27
- description: 'Your Klarna API username for Europe'
27
+ description: 'Your Klarna API username for Europe',
28
+ allow_blank: true
28
29
  field 'Europe Password',
29
30
  type: :string,
30
31
  id: 'klarna_eur_password',
31
32
  encrypted: true,
32
- description: 'Your Klarna API password for Europe'
33
+ description: 'Your Klarna API password for Europe',
34
+ allow_blank: true
33
35
  field 'North America Username',
34
36
  type: :string,
35
37
  id: 'klarna_na_username',
36
- description: 'Your Klarna API username for North America'
38
+ description: 'Your Klarna API username for North America',
39
+ allow_blank: true
37
40
  field 'North America Password',
38
41
  type: :string,
39
42
  id: 'klarna_na_password',
40
43
  encrypted: true,
41
- description: 'Your Klarna API password for North America'
44
+ description: 'Your Klarna API password for North America',
45
+ allow_blank: true
46
+
47
+ field 'On-Site Messaging Client ID',
48
+ type: :string,
49
+ id: 'klarna_on_site_messaging_client_id',
50
+ allow_blank: true,
51
+ description: %{
52
+ The client ID provided by Klarna when enabling On-Site Messaging in the
53
+ Klarna merchant portal. See
54
+ <a href="https://developers.klarna.com/documentation/on-site-messaging/integration/platform-activation/">the Klarna documentation</a>
55
+ for more information.
56
+ }.squish.html_safe
57
+
58
+ field 'On-Site Messaging Region',
59
+ type: :string,
60
+ id: 'klarna_on_site_messaging_region',
61
+ default: -> { Workarea.config.klarna_continent_keys.values.first },
62
+ values: -> { Workarea.config.klarna_continent_keys.to_a },
63
+ description: 'Region to use for contacting klarna for on-site messaging'
42
64
  end
43
65
  end
@@ -1,2 +1,5 @@
1
- Rails.application.routes.draw do
1
+ Workarea::Storefront::Engine.routes.draw do
2
+ scope '(:locale)', constraints: Workarea::I18n.routes_constraint do
3
+ get 'klarna', to: 'pages#klarna'
4
+ end
2
5
  end
@@ -22,6 +22,16 @@ module Workarea
22
22
  return Klarna::BogusGateway.new unless Workarea.config.load_klarna
23
23
  Klarna::Gateway.new
24
24
  end
25
+
26
+ def on_site_messaging_client_id
27
+ ENV["WORKAREA_KLARNA_ON_SITE_MESSAGING_CLIENT_ID"].presence ||
28
+ Rails.application.credentials.klarna.try(:[], :on_site_messaging_client_id) ||
29
+ Workarea.config.klarna_on_site_messaging_client_id
30
+ end
31
+
32
+ def on_site_messaging?
33
+ on_site_messaging_client_id.present?
34
+ end
25
35
  end
26
36
  end
27
37
  end
@@ -5,6 +5,10 @@ module Workarea
5
5
  class Engine < ::Rails::Engine
6
6
  include Workarea::Plugin
7
7
  isolate_namespace Workarea::Klarna
8
+
9
+ config.to_prepare do
10
+ Storefront::ApplicationController.helper(Storefront::KlarnaHelper)
11
+ end
8
12
  end
9
13
  end
10
14
  end
@@ -1,5 +1,5 @@
1
1
  module Workarea
2
2
  module Klarna
3
- VERSION = "1.0.0".freeze
3
+ VERSION = "1.1.0.beta1".freeze
4
4
  end
5
5
  end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class KlarnaHelperTest < ViewTest
6
+ def test_klarna_on_site_messaging_javacript_tag
7
+ Workarea.config.klarna_on_site_messaging_client_id = nil
8
+ assert_nil(klarna_on_site_messaging_javacript_tag)
9
+
10
+ Workarea.config.klarna_on_site_messaging_client_id = '123'
11
+ Workarea.config.klarna_on_site_messaging_region = 'NA'
12
+ Workarea.config.klarna_playground = true
13
+
14
+ result = klarna_on_site_messaging_javacript_tag
15
+ assert_includes(result, %(src="https://na-library.playground.klarnaservices.com/lib.js"))
16
+ assert_includes(result, %(async))
17
+ assert_includes(result, %(data-client-id="123"))
18
+ assert_includes(result, %(data-klarna-on-site-messaging))
19
+ end
20
+
21
+
22
+ def test_klarna_on_site_messaging_url
23
+ Workarea.config.klarna_on_site_messaging_region = 'NA'
24
+ Workarea.config.klarna_playground = true
25
+
26
+ assert_equal(
27
+ 'https://na-library.playground.klarnaservices.com/lib.js',
28
+ klarna_on_site_messaging_url
29
+ )
30
+
31
+ Workarea.config.klarna_playground = false
32
+ assert_equal(
33
+ 'https://na-library.klarnaservices.com/lib.js',
34
+ klarna_on_site_messaging_url
35
+ )
36
+
37
+ Workarea.config.klarna_on_site_messaging_region = 'EUR'
38
+ assert_equal(
39
+ 'https://eu-library.klarnaservices.com/lib.js',
40
+ klarna_on_site_messaging_url
41
+ )
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ module Storefront
5
+ class KlarnaInfoPageIntegrationTest < Workarea::IntegrationTest
6
+ def test_klarna_info_page
7
+ Workarea.config.klarna_on_site_messaging_client_id = nil
8
+
9
+ get storefront.klarna_path
10
+ assert_response(:missing)
11
+
12
+ Workarea.config.klarna_on_site_messaging_client_id = '123-456'
13
+
14
+ get storefront.klarna_path
15
+ assert_response(:success)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ module Workarea
4
+ class KlarnaTest < TestCase
5
+ def test_on_site_messaging_client_id
6
+ @_kosm_env = ENV['WORKAREA_KLARNA_ON_SITE_MESSAGING_CLIENT_ID']
7
+ @_kosm_cred = Rails.application.credentials.klarna
8
+
9
+ ENV['WORKAREA_KLARNA_ON_SITE_MESSAGING_CLIENT_ID'] = nil
10
+ Rails.application.credentials.klarna = nil
11
+ Workarea.config.klarna_on_site_messaging_client_id = nil
12
+
13
+ assert_nil(Klarna.on_site_messaging_client_id)
14
+ refute(Klarna.on_site_messaging?)
15
+
16
+ Workarea.config.klarna_on_site_messaging_client_id = 'config_123'
17
+ assert_equal('config_123', Klarna.on_site_messaging_client_id)
18
+ assert(Klarna.on_site_messaging?)
19
+
20
+ Rails.application.credentials.klarna = { on_site_messaging_client_id: 'cred_123' }
21
+ assert_equal('cred_123', Klarna.on_site_messaging_client_id)
22
+ assert(Klarna.on_site_messaging?)
23
+
24
+ ENV['WORKAREA_KLARNA_ON_SITE_MESSAGING_CLIENT_ID'] = 'env_123'
25
+ assert_equal('env_123', Klarna.on_site_messaging_client_id)
26
+ assert(Klarna.on_site_messaging?)
27
+ ensure
28
+ ENV['WORKAREA_KLARNA_ON_SITE_MESSAGING_CLIENT_ID'] = @_kosm_env
29
+ Rails.application.credentials.klarna = @_kosm_cred
30
+ end
31
+ end
32
+ end
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.version = Workarea::Klarna::VERSION
10
10
  spec.authors = ["Matt Duffy"]
11
11
  spec.email = ["mduffy@workarea.com"]
12
- spec.homepage = "https://www.workarea.com"
12
+ spec.homepage = "https://github.com/workarea-commerce/workarea-klarna"
13
13
  spec.summary = "Klarna API integration for the Workarea Commerce Platform."
14
14
  spec.description = "Klarna Payments and Order Management API integration with Workarea Commerce."
15
15
  spec.license = "Business Software License"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-klarna
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Duffy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2020-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workarea
@@ -43,10 +43,13 @@ files:
43
43
  - LICENSE
44
44
  - README.md
45
45
  - Rakefile
46
+ - app/assets/javascripts/workarea/storefront/klarna/modules/klarna_placement_refresh.js
46
47
  - app/assets/javascripts/workarea/storefront/klarna/modules/klarna_widget.js
47
48
  - app/controllers/workarea/storefront/checkout/addresses_controller.decorator
48
49
  - app/controllers/workarea/storefront/checkout/place_order_controller.decorator
49
50
  - app/controllers/workarea/storefront/checkouts_controller.decorator
51
+ - app/controllers/workarea/storefront/pages_controller.decorator
52
+ - app/helpers/workarea/storefront/klarna_helper.rb
50
53
  - app/models/workarea/checkout/steps/payment.decorator
51
54
  - app/models/workarea/order.decorator
52
55
  - app/models/workarea/payment.decorator
@@ -60,9 +63,13 @@ files:
60
63
  - app/view_models/workarea/storefront/checkout/payment_view_model.decorator
61
64
  - app/views/workarea/admin/orders/tenders/_klarna.html.haml
62
65
  - app/views/workarea/storefront/checkouts/_klarna_payments.html.haml
66
+ - app/views/workarea/storefront/klarna/_footer_link.html.haml
67
+ - app/views/workarea/storefront/klarna/_on_site_messaging.html.haml
63
68
  - app/views/workarea/storefront/klarna/_sdk.html.haml
64
69
  - app/views/workarea/storefront/order_mailer/tenders/_klarna.html.haml
65
70
  - app/views/workarea/storefront/orders/tenders/_klarna.html.haml
71
+ - app/views/workarea/storefront/pages/klarna.html.haml
72
+ - app/views/workarea/storefront/products/_klarna_placement.html.haml
66
73
  - bin/rails
67
74
  - config/initializers/appends.rb
68
75
  - config/initializers/configuration.rb
@@ -127,6 +134,8 @@ files:
127
134
  - test/dummy/db/seeds.rb
128
135
  - test/dummy/log/.keep
129
136
  - test/factories/workarea/klarna.rb
137
+ - test/helpers/workarea/storefront/klarna_helper_test.rb
138
+ - test/integration/workarea/storefront/klarna_info_page_integration_test.rb
130
139
  - test/integration/workarea/storefront/klarna_session_integration_test.rb
131
140
  - test/lib/workarea/klarna/gateway/capture_request_test.rb
132
141
  - test/lib/workarea/klarna/gateway/create_session_request_test.rb
@@ -137,6 +146,7 @@ files:
137
146
  - test/lib/workarea/klarna/gateway/response_test.rb
138
147
  - test/lib/workarea/klarna/gateway/update_session_request_test.rb
139
148
  - test/lib/workarea/klarna/gateway_test.rb
149
+ - test/lib/workarea/klarna_test.rb
140
150
  - test/models/workarea/checkout/steps/klarna_payment_test.rb
141
151
  - test/models/workarea/klarna_payment_test.rb
142
152
  - test/models/workarea/payment/authorize/klarna_test.rb
@@ -151,7 +161,7 @@ files:
151
161
  - test/vcr_cassettes/klarna_refund.yml
152
162
  - test/view_models/workarea/storefront/checkout/klarna_payment_view_model_test.rb
153
163
  - workarea-klarna.gemspec
154
- homepage: https://www.workarea.com
164
+ homepage: https://github.com/workarea-commerce/workarea-klarna
155
165
  licenses:
156
166
  - Business Software License
157
167
  metadata: {}
@@ -166,9 +176,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
176
  version: '0'
167
177
  required_rubygems_version: !ruby/object:Gem::Requirement
168
178
  requirements:
169
- - - ">="
179
+ - - ">"
170
180
  - !ruby/object:Gem::Version
171
- version: '0'
181
+ version: 1.3.1
172
182
  requirements: []
173
183
  rubygems_version: 3.0.3
174
184
  signing_key: