diff --git a/Gemfile b/Gemfile index 479b1325..ad11e93d 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'rails', '~> 5.1.0' gem 'mysql2', '>= 0.3.18', '< 0.5' #Use PosgreSQL -#gem 'pg' +gem 'pg' # redis server for cable # gem 'redis', '~> 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 93c2a58f..051e1595 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -268,4 +268,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 1.15.0 + 1.15.1 diff --git a/app/assets/javascripts/api/origami/paypar.coffee b/app/assets/javascripts/api/origami/paypar.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/api/origami/paypar.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/javascripts/origami/paypar.coffee b/app/assets/javascripts/origami/paypar.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/origami/paypar.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/api/origami/paypar.scss b/app/assets/stylesheets/api/origami/paypar.scss new file mode 100644 index 00000000..3ce106bb --- /dev/null +++ b/app/assets/stylesheets/api/origami/paypar.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/origami/paypar controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/origami/paypar.scss b/app/assets/stylesheets/origami/paypar.scss new file mode 100644 index 00000000..8cc055f3 --- /dev/null +++ b/app/assets/stylesheets/origami/paypar.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the origami/paypar 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/card_payments_controller.rb b/app/controllers/origami/card_payments_controller.rb new file mode 100644 index 00000000..6a0e99c9 --- /dev/null +++ b/app/controllers/origami/card_payments_controller.rb @@ -0,0 +1,29 @@ +class Origami::CardPaymentsController < BaseOrigamiController + + + def index + @membership_rebate_balance = 0 + @membership_id = 0 + if !@membership_id.nil? + membership_setting = MembershipSetting.find_by_membership_type("smartpay_url") + membership_data = SalePayment.get_paypar_account(membership_setting.gateway_url,membership_setting.auth_token,@membership_id) + if membership_data["status"]==true + membership_account_data = membership_data["data"]; + membership_account_data.each do |acc_data| + if acc_data["accountable_type"] == "REBATEACCOUNT" + @membership_rebate_balance=acc_data["balance"] + else + @membership_rebate_balance = 0 + end + end + else + @membership_rebate_balance = 0 + end + end + + end + + def create + end + +end diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb index e92c9535..fa50f6a3 100644 --- a/app/controllers/origami/others_payments_controller.rb +++ b/app/controllers/origami/others_payments_controller.rb @@ -2,6 +2,27 @@ class Origami::OthersPaymentsController < BaseOrigamiController def index + @membership_rebate_balance = 0 + @sale_id = params[:sale_id] + sale_data = Sale.find_by_sale_id(@sale_id) + customer_data= Customer.find_by_customer_id(sale_data.customer_id) + @membership_id = customer_data.membership_id + if !@membership_id.nil? + membership_setting = MembershipSetting.find_by_membership_type("smartpay_url") + membership_data = SalePayment.get_paypar_account(membership_setting.gateway_url,membership_setting.auth_token,@membership_id) + if membership_data["status"]==true + membership_account_data = membership_data["data"]; + membership_account_data.each do |acc_data| + if acc_data["accountable_type"] == "REBATEACCOUNT" + @membership_rebate_balance=acc_data["balance"] + else + @membership_rebate_balance = 0 + end + end + else + @membership_rebate_balance = 0 + end + end end def create diff --git a/app/controllers/origami/paypar_payments_controller.rb b/app/controllers/origami/paypar_payments_controller.rb new file mode 100644 index 00000000..af5ce55f --- /dev/null +++ b/app/controllers/origami/paypar_payments_controller.rb @@ -0,0 +1,22 @@ +class Origami::PayparPaymentsController < BaseOrigamiController + def create + sale_id = params[:sale_id] + redeem_amount = params[:redeem_amount] + membership_id = params[:membership_id] + payment_method = "paypar" + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + status,msg =sale_payment.process_payment(saleObj, @user, redeem_amount,payment_method) + + if status == true + @out = true, "Success!" + else + @out =false, "Please try again payment!" + end + else + @out = false, "There has no sale record!" + end + + end +end \ No newline at end of file diff --git a/app/helpers/api/origami/paypar_helper.rb b/app/helpers/api/origami/paypar_helper.rb new file mode 100644 index 00000000..0e102f10 --- /dev/null +++ b/app/helpers/api/origami/paypar_helper.rb @@ -0,0 +1,2 @@ +module Api::Origami::PayparHelper +end diff --git a/app/helpers/origami/paypar_helper.rb b/app/helpers/origami/paypar_helper.rb new file mode 100644 index 00000000..fe18e897 --- /dev/null +++ b/app/helpers/origami/paypar_helper.rb @@ -0,0 +1,2 @@ +module Origami::PayparHelper +end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 8f9b7294..cb17a325 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -8,12 +8,10 @@ class SalePayment < ApplicationRecord attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status - def process_payment(invoice, action_by, cash_amount) + def process_payment(invoice, action_by, cash_amount,payment_method) self.sale = invoice self.received_amount = cash_amount - - payment_method = "cash" amount_due = invoice.grand_total #get all payment for this invoices @@ -54,7 +52,7 @@ class SalePayment < ApplicationRecord end #record an payment in sale-audit - remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{amount} | Payment Status ->#{payment_status}" + remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) return true, self.sale @@ -66,6 +64,34 @@ class SalePayment < ApplicationRecord return false, "No outstanding Amount" end + end + + def self.get_paypar_account(paypar_url,token,membership_id) + url = paypar_url.to_s + "/api/get_membership_data".to_s + response = HTTParty.get(url, + :body => { app_token: token,membership_id:membership_id}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) + return response; + + end + + def self.redeem(paypar_url,token,membership_id,received_amount,sale_id,campaign_type_id) + url = paypar_url.to_s + "/api/redeem".to_s + response = HTTParty.post(url, + :body => { generic_customer_id:membership_id,total_amount:received_amount,receipet_no:sale_id,campaign_type_id:campaign_type_id,account_no:""}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) + puts "RRRRRRRR" + puts response.to_json + return response; + end private @@ -148,15 +174,38 @@ class SalePayment < ApplicationRecord end def paypar_payment - ##TODO - Integration with Paypar (SmartPay) + puts "Paypar Payment" + payment_status = false + + #Next time - validate if the vochure number is valid - within + self.payment_method = "paypar" + 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! + + campaign_type_id =1; + customer_data = Customer.find_by_customer_id(self.sale.customer_id) + membership_setting = MembershipSetting.find_by_membership_type("smartpay_url") + membership_data = SalePayment.redeem(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id,campaign_type_id) + if membership_data["status"]==true + 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 + + + return payment_status + end def sale_update_payment_status(paid_amount) - puts "paid_amount" - puts paid_amount #update amount_outstanding self.sale.amount_received = self.sale.amount_received + paid_amount - self.sale.amount_changed = amount - self.sale.amount_received + self.sale.amount_changed = paid_amount - self.sale.amount_received if (self.sale.grand_total <= self.sale.amount_received && self.sale.amount_changed > 0) self.sale.payment_status = "paid" self.sale.sale_status = "completed" diff --git a/app/views/origami/others_payments/index.html.erb b/app/views/origami/others_payments/index.html.erb index 86ef10b0..094c90c9 100644 --- a/app/views/origami/others_payments/index.html.erb +++ b/app/views/origami/others_payments/index.html.erb @@ -1 +1,165 @@ -Hello Card Payment +
+ +
+
+ <% if @membership_id!=0 %> +
+
Redim Amount
+
+ <% end %> +
+
+ +
+ +
+
+
+
+
+
1
+
2
+
3
+
+
+
+
1000
+
+
+
+
+
+
4
+
5
+
6
+
+
+
+
5000
+
+
+
+
+
+
7
+
8
+
9
+
+
+
+
10000
+
+
+
+
+
+
0
+
.
+
00
+
+
+
+
50000
+
+
+
+
+
+
+
DEL
+
CLR
+
+
+
+
PAY
+
+
+
+
+ +
+
+
+ +
+ \ No newline at end of file diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index ccd9fd77..fcdee809 100644 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -218,21 +218,21 @@ $( document ).ready(function() { $('#pay').click(function() { - if($('#balance').text() > 0){ - alert(" Insufficient Amount!") - }else{ + if($('#balance').text() > 0){ + alert(" Insufficient Amount!") + }else{ // payment - var cash = $('#cash').text(); - var credit = $('#credit').text(); - var card = $('#card').text(); - var sale_id = $('#sale_id').text(); - $.ajax({type: "POST", - url: "<%= origami_payment_process_path %>", - data: "cash="+ cash + "&sale_id=" + sale_id, - success:function(result){ - alert("THANK YOU") - } - }); + var cash = $('#cash').text(); + var credit = $('#credit').text(); + var card = $('#card').text(); + var sale_id = $('#sale_id').text(); + $.ajax({type: "POST", + url: "<%= origami_payment_process_path %>", + data: "cash="+ cash + "&sale_id=" + sale_id, + success:function(result){ + alert("THANK YOU") + } + }); } }); diff --git a/app/views/origami/paypar_payments/create.json.jbuilder b/app/views/origami/paypar_payments/create.json.jbuilder new file mode 100644 index 00000000..f352b148 --- /dev/null +++ b/app/views/origami/paypar_payments/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/paypar_payments/index.html.erb b/app/views/origami/paypar_payments/index.html.erb new file mode 100644 index 00000000..859a854b --- /dev/null +++ b/app/views/origami/paypar_payments/index.html.erb @@ -0,0 +1,137 @@ +
+ +
+
+ <% if @membership_id!=0 %> +
+
Redim Amount
+
+ <% end %> +
+
+ +
+ +
+
+
+
+
+
1
+
2
+
3
+
+
+
+
1000
+
+
+
+
+
+
4
+
5
+
6
+
+
+
+
5000
+
+
+
+
+
+
7
+
8
+
9
+
+
+
+
10000
+
+
+
+
+
+
0
+
.
+
00
+
+
+
+
50000
+
+
+
+
+
+
+
DEL
+
CLR
+
+
+
+
PAY
+
+
+
+
+ +
+
+
+ +
+ \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ac95eca3..6bd296a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,6 +79,7 @@ Rails.application.routes.draw do #--------- Payment ------------# get 'sale/:sale_id/payment' => 'payments#show' post 'payment_process' => 'payments#create' + post 'paypar_payment_process' => 'paypar_payments#create' get 'sale/:sale_id/payment/credit_payment' => "credit_payments#index" get 'sale/:sale_id/payment/others_payment' => "others_payments#index" diff --git a/db/migrate/2017031024747_create_accounts.rb b/db/migrate/2017031024747_create_accounts.rb new file mode 100644 index 00000000..5816aace --- /dev/null +++ b/db/migrate/2017031024747_create_accounts.rb @@ -0,0 +1,10 @@ +class CreateAccounts < ActiveRecord::Migration[5.1] + def change + create_table :accounts do |t| + t.string :title + t.string :account_type + + t.timestamps + end + end +end diff --git a/db/seeds.rb b/db/seeds.rb index c90bfff5..55f15be5 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -140,9 +140,9 @@ admin_employee = Employee.create({name: "Administrator", role: "Administrator", food = Account.create({title: "Food", account_type: "0"}) beverage = Account.create({title: "Beverage", account_type: "1"}) -shop = Shop.create( - {name: "Beauty In The Pot", address: "address", township: "Yangon", city: "Yangon", state: "Yangon", - country: "Myanmar", phone_no: "09123456789", reservation_no: "bip000001", license: "license", - activated_at: "2017-06-06", license_data: "license_data", base_currency: "Ks", id_prefix: "abc"} - ) +# shop = Shop.create( +# {name: "Beauty In The Pot", address: "address", township: "Yangon", city: "Yangon", state: "Yangon", +# country: "Myanmar", phone_no: "09123456789", reservation_no: "bip000001", license: "license", +# activated_at: "2017-06-06", license_data: "license_data", base_currency: "Ks", id_prefix: "abc"} +# ) diff --git a/dump.rdb b/dump.rdb index b931754d..3e3686b7 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/spec/controllers/api/origami/paypar_controller_spec.rb b/spec/controllers/api/origami/paypar_controller_spec.rb new file mode 100644 index 00000000..e0003e75 --- /dev/null +++ b/spec/controllers/api/origami/paypar_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::Origami::PayparController, type: :controller do + +end diff --git a/spec/controllers/origami/paypar_controller_spec.rb b/spec/controllers/origami/paypar_controller_spec.rb new file mode 100644 index 00000000..749649d4 --- /dev/null +++ b/spec/controllers/origami/paypar_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Origami::PayparController, type: :controller do + +end diff --git a/spec/helpers/api/origami/paypar_helper_spec.rb b/spec/helpers/api/origami/paypar_helper_spec.rb new file mode 100644 index 00000000..d53d9eae --- /dev/null +++ b/spec/helpers/api/origami/paypar_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::Origami::PayparHelper. For example: +# +# describe Api::Origami::PayparHelper 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 Api::Origami::PayparHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/helpers/origami/paypar_helper_spec.rb b/spec/helpers/origami/paypar_helper_spec.rb new file mode 100644 index 00000000..4613b9e7 --- /dev/null +++ b/spec/helpers/origami/paypar_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Origami::PayparHelper. For example: +# +# describe Origami::PayparHelper 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::PayparHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end