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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b2346845707634b7353b64e8d2a982136ead6009e47f7b1ea5b94d1e905b5455
|
|
4
|
+
data.tar.gz: 2a238745c13d9cd5a6cf0fde8e2854b2a7bc9c12c3ad35df25e396ea0d8a7159
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
Binary file
|
|
@@ -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" =>
|
|
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
|
data/lib/spree/kashflow.rb
CHANGED