workarea-paypal 3.0.4 → 3.0.5

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: 11b3db0ccfcaf33684bf21632d8a5ad2db9092f21993f68495b357b80962e1e3
4
- data.tar.gz: 2fb729f7458c8d9925dfdf9f8728ccbd90eeccd0e8dada3384a76e5d47a697f9
3
+ metadata.gz: 92bdac05441fd966fa90acc4cb18badd013d583b0cc69b98a36a79144e5e5fac
4
+ data.tar.gz: 519be45e1b7a3e27167df514ae49fe1ac32eaf5250156c9ed88b6c15e7c1bf7d
5
5
  SHA512:
6
- metadata.gz: c3fd4c2e52cf635eb6460b02041cef631026b31f9358a16c6b7ec55b00a92ff3f89c8eeec4ea4d14d48041c31e680d07ad26cd0c2e68383bc94ee287087d1d12
7
- data.tar.gz: a35ed6dfce864733502fe2eab4a688776d1b35e6c189bd54f2a42d5ab75369cd03f588514c3bf97e9805d66b6d61d9ce31e520bd8169e3eec8246abf5cbc68f1
6
+ metadata.gz: a6d388830f585b699138e407415190f6d8d21489d22666010d2a1a3e3c2499320c0b26b9b3c1cfb7082e0e23ea53cd11d49eba8662852e34deaefb1b7624d731
7
+ data.tar.gz: ff569d2f2291693dfbb839c84b678ccb662b8f69286c3194233550ccc7731e2b13f854d42184e635ec1a2303e5c31352f307a2a518ed5b78f706666afa099840
@@ -1,3 +1,37 @@
1
+ Workarea Paypal 3.0.5 (2020-08-14)
2
+ --------------------------------------------------------------------------------
3
+
4
+ * Address Race Condition When Using PayPal's SDK
5
+
6
+ It's possible that our modules that use the PayPal SDK will be
7
+ initialized prior to `window.paypal` being available on the page, now
8
+ that the JS is loaded in asynchronously, causing unnecessary loss in
9
+ functionality. Additionally, there doesn't seem to be a way to bind to
10
+ any kind of event given off by the SDK on `window` that would allow us
11
+ to know whether the SDK is truly loaded or not. To address this, when
12
+ the `window.paypal` object is not available yet, and there's a
13
+ `<script>` tag on the page loading the PayPal SDK (indicating that we
14
+ are indeed expecting the SDK to be there), the PayPal modules will
15
+ re-try initializing every 5 seconds until `window.paypal` is available.
16
+
17
+ PAYPAL-7
18
+
19
+ Tom Scott
20
+
21
+ * Load JavaScript From PayPal Asynchronously
22
+
23
+ Using the `async` attribute in the `<script>` tag that loads PayPal's
24
+ JavaScript code, Workarea can now prevent it blocking the page in case
25
+ of a failure, and improve load time performance to boot.
26
+
27
+ PAYPAL-7
28
+
29
+ Fixes #10
30
+
31
+ Tom Scott
32
+
33
+
34
+
1
35
  Workarea Paypal 3.0.4 (2020-06-17)
2
36
  --------------------------------------------------------------------------------
3
37
 
data/Gemfile CHANGED
@@ -3,4 +3,4 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
4
  gemspec
5
5
 
