Friday 13 September 2013

Adding a 3-Party (third party) payment gateway in woocommerce

Adding a third party payment gateway in woocommerce

  1. 3-Party Payments allow the Payment Server to manage the payment pages and collect the cardholder's card details on your behalf.The cardholder's Internet browser is redirected to take the Transaction Request to the Payment Server to process the transaction. After processing the transaction, the cardholder's Internet browser is returned to a web page that you nominate in the transaction together with a Transaction Response. The Transaction Response processing of the receipt information completes the transaction. To process a payment your application needs to be integrated with the Virtual Payment Client in order to:
    • Create the secure hash signature
    • Send it with the Transaction Request, and
    • Check that the secure hash signature in the Transaction Response is valid for the received data.
  2. Woocommerce provide default Mijireh 3-party payment gateway for payment through credit card.
  3. For integrating your own payment gateway - All payment Gateways are register in file 'Site_URL/wp-content/plugins/woocommerce/woocommerce.php' in core_gateways function. Add your gateway in the list and create its folder in 'Site_URL/wp-content/plugins/woocommerce/classes/gateways'. For easy integration copy mijireh folder and paste at the same path an rename it with you gateway name. Also replace 'mijireh' to 'Gateway_name' in all files.
  4. In 3-party payment gateway main part is to redirect user to the Payment server page and after transaction complete return back to own site and display the result. For that find the Virtual Payment Client URL and the details like Access key, merchant id, hash key which use to redirect user to payment server.
  5. 'Site_URL/wp-content/plugins/woocommerce/classes/gateways/credimax/class-wc-gateway-GATEWAY_NAME.php' contains the main redirect and return url setting. The function process_payment processes the payment of your products. For returning to your site from payment server need to send the return URL of the thank you page which is creted while installing the woocommerce plugin in Pages. Also with the return url you need to send the order id and the order key along with the URL
  6. After Successful payment or unsuccessful payment woocommerce call the 'output' function from 'Site_URL/wp-content/plugins/woocommerce/classes/shortcodes/class-wc-shortcode-thankyou.php' where you can update the code as per your results. Also 'Site_URL/wp-content/plugins/woocommerce/templates/checkout/thankyou.php' contains the thank you page. You can create your own thank you page and call page to display the results or errors.