Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant

This commit is contained in:
Yan
2018-04-18 18:12:16 +06:30
8 changed files with 90 additions and 50 deletions

View File

@@ -197,13 +197,14 @@ class SalePayment < ApplicationRecord
def self.create_payment(paypar_url,token,membership_id,received_amount,sale_id)
membership_actions_data = MembershipAction.find_by_membership_type("create_payment");
sale_data = Sale.find_by_sale_id(sale_id)
customer_data = Customer.find_by_customer_id(sale_data.customer_id)
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
@@ -211,14 +212,27 @@ class SalePayment < ApplicationRecord
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,
if membership_id.to_i <= 0
membership_id = customer_data.membership_id
params = { membership_id:membership_id,
amount:received_amount,
receipt_no:sale_data.receipt_no,
merchant_uid:merchant_uid,
auth_token:auth_token}.to_json,
auth_token:auth_token}.to_json
else
params = { account_no:membership_id,
amount:received_amount,
receipt_no:sale_data.receipt_no,
merchant_uid:merchant_uid,
auth_token:auth_token}.to_json
end
# Control for Paypar Cloud
begin
response = HTTParty.post(url,
:body => params,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
@@ -242,7 +256,7 @@ class SalePayment < ApplicationRecord
response =false;
end
Rails.logger.debug "Payment response"
Rails.logger.debug "Create Payment response"
Rails.logger.debug response.to_json
return response;
@@ -390,9 +404,13 @@ class SalePayment < ApplicationRecord
payment_status = false
#Next time - validate if the vochure number is valid - within
customer_data = Customer.find_by_customer_id(self.sale.customer_id)
# customer_data = Customer.find_by_customer_id(self.sale.customer_id)
account_no = self.payment_reference
# if account_no.to_i <= 0
# account_no = customer_data.membership_id
# end
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)
membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,account_no,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} "
@@ -433,9 +451,16 @@ class SalePayment < ApplicationRecord
payment_status = false
#Next time - validate if the vochure number is valid - within
customer_data = Customer.find_by_customer_id(self.sale.customer_id)
# customer_data = Customer.find_by_customer_id(self.sale.customer_id)
account_no = self.payment_reference
# if account_no == 0
# account_no = customer_data.customer_id
# end
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)
membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,account_no,self.received_amount,self.sale.sale_id)
#record an payment in sale-audit
remark = "#{membership_data} Dinga Payment- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} "