How phazerooman/thawani-for-woocommerce works
Project type and purpose
• This is a WordPress/WooCommerce plugin (“Thawani for WooCommerce”) that extends WooCommerce to accept Credit/Debit card payments via the Thawani payment gateway.
• The plugin provides both server-side PHP endpoints (to interact with WooCommerce orders and Thawani’s API) and client-side JavaScript (Vue components) to handle payment sessions and display status.
File structure
• Top-level plugin files (thawani-for-woocommerce.php, composer.json, package.json) register the plugin, declare dependencies, and bootstrap autoloaders.
• src/ holds core PHP classes:
– WC_Gateway_ThawaniGateway.php integrates into WooCommerce’s payment‐gateway hooks.
– Endpoint/*.php defines REST/AJAX endpoints (Customer, Session, Payment, Refund).
– RestAPI.php and ThawaniAjax.php orchestrate HTTP requests to Thawani and AJAX handlers.
– Statistics.php, AdminDashboard.php render the admin screens and session history.
• js/ contains Vue components for the checkout UI (CustomerList.vue, Sessions.vue, etc.), plus supporting CSS and language files.
• webpack.mix.js, tailwind.config.js, postcss.config.js drive asset compilation into dist/app.js and thawani-generate.js.
• template/ and static/ provide PHP view templates and static assets for README screenshots.
• languages/ holds translation files.
• vendor/ and composer.lock record PHP library dependencies.
Extract architecture hints from the README
• Plugin hooks into WooCommerce checkout page to inject “Pay with Thawani” option.
• On checkout, client-side code initiates a session via AJAX to a PHP endpoint, which calls Thawani’s Checkout API.
• A redirect or popup collects card details on Thawani’s side; Thawani sends webhook callbacks to wc-api/thawani-payment-status.
• Plugin verifies payment status via REST calls, updates WooCommerce order status, logs events, and stores session history for admin review.
a. Main components
• WordPress/WooCommerce Core (hooks & REST API)
• Thawani for WooCommerce Plugin
– PHP Layer: Gateway class, Endpoint controllers, REST/AJAX handlers, Logging subsystem
– JS Layer: Vue.js components, CSS, language translations
– Templates: Admin dashboard and session history views
• Database: WooCommerce orders, plugin’s session history, logs
• External Service: Thawani Checkout API & Webhook endpoint
• Browser/Client: Customer checkout frontend and Admin dashboard UI
b. Relationships & interactions
1. Customer → WooCommerce Checkout UI → Vue.js component (“Pay with Thawani”)
2. Vue.js → AJAX → PHP Endpoint → Thawani API (create session)
3. Thawani API → Customer’s Browser (redirect to payment page)
4. Thawani → Webhook → Plugin’s wc-api endpoint → PHP handler → validate & update order
5. Admin → WordPress Admin UI → PHP Dashboard class → reads DB → displays session logs
c. Architectural patterns & principles
• WordPress plugin hook/filter architecture (observer pattern)
• Separation of concerns: PHP backend vs. Vue.js frontend vs. template views
• RESTful/AJAX endpoints for asynchronous operations
• Build pipeline: Webpack (Laravel Mix) + Tailwind for asset bundling
• Internationalization via .mo/.pot files
d. Key technologies & frameworks
• PHP 7.x+, Composer, WordPress Plugin API, WooCommerce payment-gateway hooks
• JavaScript (ES6+), Vue.js single-file components, Axios for AJAX
• Laravel Mix (webpack.mix.js), Tailwind CSS, PostCSS
• Thawani Checkout REST API, Webhook mechanism
• MySQL (WordPress DB) for orders, plugin logs & session history