phpScheduleIt
May 22, 2013, 03:00:25 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: phpScheduleIt 2.4.2 has been released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Paypal Integration Method - Finally!  (Read 10763 times)
nymrulez
Newbie
*

Karma: 0
Posts: 13


« on: October 28, 2007, 04:48:11 AM »

Well, after driving myself crazy into the wee hours of the morning the last few nights, I finally figured out a practical way to integrate this script with Paypal. Here's how it works: after you reserve or change your time on the pop up reservation screen, you see a Paypal button along with the usual confirmation information. When clicked on, the button sends the visitor's name, e-mail address, and the cost of the event straight to Paypal.  The code calculates the cost of the event automatically by multiplying the duration by the cost per minute, and assumes the Administrator e-mail address is your Paypal e-mail address.  

So all you have to do is figure out your cost per minute and enter a name for your service and you have a Paypal solution! I should mention that this works best with reservation approval turned on. That way, your users will know you received payment by coming back and seeing that their reservation was approved. This is still a work in progress, and I still need to figure out a way to get this to go to Paypal in a new window so that the visitors have more screen to work with when they are making payment. So, without further adieu, the example below assumes your hourly rate is $60:

The file we are modifying is: /lib/Reservation.class.php. We are replacing the entire section that begins around line 415.
In the code below, where it says "$paypal_cost = $paypal_duration * 1" replace the number 1 with your cost per minute. And where it says "YOUR SERVICE NAME" replace that with the name of your service. Good luck, and I hope to make this even better soon!


Code:


/**
* Prints a message nofiying the user that their reservation was placed
* @param string $verb action word of what kind of reservation process just occcured
* @param array $dates dates that were added or modified.  Deletions are not printed.
*/
function print_success($verb, $dates = array()) {
echo '<script language="JavaScript" type="text/javascript">' . "\n"
. 'window.opener.document.location.href = window.opener.document.URL;' . "\n"
. '</script>';
$paypal_duration = '';
$paypal_duration = $this->end - $this->start;
$paypal_cost = '';
$paypal_cost = $paypal_duration * 1;
$paypal_fname = '';
$paypal_fname = $this->user->get_fname();
$paypal_lname = '';
$paypal_lname = $this->user->get_lname();
$paypal_useremail = '';
$paypal_useremail = $this->user->get_email();
$paypal_adminemail = '';
$paypal_adminemail = $this->sched['adminemail'];
$date_text = '';
for ($i = 0; $i < count($dates); $i++) {
$date_text .= Time::formatReservationDate($dates[$i], $this->start) . '<br/>';
}
CmnFns::do_message_box(translate('Your ' . $this->word . ' was successfully ' . $verb . $res['starttime'])
. (($this->type != 'd') ? ' ' . translate('for the follwing dates') . '<br /><br />' : '.')
. $date_text . '<br/><br/>'
. '<FORM ACTION="https://www.paypal.com/cgi-bin/webscr" METHOD="POST">
<INPUT TYPE="hidden" NAME="cmd" VALUE="_ext-enter">
<INPUT TYPE="hidden" NAME="redirect_cmd" VALUE="_xclick">
<INPUT TYPE="hidden" NAME="business" VALUE="'. $paypal_adminemail .'">
<INPUT TYPE="hidden" NAME="undefined_quantity" VALUE="1">
<INPUT TYPE="hidden" NAME="item_name" VALUE="YOUR SERVICE NAME - ' . $paypal_duration .' Minute Session">
<INPUT TYPE="hidden" NAME="amount" VALUE="'. $paypal_cost . '">
<INPUT TYPE="hidden" NAME="first_name" VALUE="'. $paypal_fname .'">
<INPUT TYPE="hidden" NAME="last_name" VALUE="'. $paypal_lname .'">
<INPUT TYPE="hidden" NAME="email" VALUE="'. $paypal_useremail .'">
<INPUT TYPE="image" SRC="http://www.paypal.com/en_US/i/btn/btn_paynow_LG.gif" BORDER="0" NAME="submit">'
. '</FORM>'
. '<a href="javascript: window.close();">' . translate('Close') . '</a>'
, 'width: 90%;');
}
[/code]
Logged
nymrulez
Newbie
*

Karma: 0
Posts: 13


« Reply #1 on: October 29, 2007, 01:29:35 AM »

I have worked on this system a little further, and managed to set it up such that after the visitor clicks the Pay Now button, the pop-up closes and the visitor is redirected to Paypal on the larger (original) calendar window. Here's how:

In the file, /lib/template.class.php (This deals with the large window with all the calendars), there is a section of code with "<HEAD>" at around line 57. Somewhere in the header code (preferably where the other javascript code is), add the following:

Code:

<SCRIPT LANGUAGE=" JavaScript" TYPE=" text/JavaScript" >
<!-- begin hiding
self.name=' mainWindow' ;
// end hiding --></SCRIPT>


