Author Topic: How to allow the user to enter the amount to pay  (Read 13783 times)

Offline oakey

  • Jr. Member
  • **
  • Posts: 8
    • View Profile
How to allow the user to enter the amount to pay
« on: 29/October/2007, 09:04:58 AM »
Is this posiable
I need nBill to work like a donation module...
my client needs the form data then the user to select the donation amount... then to be processed by paypal ?

[Ed: changed subject line to be more descriptive, as this topic may be useful for others]
« Last Edit: 11/November/2007, 11:19:03 AM by netshine »

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,955
    • View Profile
Re: no price
« Reply #1 on: 29/October/2007, 09:32:06 AM »
It is possible, but requires a little PHP programming on the advanced tab of your order form. You also need to create a product record for the donation - you can give it a 'one-off' price of 1.00 (or whatever, doesn't really matter because you will be overriding the amount, but it should be more than zero). Also make sure the 'payment frequency code' on the 'order' tab of your order form is set to 'AA'.

Suppose you have a numeric field on your form called donation_amount, which holds the total amount to be billed (also assuming that no VAT is going to be added), you could use the following code for the 'submit code' setting.

Code: [Select]
$orders = array();
$order = array();
$order['net_price'] = format_number(mosGetParam($_POST, 'donation_amount'), 2);
$order['tax_amount'] = 0;
$order['product_name'] = "Donation";
$order['quantity'] = 1;
$order['product_id'] = 1; //Change this to whatever your actual product ID is
$orders[] = $order;
« Last Edit: 13/February/2008, 02:40:44 PM by netshine »

Offline oakey

  • Jr. Member
  • **
  • Posts: 8
    • View Profile
Re: no price
« Reply #2 on: 29/October/2007, 10:14:57 AM »
You rok.....thanks for the great support and assistance

Offline oakey

  • Jr. Member
  • **
  • Posts: 8
    • View Profile
Re: no price
« Reply #3 on: 29/October/2007, 11:31:39 PM »
what happened was because I had to set a price higher than $0.00...it was not over ridden by the code....everything worked great except this
So to over come this set up the "set up" price as a negative.
So my price is $1.00
setup price  is -$1.00

Works perfect now


Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,955
    • View Profile
Re: no price
« Reply #4 on: 30/October/2007, 09:42:24 AM »
Well, I can't see why that would be necessary (worked fine for me without a negative setup fee), but as long as it's working, that's the main thing.  :)

Offline dazzakiller

  • Full Member
  • ***
  • Posts: 22
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #5 on: 12/February/2008, 04:01:57 PM »
I think that I might be able to use this solution for something that I'm trying to archive, for taking deposits.

I've added the above code to a form where the user can choose other products, the last "product" that they may choose is a checkbox field which adds the value 15.00 deposit. All works fine except it adds 15.00 to the total (which includes the other products they have chosen). Now I understand that this is probably how it is suppose to work.

I was wondering though if there is a way for it to only pass the 15.00 deposit to paypal (if tick box checked), so the user only pays that at time of filling out the form, but then takes the 15.00 away from the invoice total (which would include the other product items) once paid?

Regards

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,955
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #6 on: 13/February/2008, 10:02:27 AM »
The totals are calculated after the 'submit code' is executed, so even if you set the total there it will be overwritten. I could add yet another form event setting to be executed after the totals are calculated so that you can override the calculated values, but I'm not entirely convinced that would be sufficient to facilitate taking a deposit (eg. when the callback is executed by Paypal, the amount will differ from the amount of the order, so nBill will reject it as invalid and the income will not be recorded).

Until such time as deposits are supported natively by nBill (a possibility for the future), you would either have to treat them as an entirely separate transaction, or hack the payment gateway to change the amount immediately before handing over to Paypal, and maybe try to deal with the callback by hacking the gateway as well. I would not be able to provide support for such hacking though.

Offline dazzakiller

  • Full Member
  • ***
  • Posts: 22
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #7 on: 13/February/2008, 10:48:41 AM »
Thanks for your reply.
I think that 'hacking' the gateway sounds to dangerous for a mere mortal like me, so I will leave as is and handle deposits with a separate form.
The ability to handle part-payments would add a lot of extra funcionality and benefits to nBill as if possible should be pushed up the proity list.
Kind regards
 

Offline thirdsun

  • Jr. Member
  • **
  • Posts: 3
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #8 on: 27/February/2008, 05:46:55 PM »
Could this be modified to allow use with a a number of options, and one option being "other" fill in amount.  So having a set of pre-selected donation amounts and an "other" amount?

Offline thirdsun

  • Jr. Member
  • **
  • Posts: 3
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #9 on: 27/February/2008, 06:26:06 PM »
I think I have this worked out -- simply used a $1 product and named the Quantity Field "Other Amount"  I supposed that would be a simple way to accomplish this not using the PHP code above?  Any downside?


Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,955
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #10 on: 27/February/2008, 06:44:29 PM »
The main drawback of that is that the summary, payment gateway, and invoice will show the amount and quantity which will appear to the user to be the wrong way round.

It is worth pointing out that the sample code given above wipes out anything else selected by the user on the order form. If you want the user-defined amount to be in addition to other selections on the form, just delete the first line:

Code: [Select]
$orders = array();

Offline thirdsun

  • Jr. Member
  • **
  • Posts: 3
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #11 on: 27/February/2008, 06:54:33 PM »
Thanks, that seems to work.  The price of the "other" product needed to be $0.

One more question - this site is for a political candidate and donations cannot exceed a particular amount.  Can that  "other" donation limit be set somehow?
« Last Edit: 27/February/2008, 07:37:24 PM by thirdsun »

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,955
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #12 on: 28/February/2008, 09:09:37 AM »
Yes, you could replace this line:

Code: [Select]
$order['net_price'] = format_number(mosGetParam($_POST, 'donation_amount'), 2);
...with this:

Code: [Select]
$max_amount=5000.00; //Replace amount with whatever the maximum is
$donation=format_number(mosGetParam($_POST, 'donation_amount'), 2);
$order['net_price'] = $donation > $max_amount ? $max_amount : $donation;

Offline JaEvans

  • Jr. Member
  • **
  • Posts: 3
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #13 on: 30/July/2008, 03:54:48 PM »
I tried the above code in the submit box and it did not work.  I have two products that are at a fixed price via checkbox and then I wanted donations set below  that so people can pay for membership and then add a donation.  when I added the code none of the payment options worked.  When I disabled the fixed rate items and just used the code with the donation box that did not work either.  Any other ideas?

Jason

Offline netshine

  • Administrator
  • Hero Member
  • *****
  • Posts: 4,955
    • View Profile
Re: How to allow the user to enter the amount to pay
« Reply #14 on: 30/July/2008, 04:30:07 PM »
If you have other fixed price items on the form, note my previous comment:
It is worth pointing out that the sample code given above wipes out anything else selected by the user on the order form. If you want the user-defined amount to be in addition to other selections on the form, just delete the first line:

Code: [Select]
$orders = array();

The code should still work. If you have followed the instructions above and are having no success, please let me have access to your Joomla administrator (via a support ticket) so I can see what is going wrong.

 

anything