nBill Community nBill Home Page
22/May/2012, 11:37:10 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Click Here for the nBill home page, or take a tour.  
 
   Home   Help Search Login Register  
Pages: [1] 2 3
  Print  
Author Topic: How to allow the user to enter the amount to pay  (Read 12361 times)
oakey
Jr. Member
**
Offline Offline

Posts: 8


View Profile
« on: 29/October/2007, 10: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, 12:19:03 PM by netshine » Logged
netshine
Administrator
Hero Member
*****
Offline Offline

Posts: 4,563


View Profile
« Reply #1 on: 29/October/2007, 10: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:
$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, 03:40:44 PM by netshine » Logged
oakey
Jr. Member
**
Offline Offline

Posts: 8


View Profile
« Reply #2 on: 29/October/2007, 11:14:57 AM »

You rok.....thanks for the great support and assistance
Logged
oakey
Jr. Member
**
Offline Offline

Posts: 8


View Profile
« Reply #3 on: 30/October/2007, 12:31:39 AM »

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

Logged
netshine
Administrator
Hero Member
*****
Offline Offline

Posts: 4,563


View Profile
« Reply #4 on: 30/October/2007, 10: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.  Smiley
Logged
dazzakiller
Jr. Member
**
Offline Offline

Posts: 22



View Profile
« Reply #5 on: 12/February/2008, 05: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
Logged
netshine
Administrator
Hero Member
*****
Offline Offline

Posts: 4,563


View Profile
« Reply #6 on: 13/February/2008, 11: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.
Logged
dazzakiller
Jr. Member
**
Offline Offline

Posts: 22



View Profile
« Reply #7 on: 13/February/2008, 11: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
 
Logged
thirdsun
Jr. Member
**
Offline Offline

Posts: 3


View Profile
« Reply #8 on: 27/February/2008, 06: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?
Logged
thirdsun
Jr. Member
**
Offline Offline

Posts: 3


View Profile
« Reply #9 on: 27/February/2008, 07: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?

Logged
netshine
Administrator
Hero Member
*****
Offline Offline

Posts: 4,563


View Profile
« Reply #10 on: 27/February/2008, 07: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:
$orders = array();
Logged
thirdsun
Jr. Member
**
Offline Offline

Posts: 3


View Profile
« Reply #11 on: 27/February/2008, 07: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, 08:37:24 PM by thirdsun » Logged
netshine
Administrator
Hero Member
*****
Offline Offline

Posts: 4,563


View Profile
« Reply #12 on: 28/February/2008, 10:09:37 AM »

Yes, you could replace this line:

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

...with this:

Code:
$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;
Logged
JaEvans
Jr. Member
**
Offline Offline

Posts: 3


View Profile
« 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
Logged
netshine
Administrator
Hero Member
*****
Offline Offline

Posts: 4,563


View Profile
« 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:
$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.
Logged
Pages: [1] 2 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!