app/models/pay/webhook.rb in pay-6.8.1 vs app/models/pay/webhook.rb in pay-7.0.0
- old
+ new
@@ -15,22 +15,27 @@
# Then we can rehydrate as webhook objects for each payment processor
def rehydrated_event
case processor
when "braintree"
Pay.braintree_gateway.webhook_notification.parse(event["bt_signature"], event["bt_payload"])
- when "paddle"
+ when "paddle_billing"
+ to_recursive_ostruct(event["data"])
+ when "paddle_classic"
to_recursive_ostruct(event)
when "stripe"
::Stripe::Event.construct_from(event)
else
event
end
end
- def to_recursive_ostruct(hash)
- result = hash.each_with_object({}) do |(key, val), memo|
- memo[key] = val.is_a?(Hash) ? to_recursive_ostruct(val) : val
+ def to_recursive_ostruct(obj)
+ if obj.is_a?(Hash)
+ OpenStruct.new(obj.map { |key, val| [key, to_recursive_ostruct(val)] }.to_h)
+ elsif obj.is_a?(Array)
+ obj.map { |o| to_recursive_ostruct(o) }
+ else # Assumed to be a primitive value
+ obj
end
- OpenStruct.new(result)
end
end
end