Add button to send test data to endpoint

It will allow a user to easily test the endpoint
This commit is contained in:
Gaetan Craig-Riou
2025-12-02 16:05:44 +11:00
parent 72085be896
commit 5e4df41ec8
6 changed files with 86 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
# frozen_string_literal: true
class WebhookEndpointsController < BaseController
before_action :load_resource, only: :destroy
before_action :load_resource, only: [:destroy, :test]
def create
webhook_endpoint = spree_current_user.webhook_endpoints.new(webhook_endpoint_params)
@@ -25,6 +25,55 @@ class WebhookEndpointsController < BaseController
redirect_to redirect_path
end
def test # rubocop:disable Metrics/MethodLength
at = Time.zone.now
test_payload = {
payment: {
updated_at: at,
amount: 0.00,
state: "completed"
},
enterprise: {
abn: "65797115831",
acn: "",
name: "TEST Enterprise",
address: {
address1: "1 testing street",
address2: "",
city: "TestCity",
zipcode: "1234"
}
},
order: {
total: 0.00,
currency: "AUD",
line_items: [
{
quantity: 1,
price: 20.00,
tax_category_name: "VAT",
product_name: "Test product",
name_to_display: "",
unit_to_display: "1kg"
}
]
}
}
WebhookDeliveryJob.perform_later(@webhook_endpoint.url, "payment.completed", test_payload, at:)
flash[:success] = t(".success")
respond_with do |format|
format.turbo_stream do
render turbo_stream: turbo_stream.update(
:flashes, partial: "shared/flashes", locals: { flashes: flash }
)
end
end
end
private
def load_resource
@webhook_endpoint = spree_current_user.webhook_endpoints.find(params[:id])
end