diff --git a/Gemfile b/Gemfile index cd92e40b..fe3610b0 100755 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.4.1' +ruby '2.4.0' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" diff --git a/app/assets/javascripts/origami/paymal.coffee b/app/assets/javascripts/origami/paymal.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/origami/paymal.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/origami/paymal.scss b/app/assets/stylesheets/origami/paymal.scss new file mode 100644 index 00000000..93758d38 --- /dev/null +++ b/app/assets/stylesheets/origami/paymal.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the origami/Paymal controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/origami/paymal_controller.rb b/app/controllers/origami/paymal_controller.rb new file mode 100644 index 00000000..bdcee917 --- /dev/null +++ b/app/controllers/origami/paymal_controller.rb @@ -0,0 +1,101 @@ +class Origami::PaymalController < BaseOrigamiController + def index + @sale_id = params[:sale_id] + payment_method = params[:payment_method] + @cashier_type = params[:type] + @membership_rebate_balance=0 + sale_data = Sale.find_by_sale_id(@sale_id) + + @shop = Shop::ShopDetail + # if @shop.is_rounding_adj + # new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + # else + # new_total = sale_data.grand_total + # end + # @rounding_adj = new_total-sale_data.grand_total + @rounding_adj = sale_data.rounding_adjustment + + @payparcount = 0 + others = 0 + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "paypar" + @payparcount = @payparcount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @payment_prices = sale_data.grand_total - @payparcount -others + + + if sale_data + if sale_data.customer_id + customer_data= Customer.find_by_customer_id(sale_data.customer_id) + if customer_data + @membership_id = customer_data.membership_id + if !@membership_id.nil? + membership_setting = MembershipSetting.find_by_membership_type("paypar_url") + if membership_setting.gateway_url + member_actions =MembershipAction.find_by_membership_type("get_account_balance") + if member_actions.gateway_url + @campaign_type_id = nil + url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s + merchant_uid= member_actions.merchant_account_id + auth_token = member_actions.auth_token.to_s + membership_data = SalePayment.get_paypar_account(url,membership_setting.auth_token,@membership_id,@campaign_type_id,merchant_uid,auth_token) + if membership_data["status"]==true + @membership_rebate_balance=membership_data["balance"] + @out = true, @membership_rebate_balance,@membership_id + end + else + @out =false,0 + end + else + @out = false,0 + end + + + else + @out = false, 0 + end + else + @out = false, 0 + end + else + @out = false, 0 + end + else + @out = false, 0 + end + @out = false, 0 + end + def create + cash = params[:payment_amount] + sale_id = params[:sale_id] + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + shop_details = Shop::ShopDetail + + # rounding adjustment + # if shop_details.is_rounding_adj + # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + # rounding_adj = new_total-saleObj.grand_total + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # end + + # saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + status, @sale = sale_payment.process_payment(saleObj, @user, cash, "paymal") + if status == true + @out = true, "Success!" + else + @out =false, "Please try again payment!" + end + end + end + + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end +end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index cdb8752f..da5f216b 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -229,6 +229,7 @@ class Origami::PaymentsController < BaseOrigamiController @alipaycount = 0.0 @junctionpaycount = 0.0 @credit = 0.0 + @paymalcount = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) @balance = 0 @accountable_type = '' @@ -347,6 +348,8 @@ class Origami::PaymentsController < BaseOrigamiController @junctionpaycount += spay.payment_amount elsif spay.payment_method == "creditnote" @credit += spay.payment_amount + elsif spay.payment_method == "paymal" + @paymalcount += spay.payment_amount elsif spay.payment_method == "alipay" @alipaycount += spay.payment_amount end diff --git a/app/helpers/origami/paymal_helper.rb b/app/helpers/origami/paymal_helper.rb new file mode 100644 index 00000000..8d1787c8 --- /dev/null +++ b/app/helpers/origami/paymal_helper.rb @@ -0,0 +1,2 @@ +module Origami::PaymalHelper +end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index cceee884..d4b549bb 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -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 diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 4810cf13..974afe7c 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -782,12 +782,13 @@ $(".choose_payment").on('click', function () { $( "#loading_wrapper").show(); + alert(parseInt(jQuery.inArray("PAYMAL", type))); var sale_id = $('#sale_id').val(); // type = $('.payment_method').val(); type = get_selected_attributes('selected-payment'); if(parseInt(jQuery.inArray("Credit", type)) == -1){ - if (parseInt(jQuery.inArray("MPU", type)) != -1 || parseInt(jQuery.inArray("VISA", type)) != -1 || parseInt(jQuery.inArray("JCB", type)) != -1 || parseInt(jQuery.inArray("Master", type)) != -1 || parseInt(jQuery.inArray("UNIONPAY", type)) != -1 || parseInt(jQuery.inArray("Redeem", type)) != -1) { + if (parseInt(jQuery.inArray("MPU", type)) != -1 || parseInt(jQuery.inArray("VISA", type)) != -1 || parseInt(jQuery.inArray("JCB", type)) != -1 || parseInt(jQuery.inArray("Master", type)) != -1 || parseInt(jQuery.inArray("UNIONPAY", type)) != -1 || parseInt(jQuery.inArray("Redeem", type)) != -1 || parseInt(jQuery.inArray("PAYMAL",type))!= -1) { calculate_member_discount(sale_id,"Card"); }else{ diff --git a/app/views/origami/paymal/create.json.jbuilder b/app/views/origami/paymal/create.json.jbuilder new file mode 100644 index 00000000..f352b148 --- /dev/null +++ b/app/views/origami/paymal/create.json.jbuilder @@ -0,0 +1,2 @@ +json.set! :status, @out[0] +json.set! :message, @out[1] \ No newline at end of file diff --git a/app/views/origami/paymal/index.html.erb b/app/views/origami/paymal/index.html.erb new file mode 100644 index 00000000..81684256 --- /dev/null +++ b/app/views/origami/paymal/index.html.erb @@ -0,0 +1,201 @@ +
+ +
PayMal Payment
+
+
+
+
+
+
+ + <%@payment_prices = @payment_prices +@rounding_adj%> + +
+
+
+ <% if @payparcount > 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+ + +
+
+
+
+
+ +
0.0
+
+
+
+
+
+ +
+ +
+
+
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+ +
+
+ + +
+
+ +
+
+
+ diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index bca79e11..4d9f2dc5 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -285,12 +285,23 @@ <% end %> +
+
+
PAYMAL
+ <% if @paymalcount != 0.0 %> +
<%= number_with_precision(@paymalcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+ <% else %> +
<%= number_with_precision(0, precision: precision.to_i ) %>
+ <% end %> +
+ <% if @junctionpaycount != 0.0 %>
<% else %> -
Balance
<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
@@ -544,7 +554,7 @@ var customer_name = "<%= @customer.name %>"; $("#credit_payment").show(); } - if(parseInt(jQuery.inArray("MPU", payment_type)) !=-1 || parseInt(jQuery.inArray("VISA", payment_type)) !=-1 || parseInt(jQuery.inArray("JCB", payment_type)) !=-1 || parseInt(jQuery.inArray("Master", payment_type)) !=-1 || parseInt(jQuery.inArray("UNIONPAY", payment_type)) !=-1 || parseInt(jQuery.inArray("Redeem", payment_type)) !=-1 || parseInt(jQuery.inArray("JUNCTIONPAY", payment_type)) !=-1){ + if(parseInt(jQuery.inArray("MPU", payment_type)) !=-1 || parseInt(jQuery.inArray("VISA", payment_type)) !=-1 || parseInt(jQuery.inArray("JCB", payment_type)) !=-1 || parseInt(jQuery.inArray("Master", payment_type)) !=-1 || parseInt(jQuery.inArray("UNIONPAY", payment_type)) !=-1 || parseInt(jQuery.inArray("Redeem", payment_type)) !=-1, parseInt(jQuery.inArray("PAYMAL", payment_type)) !=-1 || parseInt(jQuery.inArray("JUNCTIONPAY", payment_type)) !=-1 || parseInt(jQuery.inArray("Alipay", payment_type)) !=-1){ $("#card_payment").show(); } else{ $("#card_payment").hide(); @@ -615,6 +625,8 @@ var customer_name = "<%= @customer.name %>"; } else if(payment_type == "Credit" && $('#credit').text()==0 && sub_total != 0.0){ swal("Oops","Please Pay with Credit Payment","warning"); + }else if(payment_type == "PAYMAL" && $('#paymalcount').text()==0 && sub_total != 0.0){ + swal("Oops","Please Pay with Paymal Payment","warning"); }else{ $( "#loading_wrapper").show(); @@ -892,9 +904,10 @@ var customer_name = "<%= @customer.name %>"; var jcb1 = $('#jcbcount').text(); var master1 = $('#mastercount').text(); var unionpay1 = $('#unionpaycount').text(); + var paymal1 = $('#paymalcount').text(); var alipay1 = $('#alipaycount').text(); var junctionpay1 = $('#junctionpaycount').text(); - var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(alipay1) + parseFloat(junctionpay1); + var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1) + parseFloat(alipay1) + parseFloat(junctionpay1) + parseFloat(paymal1); var total = $('#amount_due').text(); var amt = 0; <% if precision.to_i > 0 %>; @@ -922,10 +935,11 @@ var customer_name = "<%= @customer.name %>"; var jcb = $('#jcbcount').text(); var master = $('#mastercount').text(); var unionpay = $('#unionpaycount').text(); + var paymal = $('#paymalcount').text(); var alipay = $('#alipaycount').text(); var junctionpay = $('#junctionpaycount').text(); var amount_due = $('#amount_due').text(); - var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) + parseFloat(alipay) + parseFloat(junctionpay) + var total = parseFloat(cash) + parseFloat(credit) + parseFloat(card) + parseFloat(paypar) + parseFloat(visa) + parseFloat(jcb) + parseFloat(master) + parseFloat(unionpay) + parseFloat(alipay) + parseFloat(junctionpay) + parseFloat(paymal); var result = parseFloat(amount_due) - parseFloat(total); <% if precision.to_i > 0 %> $('#balance').text(parseFloat(result).toFixed(<%= precision %>)); diff --git a/app/views/origami/redeem_payments/index.html.erb b/app/views/origami/redeem_payments/index.html.erb index 4942d144..42ca124f 100755 --- a/app/views/origami/redeem_payments/index.html.erb +++ b/app/views/origami/redeem_payments/index.html.erb @@ -177,7 +177,6 @@ data: {redeem_amount:redeem_amount,membership_id:membership_id,sale_id:sale_id}, success: function(result){ if(result.status == true){ - console.log(result) swal({ title: "Information!", text: result.message, diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index e2f04018..43c4d5e7 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -741,13 +741,12 @@ $("#first_bill").on('click', function(){ $(".choose_payment").on('click', function () { $( "#loading_wrapper").show(); - var sale_id = $('#sale_id').val(); type = get_selected_attributes('selected-payment'); // type = $('.payment_method').val(); if(parseInt(jQuery.inArray("Credit", type)) == -1){ - if (parseInt(jQuery.inArray("MPU", type)) != -1 || parseInt(jQuery.inArray("VISA", type)) != -1 || parseInt(jQuery.inArray("JCB", type)) != -1 || parseInt(jQuery.inArray("Master", type)) != -1 || parseInt(jQuery.inArray("UNIONPAY", type)) != -1 || parseInt(jQuery.inArray("Redeem", type)) != -1) { + if (parseInt(jQuery.inArray("MPU", type)) != -1 || parseInt(jQuery.inArray("VISA", type)) != -1 || parseInt(jQuery.inArray("JCB", type)) != -1 || parseInt(jQuery.inArray("Master", type)) != -1 || parseInt(jQuery.inArray("UNIONPAY", type)) != -1 || parseInt(jQuery.inArray("Redeem", type)) != -1 || parseInt(jQuery.inArray("PAYMAL", type)) != -1) { calculate_member_discount(sale_id,"Card"); }else{ diff --git a/config/routes.rb b/config/routes.rb index b7e1cf7e..0c0f47a9 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -179,6 +179,7 @@ scope "(:locale)", locale: /en|mm/ do post 'payment/paypar' => 'paypar_payments#create' post 'payment/credit' => 'credit_payments#create' post 'payment/voucher' => 'voucher_payments#create' + post 'payment/paymal' => 'paymal#create' post 'payment/alipay' => 'alipay#create' post 'payment/junctionpay' => 'junctionpay#create' @@ -188,6 +189,7 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment/others_payment/VISA' => "visa#index" get 'sale/:sale_id/:type/payment/others_payment/Master' => "master#index" get 'sale/:sale_id/:type/payment/others_payment/JCB' => "jcb#index" + get 'sale/:sale_id/:type/payment/others_payment/PAYMAL' => "paymal#index" get 'sale/:sale_id/:type/payment/others_payment/UNIONPAY' => "unionpay#index" get 'sale/:sale_id/:type/payment/others_payment/Redeem' => "redeem_payments#index" get 'sale/:sale_id/:type/payment/others_payment/Voucher' => "voucher#index" diff --git a/spec/controllers/origami/paymal_controller_spec.rb b/spec/controllers/origami/paymal_controller_spec.rb new file mode 100644 index 00000000..8dffaf69 --- /dev/null +++ b/spec/controllers/origami/paymal_controller_spec.rb @@ -0,0 +1,12 @@ +require 'rails_helper' + +RSpec.describe Origami::PaymalController, type: :controller do + + describe "GET #index" do + it "returns http success" do + get :index + expect(response).to have_http_status(:success) + end + end + +end diff --git a/spec/helpers/origami/paymal_helper_spec.rb b/spec/helpers/origami/paymal_helper_spec.rb new file mode 100644 index 00000000..7d27aafa --- /dev/null +++ b/spec/helpers/origami/paymal_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Origami::PaymalHelper. For example: +# +# describe Origami::PaymalHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Origami::PaymalHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/views/origami/paymal/index.html.erb_spec.rb b/spec/views/origami/paymal/index.html.erb_spec.rb new file mode 100644 index 00000000..c047162a --- /dev/null +++ b/spec/views/origami/paymal/index.html.erb_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe "paymal/index.html.erb", type: :view do + pending "add some examples to (or delete) #{__FILE__}" +end