mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Add button to send test data to endpoint
It will allow a user to easily test the endpoint
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user