PayPal Integration Project

417 views
Skip to first unread message

Craig Tucker

unread,
Dec 25, 2016, 4:44:41 AM12/25/16
to Easy!Appointments - Support Group
This appears to be the way forward as far as I can tell:

We also need an additional field in the appointments table for validation.
We need a prepayment variable in the services table.

At step 4 an if statement is needed:

If Prepayment is Yes in the service table--the confirm button needs to be replaced with a payment button on click:

The validation column would be set with a time stamp in the future x minutes. This will stop the confirmation email.  If the payment is not validated in x minutes the appointment is deleted.  Also, the following standard paypal button format but it needs to be stripped to just a post statement on the click 

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="y...@youremail.com">
<input type="hidden" name="item_name" value="Item Name">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value="0.00">
<input type="hidden" name="custom" value="E!A hash here">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>

All of this information for the values would be gathered from the services table and appointments table.

In the post to paypal we can include the appointment hash within the custom field.  This would be our session ID that will send back to us.

In order to get payment verification we need an IPN listener built into EA. An examples of how to set up a listener are here:


A good video tutorial with code example is here:



We need to have PayPal Instant Payment Notification (IPN) activated with in PayPal.  This was a little hard for me to find: In PayPal, go to Profile, in the left panel click "My Selling Tools", in the right pannel select update by "Instant Payment Notification (IPN)" and then, choose IPN settings.  Then you enter a URL for the IPN listener.

That return URL would send back to us whether the purchase was verified or not along with the custom peramiter that carries the appointment's hash.

If verified with in the time limit: 
Varification is set to Null
Email verification is sent
Else If not verified, the appointment is canceled with an invalid payment notice.

Else, the confirm button works as is.

Does anyone want to participate in making this?





Craig Tucker

unread,
Dec 25, 2016, 1:04:40 PM12/25/16
to Easy!Appointments - Support Group
Steps for the project:

Tasks:
  1. update /assetts/sql/structure.sql to include:
    • Additional date field in the appointments table for validation.
    • Additional prepayment boolean field in the services table.
    • We need a method to self destruct the pending appointments after x minutes if validation is not completed.  I would like it not to be dependent on crontab.  Perhaps a MySQL event could be constructed? Input would be appreciated here.
  2. Add the ipn listener as a separate file or part of /application/controllers/Appointments.php.  I am not sure what is best here.  Input would be appreciated.
  3. Modify step 4: /assets/js/frontend_book.js, frontend_book_api.js, frontend_book_success.js needs to change the nature of the button from the confirm according to the condition of the prepayment field in the services table:
    • If False: Confirm as is in EA
    • If True: Change button to an onclick event that does a couple things:
      • Trigger Appointments.php to Create an appointment with a timestamp in the validation column of the appointments table.  A modification in the /application/models/Appointments_model.php is likely needed as well.  
      • I would like a MySQL event set to delete the appointment if validation is older than 10 min. for example.
      • We need to make a post to send the information usually sent by this standard paypal button with the E!A hash in the custom field:
        • <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
          <input type="hidden" name="cmd" value="_xclick">
          <input type="hidden" name="business" value="y...@youremail.com">
          <input type="hidden" name="item_name" value="Item Name">
          <input type="hidden" name="currency_code" value="USD">
          <input type="hidden" name="amount" value="0.00">
          <input type="hidden" name="custom" value="E!A hash here">
          <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
          </form>
With this paypal needs to be set up for receiving IPN: In PayPal, go to Profile, in the left panel click "My Selling Tools", in the right pannel select update by "Instant Payment Notification (IPN)" and then, choose IPN settings.  Then you enter a URL for the IPN listener.

Then it should work.

Craig Tucker

unread,
Dec 28, 2016, 12:28:03 AM12/28/16
to Easy!Appointments - Support Group
Step 1:

I added the two columns to the tables:

ALTER TABLE `ea_services`
ADD COLUMN
`prepay` tinyint(4) DEFAULT '0', AFTER `id_service_categories`;

ALTER TABLE
`ea_appointments`
ADD COLUMN
`confirm` tinyint(4) DEFAULT '0', AFTER `id_google_calendar`;

For the confirm column I chose not to do a date stamp given that it already exists in book_datetime.  I figure that "confirm" will just need yes/no.

In /application/models/Appointments_model.php I added the following function to delete an appointment that is waiting for confirmation for more than 10 min.
    public function drop_unvalidated() {
        $time
= (CURDATE() - INTERVAL 10 MINUTE);
        $array
= array('confirm ' => TRUE, 'book_datetime <' => $time);
        $this
-> db -> where($array);
        $this
-> db -> delete('ea_appointments');
   
}

I am not sure how I want to trigger this yet.  I do not want to use crontab.  One option would be to run the function each time the calendar is refreshed.  Any other ideas would be appreciated.


Craig Tucker

unread,
Dec 28, 2016, 10:54:01 AM12/28/16
to Easy!Appointments - Support Group
I changed the model's function to this:

    public function drop_unvalidated() {
        $time
= date('Y-m-d H:i:s', strtotime('-10 minutes'));

        $array
= array('confirm ' => TRUE, 'book_datetime <' => $time);
        $this
-> db -> where($array);
        $this
-> db -> delete('ea_appointments');
   
}

I also made a controller for /application/controllers/Paypal.php

I added this function to the controller:

    public function delete_confirm(){
        $this
->load->model('appointments_model');
        $this
->appointments_model->drop_unvalidated();
   
}

I launched it by command line:

php56 /my path to EA/index.php Paypal/delete_confirm

This will do the trick for deleting the unconfirmed appointments if not confirmed within 10 min. if I use crontab.  And for now I think I will add this to crontab and launch it every minute.  That will at least prove the concept.  What I would rather do is launch this when ever the calendar is called.  But I am not sure of a graceful way to implement that since there are several places it is called and I am afraid I would miss some.

Step 1 appears to be done.  Now on to Step 2.
 





Craig Tucker

unread,
Dec 31, 2016, 11:45:00 AM12/31/16
to Easy!Appointments - Support Group
I am working on the listener for PayPal and have a question about how to handle client cancellations.  One option is (if they cancel within 24 hours) to send the client a coupon code for the value of that session that they can apply to their next appointment.  And if they cancel within 24 hours they forfeit the payment.  The issue for me is how to set up coupon codes in the listener process that will work with PayPal.

Matthew Broadhead

unread,
Feb 13, 2018, 1:32:02 PM2/13/18
to Easy!Appointments - Support Group
Hi Craig,
did you get any further with this feature?  I am evaluating easy appointments and wondered if there was a PayPal integration facility.
there doesn't seem to be much of a response on this group.  did you file an issue at github?

Craig Tucker

unread,
Feb 14, 2018, 10:49:22 AM2/14/18
to Easy!Appointments - Support Group
Hello Matthew,

Yes, I have it working.  I used a different method than building my own listener. I started documenting it here:

https://groups.google.com/forum/#!searchin/easy-appointments/Paypal%7Csort:date/easy-appointments/f499QyFbvaA/sxlx0h4dBQAJ

I will post my results on github with the 1.3 build after it is released officially. 

Craig

Matthew Broadhead

unread,
Feb 14, 2018, 2:07:19 PM2/14/18
to Easy!Appointments - Support Group
Thanks Craig i will take a look and let you know if i have any problems
Reply all
Reply to author
Forward
0 new messages