square_sandbox_simulator 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 +4 -4
- data/lib/square_sandbox_simulator/generators/entity_generator.rb +1 -6
- data/lib/square_sandbox_simulator/generators/order_generator.rb +7 -0
- data/lib/square_sandbox_simulator/services/base_service.rb +4 -2
- data/lib/square_sandbox_simulator/services/square/customer_service.rb +21 -21
- data/lib/square_sandbox_simulator/services/square/payment_service.rb +2 -2
- data/lib/square_sandbox_simulator/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1c76a1f970b64c2272d26562e66eaedc69679092e19459ac7685acdd9ac4d4ee
|
|
4
|
+
data.tar.gz: a462ad9b3f0eec5aa2ab3ef84c46b28ea8d940f2cedf6c4c51328bf259c01f8a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2a99ed94ea3a8a113e44847e42d85a2bacc965acf9ae30b19a5460269f4dedb41cc285f6a72368ef82ba7c7e499b6662b145b39fce2105bb9868820ab57ad9ce
|
|
7
|
+
data.tar.gz: 06ca906215de6cd58d371e70262dbbed54b142240c4ca94866f5c97e7b72e753101a6531e9954eea73f12f511a2b799642aa49b395affd04a3278bf3988aef77
|
|
@@ -168,12 +168,7 @@ module SquareSandboxSimulator
|
|
|
168
168
|
created << match if match
|
|
169
169
|
else
|
|
170
170
|
# Square expects percentage as string (e.g. "8.25")
|
|
171
|
-
|
|
172
|
-
percentage = if rate_data["rate"]
|
|
173
|
-
(rate_data["rate"] / 100_000.0).to_s
|
|
174
|
-
else
|
|
175
|
-
rate_data["percentage"]&.to_s || "0"
|
|
176
|
-
end
|
|
171
|
+
percentage = (rate_data["rate"] || rate_data["percentage"] || 0).to_s
|
|
177
172
|
|
|
178
173
|
result = services.catalog.upsert_tax(
|
|
179
174
|
name: name,
|
|
@@ -308,6 +308,13 @@ module SquareSandboxSimulator
|
|
|
308
308
|
# Determine dining option and calculate tip
|
|
309
309
|
dining = select_dining_option(period)
|
|
310
310
|
subtotal = order.dig("total_money", "amount") || 0
|
|
311
|
+
|
|
312
|
+
# Skip payment if order total is zero (e.g. 100% discount)
|
|
313
|
+
if subtotal <= 0
|
|
314
|
+
logger.warn " Order #{order_id} has zero total — skipping payment"
|
|
315
|
+
return nil
|
|
316
|
+
end
|
|
317
|
+
|
|
311
318
|
tip_amount = calculate_tip(subtotal, dining, party_size)
|
|
312
319
|
|
|
313
320
|
# Process payment (card or cash)
|
|
@@ -31,8 +31,10 @@ module SquareSandboxSimulator
|
|
|
31
31
|
def request(method, path, payload: nil, params: nil, resource_type: nil, resource_id: nil)
|
|
32
32
|
url = build_url(path, params)
|
|
33
33
|
|
|
34
|
-
# Inject idempotency key for POST requests
|
|
35
|
-
|
|
34
|
+
# Inject idempotency key for mutating POST requests (skip search/retrieve/calculate)
|
|
35
|
+
if method == :post && payload.is_a?(Hash) && !path.match?(/search|batch-retrieve|calculate/)
|
|
36
|
+
payload = inject_idempotency_key(payload)
|
|
37
|
+
end
|
|
36
38
|
|
|
37
39
|
log_request(method, url, payload)
|
|
38
40
|
start_time = Time.now
|
|
@@ -55,26 +55,26 @@ module SquareSandboxSimulator
|
|
|
55
55
|
|
|
56
56
|
# Default customer data for deterministic setup
|
|
57
57
|
DEFAULT_CUSTOMERS = [
|
|
58
|
-
{ given: "John", family: "Smith", phone: "+
|
|
59
|
-
{ given: "Jane", family: "Doe", phone: "+
|
|
60
|
-
{ given: "Bob", family: "Johnson", phone: "+
|
|
61
|
-
{ given: "Alice", family: "Williams", phone: "+
|
|
62
|
-
{ given: "Charlie", family: "Brown", phone: "+
|
|
63
|
-
{ given: "Diana", family: "Davis", phone: "+
|
|
64
|
-
{ given: "Eve", family: "Miller", phone: "+
|
|
65
|
-
{ given: "Frank", family: "Wilson", phone: "+
|
|
66
|
-
{ given: "Grace", family: "Moore", phone: "+
|
|
67
|
-
{ given: "Henry", family: "Taylor", phone: "+
|
|
68
|
-
{ given: "Ivy", family: "Anderson", phone: "+
|
|
69
|
-
{ given: "Jack", family: "Thomas", phone: "+
|
|
70
|
-
{ given: "Karen", family: "Jackson", phone: "+
|
|
71
|
-
{ given: "Leo", family: "White", phone: "+
|
|
72
|
-
{ given: "Maria", family: "Harris", phone: "+
|
|
73
|
-
{ given: "Nate", family: "Martin", phone: "+
|
|
74
|
-
{ given: "Olivia", family: "Garcia", phone: "+
|
|
75
|
-
{ given: "Paul", family: "Martinez", phone: "+
|
|
76
|
-
{ given: "Quinn", family: "Robinson", phone: "+
|
|
77
|
-
{ given: "Rachel", family: "Clark", phone: "+
|
|
58
|
+
{ given: "John", family: "Smith", phone: "+12125550101" },
|
|
59
|
+
{ given: "Jane", family: "Doe", phone: "+12125550102" },
|
|
60
|
+
{ given: "Bob", family: "Johnson", phone: "+12125550103" },
|
|
61
|
+
{ given: "Alice", family: "Williams", phone: "+12125550104" },
|
|
62
|
+
{ given: "Charlie", family: "Brown", phone: "+12125550105" },
|
|
63
|
+
{ given: "Diana", family: "Davis", phone: "+12125550106" },
|
|
64
|
+
{ given: "Eve", family: "Miller", phone: "+12125550107" },
|
|
65
|
+
{ given: "Frank", family: "Wilson", phone: "+12125550108" },
|
|
66
|
+
{ given: "Grace", family: "Moore", phone: "+12125550109" },
|
|
67
|
+
{ given: "Henry", family: "Taylor", phone: "+12125550110" },
|
|
68
|
+
{ given: "Ivy", family: "Anderson", phone: "+12125550111" },
|
|
69
|
+
{ given: "Jack", family: "Thomas", phone: "+12125550112" },
|
|
70
|
+
{ given: "Karen", family: "Jackson", phone: "+12125550113" },
|
|
71
|
+
{ given: "Leo", family: "White", phone: "+12125550114" },
|
|
72
|
+
{ given: "Maria", family: "Harris", phone: "+12125550115" },
|
|
73
|
+
{ given: "Nate", family: "Martin", phone: "+12125550116" },
|
|
74
|
+
{ given: "Olivia", family: "Garcia", phone: "+12125550117" },
|
|
75
|
+
{ given: "Paul", family: "Martinez", phone: "+12125550118" },
|
|
76
|
+
{ given: "Quinn", family: "Robinson", phone: "+12125550119" },
|
|
77
|
+
{ given: "Rachel", family: "Clark", phone: "+12125550120" },
|
|
78
78
|
].freeze
|
|
79
79
|
|
|
80
80
|
# Create sample customers if needed (idempotent)
|
|
@@ -98,7 +98,7 @@ module SquareSandboxSimulator
|
|
|
98
98
|
else
|
|
99
99
|
given = Faker::Name.first_name
|
|
100
100
|
family = Faker::Name.last_name
|
|
101
|
-
phone =
|
|
101
|
+
phone = "+1212#{format("%07d", rand(1_000_000..9_999_999))}"
|
|
102
102
|
end
|
|
103
103
|
|
|
104
104
|
safe_given = given.downcase.gsub(/[^a-z0-9]/, "")
|