Merge branch 'develop' into feature/musician_profile_enhancements
This commit is contained in:
commit
20ac47a2e1
|
|
@ -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
|
||||
|
|
@ -49,6 +49,7 @@ gem 'iso-639'
|
|||
gem 'rubyzip'
|
||||
gem 'sanitize'
|
||||
gem 'influxdb', '0.1.8'
|
||||
gem 'recurly'
|
||||
|
||||
group :test do
|
||||
gem 'simplecov', '~> 0.7.1'
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ require "jam_ruby/resque/scheduled/stats_maker"
|
|||
require "jam_ruby/resque/google_analytics_event"
|
||||
require "jam_ruby/resque/batch_email_job"
|
||||
require "jam_ruby/mq_router"
|
||||
require "jam_ruby/recurly_client"
|
||||
require "jam_ruby/base_manager"
|
||||
require "jam_ruby/connection_manager"
|
||||
require "jam_ruby/version"
|
||||
|
|
|
|||
|
|
@ -1,3 +1,18 @@
|
|||
# initialize actionmailer
|
||||
ActionMailer::Base.raise_delivery_errors = true
|
||||
ActionMailer::Base.view_paths = File.expand_path('../../jam_ruby/app/views/', __FILE__)
|
||||
ActionMailer::Base.view_paths = File.expand_path('../../jam_ruby/app/views/', __FILE__)
|
||||
|
||||
# Use Private API Keys to communicate with Recurly's API v2. See https://docs.recurly.com/api/basics/authentication to learn more.
|
||||
case JamRuby::Environment
|
||||
when 'production'
|
||||
Recurly.api_key = "7d623daabfc2434fa2a893bb008eb3e6"
|
||||
Recurly.subdomain = 'jamkazam'
|
||||
when 'development'
|
||||
Recurly.api_key = "7d623daabfc2434fa2a893bb008eb3e6"
|
||||
Recurly.subdomain = 'jamkazam-development'
|
||||
else
|
||||
Recurly.api_key = "4631527f203b41848523125b3ae51341"
|
||||
Recurly.subdomain = 'jamkazam-test'
|
||||
end
|
||||
|
||||
Recurly.default_currency = 'USD'
|
||||
|
|
|
|||
|
|
@ -8,9 +8,11 @@ module JamRuby
|
|||
options = account_hash(current_user, billing_info)
|
||||
account = nil
|
||||
begin
|
||||
#puts "Recurly.api_key: #{Recurly.api_key}"
|
||||
account = Recurly::Account.create(options)
|
||||
raise RecurlyClientError.new(account.errors) if account.errors.any?
|
||||
rescue Recurly::Error, NoMethodError => x
|
||||
puts "Error: #{x} : #{Kernel.caller}"
|
||||
raise RecurlyClientError, x.to_s
|
||||
else
|
||||
if account
|
||||
|
|
@ -68,6 +70,46 @@ module JamRuby
|
|||
account
|
||||
end
|
||||
|
||||
def refund_user_subscription(current_user, jam_track)
|
||||
jam_track_right=JamRuby::JamTrackRight.where("user_id=? AND jam_track_id=?", current_user.id, jam_track.id).first
|
||||
if jam_track_right
|
||||
refund_subscription(jam_track_right)
|
||||
else
|
||||
raise RecurlyClientError, "The user #{current_user} does not have a subscription to #{jam_track}"
|
||||
end
|
||||
end
|
||||
|
||||
def refund_subscription(jam_track_right)
|
||||
account = get_account(jam_track_right.user)
|
||||
if (account.present?)
|
||||
terminated = false
|
||||
begin
|
||||
jam_track = jam_track_right.jam_track
|
||||
account.subscriptions.find_each do |subscription|
|
||||
puts "subscription.plan.plan_code: #{subscription.plan.plan_code} / #{jam_track.plan_code} / #{subscription.plan.plan_code == jam_track.plan_code}"
|
||||
if(subscription.plan.plan_code == jam_track.plan_code)
|
||||
subscription.terminate(:full)
|
||||
raise RecurlyClientError.new(subscription.errors) if subscription.errors.any?
|
||||
terminated = true
|
||||
end
|
||||
end
|
||||
|
||||
if terminated
|
||||
jam_track_right.destroy()
|
||||
else
|
||||
raise RecurlyClientError, "Subscription '#{jam_track.plan_code}' not found for this user; could not issue refund."
|
||||
end
|
||||
|
||||
rescue Recurly::Error, NoMethodError => x
|
||||
raise RecurlyClientError, x.to_s
|
||||
end
|
||||
|
||||
else
|
||||
raise RecurlyClientError, "Could not find account to refund order."
|
||||
end
|
||||
account
|
||||
end
|
||||
|
||||
def place_order(current_user, jam_track)
|
||||
account = get_account(current_user)
|
||||
if (account.present?)
|
||||
|
|
@ -734,6 +734,7 @@ FactoryGirl.define do
|
|||
licensor_royalty_amount 0.999
|
||||
pro_royalty_amount 0.999
|
||||
available true
|
||||
plan_code 'jamtrack-acdc-backinblack'
|
||||
|
||||
genre JamRuby::Genre.first
|
||||
association :licensor, factory: :jam_track_licensor
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
require 'spec_helper'
|
||||
require "recurly_client"
|
||||
require "jam_ruby/recurly_client"
|
||||
describe RecurlyClient do
|
||||
let(:jamtrack) { FactoryGirl.create(:jam_track) }
|
||||
#let(:client) { RecurlyClient.new }
|
||||
|
|
@ -98,6 +98,24 @@ describe RecurlyClient do
|
|||
@user.jam_track_rights.last.jam_track.id.should eq(@jamtrack.id)
|
||||
end
|
||||
|
||||
it "can refund subscription" do
|
||||
@client.find_or_create_account(@user, @billing_info)
|
||||
|
||||
# Place order:
|
||||
expect{@client.place_order(@user, @jamtrack)}.not_to raise_error()
|
||||
active_subs=@client.get_account(@user).subscriptions.find_all{|t|t.state=='active'}
|
||||
@jamtrack.reload
|
||||
@jamtrack.jam_track_rights.should have(1).items
|
||||
|
||||
# Refund:
|
||||
expect{@client.refund_user_subscription(@user, @jamtrack)}.not_to raise_error()
|
||||
active_subs=@client.get_account(@user).subscriptions.find_all{|t|t.state=='active'}
|
||||
active_subs.should have(0).items
|
||||
|
||||
@jamtrack.reload
|
||||
@jamtrack.jam_track_rights.should have(0).items
|
||||
end
|
||||
|
||||
it "detects error on double order" do
|
||||
@client.find_or_create_account(@user, @billing_info)
|
||||
expect{@client.place_order(@user, @jamtrack)}.not_to raise_error()
|
||||
|
|
@ -7,6 +7,7 @@
|
|||
var rest = context.JK.Rest();
|
||||
var showing = false;
|
||||
var perPage = 10;
|
||||
var openingRecording = false;
|
||||
|
||||
function tbody() {
|
||||
return $('#local-recordings-dialog table.local-recordings tbody');
|
||||
|
|
@ -22,6 +23,7 @@
|
|||
|
||||
|
||||
function beforeShow() {
|
||||
openingRecording = false;
|
||||
emptyList();
|
||||
resetPagination();
|
||||
showing = true;
|
||||
|
|
@ -89,6 +91,12 @@
|
|||
function registerStaticEvents() {
|
||||
$('#local-recordings-dialog table.local-recordings tbody').on('click', 'tr', function(e) {
|
||||
|
||||
if(openingRecording) {
|
||||
// prevent double-click spam
|
||||
logger.debug("localRecordingDialog: ignoring duplicate open attempt")
|
||||
return false;
|
||||
}
|
||||
|
||||
var localState = $(this).attr('data-local-state');
|
||||
|
||||
if(localState == 'MISSING') {
|
||||
|
|
@ -109,6 +117,8 @@
|
|||
{
|
||||
var claimedRecording = $(this).data('server-model');
|
||||
|
||||
openingRecording = true;
|
||||
|
||||
// tell the server we are about to start a recording
|
||||
rest.startPlayClaimedRecording({id: context.JK.CurrentSessionModel.id(), claimed_recording_id: claimedRecording.id})
|
||||
.done(function(response) {
|
||||
|
|
@ -146,6 +156,9 @@
|
|||
app.notifyServerError(jqXHR, "Unable to Open Recording For Playback");
|
||||
|
||||
})
|
||||
.always(function() {
|
||||
openingRecording = false;
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -275,6 +275,15 @@
|
|||
$expandedPanelContents.animate({"height": expandedPanelHeight + "px"}, opts.animationDuration);
|
||||
}
|
||||
|
||||
function displayCartIcon(carts) {
|
||||
var cartLink = $("a[href='" + "/client#/shoppingCart" + "']")
|
||||
if (carts.length > 0) {
|
||||
cartLink.removeClass("hidden")
|
||||
} else {
|
||||
cartLink.addClass("hidden")
|
||||
}
|
||||
}
|
||||
|
||||
function layoutHeader(screenWidth, screenHeight) {
|
||||
var width = screenWidth - 2 * opts.gutter;
|
||||
var height = opts.headerHeight - opts.gutter;
|
||||
|
|
@ -287,6 +296,8 @@
|
|||
left: left + "px"
|
||||
};
|
||||
$('[layout="header"]').css(css);
|
||||
|
||||
rest.getShoppingCarts().done(displayCartIcon)
|
||||
}
|
||||
|
||||
function layoutNotify(screenWidth, screenHeight) {
|
||||
|
|
|
|||
|
|
@ -94,6 +94,7 @@
|
|||
var $mixModeDropdown = null;
|
||||
var $templateMixerModeChange = null;
|
||||
var $closePlaybackRecording = null;
|
||||
var $openBackingTrack = null;
|
||||
var mediaTrackGroups = [ChannelGroupIds.MediaTrackGroup, ChannelGroupIds.JamTrackGroup, ChannelGroupIds.MetronomeGroup];
|
||||
|
||||
var rest = context.JK.Rest();
|
||||
|
|
@ -139,6 +140,8 @@
|
|||
|
||||
function afterShow(data) {
|
||||
|
||||
$openBackingTrack.removeClass('disabled');
|
||||
|
||||
if(!context.JK.JamServer.connected) {
|
||||
promptLeave = false;
|
||||
app.notifyAlert("Not Connected", 'To create or join a session, you must be connected to the server.');
|
||||
|
|
@ -1925,6 +1928,13 @@
|
|||
}
|
||||
|
||||
function handleBackingTrackSelectedCallback(result) {
|
||||
|
||||
$openBackingTrack.removeClass('disabled');
|
||||
|
||||
if(!sessionModel.inSession()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(result.success) {
|
||||
logger.debug("backing track selected: " + result.file);
|
||||
|
||||
|
|
@ -1937,8 +1947,6 @@
|
|||
.fail(function(jqXHR) {
|
||||
app.notifyServerError(jqXHR, "Unable to Open BackingTrack For Playback");
|
||||
})
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
logger.debug("no backing track selected")
|
||||
|
|
@ -2286,6 +2294,12 @@
|
|||
}
|
||||
|
||||
function openBackingTrack(e) {
|
||||
|
||||
if($openBackingTrack.is('.disabled')) {
|
||||
logger.debug("backing track dialog already open")
|
||||
return false;
|
||||
}
|
||||
|
||||
// just ignore the click if they are currently recording for now
|
||||
if(sessionModel.recordingModel.isRecording()) {
|
||||
app.notify({
|
||||
|
|
@ -2296,13 +2310,8 @@
|
|||
return false;
|
||||
}
|
||||
|
||||
$openBackingTrack.addClass('disabled');
|
||||
context.jamClient.ShowSelectBackingTrackDialog("window.JK.HandleBackingTrackSelectedCallback");
|
||||
|
||||
//app.layout.showDialog('open-backing-track-dialog').one(EVENTS.DIALOG_CLOSED, function(e, data) {
|
||||
// if(!data.cancel && data.result){
|
||||
// sessionModel.setBackingTrack(data.result);
|
||||
// }
|
||||
//})
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -2323,6 +2332,7 @@
|
|||
}
|
||||
|
||||
function openBackingTrackFile(e) {
|
||||
|
||||
// just ignore the click if they are currently recording for now
|
||||
if(sessionModel.recordingModel.isRecording()) {
|
||||
app.notify({
|
||||
|
|
@ -2611,7 +2621,7 @@
|
|||
$('#recording-start-stop').on('click', startStopRecording);
|
||||
$('#open-a-recording').on('click', openRecording);
|
||||
$('#open-a-jamtrack').on('click', openJamTrack);
|
||||
$('#open-a-backingtrack').on('click', openBackingTrack);
|
||||
$openBackingTrack.on('click', openBackingTrack);
|
||||
$('#open-a-metronome').on('click', openMetronome);
|
||||
$('#session-invite-musicians').on('click', inviteMusicians);
|
||||
$('#session-invite-musicians2').on('click', inviteMusicians);
|
||||
|
|
@ -2656,6 +2666,7 @@
|
|||
$mixModeDropdown = $screen.find('select.monitor-mode')
|
||||
$templateMixerModeChange = $('#template-mixer-mode-change');
|
||||
$closePlaybackRecording = $('#close-playback-recording')
|
||||
$openBackingTrack = $('#open-a-backingtrack');
|
||||
events();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
require 'recurly_client'
|
||||
require 'jam_ruby/recurly_client'
|
||||
class ApiRecurlyController < ApiController
|
||||
before_filter :api_signed_in_user
|
||||
before_filter :create_client
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@
|
|||
.jamtrack-price
|
||||
{{"$ " + data.jamtrack.price}}
|
||||
= "{% if (data.jamtrack.added_cart) { %}"
|
||||
%a.jamtrack-add-cart-disabled.button-grey.button-disabled{href: "javascript:void(0)"} Added to Cart
|
||||
%a.jamtrack-add-cart-disabled.button-grey.button-disabled{href: "javascript:void(0)"} Purchased
|
||||
= "{% } else { %}"
|
||||
%a.jamtrack-add-cart.button-orange{href: "#", "data-jamtrack-id" => "{{data.jamtrack.id}}"} Add to Cart
|
||||
= "{% }; %}"
|
||||
|
|
|
|||
|
|
@ -1,13 +1,9 @@
|
|||
require 'spec_helper'
|
||||
require 'recurly_client'
|
||||
#require 'recurly/account'
|
||||
require 'jam_ruby/recurly_client'
|
||||
|
||||
describe ApiRecurlyController, :type=>:controller do
|
||||
render_views
|
||||
|
||||
# let(:user) { FactoryGirl.create(:user) }
|
||||
# let(:jamtrack) { FactoryGirl.create(:jam_track) }
|
||||
|
||||
before(:each) do
|
||||
@user = FactoryGirl.create(:user)
|
||||
#@jamtrack = FactoryGirl.create(:jam_track)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ describe "JamTrack Shopping", :js => true, :type => :feature, :capybara_feature
|
|||
end
|
||||
|
||||
if options[:added_cart]
|
||||
jamtrack_record.find('a.jamtrack-add-cart-disabled', text: 'Added to Cart')
|
||||
jamtrack_record.find('a.jamtrack-add-cart-disabled', text: 'Purchased')
|
||||
else
|
||||
jamtrack_record.find('a.jamtrack-add-cart.button-orange', text: 'Add to Cart')
|
||||
end
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ gem 'language_list'
|
|||
gem 'rubyzip'
|
||||
gem 'sanitize'
|
||||
gem 'influxdb', '0.1.8'
|
||||
gem 'recurly'
|
||||
|
||||
group :development do
|
||||
gem 'pry'
|
||||
|
|
|
|||
Loading…
Reference in New Issue