60 lines
1.8 KiB
Ruby
60 lines
1.8 KiB
Ruby
class Origami::PaymentsController < BaseOrigamiController
|
|
|
|
|
|
def index
|
|
end
|
|
|
|
def create
|
|
cash = params[:cash]
|
|
sale_id = params[:sale_id]
|
|
if(Sale.exists?(sale_id))
|
|
saleObj = Sale.find(sale_id)
|
|
sale_payment = SalePayment.new
|
|
sale_payment.process_payment(saleObj, @user, cash, "cash")
|
|
end
|
|
end
|
|
|
|
def show
|
|
sale_id = params[:sale_id]
|
|
if Sale.exists?(sale_id)
|
|
@cash = 0.0
|
|
@other = 0.0
|
|
@sale_data = Sale.find_by_sale_id(sale_id)
|
|
|
|
#get customer amount
|
|
@customer = Customer.find(@sale_data.customer_id)
|
|
|
|
membership = MembershipSetting.find_by_membership_type("paypar_url")
|
|
|
|
memberaction = MembershipAction.find_by_membership_type("get_all_member_account")
|
|
merchant_uid = memberaction.merchant_account_id.to_s
|
|
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
|
|
|
|
response = HTTParty.get(url, :body => { membership_id: @customer.membership_id,merchant_uid:merchant_uid}.to_json,
|
|
:headers => {
|
|
'Content-Type' => 'application/json',
|
|
'Accept' => 'application/json'
|
|
}
|
|
)
|
|
|
|
@balance = 0.00
|
|
response["data"].each do |res|
|
|
if res["accountable_type"] == "RebateAccount"
|
|
@balance = res["balance"]
|
|
end
|
|
end
|
|
#end customer amount
|
|
|
|
@sale_data.sale_payments.each do |spay|
|
|
if spay.payment_method == "cash"
|
|
@cash = spay.payment_amount
|
|
end
|
|
if spay.payment_method == "mpu" || spay.payment_method == "paypar"
|
|
@other += spay.payment_amount
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|