Skip to content

Instantly share code, notes, and snippets.

@egoholic
Created May 12, 2017 08:37
Show Gist options
  • Save egoholic/f1762a121a890811d463a23bba37f1f9 to your computer and use it in GitHub Desktop.
Save egoholic/f1762a121a890811d463a23bba37f1f9 to your computer and use it in GitHub Desktop.
require 'net/http'
require 'net/https'
require 'google4r/checkout/notifications.rb'
require 'google4r/checkout/shared'
require 'google4r/checkout/commands'
#require 'google4r/checkout/notifications'
require 'google4r/checkout/xml_generation'
require 'google4r/checkout/frontend'
require 'google4r/checkout/merchant_calculation'
class BillsController < ApplicationController
before_filter :require_client, :only => [:request_extension, :delete_bill_request_extension]
before_filter :verify_merchant_credentials, :only => [:google_confirm]
protect_from_forgery :except => [:payment_confirm, :google_confirm, :payza_confirm, :moneybookers_confirm, :g2s_confirm ]
before_filter :require_jquery18, :only => [ :index, :pay_with_email ]
before_filter :require_jqueryui19, :only => [ :index, :pay_with_email ]
include OffsitePayments::Integrations
#include ActiveMerchant::Billing::Integrations
include BillHelper
layout 'chamomile', :only => [:index]
def index
if current_actor
if current_actor.is_a?( Client )
@client = current_actor
elsif current_actor.is_a?( Employer )
@client = current_actor.clients.where( " client_slug = ? ", params[:client_id] ).first
if @client.nil?
redirect_to bills_employers_path
return
end
elsif current_actor.is_a?( Outsourcer )
@client = current_actor.clients.where( " client_slug = ? ", params[:client_id] ).first
if @client.nil?
redirect_to bills_outsourcers_path
return
end
else
require_client
return
end
else
require_client
return
end
if params[:ppp_status]
if params[:ppp_status] == "OK"
flash[:notice] = "Thank you for making the payment. It will be processed in the next minute - you will receive an email notification as soon as we are done."
redirect_to(home_path, :notice => "Thank you for making the payment. It will be processed in the next minute - you will receive an email notification as soon as we are done.")
return
else
msg = case (params[:Reason])
when "Decline" then "Refused by the bank (Customer has to refer to his issuer bank)."
when "Referral" then "Request for voice authorization (to be treated as a decline)."
when "Call issuer" then "Request to call the issuer bank (usually a security violation)."
when "Lost/Stolen" then "A lost or stolen card (this can also be an indication for the Customer to pick the card from the bank)."
when "Timeout/Retry" then "There was a timeout waiting for the issuer bank's response."
when "Expired card" then "The bank indicated that the expiration date supplied is invalid."
when "Black listed by the bank" then "CC was rejected by the bank's fraud system."
when "Retain Card" then "The bank placed a hold on purchases due to issue with the cardholder account."
when "Invalid Card Number" then "Invalid card number or attempt to process a card which has been replaced by the issuer (either due to lost/stolen or new exp. date/card issued)."
when "Stolen Card, Pick Up" then "The card is reported as stolen, potential fraud."
when "Restricted Card" then "The credit card is blacklisted by card association (Visa/MC)"
when "Suspicion of Manipulation" then "CVN (CVV/CVC) either missing or invalid."
when "Insufficient Funds" then "The cardholder cannot supply the transaction's amount."
else ""
end
send_email_failed_payment( params[:productId].to_i, "G2S", @client.id, request.remote_ip, "G2S Payment error", msg )
errormsg = "Unfortunately your payment did not go through. The error code we received from our credit card processor is \"#{msg}\" Please try another card or email us for help."
flash[:notice] = errormsg
redirect_to(bills_path, :notice => errormsg) and return
end
end
unless @bill_email_pay
@bills = @client.bills.order('created_at').group_by { |b| b.created_at.year }
@payments = @client.payments
bills_not_paid = @client.bills.where('status in (?) or status is null', [Bill::PAID_NONE, Bill::PAID_PARTIAL])
@bills_not_paid = bills_not_paid.count > 0 ? false : true
@actor_rc = @client.available_referral_credit.to_i
end
main_payment_select @client
if session[:bill_payment_processor]
@client.clientOptions.bill_payment_processor = [] if @client.clientOptions.bill_payment_processor.nil?
if session[:bill_payment_processor].is_a?(String)
@client.clientOptions.bill_payment_processor << session[:bill_payment_processor]
else
@client.clientOptions.bill_payment_processor += session[:bill_payment_processor]
end
@client.clientOption.save!
session.delete( :bill_payment_processor )
end
was_processor = @client.clientOptions.bill_payment_processor
if cookies[:bill_pay_start_time] && ( params[:npp] == "rqs" )
cookies[:use_bill_pay_start_time] = { :value => cookies[:bill_pay_start_time], :expires => 1.hour.from_now }
exclude_processors = [@client.clientOptions.main_payment_order]
if was_processor
if was_processor.is_a?(String)
exclude_processors << was_processor
else
exclude_processors = exclude_processors + was_processor
end
end
payments = Paymentparam.where( "direction = ? and pay_system not in (?)", "Tax", exclude_processors ).order("probability desc")
payment_first = nil
prob = 0
max_rank = payments.sum("probability")
if max_rank > 0
r = rand(max_rank)
for payment in payments do
if r <= prob + payment.probability.to_i
payment_first = payment.pay_system
break
end
prob += payment.probability.to_i
end
payment_first = payments[0].pay_system if payment_first.nil?
@client.clientOptions.bill_payment_processor = [] if @client.clientOptions.bill_payment_processor.nil?
@client.clientOptions.bill_payment_processor << payment_first
begin
@client.clientOptions.save!
rescue Exception => e
report_exception e
end
end
if params[:npp] == "rqs"
redirect_to bills_path
return
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment