Sunday, July 14, 2013

A simple shopping cart integration with eNETS and WorldPay using jQuery and PHP with database logging

Below is the demo code written in jQuery, PHP for a simple shopping cart which performs transaction with eNETS or WorldPay and log the records to the server:

http://www.4shared.com/zip/C-bgFisq/shopping_cart.html

The basic ideas is like this:  after the user enters the registration information and click "Checkout" button, the javascript on the client web browser will perform validation (e.g. check whether required fields are entered, whether the amount is greater than 0, etc). If the validation is correct, then the registration information will first post to the server as a record, which then returns a transaction reference number to the web browser. If the transaction reference number from the server is correctly returned, the javascript on the client web browser will post the form with the updated transaction reference number as well as the total amount to the enet (or worldpay), which then takes over the transaction.

  • The enets.html contains the web page and javascripts for working with eNETS, the javascript first post the form data to the log.php to be logged in the MySQL Server, and submit the form to eNETS gateway with the transaction reference received returned by the log.php
  • The worldpay.html contains the web page and javascript for working with WorldPay, the javascript first post the form data to the log.php to be logged in the MySQL Server, and submit the form to WorldPay gateway with the transaction reference received returned by the log.php
  • The log.php contains the PHP codes that logs that transaction data to the MySQL server, then returns the id of the last inserted transaction as the transaction reference to the jQuery post script which post the request.



No comments:

Post a Comment