FIXES
-error handling from KBZ response error handling from network error
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
class Foodcourt::QrpayController < BaseFoodcourtController
|
||||
class PaymentProcessingError < StandardError; end
|
||||
|
||||
require 'rqrcode'
|
||||
skip_before_action :authenticate, only: [:create]
|
||||
skip_before_action :verify_authenticity_token, only: [:create]
|
||||
|
||||
|
||||
def init
|
||||
@cash_exist = PaymentMethodSetting.cash_exist
|
||||
@credit_exist = PaymentMethodSetting.credit_exist
|
||||
@@ -31,185 +32,199 @@ class Foodcourt::QrpayController < BaseFoodcourtController
|
||||
@membership_rebate_balance=0
|
||||
|
||||
if Sale.exists?(sale_id)
|
||||
@cash = 0.0
|
||||
@kbz_pay_amount = 0.0
|
||||
@other = 0.0
|
||||
@ppamount = 0.0
|
||||
@visacount= 0.0
|
||||
@jcbcount= 0.0
|
||||
@mastercount = 0.0
|
||||
@unionpaycount = 0.0
|
||||
@alipaycount = 0.0
|
||||
@junctionpaycount = 0.0
|
||||
@credit = 0.0
|
||||
@paymalcount = 0.0
|
||||
@dingacount = 0.0
|
||||
@giftvouchercount = 0.0
|
||||
@sale_data = Sale.find_by_sale_id(sale_id)
|
||||
@balance = 0
|
||||
@accountable_type = ''
|
||||
@table_no = ''
|
||||
@dining = ''
|
||||
@other_payment = 0.0
|
||||
@pdf_view = nil
|
||||
@lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView")
|
||||
if !@lookup_pdf.nil?
|
||||
@pdf_view = @lookup_pdf.value
|
||||
end
|
||||
begin
|
||||
@cash = 0.0
|
||||
@kbz_pay_amount = 0.0
|
||||
@other = 0.0
|
||||
@ppamount = 0.0
|
||||
@visacount= 0.0
|
||||
@jcbcount= 0.0
|
||||
@mastercount = 0.0
|
||||
@unionpaycount = 0.0
|
||||
@alipaycount = 0.0
|
||||
@junctionpaycount = 0.0
|
||||
@credit = 0.0
|
||||
@paymalcount = 0.0
|
||||
@dingacount = 0.0
|
||||
@giftvouchercount = 0.0
|
||||
@sale_data = Sale.find_by_sale_id(sale_id)
|
||||
@balance = 0
|
||||
@accountable_type = ''
|
||||
@table_no = ''
|
||||
@dining = ''
|
||||
@other_payment = 0.0
|
||||
@pdf_view = nil
|
||||
@lookup_pdf = Lookup.find_by_lookup_type("ReceiptPdfView")
|
||||
if !@lookup_pdf.nil?
|
||||
@pdf_view = @lookup_pdf.value
|
||||
end
|
||||
|
||||
amount = SalePayment.get_kbz_pay_amount(sale_id, current_user)
|
||||
@kbz_pay_amount += amount.to_f
|
||||
amount = SalePayment.get_kbz_pay_amount(sale_id, current_user)
|
||||
@kbz_pay_amount += amount.to_f
|
||||
|
||||
# @shop = shop_detail #show shop info
|
||||
# @shop = shop_detail #show shop info
|
||||
|
||||
@customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"])
|
||||
saleObj = Sale.find(sale_id)
|
||||
@customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"])
|
||||
saleObj = Sale.find(sale_id)
|
||||
|
||||
#total customer with individual total amount
|
||||
@individual_total = Array.new
|
||||
if !saleObj.equal_persons.nil?
|
||||
per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i
|
||||
@individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f })
|
||||
end
|
||||
#total customer with individual total amount
|
||||
@individual_total = Array.new
|
||||
if !saleObj.equal_persons.nil?
|
||||
per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i
|
||||
@individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f })
|
||||
end
|
||||
|
||||
if current_shop.is_rounding_adj
|
||||
a = saleObj.grand_total % 25 # Modulus
|
||||
b = saleObj.grand_total / 25 # Division
|
||||
#not calculate rounding if modulus is 0 and division is even
|
||||
#calculate rounding if modulus is zero or not zero and division are not even
|
||||
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
||||
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
||||
@rounding_adj = new_total-saleObj.grand_total
|
||||
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj)
|
||||
@sale_data.grand_total = new_total
|
||||
@sale_data.old_grand_total = saleObj.grand_total
|
||||
@sale_data.rounding_adjustment = @rounding_adj
|
||||
if current_shop.is_rounding_adj
|
||||
a = saleObj.grand_total % 25 # Modulus
|
||||
b = saleObj.grand_total / 25 # Division
|
||||
#not calculate rounding if modulus is 0 and division is even
|
||||
#calculate rounding if modulus is zero or not zero and division are not even
|
||||
if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0)
|
||||
new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
|
||||
@rounding_adj = new_total-saleObj.grand_total
|
||||
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:@rounding_adj)
|
||||
@sale_data.grand_total = new_total
|
||||
@sale_data.old_grand_total = saleObj.grand_total
|
||||
@sale_data.rounding_adjustment = @rounding_adj
|
||||
else
|
||||
@rounding_adj = @sale_data.rounding_adjustment
|
||||
end
|
||||
else
|
||||
@rounding_adj = @sale_data.rounding_adjustment
|
||||
end
|
||||
else
|
||||
@rounding_adj = @sale_data.rounding_adjustment
|
||||
end
|
||||
#end rounding adjustment
|
||||
|
||||
# get printer info
|
||||
@print_settings = PrintSetting.get_precision_delimiter()
|
||||
@print_settings = PrintSetting.get_precision_delimiter()
|
||||
|
||||
#get customer amount
|
||||
@customer = Customer.find(@sale_data.customer_id)
|
||||
# accounts = @customer.tax_profiles
|
||||
accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC")
|
||||
@account_arr =[]
|
||||
@tax_arr =[]
|
||||
accounts.each do |acc|
|
||||
account = TaxProfile.find(acc.id)
|
||||
# @account_arr.push(account)
|
||||
@tax_arr.push(account.name)
|
||||
end
|
||||
sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id)
|
||||
if !sale_taxes.empty?
|
||||
sale_taxes.each do |sale_tax|
|
||||
@account_arr.push(sale_tax)
|
||||
#get customer amount
|
||||
@customer = Customer.find(@sale_data.customer_id)
|
||||
# accounts = @customer.tax_profiles
|
||||
accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC")
|
||||
@account_arr =[]
|
||||
@tax_arr =[]
|
||||
accounts.each do |acc|
|
||||
account = TaxProfile.find(acc.id)
|
||||
# @account_arr.push(account)
|
||||
@tax_arr.push(account.name)
|
||||
end
|
||||
end
|
||||
rebate = MembershipSetting.find_by_rebate(1)
|
||||
# get member information
|
||||
if @customer.membership_id != nil && rebate
|
||||
response = Customer.get_member_account(@customer)
|
||||
if response["status"]==true
|
||||
response["account_data"].each do |res|
|
||||
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
|
||||
@balance = @balance.to_f + res["balance"].to_f
|
||||
# @accountable_type = res["accountable_type"]
|
||||
@accountable_type = "Rebate Balance"
|
||||
sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id)
|
||||
if !sale_taxes.empty?
|
||||
sale_taxes.each do |sale_tax|
|
||||
@account_arr.push(sale_tax)
|
||||
end
|
||||
end
|
||||
rebate = MembershipSetting.find_by_rebate(1)
|
||||
# get member information
|
||||
if @customer.membership_id != nil && rebate
|
||||
response = Customer.get_member_account(@customer)
|
||||
if response["status"]==true
|
||||
response["account_data"].each do |res|
|
||||
if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
|
||||
@balance = @balance.to_f + res["balance"].to_f
|
||||
# @accountable_type = res["accountable_type"]
|
||||
@accountable_type = "Rebate Balance"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#end customer amount
|
||||
#end customer amount
|
||||
|
||||
#paymal payment
|
||||
#paymal payment
|
||||
|
||||
@sale_data.bookings.each do |sbk|
|
||||
if sbk.dining_facility_id.to_i >0
|
||||
df = DiningFacility.find(sbk.dining_facility_id)
|
||||
@table_no = df.type + ' ' + df.name
|
||||
@checkin_time = sbk.checkin_at
|
||||
@dining = df
|
||||
break
|
||||
@sale_data.bookings.each do |sbk|
|
||||
if sbk.dining_facility_id.to_i >0
|
||||
df = DiningFacility.find(sbk.dining_facility_id)
|
||||
@table_no = df.type + ' ' + df.name
|
||||
@checkin_time = sbk.checkin_at
|
||||
@dining = df
|
||||
break
|
||||
else
|
||||
@table_no = nil
|
||||
@checkin_time = nil
|
||||
@dining = nil
|
||||
end
|
||||
end
|
||||
|
||||
if path.include? ("credit_payment")
|
||||
@sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data)
|
||||
else
|
||||
@table_no = nil
|
||||
@checkin_time = nil
|
||||
@dining = nil
|
||||
@sale_payment_data = SalePayment.get_sale_payments(@sale_data)
|
||||
end
|
||||
end
|
||||
@sale_payment_data.each do |spay|
|
||||
if spay.payment_method == "cash"
|
||||
@cash += spay.payment_amount
|
||||
end
|
||||
if spay.payment_method !="creditnote"
|
||||
@other_payment += spay.payment_amount
|
||||
end
|
||||
|
||||
if path.include? ("credit_payment")
|
||||
@sale_payment_data = SalePayment.get_sale_payment_for_credit(@sale_data)
|
||||
else
|
||||
@sale_payment_data = SalePayment.get_sale_payments(@sale_data)
|
||||
end
|
||||
@sale_payment_data.each do |spay|
|
||||
if spay.payment_method == "cash"
|
||||
@cash += spay.payment_amount
|
||||
end
|
||||
if spay.payment_method !="creditnote"
|
||||
@other_payment += spay.payment_amount
|
||||
if spay.payment_method == "mpu"
|
||||
@other += spay.payment_amount
|
||||
elsif spay.payment_method == "paypar"
|
||||
@ppamount += spay.payment_amount
|
||||
elsif spay.payment_method == "visa"
|
||||
@visacount += spay.payment_amount
|
||||
elsif spay.payment_method == "jcb"
|
||||
@jcbcount += spay.payment_amount
|
||||
elsif spay.payment_method == "master"
|
||||
@mastercount += spay.payment_amount
|
||||
elsif spay.payment_method == "unionpay"
|
||||
@unionpaycount += spay.payment_amount
|
||||
elsif spay.payment_method == "JunctionPay"
|
||||
@junctionpaycount += spay.payment_amount
|
||||
elsif spay.payment_method == "creditnote"
|
||||
@credit += spay.payment_amount
|
||||
elsif spay.payment_method == "paymal"
|
||||
@paymalcount += spay.payment_amount
|
||||
elsif spay.payment_method == "alipay"
|
||||
@alipaycount += spay.payment_amount
|
||||
elsif spay.payment_method == "dinga"
|
||||
@dingacount += spay.payment_amount
|
||||
elsif spay.payment_method == "giftvoucher"
|
||||
@giftvouchercount += spay.payment_amount
|
||||
end
|
||||
end
|
||||
|
||||
if spay.payment_method == "mpu"
|
||||
@other += spay.payment_amount
|
||||
elsif spay.payment_method == "paypar"
|
||||
@ppamount += spay.payment_amount
|
||||
elsif spay.payment_method == "visa"
|
||||
@visacount += spay.payment_amount
|
||||
elsif spay.payment_method == "jcb"
|
||||
@jcbcount += spay.payment_amount
|
||||
elsif spay.payment_method == "master"
|
||||
@mastercount += spay.payment_amount
|
||||
elsif spay.payment_method == "unionpay"
|
||||
@unionpaycount += spay.payment_amount
|
||||
elsif spay.payment_method == "JunctionPay"
|
||||
@junctionpaycount += spay.payment_amount
|
||||
elsif spay.payment_method == "creditnote"
|
||||
@credit += spay.payment_amount
|
||||
elsif spay.payment_method == "paymal"
|
||||
@paymalcount += spay.payment_amount
|
||||
elsif spay.payment_method == "alipay"
|
||||
@alipaycount += spay.payment_amount
|
||||
elsif spay.payment_method == "dinga"
|
||||
@dingacount += spay.payment_amount
|
||||
elsif spay.payment_method == "giftvoucher"
|
||||
@giftvouchercount += spay.payment_amount
|
||||
@paymethod = PaymentMethodSetting.find_by(payment_method: "MMQR")
|
||||
|
||||
if @paymethod.nil?
|
||||
raise "MMQR payment method not configured"
|
||||
end
|
||||
|
||||
@merchant = KbzMerchant.new(@paymethod)
|
||||
|
||||
@response = @merchant.create_order(amount: @sale_data.grand_total, merch_order_id: @sale_data.receipt_no)
|
||||
case @response[:status]
|
||||
when 'success'
|
||||
@qr_string = @response[:data]["qrCode"]
|
||||
qrcode = RQRCode::QRCode.new(@qr_string)
|
||||
|
||||
@qr_svg = qrcode.as_svg(
|
||||
color: "000",
|
||||
shape_rendering: "crispEdges",
|
||||
module_size: 3,
|
||||
standalone: true,
|
||||
use_path: true
|
||||
)
|
||||
ActionCable.server.broadcast('second_display_view_channel', { data: @qr_string, qr_svg: @qr_svg, grand_total: @sale_data.grand_total, invoice_no: @sale_data.receipt_no })
|
||||
|
||||
when 'error'
|
||||
@error = @response[:message]
|
||||
raise PaymentProcessingError, @response[:message]
|
||||
when 'failed'
|
||||
@error = @response[:message]
|
||||
raise PaymentProcessingError, @response[:message]
|
||||
end
|
||||
rescue PaymentProcessingError, StandardError => e
|
||||
Rails.logger.error("Payment processing error: #{e.message}")
|
||||
cancel_order_and_sale(sale_id, e.message)
|
||||
flash[:error] = "Payment failed: #{e.message}"
|
||||
redirect_to foodcourt_food_court_path
|
||||
return
|
||||
end
|
||||
|
||||
@paymethod = PaymentMethodSetting.find_by(payment_method: "MMQR")
|
||||
|
||||
|
||||
@merchant = KbzMerchant.new(@paymethod)
|
||||
|
||||
@response = @merchant.create_order(amount: @sale_data.grand_total, merch_order_id: @sale_data.receipt_no)
|
||||
case @response[:status]
|
||||
when 'success'
|
||||
@qr_string = @response[:data]["qrCode"]
|
||||
qrcode = RQRCode::QRCode.new(@qr_string)
|
||||
|
||||
@qr_svg = qrcode.as_svg(
|
||||
color: "000",
|
||||
shape_rendering: "crispEdges",
|
||||
module_size: 3,
|
||||
standalone: true,
|
||||
use_path: true
|
||||
)
|
||||
ActionCable.server.broadcast('second_display_view_channel', { data: @qr_string, qr_svg: @qr_svg, grand_total: @sale_data.grand_total, invoice_no: @sale_data.receipt_no })
|
||||
|
||||
when 'error'
|
||||
@error = @response[:message]
|
||||
when 'failed'
|
||||
@error = @response[:message]
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -333,4 +348,85 @@ class Foodcourt::QrpayController < BaseFoodcourtController
|
||||
format.json { render :json => { status: true, order_id: order.order_id } }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cancel_order_and_sale(sale_id, error_message = nil)
|
||||
result = { success: false, error: nil }
|
||||
|
||||
sale = Sale.find_by(sale_id: sale_id)
|
||||
unless sale
|
||||
result[:error] = "Sale not found"
|
||||
return result
|
||||
end
|
||||
|
||||
order = sale.orders.first
|
||||
unless order
|
||||
result[:error] = "Order not found"
|
||||
return result
|
||||
end
|
||||
|
||||
booking = order.booking
|
||||
unless booking
|
||||
result[:error] = "Booking not found"
|
||||
return result
|
||||
end
|
||||
|
||||
begin
|
||||
Sale.transaction do
|
||||
order.order_items.update_all(order_item_status: 'cancelled') if order.order_items.present?
|
||||
|
||||
order.update!(status: 'cancelled')
|
||||
|
||||
booking.update!(booking_status: 'cancelled')
|
||||
|
||||
if sale.shift_sale_id
|
||||
shift = ShiftSale.find(sale.shift_sale_id)
|
||||
if sale.sale_status == "completed"
|
||||
shift.calculate(sale_id, "void")
|
||||
else
|
||||
shift.update!(total_void: shift.total_void + sale.grand_total)
|
||||
end
|
||||
end
|
||||
|
||||
if sale.discount_type == "member_discount"
|
||||
sale.update!(total_discount: 0)
|
||||
sale.compute_by_sale_items(0, nil, 'foodcourt')
|
||||
end
|
||||
|
||||
sale.update!(
|
||||
rounding_adjustment: 0.0,
|
||||
payment_status: 'void',
|
||||
sale_status: 'void'
|
||||
)
|
||||
|
||||
if table = booking.dining_facility
|
||||
table.update!(status: 'available') unless table.current_bookings.exists?
|
||||
end
|
||||
|
||||
action_by = current_user.role == "cashier" && params[:access_code].present? ?
|
||||
Employee.find_by(emp_id: params[:access_code])&.name :
|
||||
current_user.name
|
||||
|
||||
remark = error_message ? "Payment failed: #{error_message}" : "Manually cancelled"
|
||||
SaleAudit.record_audit_for_edit(
|
||||
sale.sale_id,
|
||||
current_user.name,
|
||||
action_by,
|
||||
remark,
|
||||
"SALEVOID"
|
||||
)
|
||||
|
||||
SaleOrder.where(sale_id: sale.sale_id).find_each do |sodr|
|
||||
AssignedOrderItem.where(order_id: sodr.order_id).update_all(delivery_status: 1)
|
||||
end
|
||||
|
||||
result[:success] = true
|
||||
end
|
||||
rescue StandardError => e
|
||||
result[:error] = "Cancellation failed: #{e.message}"
|
||||
Rails.logger.error "Cancellation error: #{e.message}\n#{e.backtrace.join("\n")}"
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
<!-- This is now Column 1 -->
|
||||
<div class="col-6"> <!-- Using col-md-6 for responsiveness, col-6 is also fine -->
|
||||
<div class="text-center">
|
||||
<img src="/image/mmqr.webp" alt="MMQR Payment" style="max-width: 120px; margin-bottom: 10px;">
|
||||
<img src="/image/mmqr.webp" alt="MMQR Payment" style="max-width: 90px; margin-bottom: 10px;">
|
||||
<h5>Scan to Pay</h5>
|
||||
<p class="text-muted">Use your mobile wallet app</p>
|
||||
</div>
|
||||
@@ -298,16 +298,17 @@
|
||||
|
||||
@media(min-width: 600px){
|
||||
#second_display_order_items{
|
||||
margin-top: -3rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
#mmqr_payment{
|
||||
margin-top: -3rem;
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
#payment_success{
|
||||
margin-top: 3rem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@media (max-width: 576px) {
|
||||
.card-header h4 { font-size: 1.1rem; }
|
||||
#order-items-table th, #order-items-table td {
|
||||
|
||||
@@ -1,184 +1,184 @@
|
||||
<% breadcrumb_add t("payment_methods"), settings_payment_method_settings_path, settings_payment_method_settings_path, t("views.btn.#{action_name}") %>
|
||||
<% breadcrumb_add t("payment_methods"), settings_payment_method_settings_path, settings_payment_method_settings_path, t("views.btn.#{action_name}") %>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
|
||||
<div class="card">
|
||||
<div class="body">
|
||||
<%= simple_form_for([:settings, @settings_payment_method_setting]) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
<div class="row">
|
||||
<div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
|
||||
<div class="card">
|
||||
<div class="body">
|
||||
<%= simple_form_for([:settings, @settings_payment_method_setting]) do |f| %>
|
||||
<%= f.error_notification %>
|
||||
|
||||
<div class="form-inputs p-l-15">
|
||||
<%= f.input :payment_method %>
|
||||
<%= f.input :is_active %>
|
||||
<%= f.input :gateway_communication_type, collection: [ "Api", "Device", "Manual"] %>
|
||||
<%= f.input :gateway_url, required: true %>
|
||||
<%= f.input :auth_token, required: true %>
|
||||
<%= f.input :merchant_account_id, required: true %>
|
||||
<div class="form-inputs p-l-15">
|
||||
<%= f.input :payment_method %>
|
||||
<%= f.input :is_active %>
|
||||
<%= f.input :gateway_communication_type, collection: [ "Api", "Device", "Manual"] %>
|
||||
<%= f.input :gateway_url, required: true %>
|
||||
<%= f.input :auth_token, required: true %>
|
||||
<%= f.input :merchant_account_id, required: true %>
|
||||
|
||||
<!-- JSON Key-Value Editor -->
|
||||
<div class="form-group">
|
||||
<%= f.label :additional_parameters, 'Additional Parameters (Key-Value Pairs)' %>
|
||||
<div id="json-fields">
|
||||
<% if @settings_payment_method_setting.additional_parameters.present? %>
|
||||
<% JSON.parse(@settings_payment_method_setting.additional_parameters).each do |key, value| %>
|
||||
<!-- JSON Key-Value Editor -->
|
||||
<div class="form-group">
|
||||
<%= f.label :additional_parameters, 'Additional Parameters (Key-Value Pairs)' %>
|
||||
<div id="json-fields">
|
||||
<% if @settings_payment_method_setting.additional_parameters.present? %>
|
||||
<% JSON.parse(@settings_payment_method_setting.additional_parameters).each do |key, value| %>
|
||||
<div class="key-value-pair row mb-2">
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_keys[]" class="form-control" placeholder="Key" value="<%= key %>">
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_values[]" class="form-control" placeholder="Value" value="<%= value %>">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="button" class="btn btn-danger remove-field">Remove</button>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="key-value-pair row mb-2">
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_keys[]" class="form-control" placeholder="Key" value="<%= key %>">
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_values[]" class="form-control" placeholder="Value" value="<%= value %>">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_keys[]" class="form-control" placeholder="Key">
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_values[]" class="form-control" placeholder="Value">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="button" class="btn btn-danger remove-field">Remove</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<div class="key-value-pair row mb-2">
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_keys[]" class="form-control" placeholder="Key">
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_values[]" class="form-control" placeholder="Value">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="button" class="btn btn-danger remove-field">Remove</button>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<button type="button" id="add-field" class="btn btn-primary mt-2">
|
||||
<i class="material-icons">add</i> Add Parameter
|
||||
</button>
|
||||
<button type="button" id="add-field" class="btn btn-primary mt-2">
|
||||
<i class="material-icons">add</i> Add Parameter
|
||||
</button>
|
||||
|
||||
<%= f.hidden_field :additional_parameters, id: 'additional-parameters-json' %>
|
||||
</div>
|
||||
|
||||
<%= f.hidden_field :additional_parameters, id: 'additional-parameters-json' %>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="form-actions p-l-15">
|
||||
<%= f.submit "Submit", class: 'btn btn-primary submitBtn btn-lg waves-effect' %>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-actions p-l-15">
|
||||
<%= f.submit "Submit", class: 'btn btn-primary submitBtn btn-lg waves-effect' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
|
||||
<div class="card">
|
||||
<div class="body">
|
||||
<h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.detail.payment_method") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.payment_method_txt") %> <br>
|
||||
2) <%= t("views.right_panel.detail.is_active") %> - <%= t("views.right_panel.detail.checkbox") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.is_active_txt") %> <br>
|
||||
3) <%= t("views.right_panel.detail.gateway") %> <%= t("views.right_panel.detail.comm_type") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.gateway_txt") %> <%= t("views.right_panel.detail.comm_type_txt") %> <br>
|
||||
4) <%= t("views.right_panel.detail.gateway") %> <%= t("views.right_panel.detail.url_txt") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.gateway_txt") %> <%= t("views.right_panel.detail.url_txt") %> <br>
|
||||
5) <%= t("views.right_panel.detail.auth_token") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.auth_token_txt") %> <br>
|
||||
6) <%= t("views.right_panel.detail.merchant_account") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.merchant_account_txt") %> <br>
|
||||
7) <%= t("views.right_panel.detail.additional_parameters") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.additional_parameters_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.button_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.payment_method_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.link_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %> <br>
|
||||
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.payment_method_txt") %> <br>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-xs-12 col-sm-12 col-md-4 col-lg-4">
|
||||
<div class="card">
|
||||
<div class="body">
|
||||
<h5><i class="material-icons md-18">view_headline <%= t("views.right_panel.header.page_detail") %></i></h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.detail.payment_method") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.payment_method_txt") %> <br>
|
||||
2) <%= t("views.right_panel.detail.is_active") %> - <%= t("views.right_panel.detail.checkbox") %> <%= t("views.right_panel.detail.for") %> <%= t("views.right_panel.detail.is_active_txt") %> <br>
|
||||
3) <%= t("views.right_panel.detail.gateway") %> <%= t("views.right_panel.detail.comm_type") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.gateway_txt") %> <%= t("views.right_panel.detail.comm_type_txt") %> <br>
|
||||
4) <%= t("views.right_panel.detail.gateway") %> <%= t("views.right_panel.detail.url_txt") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.gateway_txt") %> <%= t("views.right_panel.detail.url_txt") %> <br>
|
||||
5) <%= t("views.right_panel.detail.auth_token") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.auth_token_txt") %> <br>
|
||||
6) <%= t("views.right_panel.detail.merchant_account") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.merchant_account_txt") %> <br>
|
||||
7) <%= t("views.right_panel.detail.additional_parameters") %> - <%= t("views.right_panel.detail.write_txt") %> <%= t("views.right_panel.detail.additional_parameters_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.button_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.submit") %> - <%= t("views.right_panel.detail.submit_btn_txt") %> <%= t("views.right_panel.detail.payment_method_txt") %> <br>
|
||||
</p>
|
||||
<h5><i class="material-icons md-18">list <%= t("views.right_panel.header.link_lists") %></i> </h5>
|
||||
<p>
|
||||
1) <%= t("views.right_panel.button.home") %> - <%= t("views.right_panel.detail.home_txt") %> <br>
|
||||
2) <%= t("views.right_panel.button.back") %> - <%= t("views.right_panel.detail.back_txt") %> <%= t("views.right_panel.detail.payment_method_txt") %> <br>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const jsonFields = document.getElementById('json-fields');
|
||||
const jsonOutput = document.getElementById('additional-parameters-json');
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const jsonFields = document.getElementById('json-fields');
|
||||
const jsonOutput = document.getElementById('additional-parameters-json');
|
||||
|
||||
document.getElementById('add-field').addEventListener('click', function() {
|
||||
const newPair = document.createElement('div');
|
||||
newPair.className = 'key-value-pair row mb-2';
|
||||
newPair.innerHTML = `
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_keys[]" class="form-control" placeholder="Key">
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_values[]" class="form-control" placeholder="Value">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="button" class="btn btn-danger remove-field">Remove</button>
|
||||
</div>
|
||||
`;
|
||||
jsonFields.appendChild(newPair);
|
||||
attachRemoveListener(newPair);
|
||||
attachInputListeners(newPair);
|
||||
});
|
||||
document.getElementById('add-field').addEventListener('click', function() {
|
||||
const newPair = document.createElement('div');
|
||||
newPair.className = 'key-value-pair row mb-2';
|
||||
newPair.innerHTML = `
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_keys[]" class="form-control" placeholder="Key">
|
||||
</div>
|
||||
<div class="col-md-5">
|
||||
<input type="text" name="param_values[]" class="form-control" placeholder="Value">
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<button type="button" class="btn btn-danger remove-field">Remove</button>
|
||||
</div>
|
||||
`;
|
||||
jsonFields.appendChild(newPair);
|
||||
attachRemoveListener(newPair);
|
||||
attachInputListeners(newPair);
|
||||
});
|
||||
|
||||
function attachRemoveListener(element) {
|
||||
const removeBtn = element.querySelector('.remove-field');
|
||||
if (removeBtn) {
|
||||
removeBtn.addEventListener('click', function() {
|
||||
element.remove();
|
||||
updateJsonOutput();
|
||||
});
|
||||
function attachRemoveListener(element) {
|
||||
const removeBtn = element.querySelector('.remove-field');
|
||||
if (removeBtn) {
|
||||
removeBtn.addEventListener('click', function() {
|
||||
element.remove();
|
||||
updateJsonOutput();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function attachInputListeners(element) {
|
||||
element.querySelectorAll('input').forEach(input => {
|
||||
input.addEventListener('input', updateJsonOutput);
|
||||
});
|
||||
}
|
||||
function attachInputListeners(element) {
|
||||
element.querySelectorAll('input').forEach(input => {
|
||||
input.addEventListener('input', updateJsonOutput);
|
||||
});
|
||||
}
|
||||
|
||||
function updateJsonOutput() {
|
||||
const keys = document.querySelectorAll('input[name="param_keys[]"]');
|
||||
const values = document.querySelectorAll('input[name="param_values[]"]');
|
||||
const data = {};
|
||||
let hasData = false;
|
||||
function updateJsonOutput() {
|
||||
const keys = document.querySelectorAll('input[name="param_keys[]"]');
|
||||
const values = document.querySelectorAll('input[name="param_values[]"]');
|
||||
const data = {};
|
||||
let hasData = false;
|
||||
|
||||
keys.forEach((keyInput, index) => {
|
||||
const key = keyInput.value.trim();
|
||||
const value = values[index]?.value.trim() || '';
|
||||
keys.forEach((keyInput, index) => {
|
||||
const key = keyInput.value.trim();
|
||||
const value = values[index]?.value.trim() || '';
|
||||
|
||||
if (key) {
|
||||
data[key] = value;
|
||||
hasData = true;
|
||||
}
|
||||
if (key) {
|
||||
data[key] = value;
|
||||
hasData = true;
|
||||
}
|
||||
});
|
||||
|
||||
jsonOutput.value = hasData ? JSON.stringify(data) : '';
|
||||
}
|
||||
|
||||
document.querySelectorAll('.key-value-pair').forEach(pair => {
|
||||
attachRemoveListener(pair);
|
||||
attachInputListeners(pair);
|
||||
});
|
||||
|
||||
jsonOutput.value = hasData ? JSON.stringify(data) : '';
|
||||
}
|
||||
|
||||
document.querySelectorAll('.key-value-pair').forEach(pair => {
|
||||
attachRemoveListener(pair);
|
||||
attachInputListeners(pair);
|
||||
});
|
||||
|
||||
updateJsonOutput();
|
||||
|
||||
document.querySelector('form').addEventListener('submit', function(e) {
|
||||
updateJsonOutput();
|
||||
if (!confirm('Are you sure you want to save these parameters?')) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- <script type="text/javascript">
|
||||
$(function() {
|
||||
$(document).on('click', '#payment_method_setting_gateway_communication_type', function(event){
|
||||
if ($(this).val() == "Api") {
|
||||
$('.submitBtn').attr("disabled", true);
|
||||
}else{
|
||||
$('.submitBtn').removeAttr("disabled");
|
||||
}
|
||||
document.querySelector('form').addEventListener('submit', function(e) {
|
||||
updateJsonOutput();
|
||||
if (!confirm('Are you sure you want to save these parameters?')) {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
$( "#payment_method_setting_gateway_url" ).keypress(function() {
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
-->
|
||||
<!-- <script type="text/javascript">
|
||||
$(function() {
|
||||
$(document).on('click', '#payment_method_setting_gateway_communication_type', function(event){
|
||||
if ($(this).val() == "Api") {
|
||||
$('.submitBtn').attr("disabled", true);
|
||||
}else{
|
||||
$('.submitBtn').removeAttr("disabled");
|
||||
}
|
||||
});
|
||||
$( "#payment_method_setting_gateway_url" ).keypress(function() {
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
-->
|
||||
|
||||
Reference in New Issue
Block a user