Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant into adminbsb_ui_changes
This commit is contained in:
@@ -1,31 +0,0 @@
|
||||
require 'openssl'
|
||||
require 'base64'
|
||||
require 'uri'
|
||||
|
||||
class AESEncDec {
|
||||
cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
||||
|
||||
def self.export_key
|
||||
ENV['aes_key'] = cipher.key = cipher.random_key # stores the key in key, and also sets the generated key on the cipher
|
||||
ENV['aes_iv'] = cipher.iv = cipher.random_iv # stores the iv in iv, and also sets the generated iv on the cipher
|
||||
end
|
||||
|
||||
def self.encrypt(data)
|
||||
cipher.encrypt
|
||||
cipher.key = ENV["aes_key"]
|
||||
cipher.iv = ENV["aes_iv"]
|
||||
encrypted = cipher.update(data) + cipher.final
|
||||
encrypted = Base64.urlsafe_encode64(encrypted)
|
||||
return encrypted
|
||||
end
|
||||
|
||||
def self.decrypt(data)
|
||||
cipher.decrypt
|
||||
cipher.key = ENV["aes_key"]
|
||||
cipher.iv = ENV["aes_iv"]
|
||||
|
||||
# Start the decryption
|
||||
decoded = Base64.urlsafe_decode64(data)
|
||||
decrypted = cipher.update(decoded) + cipher.final
|
||||
end
|
||||
}
|
||||
@@ -32,6 +32,7 @@ class Ability
|
||||
|
||||
|
||||
can :manage, Order
|
||||
can :manage, Booking
|
||||
can :manage, Sale
|
||||
|
||||
|
||||
@@ -84,7 +85,7 @@ class Ability
|
||||
|
||||
can :read, Order
|
||||
can :update, Order
|
||||
|
||||
can :menage, Booking
|
||||
can :read, Sale
|
||||
can :update, Sale
|
||||
can :get_customer, Customer
|
||||
|
||||
@@ -41,6 +41,22 @@ class Booking < ApplicationRecord
|
||||
return new_dining.type
|
||||
end
|
||||
|
||||
def self.search(filter,from,to)
|
||||
if filter.blank?
|
||||
keyword = ''
|
||||
else
|
||||
keyword = "booking_id LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%"
|
||||
end
|
||||
|
||||
if from.present? && to.present?
|
||||
sale = Sale.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and NOT sale_status = 'void' ", from,to)
|
||||
query = sale.where(keyword)
|
||||
else
|
||||
where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%",)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
def generate_custom_id
|
||||
self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI")
|
||||
|
||||
@@ -23,13 +23,17 @@ class Customer < ApplicationRecord
|
||||
# urltest =self.url_exist?(url)
|
||||
|
||||
begin
|
||||
response = HTTParty.get(url, :body => { membership_id: customer.membership_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
},
|
||||
:timeout => 10
|
||||
)
|
||||
response = HTTParty.get(url, :body => {
|
||||
membership_id: customer.membership_id,
|
||||
merchant_uid:merchant_uid,
|
||||
type: "summary",
|
||||
auth_token:auth_token
|
||||
}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json; version=2'
|
||||
},
|
||||
:timeout => 10)
|
||||
rescue HTTParty::Error
|
||||
response = {status: false, message: "Server Error"}
|
||||
|
||||
@@ -63,7 +67,7 @@ class Customer < ApplicationRecord
|
||||
}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
'Accept' => 'application/json; version=2'
|
||||
},
|
||||
:timeout => 10
|
||||
)
|
||||
@@ -91,7 +95,7 @@ class Customer < ApplicationRecord
|
||||
auth_token = memberaction.auth_token.to_s
|
||||
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
||||
|
||||
@customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL")
|
||||
@customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL")
|
||||
|
||||
@customers.each do |customer|
|
||||
member_params = { name: customer.name,phone: customer.contact_no,
|
||||
@@ -102,7 +106,7 @@ class Customer < ApplicationRecord
|
||||
|
||||
# Check for paypar account exists
|
||||
# if paypar_account_no != nil || paypar_account_no != ''
|
||||
if paypar_account_no.present?
|
||||
if customer.paypar_account_no.present?
|
||||
member_params = { name: customer.name,phone: customer.contact_no,
|
||||
email: customer.email,dob: customer.date_of_birth,
|
||||
address: customer.address,nrc:customer.nrc_no,
|
||||
@@ -116,7 +120,7 @@ class Customer < ApplicationRecord
|
||||
:body => member_params,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
'Accept' => 'application/json; version=2'
|
||||
})
|
||||
rescue Net::OpenTimeout
|
||||
response = { status: false, message: "Server Time out" }
|
||||
@@ -127,7 +131,6 @@ class Customer < ApplicationRecord
|
||||
rescue SocketError
|
||||
response = { status: false, message: "Can't connect server"}
|
||||
end
|
||||
|
||||
if response["status"] == true
|
||||
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
|
||||
end
|
||||
@@ -161,10 +164,12 @@ class Customer < ApplicationRecord
|
||||
credit = 1
|
||||
end
|
||||
end
|
||||
|
||||
# overall_dis = SaleItem.get_overall_discount(sObj.id)
|
||||
overall_dis = sObj.total_discount
|
||||
|
||||
total_amount = rebate_prices - payparcost - overall_dis
|
||||
|
||||
if credit == 1
|
||||
total_amount = 0
|
||||
end
|
||||
@@ -183,7 +188,7 @@ class Customer < ApplicationRecord
|
||||
receipt_no: receipt_no,auth_token:auth_token}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
'Accept' => 'application/json; version=2'
|
||||
}, :timeout => 10)
|
||||
rescue Net::OpenTimeout
|
||||
response = { "status": false , "message": "Connect To" }
|
||||
@@ -215,7 +220,7 @@ class Customer < ApplicationRecord
|
||||
}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
'Accept' => 'application/json; version=2'
|
||||
},
|
||||
:timeout => 10
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class License
|
||||
include HTTParty
|
||||
|
||||
base_uri "secure.smartsales.asia/api"
|
||||
base_uri "provision.zsai.ws/api"
|
||||
|
||||
attr_accessor :name, :address_1, :address_2, :township, :city, :country, :email, :phone, :fax, :logo, :subdomain,
|
||||
:plan_activation_date, :plan_next_renewal_date, :plan_max_products,:plan_max_customers, :plan_active_connections,
|
||||
@@ -13,17 +13,14 @@ class License
|
||||
|
||||
def initialize(server = "", lookup = "")
|
||||
#this code is hard-code to reflect server mode - Very important.
|
||||
self.server_mode = ENV["server_mode"]
|
||||
self.server_mode = ENV["SERVER_MODE"]
|
||||
|
||||
if (server != "")
|
||||
self.class.base_uri server
|
||||
end
|
||||
|
||||
# generate key for license file encrypt
|
||||
AESCrypt.export_key()
|
||||
|
||||
@secret = ENV["aes_key"]
|
||||
@params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } }
|
||||
# @secret = ENV["aes_key"]
|
||||
# @params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } }
|
||||
end
|
||||
|
||||
def shop_code
|
||||
@@ -32,15 +29,11 @@ class License
|
||||
else
|
||||
return self.subdomain.upcase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_license_file
|
||||
return File.exist?("config/license.yml")
|
||||
end
|
||||
|
||||
def detail_with_local_cache(lookup)
|
||||
def detail_with_local_cache(lookup, key, iv)
|
||||
##Check from local redis - if available load local otherwise get from remote
|
||||
cache_key = "store:license:#{@secret}:hostname"
|
||||
cache_key = "#{lookup}:license:#{key}:hostname"
|
||||
|
||||
# No Needs for current
|
||||
# @secret = key
|
||||
@@ -53,12 +46,11 @@ class License
|
||||
end
|
||||
|
||||
Rails.logger.info "Cache key - " + cache_key.to_s
|
||||
|
||||
if cache_license.nil?
|
||||
##change the d/e key
|
||||
@params = { query: { lookup_type: "cloud", lookup: lookup, encrypted_key: @secret } }
|
||||
|
||||
response = self.class.get("/request_license", @params)
|
||||
# @options = { query: {device: "SXlite", lookup: lookup, skey: @secret, token: SECRETS_CONFIG['provision_key']} }
|
||||
@params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} }
|
||||
response = self.class.get("/subdomain", @params)
|
||||
@license = response.parsed_response
|
||||
|
||||
if (@license["status"] == true)
|
||||
@@ -78,23 +70,56 @@ class License
|
||||
end
|
||||
|
||||
Rails.logger.info 'API License'
|
||||
|
||||
else
|
||||
|
||||
@license = Marshal.load(cache_license) if cache_license
|
||||
|
||||
Rails.logger.info 'Cache License'
|
||||
|
||||
if (@license["status"] == true)
|
||||
assign()
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
def detail_with_local_file()
|
||||
has_license = true #verify_license()
|
||||
|
||||
if has_license
|
||||
puts "VERIFIED"
|
||||
end
|
||||
|
||||
# if cache_license.nil?
|
||||
# ##change the d/e key
|
||||
# @params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} }
|
||||
|
||||
# response = self.class.get("/request_license", @params)
|
||||
# @license = response.parsed_response
|
||||
|
||||
# if (@license["status"] == true)
|
||||
|
||||
# assign()
|
||||
|
||||
# Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
|
||||
# Redis.current do |conn|
|
||||
# ##Remote - store the remote response in local redis cache
|
||||
# conn.set(cache_key, Marshal.dump(@license))
|
||||
# ##ADD to List to remove later
|
||||
# conn.sadd("License:cache:keys", cache_key)
|
||||
# end
|
||||
|
||||
# return true
|
||||
# end
|
||||
|
||||
# Rails.logger.info 'API License'
|
||||
|
||||
# else
|
||||
# @license = Marshal.load(cache_license) if cache_license
|
||||
|
||||
# Rails.logger.info 'Cache License'
|
||||
|
||||
# if (@license["status"] == true)
|
||||
# assign()
|
||||
# return true
|
||||
# end
|
||||
# end
|
||||
# return false
|
||||
end
|
||||
|
||||
def detail
|
||||
|
||||
response = self.class.get("/subdomain", @options)
|
||||
@license = response.parsed_response
|
||||
|
||||
@@ -110,6 +135,23 @@ class License
|
||||
return false
|
||||
end
|
||||
|
||||
def verify_license
|
||||
api_token = read_license("api_token")
|
||||
@options = { query: {lookup_type: "application", token: api_token} }
|
||||
response = self.class.get("/verify", @options)
|
||||
@varified = response.parsed_response
|
||||
|
||||
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
|
||||
if (@varified["status"])
|
||||
if (!check_expired(@varified["plan_next_renewal_date"]))
|
||||
return true
|
||||
end
|
||||
else
|
||||
delete_license_file
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def check_remote_license(license_key)
|
||||
# @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} }
|
||||
@options = { query: {lookup_type: "application", encrypted_key: @secret, token: SECRETS_CONFIG['provision_key']} }
|
||||
@@ -141,15 +183,32 @@ class License
|
||||
#Load License is remove from the cloud license because - this license is must be validated against subdmain instead of license.data from file.
|
||||
|
||||
|
||||
def expired?
|
||||
if (self.plan_next_renewal_date < Date.today)
|
||||
def check_expired(renewal_date)
|
||||
if (renewal_date < Date.today)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def self.check_license_file
|
||||
return File.exist?("config/license.yml")
|
||||
end
|
||||
|
||||
private
|
||||
# read line by key for license file
|
||||
def read_license(key)
|
||||
decrypted_line = ""
|
||||
if File.exist?("config/license.yml")
|
||||
File.open("config/license.yml").each do |line|
|
||||
if line.include? (key)
|
||||
decrypted_line_array = line.split(":")
|
||||
decrypted_line = AESCrypt.decrypt(decrypted_line_array[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def assign
|
||||
# self.name = @license["name"]
|
||||
# self.address_1 = @license["address_1"]
|
||||
|
||||
38
app/models/my_aes_crypt.rb
Normal file
38
app/models/my_aes_crypt.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
class MyAesCrypt
|
||||
@cipher = ""
|
||||
|
||||
def initialize
|
||||
@cipher = OpenSSL::Cipher::Cipher.new(ENV["CIPHER_TYPE"])
|
||||
end
|
||||
|
||||
def export_key(passphrase)
|
||||
# We want a 256 bit key symetric key based on passphrase
|
||||
digest = Digest::SHA256.new
|
||||
key = digest.update(passphrase)
|
||||
key = digest.digest
|
||||
ENV['AES_KEY'] = cipher_key = key # stores the key in key, and also sets the generated key on the @cipher
|
||||
ENV['AES_IV'] = cipher_iv = @cipher.random_iv # stores the iv in iv, and also sets the generated iv on the @cipher
|
||||
return cipher_key, cipher_iv
|
||||
end
|
||||
|
||||
private
|
||||
def encrypt(data)
|
||||
cipher.encrypt
|
||||
cipher.key = ENV["aes_key"]
|
||||
cipher.iv = ENV["aes_iv"]
|
||||
encrypted = cipher.update(data) + cipher.final
|
||||
encrypted = Base64.encode64(encrypted)
|
||||
return encrypted
|
||||
end
|
||||
|
||||
def decrypt(data)
|
||||
cipher.decrypt
|
||||
cipher.key = ENV["aes_key"]
|
||||
cipher.iv = ENV["aes_iv"]
|
||||
|
||||
# Start the decryption
|
||||
decoded = Base64.decode64(data)
|
||||
decrypted = cipher.update(decoded) + cipher.final
|
||||
return decrypted
|
||||
end
|
||||
end
|
||||
@@ -85,7 +85,7 @@ class SalePayment < ApplicationRecord
|
||||
}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
'Accept' => 'application/json; version=2'
|
||||
}, :timeout => 10
|
||||
)
|
||||
rescue Net::OpenTimeout
|
||||
@@ -120,17 +120,18 @@ class SalePayment < ApplicationRecord
|
||||
# Control for Paypar Cloud
|
||||
begin
|
||||
response = HTTParty.post(url,
|
||||
:body => { generic_customer_id:membership_id,
|
||||
:body => { membership_id:membership_id,
|
||||
total_amount: redeem_prices,
|
||||
total_sale_transaction_amount: sale_data.grand_total,
|
||||
redeem_amount:received_amount,
|
||||
receipt_no:sale_data.receipt_no,
|
||||
campaign_type_id:campaign_type_id,
|
||||
account_no:"",merchant_uid:merchant_uid,
|
||||
account_no:"",
|
||||
merchant_uid:merchant_uid,
|
||||
auth_token:auth_token}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
'Accept' => 'application/json; version=2'
|
||||
},
|
||||
:timeout => 10
|
||||
)
|
||||
@@ -399,7 +400,7 @@ class SalePayment < ApplicationRecord
|
||||
}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
'Accept' => 'application/json; version=2'
|
||||
}, :timeout => 10)
|
||||
rescue Net::OpenTimeout
|
||||
response = { "status": false , "message": "Connect To" }
|
||||
@@ -468,7 +469,7 @@ class SalePayment < ApplicationRecord
|
||||
}.to_json,
|
||||
:headers => {
|
||||
'Content-Type' => 'application/json',
|
||||
'Accept' => 'application/json'
|
||||
'Accept' => 'application/json; version=2'
|
||||
}, :timeout => 10)
|
||||
rescue Net::OpenTimeout
|
||||
response = { "status": false , "message": "Connect To" }
|
||||
|
||||
Reference in New Issue
Block a user