My current project using the EasyBlue/Bullmoose build is to integrate
the Wordpress WP-Invoice into Easy Appointments. This will not work on
the standard EA build because it does not fully hook into Wordpress.
The EasyBlue/Bullmoose build fully hooks in and allows the use of WP
functions within the program. My method requires using the WP-Invoice
sortcode within Easy Appointments. I have chosen WP-Invoice because it
is fully managed on my server and therefore no patient data is stored on
an external server. That is good for HIPPA. There are better
invoicing systems but this really does do the job and it is very
affordable. The basic WP-Invoice plugin is free. But you will need the
Single Page Checkout feature for my approach to work. There is a one
time fee ($75) to get Single Page Checkout added to the plugin. Another
advantage is that WP-Invoice already has interfaces for multiple
payments options. I do not have to write the API code and return codes
for these. I am focusing on Paypal.
I did some CSS things to
eliminate a lot of the portions of this plugin and to just keep the
button. I styled the button like the confirm button. It looks great. I
am not posting that here. I have also made a settings switch to turn
on and off the feature. That is also not being shown here. I have
tried the approach by building the shortcode by hand in a PHP veriable
and it works great. Now to code it properly so that the short code
changes with the service selection.
To do that we need to first build the short code using some Java Script:
var serviceItem = $('#select-service option:selected').text();
var shortcode= "[wpi_checkout item='" + serviceItem + "' customer_information='Date of Service' callback_function='enableconfirm']";
I
have this triggered with an on click event within the book.php view
(should be in frontend_book.js but it is in book.php for now):
$('#button-next-1').on('click', function(){
FrontendBookApi.getShortcode();
});
Then
we need to get this script into a this Wordpress function that sits in
book.php that will replace the confirm button with the trigger to start
the payment sequence:
<?php echo do_shortcode($shortcode); ?>
So what is needed is an ajax call that will take the JS shortcode and turn it in to the PHP $shortcode in the book.php view.
I have tried using a function like this:
exports.getShortcode = function() {
var serviceItem = $('#select-service option:selected').text();
var serviceString = "[wpi_checkout item='" + serviceItem + "'
customer_information='Date of Service'
callback_function='enableconfirm']";
var data = {'shortcode': serviceString};
var postUrl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_serviceitem';
$.ajax({
csrfToken: GlobalVariables.csrfToken,
url: postUrl,
method: 'post',
data: data,
dataType: 'json',
success: function(data) {
alert(data);
}
});
};
This is then processed in the Appointments controller with something like this:
//WP-Invoice Integration
public function ajax_serviceitem() {
$shortcode = $_POST['shortcode'];
echo json_encode($shortcode);
}
The result is an error:
HTTP403: FORBIDDEN - The server understood the request, but is refusing to fulfill it.
(XHR)POST - https://pathtoEA/easy/index.php/appointments/ajax_serviceitem
I
am not too good with Ajax and so obviously I am getting something wrong
here. So any better developers who can see my error I would love your
input. I will then include this code with the EasyBlue/Bullemoose build
for all to use.
The last step after making this step work the
next step is the return function 'enableconfirm' that will move us to
the success window. This is very close to being done. Please help.
One
thing I have tried is to use a cookie in stead to move the JS variable
to my PHP variable. That works (kind of). The problem is that it will
only update on refresh of the screen and that is not so good. But it
did prove the concept. Ajax is the way.