Then, in the /lib/Reservation.class.php file that you worked on in my prior post (This deals with the smaller pop-up window that comes up when you click to reserve a time slot), change the Paypal form line to the following:

Code:

<FORM ACTION="https://www.paypal.com/cgi-bin/webscr" target=" mainWindow" onSubmit=" self.close();" METHOD="POST">


Do not forget to include the extra spaces in the code. They are necessary and this will not work properly unless the code is on your site exactly as it appears here.
Enjoy!
Logged
Nick
Administrator
Hero Member
*****

Karma: 15
Posts: 5419


WWW
« Reply #2 on: October 29, 2007, 10:11:28 AM »

Very nice!  Thanks!
Logged
efusemedia
Newbie
*

Karma: 0
Posts: 3


WWW
« Reply #3 on: November 28, 2007, 08:31:57 AM »

is it possible to pas different prices per minute to paypal for different resourses or does only work with one set price?
Logged
stardom
Newbie
*

Karma: 0
Posts: 10


« Reply #4 on: December 29, 2007, 03:56:51 PM »

my congrats to Nymrulez for this paypal script, you are a total genius!... and together with PhpSheduleit you guys have practically saved my life, I was searching for exactly this kind of resource. God bless OpenSource.

I know this script is a work in progress (I wish I could contributte but I'm not a programmer) but I have actually noticed a small detail: if I try to delete my own reservation, the "pay now" button is still there, which is a bit contradictory as I'm actually deleting. Maybe there could be a button saying "claim refund"... what do you think??

Criss

PS. obviously, the "pay now" button appears in every pop-up, i.e approve, delete, etc.   is there a way to have it only on the reservations pop-up ?
Logged
StamfordRob
Newbie
*

Karma: 0
Posts: 17


« Reply #5 on: March 27, 2008, 04:33:34 PM »

all.

i am using phpscheduleit for resources in a lab area.. we are using the resources for workstation chassis reservations and the accessories for hard drives, peripherals, etc.. what i want to do is put a fee on the reservation time.  nick lead me to your modification and said that it may be a good start for me.. i looked and it may work for what i need.. but being a newbie here to php i was looking for the steps to set this up .. cradle to grave.. if you have alternate ideas please let me know.. i want to have a fee for the table time for each unit at the resource level.. eventually at the accessory level..

thanks in advance.

r
Logged

Life is like a roll of toilet paper, I just don't know how far into the roll I am.
rigbro
Newbie
*

Karma: 0
Posts: 1


« Reply #6 on: August 18, 2008, 05:30:25 PM »

Hey!  I got it working.  I had to change the code a little for Safari on my mac.  It wouldn't redirect the mainWindow to paypal. 

I also managed to add variable pricing.  I know someone was interested in that.  It's a little difficult to explain, but I could show someone the code if they are interested.

This is a great add-on for phpScheduleIt.  The only improvement would be to charge paypal and verify the payment before the time slot is scheduled.  I'm not too familiar with paypal integration, but I would imagine that it would be possible.

Thanks!


 
« Last Edit: March 26, 2009, 12:19:22 AM by rigbro » Logged
jaycee
Newbie
*

Karma: 0
Posts: 5


« Reply #7 on: December 05, 2008, 11:48:37 PM »

I also managed to add variable pricing.  I know someone was interested in that.  It's a little difficult to explain, but I could show someone the code if they are interested.

Hi rigbro,
I am in kind of similar requirement. I have around 7 services to sell all having variable pricing. Will be happy to see how you managed to do this.
Thanks
Jay
Logged
fleury
Newbie
*

Karma: 0
Posts: 1


« Reply #8 on: June 27, 2009, 10:15:34 PM »

I also managed to add variable pricing.  I know someone was interested in that.  It's a little difficult to explain, but I could show someone the code if they are interested.

Hi rigbro,
I am in kind of similar requirement. I have around 7 services to sell all having variable pricing. Will be happy to see how you managed to do this.
Thanks
Jay

Hi, Has anyone figured out the Paypal approval prior to the time slot getting booked? I'd appreciate this.

Cheers

Fleury
Logged
Davam
Newbie
*

Karma: 1
Posts: 11


« Reply #9 on: September 03, 2009, 02:32:44 AM »

Hi, Has anyone figured out the Paypal approval prior to the time slot getting booked? I'd appreciate this.

Cheers

Fleury

I'm working on a solution for that now. I'm adding a field to the login database that will hold the user's "gift certificate" balance. In order to make a reservation, they will need to have a large enough balance to cover the reservation cost. Upon making a reservation, the appropriate amount will be deducted from their balance. There will also be a link for them to purchase gift certificates that they can print to give to a friend or have immediately applied to add to their own gift certificate balance. I will need to add a table to record the gift certificate transactions. This table will hold the gift certificate id number, the userid of the purchaser, the userid of the person redeeming it, the date purchased, the date redeemed, the gift certificate amount, and its expiration date.

In addition to paypal as a payment method I'll also add add TrialPay.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!