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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97c99937dc2438c125576c76a62612f9642a065d4be80f501680dc02bf2f3118
4
- data.tar.gz: 99dc484286596d4a19ae911f9d5600dc784445323f94d7f87b61e33595d0d566
3
+ metadata.gz: 1c76a1f970b64c2272d26562e66eaedc69679092e19459ac7685acdd9ac4d4ee
4
+ data.tar.gz: a462ad9b3f0eec5aa2ab3ef84c46b28ea8d940f2cedf6c4c51328bf259c01f8a
5
5
  SHA512:
6
- metadata.gz: 1a4e5e86e18e94828bc3bda772e22fc243814779615b3f8eade31da9187524c412610fc75915f10519d2e4aa3af3a373dc775fd9ed9f856741c2102593b11ad2
7
- data.tar.gz: fba074d8567aec60944de486d64e5e1576c47a4df91fdff97c9fb8f16a7bc0d3e4225aaa262cd8467e2b6bad8cdffd3ee2fda2d5b91264881ba253dfd74342bc
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
- # Clover stores rate as integer (e.g. 825000 = 8.25%)
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
- payload = inject_idempotency_key(payload) if method == :post && payload.is_a?(Hash)
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: "+15551000001" },
59
- { given: "Jane", family: "Doe", phone: "+15551000002" },
60
- { given: "Bob", family: "Johnson", phone: "+15551000003" },
61
- { given: "Alice", family: "Williams", phone: "+15551000004" },
62
- { given: "Charlie", family: "Brown", phone: "+15551000005" },
63
- { given: "Diana", family: "Davis", phone: "+15551000006" },
64
- { given: "Eve", family: "Miller", phone: "+15551000007" },
65
- { given: "Frank", family: "Wilson", phone: "+15551000008" },
66
- { given: "Grace", family: "Moore", phone: "+15551000009" },
67
- { given: "Henry", family: "Taylor", phone: "+15551000010" },
68
- { given: "Ivy", family: "Anderson", phone: "+15551000011" },
69
- { given: "Jack", family: "Thomas", phone: "+15551000012" },
70
- { given: "Karen", family: "Jackson", phone: "+15551000013" },
71
- { given: "Leo", family: "White", phone: "+15551000014" },
72
- { given: "Maria", family: "Harris", phone: "+15551000015" },
73
- { given: "Nate", family: "Martin", phone: "+15551000016" },
74
- { given: "Olivia", family: "Garcia", phone: "+15551000017" },
75
- { given: "Paul", family: "Martinez", phone: "+15551000018" },
76
- { given: "Quinn", family: "Robinson", phone: "+15551000019" },
77
- { given: "Rachel", family: "Clark", phone: "+15551000020" },
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 = Faker::PhoneNumber.cell_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]/, "")
@@ -51,8 +51,8 @@ module SquareSandboxSimulator
51
51
  payload = {
52
52
  "source_id" => "EXTERNAL",
53
53
  "external_details" => {
54
- "type" => "CASH",
55
- "source" => "Cash Register",
54
+ "type" => "OTHER",
55
+ "source" => "Cash",
56
56
  },
57
57
  "amount_money" => {
58
58
  "amount" => amount,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SquareSandboxSimulator
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: square_sandbox_simulator
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
  - Dan