Merge branch 'topup_payment' of bitbucket.org:code2lab/sxrestaurant into adminbsb_ui_changes

This commit is contained in:
phyusin
2018-03-30 16:38:00 +06:30
17 changed files with 458 additions and 9 deletions

View File

@@ -49,10 +49,15 @@ class SalePayment < ApplicationRecord
payment_status = paypar_payment
when "foc"
payment_status = foc_payment
<<<<<<< HEAD
when "paymal"
payment_status = paymal_payment
=======
when "JunctionPay"
payment_status = junction_pay_payment
when "alipay"
payment_status = external_terminal_card_payment(:alipay)
>>>>>>> 996392a041cb5f92a3b2985cbd0379210132d829
else
puts "it was something else"
end
@@ -164,6 +169,60 @@ class SalePayment < ApplicationRecord
return response;
end
def self.create_payment(paypar_url,token,membership_id,received_amount,sale_id)
membership_actions_data = MembershipAction.find_by_membership_type("create_payment");
if !membership_actions_data.nil?
url = paypar_url.to_s + membership_actions_data.gateway_url.to_s
merchant_uid = membership_actions_data.merchant_account_id
auth_token = membership_actions_data.auth_token
sale_data = Sale.find_by_sale_id(sale_id)
if sale_data
others = 0
sale_data.sale_payments.each do |sale_payment|
others = others + sale_payment.payment_amount
end
payment_prices = sale_data.grand_total - others
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => { membership_id:membership_id,
amount:received_amount,
receipt_no:sale_data.receipt_no,
merchant_uid:merchant_uid,
auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
},
:timeout => 10
)
rescue Net::OpenTimeout
response = false
rescue OpenURI::HTTPError
response = { status: false}
rescue SocketError
response = { status: false}
end
else
response = false;
end
else
response =false;
end
Rails.logger.debug "Payment response"
Rails.logger.debug response.to_json
return response;
end
# Check for Card Payment
@@ -301,6 +360,33 @@ class SalePayment < ApplicationRecord
end
<<<<<<< HEAD
def paymal_payment
payment_status = false
#Next time - validate if the vochure number is valid - within
customer_data = Customer.find_by_customer_id(self.sale.customer_id)
membership_setting = MembershipSetting.find_by_membership_type("paypar_url")
membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id)
#record an payment in sale-audit
remark = "#{membership_data} PayMal Payment- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} "
sale_audit = SaleAudit.record_paymal(self.sale.sale_id, remark, 1)
if membership_data["status"]==true
self.payment_method = "paymal"
self.payment_amount = self.received_amount
self.payment_reference = self.voucher_no
self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f
self.payment_status = "pending"
payment_method = self.save!
SalePayment.where(:sale_payment_id => self.sale_payment_id).update_all(:payment_status => 'paid')
sale_update_payment_status(self.received_amount.to_f)
else
sale_update_payment_status(0)
end
=======
def junction_pay_payment
payment_status = false
@@ -313,6 +399,7 @@ class SalePayment < ApplicationRecord
payment_method = self.save!
sale_update_payment_status(self.received_amount)
>>>>>>> 996392a041cb5f92a3b2985cbd0379210132d829
return payment_status
end