var edx = edx || {};
(function($) {
'use strict';
edx.dashboard = edx.dashboard || {};
edx.dashboard.donation = {};
/**
* View for making donations for a course.
* @constructor
* @param {Object} params
* @param {Object} params.el - The container element.
* @param {string} params.course - The ID of the course for the donation.
*/
edx.dashboard.donation.DonationView = function(params) {
/**
* Dynamically configure a form, which the client can submit
* to the payment processor.
* @param {Object} form - The form to modify.
* @param {string} method - The HTTP method used to submit the form.
* @param {string} url - The URL where the form data will be submitted.
* @param {Object} params - Form data, included as hidden inputs.
*/
var configureForm = function(form, method, url, params) {
$('input', form).remove();
form.attr('action', url);
form.attr('method', method);
_.each(params, function(value, key) {
$('').attr({
type: 'hidden',
name: key,
value: value
}).appendTo(form);
});
};
/**
* Fire an analytics event indicating that the user
* is about to be sent to the external payment processor.
*
* @param {string} course - The course ID for the donation.
*/
var firePaymentAnalyticsEvent = function(course) {
analytics.track(
'edx.bi.user.payment_processor.visited',
{
category: 'donations',
label: course
}
);
};
/**
* Add a donation to the user's cart.
*
* @param {string} amount - The amount of the donation (e.g. "23.45")
* @param {string} course - The ID of the course.
* @returns {Object} The promise from the AJAX call to the server,
* which resolves with a data object of the form
* { payment_url: , payment_params: