VRFS-2785 : Add Jam Track Right (purchased jam track) to admin ui. Hook up a refund action.
This commit is contained in:
parent
bcd3785b45
commit
e662c95fba
|
|
@ -74,6 +74,7 @@ gem 'sanitize'
|
|||
gem 'slim'
|
||||
gem 'influxdb', '0.1.8'
|
||||
gem 'influxdb-rails', '0.1.10'
|
||||
gem 'recurly'
|
||||
|
||||
group :libv8 do
|
||||
gem 'libv8', "~> 3.11.8"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,87 @@
|
|||
require 'jam_ruby/recurly_client'
|
||||
ActiveAdmin.register JamRuby::JamTrackRight, :as => 'JamTrackRights' do
|
||||
|
||||
menu :label => 'Purchased JamTracks', :parent => 'JamTracks'
|
||||
|
||||
config.sort_order = 'updated_at DESC'
|
||||
config.batch_actions = false
|
||||
|
||||
#form :partial => 'form'
|
||||
|
||||
index do
|
||||
default_actions
|
||||
|
||||
column "Order" do |right|
|
||||
link_to("Place", order_admin_jam_track_right_path(right)) + " | " +
|
||||
link_to("Refund", refund_admin_jam_track_right_path(right))
|
||||
end
|
||||
|
||||
column "Last Name" do |right|
|
||||
right.user.last_name
|
||||
end
|
||||
column "First Name" do |right|
|
||||
right.user.first_name
|
||||
end
|
||||
column "Jam Track" do |right|
|
||||
link_to(right.jam_track.name, admin_jam_track_right_path(right.jam_track))
|
||||
# right.jam_track
|
||||
end
|
||||
column "Plan Code" do |right|
|
||||
|
||||
right.jam_track.plan_code
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
form do |f|
|
||||
f.inputs 'New Jam Track Right' do
|
||||
f.input :jam_track, :required=>true, collection: JamTrack.all, include_blank: false
|
||||
f.input :user, :required=>true, collection: User.all, include_blank: false
|
||||
end
|
||||
f.actions
|
||||
end
|
||||
|
||||
member_action :order, :method => :get do
|
||||
right = JamTrackRight.where("id=?",params[:id]).first
|
||||
user = right.user
|
||||
jam_track = right.jam_track
|
||||
client = RecurlyClient.new
|
||||
billing_info = {
|
||||
first_name: user.first_name,
|
||||
last_name: user.last_name,
|
||||
address1: 'Test Address 1',
|
||||
address2: 'Test Address 2',
|
||||
city: user.city,
|
||||
state: user.state,
|
||||
country: user.country,
|
||||
zip: '12345',
|
||||
number: '4111-1111-1111-1111',
|
||||
month: '08',
|
||||
year: '2017',
|
||||
verification_value: '111'
|
||||
}
|
||||
|
||||
begin
|
||||
client.find_or_create_account(user, billing_info)
|
||||
client.place_order(user, jam_track)
|
||||
rescue RecurlyClientError=>x
|
||||
redirect_to admin_jam_track_rights_path, notice: "Could not order #{jam_track} for #{user.to_s}: #{x.errors.inspect}"
|
||||
else
|
||||
redirect_to admin_jam_track_rights_path, notice: "Placed order of #{jam_track} for #{user.to_s}."
|
||||
end
|
||||
end
|
||||
|
||||
member_action :refund, :method => :get do
|
||||
right = JamTrackRight.where("id=?",params[:id]).first
|
||||
client = RecurlyClient.new
|
||||
|
||||
begin
|
||||
client.refund_user_subscription(right.user, right.jam_track)
|
||||
rescue RecurlyClientError=>x
|
||||
redirect_to admin_jam_track_rights_path, notice: "Could not issue refund on #{right.jam_track} for #{right.user.to_s}: #{x.errors.inspect}"
|
||||
else
|
||||
redirect_to admin_jam_track_rights_path, notice: "Issued full refund on #{right.jam_track} for #{right.user.to_s}"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue