spree-paypal_merchant 6.0.1 → 6.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d09d026a692438a7e89cd1eb47700bc34fb8ef077da6475c94dd61471e70dfed
4
- data.tar.gz: fca83a3ef6cfb0bb6e27851d65c0ae0daa35b414506acc25218246bbe0a0c19a
3
+ metadata.gz: 628bafaed312453b5971e9fa948b04974c7befe223923a432dd981562eb1d3db
4
+ data.tar.gz: 808222f11a91d8f2f835162d9ce64b3782c95de2acc11c0d06621b70ac44a91d
5
5
  SHA512:
6
- metadata.gz: 765ffdaf6c95115be5c8f51cf31d42b1c3e171ff0cef1435abff604112735d45eae3051dde53ce5da75d6bb52f29108d6b7c811e02b834f997cef954f2c115c8
7
- data.tar.gz: 3ddd64eabd1c28835cd4c4760f1c375ede3c45d9dc7251ab69be6f478703633f83f193d4f3498ac13aa7b92c8ea827d12e51e8ceb7f09e9b6a6a65f271c809c2
6
+ metadata.gz: 1833821671186a5de1ffa8b1a8df6c0099bb09c20e27c5ac843511c11325a1db3efbb612e4d1b2a802b83bf3236fd4e83590a01299d57caa4f4a19f8bc10e42a
7
+ data.tar.gz: f922a3aa04ccd11e9fbb1c77dd649038fad83c8790106d539c12bdb5c8718feb6b2c03d0dedaa4696a78fd6fa9ad322ae67587dd13252a0e956b21ba0481fb55
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.3
4
+
5
+ ### Added
6
+
7
+ - A payment session's `external_data` carries `client_id`, the payment
8
+ method's PayPal client id. A storefront that loads PayPal's JS SDK with it
9
+ always uses the same PayPal app (sandbox or live) as the order. A client id
10
+ set in storefront config at build time could point at the live app while the
11
+ backend used the sandbox one, and checkout then failed. PayPal client ids are
12
+ public: the SDK sends them in its script URL.
13
+
14
+ ## 6.0.2
15
+
16
+ ### Fixed
17
+
18
+ - The PayPal SDK no longer writes a `WARN Request …` and `WARN Response …` line
19
+ to standard output for every PayPal call. Given no logger, the SDK printed to
20
+ standard output at the level the gem passed, outside the app's log level and
21
+ format. `Spree::PaypalMerchant::SdkLogger` now hands those lines to the Rails
22
+ log at `debug`, prefixed `[spree-paypal_merchant]`, so a production log at
23
+ `info` leaves them out (see "Logging" in the README).
24
+
3
25
  ## 6.0.1
4
26
 
5
27
  To record refunds made in PayPal, subscribe the webhook to
data/README.md CHANGED
@@ -23,6 +23,10 @@ releases, on the `5-2-stable` branch.
23
23
  (`POST /api/v3/store/carts/:id/payment_sessions` → complete).
24
24
  - The storefront owns the address. The gem pins it with
25
25
  `SET_PROVIDED_ADDRESS` so PayPal does not re-collect it.
26
+ - The payment session's `external_data.client_id` is the client id to load
27
+ PayPal's JS SDK with. It comes from the payment method, so the SDK always
28
+ belongs to the same PayPal app (sandbox or live) as the order, and one
29
+ storefront build can serve a sandbox and a live backend.
26
30
  - PayPal **captures at checkout**, whatever capture method the store defaults
27
31
  to. Authorize now, capture later is not supported: a payment method whose own
28
32
  capture method is `on_dispatch` or `manual` is refused. Spree never captures a
@@ -207,6 +211,13 @@ Three things to know before you cut over:
207
211
  id is now keyed by the cart's (or order's) prefixed id instead of the order
208
212
  number. Such a source isn't reused, and a new one is created.
209
213
 
214
+ ## Logging
215
+
216
+ The PayPal SDK logs one line per request and one per response: the method, URL,
217
+ status and content type, never bodies or headers. The gem sends these lines to
218
+ the Rails log at `debug`, prefixed `[spree-paypal_merchant]`, so a production
219
+ log at `info` leaves them out. To see them, set the log level to `debug`.
220
+
210
221
  ## Known limitations
211
222
 
212
223
  - PayPal treats HUF and TWD as zero-decimal currencies, but Spree formats them
@@ -105,6 +105,11 @@ module Spree
105
105
 
106
106
  session_data = paypal_response.data.as_json
107
107
 
