card payment

This commit is contained in:
Myat Zin Wai Maw
2019-11-27 15:05:42 +06:30
parent 98b74af6cf
commit fe5dc6bb5a
15 changed files with 93 additions and 78 deletions

View File

@@ -33,7 +33,7 @@ class Customer < ApplicationRecord
cus.save
return cus
end
end
end
def self.get_member_account(customer)
membership = MembershipSetting.active.find_by_membership_type("paypar_url")
@@ -44,7 +44,7 @@ class Customer < ApplicationRecord
# urltest =self.url_exist?(url)
if !membership.nil? && !memberaction.nil?
begin
response = HTTParty.get(url, :body => {
response = HTTParty.get(url, :body => {
membership_id: customer.membership_id,
merchant_uid:merchant_uid,
type: "summary",
@@ -57,7 +57,7 @@ class Customer < ApplicationRecord
:timeout => 10)
rescue HTTParty::Error
response = {status: false, message: "Server Error"}
rescue Net::OpenTimeout
response = { status: false , message: "Server Time out"}
@@ -125,7 +125,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,
@@ -143,7 +143,7 @@ class Customer < ApplicationRecord
paypar_account_no: customer.paypar_account_no,
card_no:customer.card_no,member_group_id: customer.membership_type,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
end
end
begin
response = HTTParty.post(url,
@@ -154,7 +154,7 @@ class Customer < ApplicationRecord
})
rescue Net::OpenTimeout
response = { status: false, message: "Server Time out" }
rescue OpenURI::HTTPError
response = { status: false, message: "Can't connect server"}
@@ -172,12 +172,12 @@ class Customer < ApplicationRecord
def self.update_rebate
sales = Sale.where("rebate_status = 'false'")
sales.each do |sale|
if sale.customer.membership_id
if sale.customer.membership_id
response = self.rebat(Sale.find(sale.sale_id))
#record an payment in sale-audit
if !response.nil?
remark = "UPdate Rebate Response - #{response} for Customer #{sale.customer_id} Sale Id [#{sale.sale_id}]| pay amount -> #{sale.amount_received} "
sale_audit = SaleAudit.record_paymal(sale.sale_id, remark, 1)
sale_audit = SaleAudit.record_paymal(sale.sale_id, remark, 1)
end
if response["status"] == true
status = sale.update_attributes(rebate_status: "true")
@@ -190,7 +190,7 @@ class Customer < ApplicationRecord
rebate_prices,campaign_method = SaleItem.calculate_rebate_by_account(sObj.sale_items)
generic_customer_id = sObj.customer.membership_id
if generic_customer_id.present?
paypar = sObj.sale_payments
payparcost = 0
@@ -207,7 +207,7 @@ class Customer < ApplicationRecord
end
# overall_dis = SaleItem.get_overall_discount(sObj.id)
overall_dis = sObj.total_discount
if credit != 1
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("get_member_campaign")
@@ -218,8 +218,8 @@ class Customer < ApplicationRecord
# Control for Paypar Cloud
begin
response = HTTParty.get(url,
:body => {
response = HTTParty.get(url,
:body => {
member_group_id:sObj.customer.membership_type,
merchant_uid:merchant_uid,
campaign_type_id: campaign_type_id,
@@ -233,7 +233,7 @@ class Customer < ApplicationRecord
response = { "status": false , "message": "Connect To" }
rescue OpenURI::HTTPError
response = { "status": false, "message": "Can't connect server"}
rescue SocketError
response = { "status": false, "message": "Can't connect server"}
end
@@ -250,7 +250,7 @@ class Customer < ApplicationRecord
response["membership_campaign_data"].each do |a|
data = {:type => a["rules_type"], :percentage => a["change_unit"].to_i * a["base_unit"].to_i}
total_percentage = total_percentage + a["change_unit"].to_i * a["base_unit"].to_i
type_arr.push(data)
end
end
@@ -267,7 +267,7 @@ class Customer < ApplicationRecord
actual = a[:amount] - amount
data[:amount] = actual
end
end
end
rebate_arr.push(data)
@@ -290,8 +290,8 @@ class Customer < ApplicationRecord
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => {
response = HTTParty.post(url,
:body => {
generic_customer_id:generic_customer_id ,
total_sale_transaction_amount: sObj.grand_total,
merchant_uid:merchant_uid,
@@ -309,7 +309,7 @@ class Customer < ApplicationRecord
response = { "status": false , "message": "Connect To" }
rescue OpenURI::HTTPError
response = { "status": false, "message": "Can't connect server"}
rescue SocketError
response = { "status": false, "message": "Can't connect server"}
end
@@ -320,7 +320,7 @@ class Customer < ApplicationRecord
end
else
puts "no Response"
response = { "status": "no_member", "message": "Not membership"}
response = { "status": "no_member", "message": "Not membership"}
end
end
@@ -331,8 +331,8 @@ class Customer < ApplicationRecord
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
begin
response = HTTParty.get(url,
:body => { paypar_account_no:account_no,
response = HTTParty.get(url,
:body => { paypar_account_no:account_no,
merchant_uid:merchant_uid,
auth_token:auth_token
}.to_json,

View File

@@ -171,7 +171,8 @@ class SalePayment < ApplicationRecord
#record an payment in sale-audit
remark = "Payment failed - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]"
sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by.name)
return false, "Payment failed"
# return false, "Payment failed"
return false, self.save,membership_data
end
else
#record an payment in sale-audit
@@ -303,8 +304,8 @@ class SalePayment < ApplicationRecord
def self.create_payment(paypar_url,payment_type,membership_id,received_amount,sale_id)
# membership_actions_data = MembershipAction.find_by_membership_type("create_payment");
membership_actions_data = PaymentMethodSetting.find_by_payment_method(payment_type)
sale_data = Sale.find_by_sale_id(sale_id)
membership_actions_data = PaymentMethodSetting.find_by_payment_method_and_shop_code(payment_type,sale_data.shop_code)
customer_data = Customer.find_by_customer_id(sale_data.customer_id)
if !membership_actions_data.nil?
@@ -543,7 +544,7 @@ class SalePayment < ApplicationRecord
# if account_no.to_i <= 0
# account_no = customer_data.membership_id
# end
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",self.sale.shop_code)
membership_data = SalePayment.create_payment(membership_setting.gateway_url,"PAYMAL",account_no,self.received_amount,self.sale.sale_id)
#record an payment in sale-audit
@@ -686,7 +687,7 @@ class SalePayment < ApplicationRecord
self.sale.sale_status = "completed"
if MembershipSetting.find_by_rebate(1) && is_foc == 0 && is_credit == 0
if MembershipSetting.find_by_rebate_and_shop_code(1,self.sale.shop_code) && is_foc == 0 && is_credit == 0
response = rebat(sObj)
#record an payment in sale-audit
@@ -845,8 +846,8 @@ class SalePayment < ApplicationRecord
overall_dis = sObj.total_discount
if credit != 1
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("get_member_campaign")
membership = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",sObj.shop_code)
memberaction = MembershipAction.find_by_membership_type_and_shop_code("get_member_campaign",sObj.shop_code)
merchant_uid = memberaction.merchant_account_id.to_s
campaign_type_id = memberaction.additional_parameter["campaign_type_id"]
auth_token = memberaction.auth_token.to_s
@@ -930,8 +931,8 @@ class SalePayment < ApplicationRecord
if total_amount >= 0
receipt_no = sObj.receipt_no
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("rebate")
membership = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",sObj.shop_code)
memberaction = MembershipAction.find_by_membership_type_and_shop_code("rebate",sObj.shop_code)
merchant_uid = memberaction.merchant_account_id.to_s
campaign_type_id = memberaction.additional_parameter["campaign_type_id"]
auth_token = memberaction.auth_token.to_s
@@ -962,7 +963,7 @@ class SalePayment < ApplicationRecord
rescue SocketError
response = { "status": false, "message": "Can't connect server"}
end
Rails.logger.debug "Rebage Response"
Rails.logger.debug "Rebate Response"
Rails.logger.debug response.to_json
return response
end