fc77ee76d6
The primary license of the project is changing to: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later The Additional Permission is designed to permit publicly distributed Javascript code to be relicensed under LGPL-3.0-or-later, but not server-side Javascript code. As such, we've relicensed here static Javscript files under LGPL-3.0-or-later, and those that run as part of build and/or server side under AGPL-3.0-or-later. Note that in future, Javascript files may be updated to be stronger copyleft license with the Additional Permission, particularly if they adapted to run on server side and/or turned into templates. Of course, we'd seek public discussion with the contributor community about such changes. This commit is one of the many steps to relicense the entire codebase. Documentation granting permission for this relicensing (from all past contributors who hold copyrights) is on file with Software Freedom Conservancy, Inc.
69 lines
1.6 KiB
JavaScript
69 lines
1.6 KiB
JavaScript
// License: LGPL-3.0-or-later
|
|
const R = require('ramda')
|
|
const format = require('../common/format')
|
|
var format_err = require('../common/format_response_error')
|
|
var request = require('../common/super-agent-promise')
|
|
|
|
appl.def('ajax_refunds', {
|
|
create: function(charge_id, form_obj, node) {
|
|
form_obj = formatter(form_obj)
|
|
appl.def({
|
|
loading: true,
|
|
refunds: { error: '', loading: true }
|
|
})
|
|
post_refund(charge_id, form_obj)
|
|
.then(function(resp) {
|
|
not_loading()
|
|
appl.close_modal()
|
|
return resp
|
|
})
|
|
.then(function(resp) { return resp.body })
|
|
.then(fetch_data_on_success)
|
|
.then(display_success_message)
|
|
.catch(show_err)
|
|
}
|
|
})
|
|
|
|
const formatter = R.evolve({
|
|
amount: format.dollarsToCents
|
|
})
|
|
|
|
// Re-fetch all the payment data on the page after a refund has been made
|
|
function fetch_data_on_success(refund) {
|
|
appl.payments.index()
|
|
appl.ajax_payment_details.fetch(appl.payment_details.data.id)
|
|
return refund
|
|
}
|
|
|
|
// Display a nice message confirming the amounts of the refund they just made
|
|
function display_success_message(refund) {
|
|
appl.notify(
|
|
"Your refund was successful!"
|
|
)
|
|
return refund
|
|
}
|
|
|
|
// Reset the loading state in the ui
|
|
function not_loading(x) {
|
|
appl.def({loading: false, refunds: {loading: false}})
|
|
return x
|
|
}
|
|
|
|
// Display an error in the ui
|
|
function show_err(resp) {
|
|
not_loading()
|
|
console.warn('Error in promise chain: ', resp)
|
|
appl.def('refunds', {
|
|
error: format_err(resp),
|
|
loading: false
|
|
})
|
|
}
|
|
|
|
// Make the ajax request, returning a Promise
|
|
function post_refund(charge_id, obj) {
|
|
return request
|
|
.post('/nonprofits/' + app.nonprofit_id + '/charges/' + charge_id + '/refunds')
|
|
.send({refund: obj})
|
|
.perform()
|
|
}
|
|
|