diff --git a/ruby/lib/jam_ruby/recurly_client.rb b/ruby/lib/jam_ruby/recurly_client.rb
index 3bf68e991..25d822c24 100644
--- a/ruby/lib/jam_ruby/recurly_client.rb
+++ b/ruby/lib/jam_ruby/recurly_client.rb
@@ -53,6 +53,29 @@ module JamRuby
account
end
+ def payment_history(current_user)
+ payments = []
+ account = get_account(current_user)
+ if(account.present?)
+ begin
+ account.transactions.find_each do |transaction|
+ if transaction.amount_in_cents > 0 # Account creation adds a transaction record
+ payments << {
+ :created_at => transaction.created_at,
+ :amount_in_cents => transaction.amount_in_cents,
+ :status => transaction.status,
+ :payment_method => transaction.payment_method,
+ :reference => transaction.reference
+ }
+ end
+ end
+ rescue Recurly::Error, NoMethodError => x
+ raise RecurlyClientError, x.to_s
+ end
+ end
+ payments
+ end
+
def update_billing_info(current_user, billing_info=nil)
account = get_account(current_user)
if (account.present?)
diff --git a/ruby/spec/jam_ruby/recurly_client_spec.rb b/ruby/spec/jam_ruby/recurly_client_spec.rb
index 82217851d..ca9cd94c1 100644
--- a/ruby/spec/jam_ruby/recurly_client_spec.rb
+++ b/ruby/spec/jam_ruby/recurly_client_spec.rb
@@ -88,6 +88,7 @@ describe RecurlyClient do
end
it "can place order" do
+ history_items = @client.payment_history(@user).length
@client.find_or_create_account(@user, @billing_info)
expect{@client.place_order(@user, @jamtrack)}.not_to raise_error()
subs = @client.get_account(@user).subscriptions
@@ -96,6 +97,7 @@ describe RecurlyClient do
@user.jam_track_rights.should_not be_nil
@user.jam_track_rights.should have(1).items
@user.jam_track_rights.last.jam_track.id.should eq(@jamtrack.id)
+ @client.payment_history(@user).should have(history_items+1).items
end
it "can refund subscription" do
diff --git a/web/app/assets/javascripts/accounts.js b/web/app/assets/javascripts/accounts.js
index f56fa4897..d3a02d2db 100644
--- a/web/app/assets/javascripts/accounts.js
+++ b/web/app/assets/javascripts/accounts.js
@@ -100,7 +100,7 @@
// events for main screen
function events() {
- // wire up main panel clicks
+ // wire up main panel clicks:
$('#account-content-scroller').on('click', '#account-scheduled-sessions-link', function(evt) { evt.stopPropagation(); navToScheduledSessions(); return false; } );
$('#account-content-scroller').on('click', '#account-my-jamtracks-link', function(evt) { evt.stopPropagation(); navToMyJamTracks(); return false; } );
@@ -111,7 +111,9 @@
$('#account-content-scroller').on('click', '#account-edit-audio-link', function(evt) { evt.stopPropagation(); navToEditAudio(); return false; } );
$('#account-content-scroller').on('avatar_changed', '#profile-avatar', function(evt, newAvatarUrl) { evt.stopPropagation(); updateAvatar(newAvatarUrl); return false; })
+ // License dialog:
$("#account-content-scroller").on('click', '#account-view-license-link', function(evt) {evt.stopPropagation(); app.layout.showDialog('jamtrack-license-dialog'); return false; } );
+ $("#account-content-scroller").on('click', '#account-payment-history-link', function(evt) {evt.stopPropagation(); app.layout.showDialog('jamtrack-payment-history-dialog'); return false; } );
}
function renderAccount() {
diff --git a/web/app/assets/javascripts/dialog/jamtrack_payment_history_dialog.js.coffee b/web/app/assets/javascripts/dialog/jamtrack_payment_history_dialog.js.coffee
new file mode 100644
index 000000000..a73460c58
--- /dev/null
+++ b/web/app/assets/javascripts/dialog/jamtrack_payment_history_dialog.js.coffee
@@ -0,0 +1,61 @@
+$ = jQuery
+context = window
+context.JK ||= {}
+
+context.JK.JamtrackPaymentHistoryDialog = class JamtrackPaymentHistoryDialog
+ constructor: (@app) ->
+ @rest = context.JK.Rest()
+ @client = context.jamClient
+ @logger = context.JK.logger
+ @screen = null
+ @dialogId = 'jamtrack-payment-history-dialog';
+ @dialog = null;
+
+ initialize:() =>
+ dialogBindings = {
+ 'beforeShow' : @beforeShow,
+ 'afterShow' : @afterShow
+ }
+
+ @dialog = $('[layout-id="' + @dialogId + '"]');
+ @app.bindDialog(@dialogId, dialogBindings);
+ @tbody = @dialog.find("table.payment-table tbody")
+ @rowTemplate = $('#template-payment-history-row').html()
+
+ beforeShow:() =>
+ # Get payment history from jamrest
+ payments = [
+ {date: new Date(2013, 4, 5), amount: 372.33},
+ {date: new Date(2014, 5, 5), amount: 338.44}
+ ]
+
+ @rest.getPaymentHistory()
+ .done(@showPaymentHistory)
+ .fail(@app.ajaxError)
+
+ showPaymentHistory:(data) =>
+ # Turn in to HTML rows and append:
+ @tbody.html("")
+ if data.payments? && data.payments.length > 0
+ for p in data.payments
+ amt = p.amount
+ amt = 0 if !amt?
+ payment = {
+ date: context.JK.formatDateYYYYMMDD(p.created_at)
+ amount: (amt * 100).toFixed(2)
+ status: p.status
+ payment_method: p.payment_method.replace("_", " ")
+ reference: p.reference
+ }
+ tr = $(context._.template(@rowTemplate, payment, { variable: 'data' }));
+ @tbody.append(tr);
+ else
+ tr = "
| No payments found |
"
+ @tbody.append(tr);
+
+ afterShow:() =>
+
+ showDialog:() =>
+ @app.layout.showDialog(@dialogId)
+
+
\ No newline at end of file
diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js
index dca216937..8a393633b 100644
--- a/web/app/assets/javascripts/jam_rest.js
+++ b/web/app/assets/javascripts/jam_rest.js
@@ -1465,6 +1465,15 @@
});
}
+ function getPaymentHistory(options) {
+ return $.ajax({
+ type: "GET",
+ url: '/api/recurly/payment_history',
+ dataType: "json",
+ contentType: 'application/json'
+ });
+ }
+
function getBackingTracks(options) {
return $.ajax({
type: "GET",
@@ -1726,6 +1735,7 @@
this.updateAudioLatency = updateAudioLatency;
this.getJamtracks = getJamtracks;
this.getPurchasedJamTracks = getPurchasedJamTracks;
+ this.getPaymentHistory = getPaymentHistory;
this.getJamTrackRight = getJamTrackRight;
this.enqueueJamTrack = enqueueJamTrack;
this.getBackingTracks = getBackingTracks;
diff --git a/web/app/assets/stylesheets/client/jamtrack.css.scss b/web/app/assets/stylesheets/client/jamtrack.css.scss
index e660b1488..d63839387 100644
--- a/web/app/assets/stylesheets/client/jamtrack.css.scss
+++ b/web/app/assets/stylesheets/client/jamtrack.css.scss
@@ -207,9 +207,14 @@
}
border: 1px solid #222;
margin: 4px 4px 8px 4px;
- }
- .jamtrack_buttons {
- margin: 4px 4px 8px 4px;
- }
+ }
}
+}
+
+.jamtrack_buttons {
+ margin: 8px 4px 12px 4px;
+}
+
+.capitalize {
+ text-transform: capitalize
}
\ No newline at end of file
diff --git a/web/app/assets/stylesheets/client/sessionList.css.scss b/web/app/assets/stylesheets/client/sessionList.css.scss
index 6bc54dc93..ce326ef9c 100644
--- a/web/app/assets/stylesheets/client/sessionList.css.scss
+++ b/web/app/assets/stylesheets/client/sessionList.css.scss
@@ -1,7 +1,7 @@
@import "client/common";
-table.findsession-table, table.local-recordings, table.open-jam-tracks, table.open-backing-tracks, table.cart-items, #account-session-detail {
+table.findsession-table, table.local-recordings, table.open-jam-tracks, table.open-backing-tracks, table.cart-items, #account-session-detail, table.payment-table {
.latency-unacceptable {
width: 50px;
@@ -64,7 +64,7 @@ table.findsession-table, table.local-recordings, table.open-jam-tracks, table.op
text-align:center;
}
}
-table.findsession-table, table.local-recordings, table.open-jam-tracks, table.open-backing-tracks, table.cart-items {
+table.findsession-table, table.local-recordings, table.open-jam-tracks, table.open-backing-tracks, table.cart-items, table.payment-table {
width:98%;
height:10%;
font-size:11px;
diff --git a/web/app/controllers/api_recurly_controller.rb b/web/app/controllers/api_recurly_controller.rb
index 28d16933b..36e6a0851 100644
--- a/web/app/controllers/api_recurly_controller.rb
+++ b/web/app/controllers/api_recurly_controller.rb
@@ -28,6 +28,14 @@ class ApiRecurlyController < ApiController
render json: { message: x.inspect, errors: x.errors}, :status => 404
end
+ # get Recurly payment history
+ def payment_history
+ @payments=@client.payment_history(current_user)
+ render :json=>{payments: @payments}
+ rescue RecurlyClientError => x
+ render json: { message: x.inspect, errors: x.errors}, :status => 404
+ end
+
# update Recurly account
def update_account
@account=@client.update_account(current_user, params[:billing_info])
@@ -56,7 +64,6 @@ class ApiRecurlyController < ApiController
def place_order
error=nil
- puts "PLACING ORDER #{params.inspect}"
response = {jam_tracks:[]}
# 1st confirm that all specified JamTracks exist
diff --git a/web/app/views/clients/_account.html.erb b/web/app/views/clients/_account.html.erb
index 9fdc6100a..a630ef918 100644
--- a/web/app/views/clients/_account.html.erb
+++ b/web/app/views/clients/_account.html.erb
@@ -118,15 +118,11 @@
diff --git a/web/app/views/clients/index.html.erb b/web/app/views/clients/index.html.erb
index af8eff770..a7cc88215 100644
--- a/web/app/views/clients/index.html.erb
+++ b/web/app/views/clients/index.html.erb
@@ -173,6 +173,10 @@
var jamtrackLicenseDialog = new JK.JamtrackLicenseDialog(JK.app);
jamtrackLicenseDialog.initialize();
+ var jamtrackPaymentHistoryDialog = new JK.JamtrackPaymentHistoryDialog(JK.app);
+ jamtrackPaymentHistoryDialog.initialize();
+
+
var audioProfileInvalidDialog = new JK.AudioProfileInvalidDialog(JK.app);
audioProfileInvalidDialog.initialize();
diff --git a/web/app/views/dialogs/_dialogs.html.haml b/web/app/views/dialogs/_dialogs.html.haml
index ee7aad8a9..ff7a92997 100644
--- a/web/app/views/dialogs/_dialogs.html.haml
+++ b/web/app/views/dialogs/_dialogs.html.haml
@@ -35,3 +35,4 @@
= render 'dialogs/adjustGearSpeedDialog'
= render 'dialogs/openJamTrackDialog'
= render 'dialogs/openBackingTrackDialog'
+= render 'dialogs/jamtrackPaymentHistoryDialog'
diff --git a/web/app/views/dialogs/_jamtrackPaymentHistoryDialog.html.slim b/web/app/views/dialogs/_jamtrackPaymentHistoryDialog.html.slim
new file mode 100644
index 000000000..663d0f939
--- /dev/null
+++ b/web/app/views/dialogs/_jamtrackPaymentHistoryDialog.html.slim
@@ -0,0 +1,33 @@
+#jamtrack-payment-history-dialog.dialog.dialog-overlay-sm layout='dialog' layout-id = 'jamtrack-payment-history-dialog'
+ .content-head
+ h1 Payment History:
+ .dialog-inner
+ .content-body
+ .content-body-scroller
+ table.payment-table
+ thead
+ tr
+ th DATE
+ th AMOUNT
+ th STATUS
+ th PAYMENT_METHOD
+ th REFERENCE
+ tbody
+ tr: td colspan="5" Loading payment history...
+
+ .jamtrack_buttons
+ .right
+ a.button-orange class='btnCancel' layout-action='cancel' OK
+
+ script#template-payment-history-row type="text/template"
+ tr
+ td
+ | {{data.date}}
+ td
+ | ${{data.amount}}
+ td.capitalize
+ | {{data.status}}
+ td.capitalize
+ | {{data.payment_method}}
+ td
+ | {{data.reference}}
diff --git a/web/config/routes.rb b/web/config/routes.rb
index 00fd25f38..682ad0897 100644
--- a/web/config/routes.rb
+++ b/web/config/routes.rb
@@ -259,6 +259,7 @@ SampleApp::Application.routes.draw do
match '/recurly/create_account' => 'api_recurly#create_account', :via => :post
match '/recurly/delete_account' => 'api_recurly#delete_account', :via => :delete
match '/recurly/get_account' => 'api_recurly#get_account', :via => :get
+ match '/recurly/payment_history' => 'api_recurly#payment_history', :via => :get
#match '/recurly/get_subscription' => 'api_recurly#get_subscription', :via => :get
match '/recurly/update_account' => 'api_recurly#update_account', :via => :put
match '/recurly/billing_info' => 'api_recurly#billing_info', :via => :get