diff --git a/app/controllers/api/v1/callback_handler/callback_handler_controller.rb b/app/controllers/api/v1/callback_handler/callback_handler_controller.rb index 81c902b..306f134 100644 --- a/app/controllers/api/v1/callback_handler/callback_handler_controller.rb +++ b/app/controllers/api/v1/callback_handler/callback_handler_controller.rb @@ -36,10 +36,12 @@ class CallbackHandlerController < ApplicationController param :event_name, String, desc: event_descr def callback - puts '============ CALLBACK' puts params puts '============ CALLBACK' + Rails.logger.info '============ CALLBACK' + Rails.logger.info params + Rails.logger.info '============ CALLBACK' payment_reference = params[:payment_reference] response = EverypayResponse.call(payment_reference) diff --git a/app/controllers/invoice_creators_controller.rb b/app/controllers/invoice_creators_controller.rb index 7b898f3..548fc4e 100644 --- a/app/controllers/invoice_creators_controller.rb +++ b/app/controllers/invoice_creators_controller.rb @@ -1,6 +1,10 @@ class InvoiceCreatorsController < ParentController def index - @invoices = Invoice.where(initiator: 'billing_system').order(created_at: :desc) + @pagy, @invoices = pagy(Invoice.search(params).where(initiator: 'billing_system').order(created_at: :desc), + items: params[:per_page] ||= 25, + link_extra: 'data-turbo-action="advance"') + @min_amount = 0 + @max_amount = 200_000 end def new @@ -25,12 +29,17 @@ def create linkpay_params_mutation = params[:linkpay].merge( invoice_number: @invoice.invoice_number, - transaction_amount: @invoice.transaction_amount, + transaction_amount: @invoice.transaction_amount ) @linkpay = EverypayLinkGenerator.create(params: linkpay_params_mutation) - @invoice.everypay_response = { + @invoice.linkpay_info = { linkpay: @linkpay, + customer_name: params[:linkpay][:customer_name], + customer_email: params[:linkpay][:customer_email], + description: params[:linkpay][:custom_field1], + custom_field2: params[:linkpay][:custom_field2], + invoice_number: @invoice.invoice_number } @invoice.save! diff --git a/app/controllers/invoice_details/linkpay_informations_controller.rb b/app/controllers/invoice_details/linkpay_informations_controller.rb new file mode 100644 index 0000000..ad39215 --- /dev/null +++ b/app/controllers/invoice_details/linkpay_informations_controller.rb @@ -0,0 +1,5 @@ +class InvoiceDetails::LinkpayInformationsController < ParentController + def show + @info = Invoice.find(params[:id])&.linkpay_info + end +end diff --git a/app/services/notify.rb b/app/services/notify.rb index 2d45ea9..e8ac25b 100644 --- a/app/services/notify.rb +++ b/app/services/notify.rb @@ -16,6 +16,14 @@ def self.call(response:) parsed_response = notifier.parse_response(response) + puts '============ parsed_response' + puts parsed_response + puts '============ parsed_response' + + Rails.logger.info '============ parsed_response' + Rails.logger.info parsed_response + Rails.logger.info '============ parsed_response' + order_number = if parsed_response[:order_reference].split(', ').size > 1 parsed_response[:order_reference].split(', ')[0].split(':')[1] else @@ -32,6 +40,7 @@ def self.call(response:) notifier.update_invoice_state(parsed_response:, invoice:) return unless invoice.paid? + return if invoice.billing_system? url = notifier.get_update_payment_url[invoice.initiator.to_sym] return notifier.define_for_deposit(invoice, url) if invoice.auction_deposit_prepayment? diff --git a/app/views/invoice_creators/index.html.erb b/app/views/invoice_creators/index.html.erb index a3567f2..3369923 100644 --- a/app/views/invoice_creators/index.html.erb +++ b/app/views/invoice_creators/index.html.erb @@ -1,29 +1,108 @@
-
+
+ + <%= form_with url: invoice_creators_path, + method: :get, + data: { controller: 'debounce', + debounce_target: 'form', + turbo_action: "advance", + turbo_frame: "results", + action: 'input->debounce#search' + } do |form| %> + <%= form.search_field :invoice_number, value: params[:invoice_number], + class: 'w-full pl-3 pr-10 py-2 border-2 border-gray-200 rounded-xl hover:border-gray-300 focus:outline-none focus:border-blue-500 transition-colors mb-7 bg-white', + placeholder: 'Type by invoice' %> + +
+ +
+ <%= form.select :status, Invoice.statuses, {include_blank: 'Invoice status' }, { class: 'border-0 px-3 py-3 placeholder-gray-300 text-gray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring w-full ease-linear transition-all duration-150'} %> +
+ + <%= form.hidden_field :sort, value: params[:sort], data: { sort_link_target: "sort"} %> + <%= form.hidden_field :direction, value: params[:direction], data: { sort_link_target: "direction"} %> + +
+ +
+ + <%= form.hidden_field :min_amount, + value: params[:min_amount] || @min_amount, + data: { range_slider_target: "currentMin" } %> + + <%= form.hidden_field :max_amount, + value: params[:max_amount] || @max_amount, + data: { range_slider_target: "currentMax" } %> + +
+ Invoice amount +
+
+ +
+ <%= form.select :per_page, options_for_select([5, 10, 25, 50, 100], + selected: params[:per_page]), { }, { class: 'border-0 px-3 py-3 placeholder-gray-300 text-gray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring w-full ease-linear transition-all duration-150'} %> +
+ +
+

+ Total pages: + <%= @pagy.pages %> +

+ <%= form.number_field :page, + class: 'w-full px-2 py-2 border-2 border-gray-200 rounded-xl hover:border-gray-300 focus:outline-none focus:border-blue-500 transition-colors bg-white w-64' %> +
+ +
+ <% end %> + +
<%= link_to 'New Invoice', new_invoice_creator_path, class: 'h-10 py-2 my-1 px-4 border border-transparent text-sm font-semibold rounded-md text-white bg-violet-700 hover:bg-violet-800 transition duration-150 ease-in-out shadow-md cursor-pointer' %>
-
- - - - - - - - - - - <% @invoices.each do |invoice| %> - - - - - - - <% end %> - -
Invoice numberStatustransaction_amountLinkpay URL
<%= invoice.invoice_number %><%= invoice.status %><%= invoice.transaction_amount %><%= invoice.everypay_response["linkpay"] if invoice.everypay_response.present? %>
+ <%= turbo_frame_tag "results" do %> + + + + + + + + + + + + <%= turbo_frame_tag "modal" %> + <% @invoices.each do |invoice| %> + + + + + + + + <% end %> + +
Invoice numberStatustransaction_amountLinkpay InfoEverypay Response Info
<%= invoice.invoice_number %><%= invoice.status %><%= invoice.transaction_amount %> + <%= link_to invoice_details_linkpay_information_path(invoice), class: 'w-6 h-6 p-2 rounded-full bg-blue-300 hover:bg-blue-500 text-black border-gray-300 flex items-center justify-center focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black text-center', data: { turbo_frame: 'modal' } do %> + + <% end %> + + <%= link_to invoice_details_everypay_response_path(invoice), class: 'w-6 h-6 p-2 rounded-full bg-blue-300 hover:bg-blue-500 text-black border-gray-300 flex items-center justify-center focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black text-center', data: { turbo_frame: 'modal' } do %> + + <% end %> +
+ + <% if @pagy.pages > 1 %> + + <% end %> + <% end %>
diff --git a/app/views/invoice_details/linkpay_informations/show.html.erb b/app/views/invoice_details/linkpay_informations/show.html.erb new file mode 100644 index 0000000..82b15ca --- /dev/null +++ b/app/views/invoice_details/linkpay_informations/show.html.erb @@ -0,0 +1,3 @@ +<%= render 'shared/modal', title: 'Linkpay Informations' do %> + <%= JSON.pretty_generate(@info) %> +<% end %> diff --git a/app/views/invoices/_invoice.html.erb b/app/views/invoices/_invoice.html.erb index f44e55f..2e11f82 100644 --- a/app/views/invoices/_invoice.html.erb +++ b/app/views/invoices/_invoice.html.erb @@ -32,7 +32,7 @@ <% end %> - + <%= link_to invoice_details_description_path(invoice), class: 'w-6 h-6 p-2 rounded-full bg-blue-300 hover:bg-blue-500 text-black border-gray-300 flex items-center justify-center focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black text-center', data: { turbo_frame: 'modal' } do %> <% end %> diff --git a/app/views/shared/_modal.html.erb b/app/views/shared/_modal.html.erb index ea952e4..09545bb 100644 --- a/app/views/shared/_modal.html.erb +++ b/app/views/shared/_modal.html.erb @@ -2,13 +2,13 @@ <%= tag.div data: { controller: "turbo-modal", turbo_modal_target: "modal", action: "turbo:submit-end->turbo-modal#submitEnd keyup@window->turbo-modal#closeWithKeyboard click@window->turbo-modal#closeBackground" }, - class: "p-5 bg-yellow-100 absolute z-10 top-20 right-12 rounded-md break-words" do %> + class: "p-5 bg-yellow-100 absolute z-10 top-20 right-12 rounded-md break-words w-96 max-w-full overflow-x-auto" do %>

<%= title %>

-
+    
       <%= yield %>
     
<%= button_tag "Close", data: { action: "turbo-modal#hideModal" }, type: "button", class: "rounded-lg py-3 px-5 bg-red-600 text-white" %> <% end %> -<% end %> +<% end %> \ No newline at end of file diff --git a/app/views/shared/_navbar.html.erb b/app/views/shared/_navbar.html.erb index 46a0b26..b42cd97 100644 --- a/app/views/shared/_navbar.html.erb +++ b/app/views/shared/_navbar.html.erb @@ -23,7 +23,7 @@ <% end %> <%= link_to invoice_creators_path, class: 'px-6 py-1 flex flex-col md:flex-row md:items-center' do %> - Invoice creator + Invoice creator <% end %> <%= link_to white_codes_path, class: 'px-6 py-1 flex flex-col md:flex-row md:items-center' do %> diff --git a/config/routes.rb b/config/routes.rb index f28f1c0..e105479 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,6 +23,7 @@ namespace :invoice_details do resources :payment_references, only: [:show] resources :everypay_response, only: [:show] + resources :linkpay_informations, only: [:show] resources :directo, only: [:show] resources :descriptions, only: [:show] end diff --git a/db/migrate/20231130114315_add_linkpay_info_to_invoices.rb b/db/migrate/20231130114315_add_linkpay_info_to_invoices.rb new file mode 100644 index 0000000..54a6f88 --- /dev/null +++ b/db/migrate/20231130114315_add_linkpay_info_to_invoices.rb @@ -0,0 +1,5 @@ +class AddLinkpayInfoToInvoices < ActiveRecord::Migration[7.0] + def change + add_column :invoices, :linkpay_info, :jsonb, default: {}, null: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 3b96e01..fbb91db 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_09_21_075925) do +ActiveRecord::Schema[7.0].define(version: 2023_11_30_114315) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -65,6 +65,7 @@ t.string "description" t.datetime "sent_at_omniva", precision: nil t.integer "affiliation", default: 0 + t.jsonb "linkpay_info", default: {} t.index ["status"], name: "index_invoices_on_status" end @@ -74,6 +75,7 @@ t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "owner" + t.string "email" end create_table "setting_entries", force: :cascade do |t|