From 2a26abff9ad823164ce7308f2be34e9efe2da296 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Wed, 18 Apr 2018 16:47:38 +0630 Subject: [PATCH] finished dinga and paymal payment --- app/controllers/origami/paymal_controller.rb | 1 + app/models/sale_payment.rb | 46 ++++++++++++-------- app/views/origami/dinga/index.html.erb | 24 +++++----- app/views/origami/paymal/index.html.erb | 19 +++++--- 4 files changed, 55 insertions(+), 35 deletions(-) diff --git a/app/controllers/origami/paymal_controller.rb b/app/controllers/origami/paymal_controller.rb index 499a0625..1321cf87 100644 --- a/app/controllers/origami/paymal_controller.rb +++ b/app/controllers/origami/paymal_controller.rb @@ -74,6 +74,7 @@ def create sale_id = params[:sale_id] transaction_ref = params[:transaction_ref] account_no = params[:account_no] + puts params.to_json if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop.first diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 50599f68..29d755d7 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -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) diff --git a/app/views/origami/dinga/index.html.erb b/app/views/origami/dinga/index.html.erb index 1bd18f39..e9205fbf 100644 --- a/app/views/origami/dinga/index.html.erb +++ b/app/views/origami/dinga/index.html.erb @@ -205,7 +205,7 @@ $.ajax({ type: "POST", url: "<%=origami_payment_dinga_path%>", - data: {payment_amount:payment_amount,membership_id:membership_id,sale_id:sale_id,transaction_ref:""}, + data: {payment_amount:payment_amount,membership_id:membership_id,sale_id:sale_id,transaction_ref:"",account_no:0}, success: function(result){ if(result.status == true){ swal({ @@ -244,11 +244,11 @@ var receipt_no = $("#receipt_no").text() || 0; var customer_mamber_card_no = 0; - // $("#is_paymemberModal").hide(); - // $("#sxModal").show(); - // setTimeout(function(){ - // getCardNo(); - // $("#sxModal").hide(); + $("#is_paymemberModal").hide(); + $("#sxModal").show(); + setTimeout(function(){ + getCardNo(); + $("#sxModal").hide(); customer_mamber_card_no = $("#paypar_account_no").val(); if(sale_id != 0 && customer_mamber_card_no != 0){ $.ajax({ @@ -302,7 +302,7 @@ } }); } - // },100); + },100); }); // Read NFC card no from java @@ -320,13 +320,13 @@ // QR Code Reader $(".btn_qr_code").on('click', function(e){ $("#is_memberModal").hide(); - var code = "1011002923682533"; + var code = ""; var customer_id = ''; var customer_name = ''; var membership_id = ''; var membership_type = ''; - // setTimeout(function(){ - // code=getQRCode(); + setTimeout(function(){ + code=getQRCode(); if(sale_id != 0 && code != ""){ $.ajax({ type: "POST", @@ -341,7 +341,7 @@ $.ajax({ type: "POST", url: "<%=origami_payment_paymal_path%>", - data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no : code}, + data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no:code}, success: function(result){ if(result.status == true){ swal({ @@ -376,7 +376,7 @@ } }); } - // },100); + },100); }); // Read qrcode from java diff --git a/app/views/origami/paymal/index.html.erb b/app/views/origami/paymal/index.html.erb index d92f162a..5594eb13 100644 --- a/app/views/origami/paymal/index.html.erb +++ b/app/views/origami/paymal/index.html.erb @@ -14,6 +14,8 @@
+ +
@@ -204,7 +206,7 @@ $.ajax({ type: "POST", url: "<%=origami_payment_paymal_path%>", - data: {payment_amount:payment_amount,membership_id:membership_id,sale_id:sale_id,transaction_ref:""}, + data: {payment_amount:payment_amount,membership_id:membership_id,sale_id:sale_id,transaction_ref:"",account_no:0}, success: function(result){ if(result.status == true){ swal({ @@ -237,6 +239,7 @@ var cardNo = ""; var sale_id = $("#sale_id").text() || 0; var receipt_no = $("#receipt_no").val() || ""; + var customer_mamber_card_no = 0; var payment_amount = parseFloat($("#used_amount").text()); @@ -246,8 +249,10 @@ getCardNo(); $("#sxModal").hide(); customer_mamber_card_no = $("#paypar_account_no").val(); - - if(sale_id != 0 && customer_mamber_card_no != 0){ + if (customer_mamber_card_no == 0) { + customer_mamber_card_no = $("#membership_id").text() || 0; + } + if(sale_id != 0 && customer_mamber_card_no !=0){ $.ajax({ type: "POST", url: "/origami/"+sale_id+"/send_account" , @@ -261,7 +266,7 @@ $.ajax({ type: "POST", url: "<%=origami_payment_paymal_path%>", - data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref}, + data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no:customer_mamber_card_no}, success: function(result){ if(result.status == true){ swal({ @@ -296,8 +301,10 @@ } }); + }else{ + swal("Opp","Please Check Member","warning") } - },100); + },100); }); // Read NFC card no from java @@ -335,7 +342,7 @@ $.ajax({ type: "POST", url: "<%=origami_payment_paymal_path%>", - data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref}, + data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no:code}, success: function(result){ if(result.status == true){ swal({