finished dinga and paymal payment

This commit is contained in:
Aung Myo
2018-04-18 16:47:38 +06:30
parent 5816a48d32
commit 2a26abff9a
4 changed files with 55 additions and 35 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 => { account_no: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'
@@ -390,12 +404,11 @@ 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
# 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,account_no,self.received_amount,self.sale.sale_id)
@@ -439,13 +452,12 @@ class SalePayment < ApplicationRecord
#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
# 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,account_no,self.received_amount,self.sale.sale_id)