108
+ # The client id the storefront loads PayPal's JS SDK with. It must
109
+ # be the same app as the client secret that created the order, so
110
+ # it comes from this payment method rather than storefront config.
111
+ # PayPal client ids are public: the SDK puts them in its URL.
112
+ session_data['client_id'] = preferred_client_id
108
113
  session_data['enable_apple_pay'] = apple_pay_enabled?
109
114
  session_data['enable_card_fields'] = card_fields_enabled?
110
115
 
@@ -135,10 +140,10 @@ module Spree
135
140
  # the new amount. The same amount is accepted.
136
141
  #
137
142
  # +external_data+ is ignored. The gem writes every key the storefront
138
- # reads (+id+, +status+, +client_token+, +enable_apple_pay+,
139
- # +enable_card_fields+), and settlement reads PayPal's own order
140
- # (+purchase_units+, +payment_source+), so no key is the client's to
141
- # write.
143
+ # reads (+id+, +status+, +client_id+, +client_token+,
144
+ # +enable_apple_pay+, +enable_card_fields+), and settlement reads
145
+ # PayPal's own order (+purchase_units+, +payment_source+), so no key
146
+ # is the client's to write.
142
147
  #
143
148
  # @param payment_session [Spree::PaymentSessions::PaypalMerchant]
144
149
  # @param amount [Numeric, String, NilClass]
@@ -271,8 +271,11 @@ module Spree
271
271
  timeout: REQUEST_TIMEOUT,
272
272
  max_retries: MAX_RETRIES,
273
273
  retry_methods: RETRY_METHODS,
274
+ # Request and response lines go to the Rails log at debug, so a
275
+ # production log at info leaves them out.
274
276
  logging_configuration: PaypalServerSdk::LoggingConfiguration.new(
275
- log_level: Logger::WARN,
277
+ logger: Spree::PaypalMerchant::SdkLogger.new,
278
+ log_level: Logger::DEBUG,
276
279
  request_logging_config: PaypalServerSdk::RequestLoggingConfiguration.new(
277
280
  log_body: false
278
281
  ),
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Spree
4
+ module PaypalMerchant
5
+ ##
6
+ # Hands the PayPal SDK's request and response lines to the Rails log.
7
+ #
8
+ # Given no logger, the SDK writes each line to standard output, outside
9
+ # the app's log level and format. It calls #log with a template such as
10
+ # "Request {method} {url}" and the values that fill it; a plain Logger
11
+ # would print the template unfilled.
12
+ #
13
+ # @example
14
+ # PaypalServerSdk::LoggingConfiguration.new(logger: Spree::PaypalMerchant::SdkLogger.new, log_level: Logger::DEBUG)
15
+ #
16
+ class SdkLogger
17
+ PREFIX = '[spree-paypal_merchant]'
18
+ PLACEHOLDER = /\{([\w-]+)\}/
19
+
20
+ ##
21
+ # @param logger [Logger] where the lines go
22
+ #
23
+ def initialize(logger = Rails.logger)
24
+ @logger = logger
25
+ end
26
+
27
+ ##
28
+ # @param level [Integer] the Logger severity to write at
29
+ # @param message [String] the SDK's template, with {name} placeholders
30
+ # @param params [Hash{String, Symbol => Object}] the placeholder values
31
+ # @return [true]
32
+ #
33
+ def log(level, message, params = {})
34
+ @logger.add(level) { "#{PREFIX} #{fill(message, params)}" }
35
+ end
36
+
37
+ private
38
+
39
+ def fill(message, params)
40
+ message.gsub(PLACEHOLDER) do
41
+ key = Regexp.last_match(1)
42
+ params.fetch(key) { params[key.to_sym] }
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -4,6 +4,6 @@ module Spree
4
4
  module PaypalMerchant
5
5
  # Major version tracks Spree's major version: 6.x supports Spree 6.
6
6
  # 5.2.x supports Spree 5.6 and lives on the `5-2-stable` branch.
7
- VERSION = '6.0.1'
7
+ VERSION = '6.0.3'
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree-paypal_merchant
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.1
4
+ version: 6.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aypex
@@ -141,6 +141,7 @@ files:
141
141
  - app/models/spree/paypal_merchant/payment_sources/apple_pay.rb
142
142
  - app/models/spree/paypal_merchant/payment_sources/card.rb
143
143
  - app/models/spree/paypal_merchant/payment_sources/paypal.rb
144
+ - app/models/spree/paypal_merchant/sdk_logger.rb
144
145
  - app/models/spree/paypal_merchant/store_decorator.rb
145
146
  - app/presenters/spree/paypal_merchant/order_presenter.rb
146
147
  - app/serializers/spree/api/v3/payment_method_serializer_decorator.rb