waffo-pancake 0.4.0 → 0.5.0
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/CHANGELOG.md +19 -0
- data/README.md +40 -2
- data/lib/generators/waffo_pancake/install/templates/webhook_job.rb.tt +6 -0
- data/lib/waffo/pancake/api/queries.rb +2 -1
- data/lib/waffo/pancake/invoice.rb +27 -0
- data/lib/waffo/pancake/version.rb +1 -1
- data/lib/waffo/pancake/webhook/event.rb +43 -3
- data/lib/waffo/pancake/webhook.rb +1 -0
- data/lib/waffo/pancake.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f18c75d9eb86e7b1cd10a99fd51cc078ecc9964209bf419136e7a401fedd98bd
|
|
4
|
+
data.tar.gz: ed4f28af7464c740a900d0f35b5d28aa79c125ce9a0ad5939fd987dd6ad26a8d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f451e9e62bc478c82f0651903f69ecb2ce15f657364488ab5a4c8b54bc9b2322005dbc3c159c0219337d54bb49c32c12a0f138ebf84cbf262a8fd8a010f3e987
|
|
7
|
+
data.tar.gz: 21eae65851e7af4d21220b0e000e60917ecf3cbc0d9709f7ced5eb2c4a7851a2131e8b4a135f2106efaa0f68bf2596a05ab4672e07b8f68d8a0b638491a401ba
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
- Webhook event types: `store.domain_changed` and `store.domain_unbound` (Waffo's November update),
|
|
6
|
+
so `EVENT_TYPES` lists 16. `Webhook.family` returns `:store` for them, and `Event#store?` answers.
|
|
7
|
+
- `EventData` readers for the fields Waffo documents but the gem did not read: `payment_timestamp`,
|
|
8
|
+
`payment_method`, `payment_method_brand`, `payment_id`, `payment_status`, `payment_date`,
|
|
9
|
+
`payment_last4`, `payment_failure_reason`, `refund_status`, `refund_reason`, `refund_created_at`,
|
|
10
|
+
`plan_change`, `store_id`, `store_name`, `old_domain`, `new_domain`, `effective_at`, `domain`,
|
|
11
|
+
`unbound_at` and `unbind_method`.
|
|
12
|
+
- Fixed: reading a deprecated field (`amount`, `total`, ...) on an event that does not carry its
|
|
13
|
+
replacement, such as a store event, raised `KeyError`. It now warns with the replacements for all
|
|
14
|
+
payment, refund and subscription events.
|
|
15
|
+
- `Waffo::Pancake::Invoice.url(payment_id, invoice_token)`: the buyer's invoice link, nil until the
|
|
16
|
+
token exists.
|
|
17
|
+
- GraphQL `PAYMENT_FIELDS` selects `invoiceToken`.
|
|
18
|
+
- The generated `WaffoWebhookJob` template has branches for the two store events. Apps that already
|
|
19
|
+
ran the generator need to add them by hand.
|
|
20
|
+
- README: the idempotency key is required for any write a retry could repeat.
|
|
21
|
+
|
|
3
22
|
## 0.4.0
|
|
4
23
|
|
|
5
24
|
- Every endpoint in Waffo's API reference now has a method:
|
data/README.md
CHANGED
|
@@ -143,7 +143,10 @@ client.scan_prompt(prompt: "...")
|
|
|
143
143
|
```
|
|
144
144
|
|
|
145
145
|
Every action takes `idempotency_key:` (1 to 256 characters of `A-Z a-z 0-9 _ -`). It is sent as
|
|
146
|
-
`X-Idempotency-Key`, and Waffo keeps the answer for 24 hours. Nothing is sent unless you pass one
|
|
146
|
+
`X-Idempotency-Key`, and Waffo keeps the answer for 24 hours. Nothing is sent unless you pass one,
|
|
147
|
+
and Waffo does not deduplicate a write without a key: a write retried after a timeout can run twice.
|
|
148
|
+
Pass a key on every write that a retry could repeat. Use a key that is unique per request; a key
|
|
149
|
+
built from a hash of the body, or a short guessable one, can collide with another request's key.
|
|
147
150
|
|
|
148
151
|
```ruby
|
|
149
152
|
client.create_refund_ticket(..., idempotency_key: "refund-#{order.id}")
|
|
@@ -219,6 +222,20 @@ client.graphql("query ($id: String!) { payoutTicket(id: $id) { id status } }", i
|
|
|
219
222
|
client.action("/v1/actions/some-group/some-action", { some_param: "..." })
|
|
220
223
|
```
|
|
221
224
|
|
|
225
|
+
## Invoices
|
|
226
|
+
|
|
227
|
+
Waffo gives every succeeded payment an `invoiceToken`, read with the payment's GraphQL fields.
|
|
228
|
+
`Invoice.url` builds the buyer's invoice link from the payment id and that token. It returns nil
|
|
229
|
+
while the token is missing, which is before the payment succeeds:
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
Waffo::Pancake::Invoice.url("PAY_...", invoice_token)
|
|
233
|
+
# => "https://pancake.waffo.ai/invoice/PAY_...?token=..."
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
The link is a bearer credential for that one invoice: it grants nothing else, and the receipt email
|
|
237
|
+
contains the same link. `payments` selects `invoiceToken` by default.
|
|
238
|
+
|
|
222
239
|
## Webhooks
|
|
223
240
|
|
|
224
241
|
Pass the raw body; a body that was parsed and re-serialized will not verify.
|
|
@@ -251,7 +268,28 @@ The platform's public keys are built in. When Waffo rotates them, set
|
|
|
251
268
|
both), or pass `public_key:`. Timestamps may be up to 45 minutes old and 1 minute ahead by default
|
|
252
269
|
(`tolerance:`, `future_tolerance:`, in seconds; `tolerance: 0` turns the check off).
|
|
253
270
|
|
|
254
|
-
`Waffo::Pancake::Webhook::EVENT_TYPES` lists the event types
|
|
271
|
+
`Waffo::Pancake::Webhook::EVENT_TYPES` lists the 16 event types: payment, subscription, refund and
|
|
272
|
+
store. `Webhook.family` names each one's family (`:payment`, `:refund`, `:subscription`, `:store`), and
|
|
273
|
+
`event.store?` answers for the store family.
|
|
274
|
+
|
|
275
|
+
`store.domain_changed` and `store.domain_unbound` carry the store's domain. A store that leaves
|
|
276
|
+
production with `store.domain_unbound` gets it from production webhooks only; its `id` and `eventId`
|
|
277
|
+
are plain UUIDs, not `PAY_xxx` style ids.
|
|
278
|
+
|
|
279
|
+
### Payment, refund and store fields
|
|
280
|
+
|
|
281
|
+
| Reader | Field | Events |
|
|
282
|
+
|---|---|---|
|
|
283
|
+
| `payment_timestamp` | `paymentTimestamp` | Payment, `refund.*`: UTC with milliseconds, e.g. `2026-03-10T08:29:58.412Z` |
|
|
284
|
+
| `payment_method`, `payment_method_brand` | `paymentMethod`, `paymentMethodBrand` | Same, when known. The brand is an open string (`wechatpay`, `alipay`, `visa`, ...) |
|
|
285
|
+
| `payment_id`, `payment_status`, `payment_date`, `payment_last4`, `payment_failure_reason` | `paymentId`, `paymentStatus`, `paymentDate`, `paymentLast4`, `paymentFailureReason` | Payment and `refund.*` events |
|
|
286
|
+
| `refund_status`, `refund_reason`, `refund_created_at` | `refundStatus`, `refundReason`, `refundCreatedAt` | `refund.*` |
|
|
287
|
+
| `plan_change` | `planChange` | `subscription.plan_changed`, `plan_change_scheduled`, `plan_change_failed` |
|
|
288
|
+
| `store_id`, `store_name`, `old_domain`, `new_domain`, `effective_at` | `storeId`, `storeName`, `oldDomain`, `newDomain`, `effectiveAt` | `store.domain_changed`; `old_domain` is nil when the store had no verified domain |
|
|
289
|
+
| `domain`, `unbound_at`, `unbind_method` | `domain`, `unboundAt`, `method` | `store.domain_unbound`; `unbind_method` is `"merchant"` or `"admin"` |
|
|
290
|
+
|
|
291
|
+
A deprecated field read on an event that does not carry it (for example `amount` on a store event)
|
|
292
|
+
reports the warning without raising.
|
|
255
293
|
|
|
256
294
|
### Amount fields
|
|
257
295
|
|
|
@@ -24,6 +24,12 @@ class WaffoWebhookJob < ApplicationJob
|
|
|
24
24
|
# The renewal failed; the payment channel retries once, usually the next day.
|
|
25
25
|
when "refund.succeeded"
|
|
26
26
|
# event.data.refunded_amount, out of event.data.original_charged_amount actually collected.
|
|
27
|
+
when "store.domain_changed"
|
|
28
|
+
# The store serves event.data.new_domain from event.data.effective_at. event.data.old_domain
|
|
29
|
+
# is nil when the store had no verified domain before.
|
|
30
|
+
when "store.domain_unbound"
|
|
31
|
+
# The store left production at event.data.unbound_at (event.data.unbind_method: "merchant" or
|
|
32
|
+
# "admin"). event.data.domain is no longer bound to the store.
|
|
27
33
|
end
|
|
28
34
|
|
|
29
35
|
event.update!(processed_at: Time.current)
|
|
@@ -30,7 +30,8 @@ module Waffo
|
|
|
30
30
|
SUBSCRIPTION_ORDER_FIELDS = "#{ORDER_FIELDS} billingPeriod isInTrial willRenew canReactivate " \
|
|
31
31
|
"currentPeriodStart currentPeriodEnd canceledAt"
|
|
32
32
|
PAYMENT_FIELDS = "id orderId status refundStatus orderMerchantExternalId periodNumber testMode " \
|
|
33
|
-
"snapshotAmountDetails { subtotal listTotal discountAmount taxAmount total
|
|
33
|
+
"invoiceToken snapshotAmountDetails { subtotal listTotal discountAmount taxAmount total " \
|
|
34
|
+
"currency } createdAt"
|
|
34
35
|
REFUND_FIELDS = "id paymentId ticketId status testMode orderMerchantExternalId " \
|
|
35
36
|
"refundTicketMerchantExternalId pspAmountDetails { amount currency } createdAt"
|
|
36
37
|
REFUND_TICKET_FIELDS = "id status refundTicketMerchantExternalId " \
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "erb"
|
|
4
|
+
|
|
5
|
+
module Waffo
|
|
6
|
+
module Pancake
|
|
7
|
+
# The buyer-facing invoice page of one payment. Waffo gives a succeeded payment an
|
|
8
|
+
# `invoiceToken` (GraphQL `payment(id:) { invoiceToken }`); the page needs both values.
|
|
9
|
+
# The token is a bearer credential for that one invoice and grants nothing else.
|
|
10
|
+
module Invoice
|
|
11
|
+
BASE_URL = "https://pancake.waffo.ai/invoice"
|
|
12
|
+
|
|
13
|
+
module_function
|
|
14
|
+
|
|
15
|
+
# Returns nil until the payment succeeds, because Waffo issues the token then.
|
|
16
|
+
#
|
|
17
|
+
# Invoice.url("PAY_...", payment["invoiceToken"])
|
|
18
|
+
# # => "https://pancake.waffo.ai/invoice/PAY_...?token=..."
|
|
19
|
+
def url(payment_id, invoice_token)
|
|
20
|
+
raise ArgumentError, "payment_id is required" if payment_id.to_s.strip.empty?
|
|
21
|
+
return nil if invoice_token.to_s.strip.empty?
|
|
22
|
+
|
|
23
|
+
"#{BASE_URL}/#{ERB::Util.url_encode(payment_id)}?token=#{ERB::Util.url_encode(invoice_token)}"
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -27,11 +27,13 @@ module Waffo
|
|
|
27
27
|
|
|
28
28
|
module_function
|
|
29
29
|
|
|
30
|
-
# :payment (one charge), :refund, :subscription (a subscription's status),
|
|
30
|
+
# :payment (one charge), :refund, :subscription (a subscription's status), :store (a store's
|
|
31
|
+
# domain), or nil.
|
|
31
32
|
def family(event_type)
|
|
32
33
|
event_type = event_type.to_s
|
|
33
34
|
return :payment if PAYMENT_EVENT_TYPES.include?(event_type)
|
|
34
35
|
return :refund if REFUND_EVENT_TYPES.include?(event_type)
|
|
36
|
+
return :store if event_type.start_with?("store.")
|
|
35
37
|
|
|
36
38
|
:subscription if event_type.start_with?("subscription.")
|
|
37
39
|
end
|
|
@@ -68,6 +70,7 @@ module Waffo
|
|
|
68
70
|
def payment? = family == :payment
|
|
69
71
|
def refund? = family == :refund
|
|
70
72
|
def subscription? = family == :subscription
|
|
73
|
+
def store? = family == :store
|
|
71
74
|
end
|
|
72
75
|
|
|
73
76
|
# The `data` of a delivery. Reading `amount`, `total`, `subtotal`, `taxAmount`, `taxRate` or
|
|
@@ -127,6 +130,41 @@ module Waffo
|
|
|
127
130
|
def first_period? = period_number == 1
|
|
128
131
|
def renewal? = period_number.is_a?(Integer) && period_number > 1
|
|
129
132
|
|
|
133
|
+
def store_id = self["storeId"]
|
|
134
|
+
|
|
135
|
+
# How the buyer paid, from the payment channel. Payment, refund and chargeback events.
|
|
136
|
+
# `payment_timestamp` is UTC with milliseconds; `payment_date` is its date part.
|
|
137
|
+
def payment_id = self["paymentId"]
|
|
138
|
+
def payment_status = self["paymentStatus"]
|
|
139
|
+
def payment_date = self["paymentDate"]
|
|
140
|
+
def payment_timestamp = self["paymentTimestamp"]
|
|
141
|
+
def payment_method = self["paymentMethod"]
|
|
142
|
+
# An open string, not an enum: "wechatpay", "alipay", "alipayhk", "visa", "mastercard", ...
|
|
143
|
+
def payment_method_brand = self["paymentMethodBrand"]
|
|
144
|
+
def payment_last4 = self["paymentLast4"]
|
|
145
|
+
def payment_failure_reason = self["paymentFailureReason"]
|
|
146
|
+
|
|
147
|
+
# Refund events only.
|
|
148
|
+
def refund_status = self["refundStatus"]
|
|
149
|
+
def refund_reason = self["refundReason"]
|
|
150
|
+
def refund_created_at = self["refundCreatedAt"]
|
|
151
|
+
|
|
152
|
+
# subscription.plan_changed, plan_change_scheduled and plan_change_failed only. Waffo's docs
|
|
153
|
+
# show it in examples only; its keys are direction, oldPlanName, oldAmount, newPlanName,
|
|
154
|
+
# newAmount, chargedAmount and effectiveDate.
|
|
155
|
+
def plan_change = self["planChange"]
|
|
156
|
+
|
|
157
|
+
# store.domain_changed: old_domain is nil when the store had no verified domain before.
|
|
158
|
+
def store_name = self["storeName"]
|
|
159
|
+
def old_domain = self["oldDomain"]
|
|
160
|
+
def new_domain = self["newDomain"]
|
|
161
|
+
def effective_at = self["effectiveAt"]
|
|
162
|
+
|
|
163
|
+
# store.domain_unbound (production webhooks only): unbind_method is "merchant" or "admin".
|
|
164
|
+
def domain = self["domain"]
|
|
165
|
+
def unbound_at = self["unboundAt"]
|
|
166
|
+
def unbind_method = self["method"]
|
|
167
|
+
|
|
130
168
|
private
|
|
131
169
|
def deprecated_read(key)
|
|
132
170
|
replacements = DEPRECATED_FIELDS[key.to_s]
|
|
@@ -135,14 +173,16 @@ module Waffo
|
|
|
135
173
|
Deprecation.warn(deprecation_message(key.to_s, replacements), caller_locations(2))
|
|
136
174
|
end
|
|
137
175
|
|
|
176
|
+
# A family with its own replacement names it; any other family (or none) lists them all.
|
|
138
177
|
def deprecation_message(key, replacements)
|
|
139
178
|
family = Webhook.family(event_type)
|
|
140
|
-
|
|
179
|
+
specific = family && replacements.key?(family)
|
|
180
|
+
instead = if specific
|
|
141
181
|
reader(replacements.fetch(family))
|
|
142
182
|
else
|
|
143
183
|
replacements.map { |name, field| "#{reader(field)} on #{name} events" }.join(", ")
|
|
144
184
|
end
|
|
145
|
-
"Waffo webhook data[#{key.inspect}] is deprecated#{" on #{event_type}" if
|
|
185
|
+
"Waffo webhook data[#{key.inspect}] is deprecated#{" on #{event_type}" if specific}; read #{instead} " \
|
|
146
186
|
"instead. Waffo removes it in its next major API version, not before #{DEPRECATED_FIELDS_REMOVAL}."
|
|
147
187
|
end
|
|
148
188
|
|
|
@@ -57,6 +57,7 @@ module Waffo
|
|
|
57
57
|
subscription.plan_changed subscription.plan_change_scheduled subscription.plan_change_failed
|
|
58
58
|
subscription.canceling subscription.uncanceled subscription.canceled subscription.past_due
|
|
59
59
|
refund.succeeded refund.failed
|
|
60
|
+
store.domain_changed store.domain_unbound
|
|
60
61
|
].freeze
|
|
61
62
|
|
|
62
63
|
module_function
|
data/lib/waffo/pancake.rb
CHANGED
|
@@ -8,6 +8,7 @@ require_relative "pancake/store_checkout"
|
|
|
8
8
|
require_relative "pancake/deprecation"
|
|
9
9
|
require_relative "pancake/webhook"
|
|
10
10
|
require_relative "pancake/webhook/event"
|
|
11
|
+
require_relative "pancake/invoice"
|
|
11
12
|
require_relative "pancake/configuration"
|
|
12
13
|
require_relative "pancake/railtie" if defined?(Rails::Railtie)
|
|
13
14
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: waffo-pancake
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Good First Issue
|
|
@@ -53,6 +53,7 @@ files:
|
|
|
53
53
|
- lib/waffo/pancake/customer_session.rb
|
|
54
54
|
- lib/waffo/pancake/deprecation.rb
|
|
55
55
|
- lib/waffo/pancake/errors.rb
|
|
56
|
+
- lib/waffo/pancake/invoice.rb
|
|
56
57
|
- lib/waffo/pancake/keys.rb
|
|
57
58
|
- lib/waffo/pancake/railtie.rb
|
|
58
59
|
- lib/waffo/pancake/requests.rb
|