spree-kashflow 0.1.0 → 0.1.1

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: ff9334bd3e09ee1cdb9965f3eddc61af9d887161dd95901c9b54bc6feaf15cdc
4
- data.tar.gz: 7e4576dd85f13c15326591811c0d05a6efa17de61a44e1b82b6a62fca8dd0717
3
+ metadata.gz: b2346845707634b7353b64e8d2a982136ead6009e47f7b1ea5b94d1e905b5455
4
+ data.tar.gz: 2a238745c13d9cd5a6cf0fde8e2854b2a7bc9c12c3ad35df25e396ea0d8a7159
5
5
  SHA512:
6
- metadata.gz: d55939c427bc7154665e69801126b67a35cc95f01024f9303f9d380377b3b290db422ce3e67cd802c98465a65db9b85bdb47f01c015e84340062bdcebe60856a
7
- data.tar.gz: b785bbb7a59d6a80686fe13b3cab2f37b83e4d7d7d97d87369c13c09a469852a76604a51d431f5a6e433953ce1e1242feb68f67ffecc10397ee5dff8576f28e7
6
+ metadata.gz: ff74935654982f15a9094b50b36a26d1507705b33955444df4d9490c7511d51008c6c01cd92c42ff036475f5eb7d5ad475e820aa3ddee699fe9c35d895681956
7
+ data.tar.gz: ecca24ec4c22aef839778a214b0a62e206588836810cb012ac762151e08ef9aed538a5e0c5b8c5a8c90ca21151658003b644691437ac19e4a8244d68a8b46438
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1
4
+
5
+ - **Fix: every order sync failed against a live KashFlow account.** The customer
6
+ `Code` was set to the order's email address, which KashFlow rejects — "the
7
+ customer code specified is invalid, please re-enter without any special
8
+ characters" — on the customer upsert, before an invoice was ever attempted.
9
+ Codes are now uppercase-alphanumeric and derived from the customer rather than
10
+ the order: `SPU<user id>` for a registered user, `SPG<email digest>` for a
11
+ guest. Both are stable across that customer's orders, which is what keeps
12
+ `InsertCustomer` an update rather than a duplicate.
13
+ - Require `digest` explicitly rather than relying on a transitive dependency to
14
+ load it.
15
+ - Replace the placeholder integration logo with the IRIS KashFlow brand asset.
16
+
3
17
  ## 0.1.0
4
18
 
5
19
  - Initial release.
@@ -23,6 +23,42 @@ module Spree
23
23
  # column, so this gem reads it out of `order.metadata` under this key.
24
24
  VAT_NUMBER_METADATA_KEY = "vat_number"
25
25
 
26
+ ##
27
+ # KashFlow rejects a customer `Code` that carries special characters:
28
+ #
29
+ # NO: The customer code specified is invalid, please re-enter without
30
+ # any special characters.
31
+ #
32
+ # v0.1.0 sent `order.email` here, so EVERY sync failed on the customer
33
+ # upsert before an invoice was ever attempted — caught on the first live
34
+ # order (tkf-prd order 12, 2026-08-18). The WSDL types `Code` as a bare
35
+ # `s:string` with no facets, so the rule is server-side and undiscoverable
36
+ # from the schema; these codes are therefore deliberately conservative —
37
+ # uppercase alphanumerics only, comfortably short.
38
+ #
39
+ # `InsertCustomer` upserts BY `Code`, so the code identifies the CUSTOMER,
40
+ # not the order. Anything per-order would create a fresh KashFlow customer
41
+ # on every purchase instead of updating the existing one.
42
+
43
+ # @return [String] format for a registered user's code, keyed on the Spree
44
+ # user id so it survives the customer changing their email address.
45
+ USER_CODE_FORMAT = "SPU%d"
46
+
47
+ # @return [String] format for a guest's code. Guests have no stable id, so
48
+ # the normalised email is hashed — same email in, same code out, which is
49
+ # what keeps the upsert an update rather than a duplicate.
50
+ GUEST_CODE_FORMAT = "SPG%s"
51
+
52
+ # @return [Integer] hex characters of the email digest kept in a guest code.
53
+ # 12 hex chars is 48 bits: collision-safe at any plausible customer count
54
+ # while leaving the total code short.
55
+ GUEST_CODE_DIGEST_LENGTH = 12
56
+
57
+ # @return [Integer] the longest code this presenter will emit. KashFlow does
58
+ # not publish the limit in the WSDL; this is a conservative ceiling that
59
+ # both formats stay well inside.
60
+ CODE_MAX_LENGTH = 20
61
+
26
62
  ##
27
63
  # @param order [Spree::Order] a completed order with a billing address
28
64
  #
@@ -43,7 +79,7 @@ module Spree
43
79
  #
44
80
  def to_h
45
81
  payload = {
46
- "Code" => order.email,
82
+ "Code" => customer_code,
47
83
  "Name" => customer_name,
48
84
  "Email" => order.email,
49
85
  "Address1" => bill_address&.address1,
@@ -66,6 +102,41 @@ module Spree
66
102
  # @return [Spree::Order]
67
103
  attr_reader :order
68
104
 
105
+ ##
106
+ # The KashFlow customer reference. See {USER_CODE_FORMAT} for why this is
107
+ # keyed on the customer rather than the order, and why it is alphanumeric.
108
+ #
109
+ # The order-number fallback is unreachable for a completed order — Spree
110
+ # validates email presence — but it exists so a blank email cannot collapse
111
+ # every such order onto one shared code, which would merge unrelated
112
+ # customers into a single KashFlow record.
113
+ #
114
+ # @return [String] an uppercase-alphanumeric customer code
115
+ #
116
+ def customer_code
117
+ return format(USER_CODE_FORMAT, order.user_id) if order.user_id.present?
118
+ return order.number if normalized_email.blank?
119
+
120
+ format(GUEST_CODE_FORMAT, email_digest)
121
+ end
122
+
123
+ ##
124
+ # @return [String] the order email, lowercased and stripped, so that the
125
+ # same guest is not split across several KashFlow customers by casing or
126
+ # stray whitespace
127
+ #
128
+ def normalized_email
129
+ order.email.to_s.strip.downcase
130
+ end
131
+
132
+ ##
133
+ # @return [String] the leading {GUEST_CODE_DIGEST_LENGTH} hex characters of
134
+ # the normalised email's SHA-256, uppercased
135
+ #
136
+ def email_digest
137
+ Digest::SHA256.hexdigest(normalized_email)[0, GUEST_CODE_DIGEST_LENGTH].upcase
138
+ end
139
+
69
140
  ##
70
141
  # Nullable on purpose. A digital-only order can complete with no billing
71
142
  # address at all, and a `NoMethodError` here would escape the sync job's
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Spree
4
4
  module Kashflow
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.1"
6
6
  end
7
7
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "digest"
3
4
  require "spree/core"
4
5
  require "savon"
5
6
  require "spree/kashflow/version"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree-kashflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aypex