VRFS-2830 : Payment History
API, client, view, styles and test
This commit is contained in:
parent
5e2d860bf7
commit
adef8c8c45
|
|
@ -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?)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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 = "<tr><td colspan='5'>No payments found</td></tr>"
|
||||
@tbody.append(tr);
|
||||
|
||||
afterShow:() =>
|
||||
|
||||
showDialog:() =>
|
||||
@app.layout.showDialog(@dialogId)
|
||||
|
||||
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -118,15 +118,11 @@
|
|||
</div>
|
||||
|
||||
<div class="account-mid payments">
|
||||
<strong>Method:</strong>
|
||||
<div class="payment-method-text">
|
||||
{{data.payment_method}}
|
||||
</div>
|
||||
<a href="#">View Payment History</a> <a href="#">Update Payment Method</a>
|
||||
<a id="account-payment-history-link" href="#">View Payment History</a>
|
||||
</div>
|
||||
|
||||
<div class="right">
|
||||
<a id="account-edit-payments-link" href="#" class="button-orange">UPDATE</a>
|
||||
<a id="account-payment-history-link" href="#" class="button-orange">VIEW</a>
|
||||
</div>
|
||||
<br clear="all" />
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,3 +35,4 @@
|
|||
= render 'dialogs/adjustGearSpeedDialog'
|
||||
= render 'dialogs/openJamTrackDialog'
|
||||
= render 'dialogs/openBackingTrackDialog'
|
||||
= render 'dialogs/jamtrackPaymentHistoryDialog'
|
||||
|
|
|
|||
|
|
@ -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}}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue