Donor Pays Fees

Add the ability for the donor to cover transaction charges during SDK transactions.

This code section contains the logic for using Donor Pays Fee when using SDK giving forms.

Methods

This method is called when relevant fields are updated.

Local Variables

var dpfPercentage = 0.08; //Set this to your DPF percentage in decimal form.
var dpfCalculatedPercentage; //This will be the dollar amount of the fees.
var newTotal; //This will be the new total transaction amount.

Method

function updateDPFTotal() {

    dpfCalculatedPercentage = parseFloat(dpfPercentage * parseFloat(
         $('#paymentAmount').val())).toFixed(2);
     $('#dpf-amount').text("$" + dpfCalculatedPercentage);

     if ($('#dpf-checkbox').prop('checked')) {
          var activeAmount = parseFloat($('.amount-active')[0].innerHTML.slice(1));
         $('#paymentAmount').val(
              activeAmount + parseFloat(dpfCalculatedPercentage)
         );
    }
}

DOM Events

Sets up the interface events for updating Donor Pays Fees.

window.addEventListener('DOMContentLoaded', function () {

   updateDPFTotal();

   $('#dpf-checkbox').click(function () {
       if ($('#dpf-checkbox').prop('checked')) {
           theData.donorPaidFeeAmount = dpfCalculatedPercentage;

          $('#paymentAmount').val(
              (parseFloat($('#custom-amount-text').val()) + parseFloat(
                  dpfCalculatedPercentage)).toFixed(2)
           );

           updatePaymentAmount();

       } else {
          theData.donorPaidFeeAmount = null;

           var originalAmount = $('.amount-active')[0].innerHTML.slice(1);

          $('#paymentAmount').val(
              $('#custom-amount-text').val()
           );

          updatePaymentAmount();
      }
  });
});