6
- gem 'workarea'
6
+ gem 'workarea', github: 'workarea-commerce/workarea', branch: 'v3.5-stable'
@@ -0,0 +1,63 @@
1
+ /**
2
+ *
3
+ * Reliably ensure that the PayPal SDK is either loaded or will
4
+ * be loading.
5
+ *
6
+ * @namespace WORKAREA.paypal
7
+ */
8
+ WORKAREA.registerModule('paypal', (function () {
9
+ 'use strict';
10
+
11
+ var handlers = [],
12
+ attempts = 0,
13
+ paypalLoaded = null,
14
+
15
+ /**
16
+ * Define a function that will be called when the paypal SDK has
17
+ * loaded.
18
+ *
19
+ * @method
20
+ * @name ready
21
+ * @param function handler - A function to be called when PayPal
22
+ * is available.
23
+ * @memberof WORKAREA.paypal
24
+ */
25
+ ready = function(handler) {
26
+ if (paypalLoaded) {
27
+ handler();
28
+ } else {
29
+ handlers.push(handler);
30
+ }
31
+ },
32
+
33
+ /**
34
+ * Continuously check for whether the Paypal SDK has loaded
35
+ * every 5 seconds, and call function handlers defined in
36
+ * `ready()` when the `window.paypal` object is available. This
37
+ * will only occur if the `<script>` tag containing the PayPal
38
+ * SDK is detected to be on the page.
39
+ *
40
+ * @method
41
+ * @name init
42
+ * @memberof WORKAREA.paypal
43
+ */
44
+ init = function() {
45
+ var $sdk = $('script[data-partner-attribution-id]'),
46
+ paypalExpectedToLoad = !_.isEmpty($sdk);
47
+
48
+ attempts += 1;
49
+ paypalLoaded = window.paypal !== undefined;
50
+
51
+ if (!paypalLoaded && paypalExpectedToLoad && attempts <= 20) {
52
+ window.setTimeout(init, 2000);
53
+ } else if (paypalLoaded) {
54
+ _.each(handlers, function(handler) { handler(); });
55
+ handlers = [];
56
+ }
57
+ };
58
+
59
+ return {
60
+ ready: ready,
61
+ init: init
62
+ };
63
+ }()));
@@ -56,13 +56,14 @@ WORKAREA.registerModule('paypalButtons', (function () {
56
56
  * @name init
57
57
  * @memberof WORKAREA.paypalButtons
58
58
  */
59
- init = function ($scope) {
60
- var $buttonContainer = $('#paypal-button-container', $scope);
59
+ init = function($scope) {
60
+ WORKAREA.paypal.ready(function() {
61
+ var $buttonContainer = $('#paypal-button-container', $scope);
61
62
 
62
- if (window.paypal === undefined) { return; }
63
- if (_.isEmpty($buttonContainer)) { return; }
63
+ if (_.isEmpty($buttonContainer)) { return; }
64
64
 
65
- setup($buttonContainer);
65
+ setup($buttonContainer);
66
+ });
66
67
  };
67
68
 
68
69
  return {
@@ -81,13 +81,14 @@ WORKAREA.registerModule('paypalHostedFields', (function () {
81
81
  * @memberof WORKAREA.paypalHostedFields
82
82
  */
83
83
  init = function ($scope) {
84
- var $placeholder = $('[data-paypal-hosted-fields]', $scope);
84
+ WORKAREA.paypal.ready(function () {
85
+ var $placeholder = $('[data-paypal-hosted-fields]', $scope);
85
86
 
86
- if (_.isEmpty($placeholder)) { return; }
87
- if (window.paypal === undefined) { return; }
88
- if (!paypal.HostedFields.isEligible()) { return; }
87
+ if (_.isEmpty($placeholder)) { return; }
88
+ if (!paypal.HostedFields.isEligible()) { return; }
89
89
 
90
- setup($placeholder, $scope);
90
+ setup($placeholder, $scope);
91
+ });
91
92
  };
92
93
 
93
94
  return {
@@ -27,6 +27,7 @@ module Workarea
27
27
 
28
28
  javascript_include_tag(
29
29
  "https://www.paypal.com/sdk/js?#{params.to_query}",
30
+ async: true,
30
31
  data: {
31
32
  partner_attribution_id: 'Workarea_SP', # Do not change this
32
33
  client_token: @paypal_client_token
@@ -25,6 +25,7 @@ Workarea::Plugin.append_javascripts(
25
25
 
26
26
  Workarea::Plugin.append_javascripts(
27
27
  'storefront.modules',
28
+ 'workarea/storefront/paypal/modules/paypal',
28
29
  'workarea/storefront/paypal/modules/update_checkout_submit_text',
29
30
  'workarea/storefront/paypal/modules/paypal_buttons',
30
31
  'workarea/storefront/paypal/modules/paypal_hosted_fields'
@@ -1,5 +1,5 @@
1
1
  module Workarea
2
2
  module Paypal
3
- VERSION = '3.0.4'.freeze
3
+ VERSION = '3.0.5'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workarea-paypal
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - bcrouse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-17 00:00:00.000000000 Z
11
+ date: 2020-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workarea
@@ -76,6 +76,7 @@ files:
76
76
  - app/assets/images/workarea/admin/payment_icons/paypal.svg
77
77
  - app/assets/images/workarea/storefront/payment_icons/paypal.svg
78
78
  - app/assets/javascripts/workarea/storefront/paypal/config.js.erb
79
+ - app/assets/javascripts/workarea/storefront/paypal/modules/paypal.js
79
80
  - app/assets/javascripts/workarea/storefront/paypal/modules/paypal_buttons.js
80
81
  - app/assets/javascripts/workarea/storefront/paypal/modules/paypal_hosted_fields.js
81
82
  - app/assets/javascripts/workarea/storefront/paypal/modules/update_checkout_submit_text.js