Skip to content

Commit 7b44f81

Browse files
lalit-swain-ckoLalit Swain
andauthored
Refactor/reduce complexity v2 (#402)
* WIP: Refactor reduce complexity v2 - local changes * Remove backups folder from repository * Remove all markdown documentation files * Fix: Production-ready improvements and critical fixes - Fix workflow region validation to prevent invalid API URLs - Add input sanitization for region settings - Early load utility class to fix critical error on plugin activation - Wrap debug error_log statements in WP_DEBUG checks - Remove unnecessary debug logging from wrapper functions - Regenerate composer autoloader without dev dependencies - Restore README.md and languages/README.md files - Improve production readiness and WordPress coding standards compliance * Fix: Prevent invalid public key error during key registration - Add validation to check API keys before SDK initialization - Gracefully handle empty keys during initial setup/registration - Only log SDK initialization failures when WP_DEBUG is enabled - Fix region subdomain validation to handle 'global' value - Use null coalescing operator for safer array access * Fix: PayPal Express webhook matching for order status updates - Update Flow webhook handler Method 3 to check both _cko_flow_payment_id and _cko_payment_id meta keys - Add immediate order save after PayPal Express payment ID is set (before status update) - Process pending webhooks after payment ID is saved to handle race conditions - Update payment ID validation to check both meta keys for compatibility - Fixes issue where PayPal Express orders (using _cko_payment_id) were not found by webhook handler - Ensures webhooks can match orders regardless of payment method type * Fix payment method title spacing and improve webhook/flow integration - Fix payment method title spacing issues on checkout page for both newer and older WooCommerce versions - Add higher specificity CSS rules to override theme styles - Move Terms Checkbox Guard setting to Advanced → Debug Settings - Improve webhook/workflow duplicate detection with URL normalization - Add auto-generated webhook/workflow names - Enhance error messaging for multiple webhook scenarios - Add Flow integration modules for better code organization - Improve CSS loading order to ensure proper style precedence * docs: update README with setup guides for Flow, Apple Pay, Google Pay, and PayPal * Refactor: Remove Reflection, implement WooCommerce public APIs and order-first checkout flow - Remove all Reflection usage and migrate to public WooCommerce APIs - Implement order-first checkout flow using WC()->checkout->create_order() for subscription compatibility - Add proper WooCommerce hooks (woocommerce_checkout_order_processed, etc.) - Fix webhook queue cleanup handler with proper error handling and redirects - Register standalone webhook queue admin page for action handlers - Move diagnostics to admin-only tools page (class-wc-checkoutcom-diagnostics.php) - Remove subscription diagnostic logs - Add Docker setup files for local development - Fix WordPress coding standards (sanitization, capability checks, nonces) - Remove test scripts from build (moved to admin diagnostics page) * Remove Docker files from repository and add to .gitignore - Remove Docker setup files from git tracking (keep locally for development) - Add Docker files to .gitignore to prevent future commits * Remove composer.phar from git tracking (should be local only) * Add plugin zip file for distribution * Move plugin zip file to releases directory * Add plugin zip file to releases directory * Update .gitignore to allow zip files in releases directory * Add defensive JSON parsing for AJAX responses with leading junk - Handle responses that contain extra output before JSON (e.g., '200' prefix) - Extract JSON from response text even if plugins/server inject output - Prevents parsererror when response is valid JSON but has leading characters - Minimal performance impact (only runs on order creation AJAX call) * Apply WooCommerce coding standards: prefix CSS classes and global functions - Prefix all Flow CSS classes with cko-flow__ (BEM naming convention) - Prefix global functions with cko_ prefix - Update JavaScript to use prefixed CSS classes - Scope admin script enqueues to specific pages - Fix CSS syntax errors and brace balance * Fix Flow checkout styling and localize waiting text * Simplify express checkout CSS and unify cart button placement - Remove inline styles and hardcoded headings from express checkout buttons - Move minimal CSS to external stylesheet for theme compatibility - Remove 'Express Checkout' headings to let themes control labels - Unify cart page button placement - all buttons now render in shared container - Consistent placement for Apple Pay, Google Pay, and PayPal on cart page - Industry-standard approach: minimal plugin CSS, provider handles button styling * Update release zip with express checkout CSS simplifications * Fix Flow postcode validation on custom checkouts * Update release zip * Fix webhook processing for subscription renewals * Update release zip * Fix Cardholder Name Position setting save and display - Add manual sync for Flow settings (flow_component_cardholder_name_position, flow_show_card_holder_name, flow_saved_payment) in Card Settings save handler - Normalize cardholder name position value (top/bottom/hidden) in flow-customization.js - Only prefill cardholder name when position is not 'hidden' - Ensures settings save correctly and pass through to Flow SDK * Update release zip with Cardholder Name Position fix * Fix multiple Checkout.com entries in Payments settings and update README - Fix admin.js loading on main Payments list to hide duplicate gateways - Update README with comprehensive upgrade guide to Flow - Add Express Payments Apple Pay setup guide with detailed steps - Document Card Settings and Order Settings review steps * Clean up admin JS and Flow terms helper for CodeQL --------- Co-authored-by: Lalit Swain <lalit@example.com>
1 parent aae35f6 commit 7b44f81

File tree

60 files changed

+15231
-4663
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+15231
-4663
lines changed

.gitignore

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,16 @@ tests/node
44
node_modules/
55
**/**.mp4
66
vendor/
7-
checkout-com-unified-payments-api.zip
7+
checkout-com-unified-payments-api.zip
8+
composer.phar
9+
10+
# Docker files (local development only)
11+
.dockerignore
12+
docker-compose.yml
13+
docker-php.ini
14+
docker-start.sh
15+
16+
# Allow releases directory (but ignore other files in releases/)
17+
!releases/
18+
releases/*
19+
!releases/*.zip

README.md

Lines changed: 182 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ Checkout.com Payment Gateway plugin for WooCommerce with Flow integration suppor
44

55
## Version
66

7-
**Current Version:** 5.0.0
7+
**Current Version:** 5.0.1
88

99
## Features
1010

1111
### Flow Integration
1212
- **Checkout.com Flow** - Modern, secure payment processing using Checkout.com's Flow Web Components
1313
- **Saved Cards** - Customers can save payment methods for future use
1414
- **3D Secure (3DS)** - Full support for 3D Secure authentication
15+
- **3DS Return Handling** - Server-side processing on return to reduce client-side failures
1516
- **Card Validation** - Real-time card validation before order creation
16-
- **Webhook Processing** - Reliable webhook handling with queue system
17+
- **Webhook Processing** - Reliable webhook handling with queue system and duplicate detection
1718
- **Order Management** - Automatic order status updates based on payment status
1819

1920
### Payment Methods Supported
@@ -38,7 +39,7 @@ Checkout.com Payment Gateway plugin for WooCommerce with Flow integration suppor
3839

3940
1. **Secret Key** - Your Checkout.com secret key
4041
2. **Public Key** - Your Checkout.com public key
41-
3. **Webhook URL** - Configure in Checkout.com Hub:
42+
3. **Webhook URL** - Configure in Plugin Settings
4243
```
4344
https://your-site.com/?wc-api=wc_checkoutcom_webhook
4445
```
@@ -50,6 +51,162 @@ Checkout.com Payment Gateway plugin for WooCommerce with Flow integration suppor
5051
- Set up saved cards functionality
5152
- Configure 3DS settings
5253

54+
### Quick Setup (Flow)
55+
56+
1. In WordPress, go to **Plugins → Checkout.com Payment Gateway → Settings**.
57+
2. If the Checkout.com gateways are disabled, enable them in **WooCommerce → Settings → Payments**.
58+
3. In **Quick Setup**, set:
59+
- **Checkout Mode**: Flow
60+
- **Environment**: Sandbox (or Live)
61+
- **Account Type**: NAS (if applicable)
62+
- **Secret Key** and **Public Key**
63+
- **Payment Method Title**
64+
4. Under **Webhook Status**, click **Refresh Status**.
65+
5. If not configured, click **Register Webhook**.
66+
6. (Optional) Set **Enabled Payment Methods** for Flow.
67+
7. Click **Save changes**.
68+
69+
## Upgrade Your WooCommerce Integration to Flow
70+
71+
72+
73+
Follow this guide to upgrade your WooCommerce plugin to Flow.
74+
75+
### Before You Begin
76+
77+
- Ensure your WordPress and WooCommerce instances are up to date.
78+
- You need the following Checkout.com API credentials:
79+
- Public key
80+
- Secret key
81+
- Signature key
82+
83+
### Key Considerations
84+
85+
- Your existing Checkout.com keys will continue to work after upgrading.
86+
- Make sure all required APMs and wallet methods are selected under **Enabled Payment Methods** (Flow).
87+
- Confirm with Checkout.com Support that those APMs and wallets are onboarded for **Flow** on your account.
88+
89+
### Upgrade Steps
90+
91+
1. **Install the updated plugin**
92+
- Use the WordPress plugin directory:
93+
- Go to **Plugins → Add New**.
94+
- Search for **Checkout.com Payment Gateway**.
95+
- Select **Install Now**, then **Activate Plugin**.
96+
- Or install manually:
97+
- Download the latest release from the WooCommerce plugin repository.
98+
- Go to **Plugins → Add New → Upload Plugin → Choose file**.
99+
- Upload the ZIP file and select **Install Now**, then **Activate Plugin**.
100+
2. **Configure the plugin**
101+
- Go to **Checkout.com → Quick Settings**.
102+
- Set **Checkout Mode** to **Flow**.
103+
- Set **Environment** to **Sandbox** or **Live** depending on the environment you are upgrading.
104+
- Your existing **Public Key** and **Secret Key** will be pre-populated during upgrade.
105+
- Set **Payment Method Title**.
106+
- Use **Refresh Status** (Webhook) to check the webhook status.
107+
- If not registered, select **Register Webhook**.
108+
- If already registered, you will see a green confirmation line with the webhook URL.
109+
- Recheck **Card Settings** and **Order Settings**; existing values remain, no changes needed.
110+
- For **Express Payments**, follow the instructions under **Express Payments**.
111+
- For Flow look-and-feel changes, update **Flow Settings**.
112+
3. **Test your updated integration**
113+
- Follow WooCommerce test instructions and confirm order updates in WooCommerce.
114+
115+
### Go Live
116+
117+
After validating the upgrade:
118+
- Set **Environment** to **Live**.
119+
- Set **Secret Key** and **Public Key** to your production keys.
120+
121+
## Apple Pay Setup Guide
122+
123+
**Path A: New merchant (Flow checkout)**
124+
- Complete Checkout.com Apple Pay for web (Flow) setup:
125+
https://www.checkout.com/docs/payments/add-payment-methods/apple-pay/web
126+
- Enable **Apple Pay** in **Quick Setup**.
127+
- For **Fast Checkout** (Express Checkout), configure Apple Pay under **Express Checkout**:
128+
https://www.checkout.com/docs/payments/add-payment-methods/apple-pay/api-only
129+
130+
**Path B: Upgrading from classic checkout**
131+
- Ask Checkout.com support to enable Apple Pay for **Flow** and share your **site URL/domain**:
132+
https://www.checkout.com/docs/payments/add-payment-methods/apple-pay/web
133+
- Enable **Apple Pay** in **Quick Setup** and save.
134+
135+
**Path C: Express Checkout already configured**
136+
- Go to **Express Checkout** settings and verify Apple Pay.
137+
- Enable **Fast Checkout**.
138+
139+
### Express Payments (Apple Pay) Guide
140+
141+
Use this if you want Apple Pay buttons outside the Flow card form.
142+
143+
#### If you already have Apple Pay configured
144+
- Go to **Checkout.com → Express Payments → Apple Pay**.
145+
- You should see **✅ Setup Detected** with a prompt to run **Step 4: Test Certificate and Key**.
146+
- Click **Test Certificate and Key** to verify compatibility with the new plugin version.
147+
- No other changes are needed unless the test fails.
148+
149+
#### Full setup (new or reconfiguration)
150+
Apple Pay setup requires moving between **Checkout.com Settings** and your **Apple Developer** account. You will generate files in the plugin, upload them to Apple, download certificates from Apple, and upload them back in the plugin.
151+
152+
1. **Step 1a: Generate Certificate Signing Request (CSR)**
153+
- Create a Merchant ID in Apple Developer if needed.
154+
- Generate the CSR in the plugin and upload it to Apple Developer within 24 hours.
155+
2. **Step 1b: Upload Domain Association File**
156+
- Download the domain association file from Apple Developer and upload it here.
157+
- Verify the file is publicly accessible at:
158+
`https://YOUR-DOMAIN/.well-known/apple-developer-merchantid-domain-association.txt`
159+
- For Bitnami, you may need to place it manually:
160+
`sudo cp /path/to/apple-developer-merchantid-domain-association.txt /opt/bitnami/apps/letsencrypt/.well-known/apple-developer-merchantid-domain-association.txt`
161+
3. **Step 3a: Generate Merchant Identity CSR and Key**
162+
- Generate `uploadMe.csr` and `certificate_sandbox.key`.
163+
- Upload the CSR to Apple Developer and download the signed certificate.
164+
4. **Step 3b: Upload and Convert Merchant Identity Certificate**
165+
- Upload the signed certificate and convert it to PEM.
166+
5. **Step 4: Test Certificate and Key (Final Verification)**
167+
- Ensure Merchant Identifier, Domain Name, Display Name, certificate, and key are configured.
168+
- Click **Test Certificate and Key**.
169+
170+
#### Apple Pay settings to verify
171+
- **Enable Apple Pay**
172+
- **Payment Method Title** and **Description**
173+
- **Merchant Identifier**
174+
- **Merchant Identity Certificate Path** and **Key Path**
175+
- **Domain Name** and **Display Name**
176+
177+
#### Express Checkout settings
178+
- Enable **Apple Pay / Google Pay**
179+
- Choose where to show buttons (Product, Shop/Category, Cart, Checkout)
180+
- Configure appearance (Theme, Button Language)
181+
182+
Docs: https://www.checkout.com/docs/payments/add-payment-methods/apple-pay/api-only
183+
184+
## Google Pay Setup Guide
185+
186+
**Path A: New merchant (Flow checkout)**
187+
- Enable **Google Pay** in **Quick Setup**.
188+
- For **Fast Checkout**, configure Google Pay under **Express Checkout**.
189+
190+
**Path B: Upgrading from classic checkout**
191+
- Enable **Google Pay** in **Quick Setup** and save.
192+
193+
**Path C: Express Checkout already configured**
194+
- Go to **Express Checkout** settings and verify Google Pay.
195+
- Enable **Fast Checkout**.
196+
197+
## PayPal Setup Guide
198+
199+
**Path A: New merchant (Flow checkout)**
200+
- Enable **PayPal** in **Quick Setup**.
201+
- For **Fast Checkout**, configure PayPal under **Express Checkout**.
202+
203+
**Path B: Upgrading from classic checkout**
204+
- Enable **PayPal** in **Quick Setup** and save.
205+
206+
**Path C: Express Checkout already configured**
207+
- Go to **Express Checkout** settings and verify PayPal.
208+
- Enable **Fast Checkout**.
209+
53210
## Flow Integration Details
54211

55212
### Overview
@@ -86,6 +243,7 @@ The payment flow follows these steps:
86243
- Payment is processed securely through Checkout.com
87244
- For 3D Secure: Customer is redirected for authentication
88245
- Payment result is returned
246+
- For 3DS return: server-side handler processes the return and redirects to success page
89247

90248
#### Step 6: Webhook Processing
91249
- Checkout.com sends webhook with payment status
@@ -152,8 +310,9 @@ The payment flow follows these steps:
152310
2. Customer is redirected to bank's 3DS page
153311
3. Customer completes authentication
154312
4. Customer is redirected back to store
155-
5. Payment status is confirmed via webhook
156-
6. Order status is updated accordingly
313+
5. Server-side handler processes the return and redirects to success page
314+
6. Payment status is confirmed via webhook
315+
7. Order status is updated accordingly
157316

158317
**Features:**
159318
- Automatic 3DS detection
@@ -217,6 +376,7 @@ Update Order Status
217376
- **payment-session.js**: Handles order creation, payment session, Flow component integration
218377
- **flow-container.js**: Manages Flow component container and initialization
219378
- **flow-customization.js**: Customizes Flow component appearance and behavior
379+
- **modules/**: Flow modules (logger, state, 3DS detection, validation, guards)
220380

221381
#### Backend (PHP)
222382
- **class-wc-gateway-checkout-com-flow.php**: Main gateway class, handles payment processing
@@ -267,7 +427,17 @@ checkout-com-unified-payments-api/
267427
│ ├── js/
268428
│ │ ├── payment-session.js
269429
│ │ ├── flow-container.js
270-
│ │ └── flow-customization.js
430+
│ │ ├── flow-customization.js
431+
│ │ └── modules/
432+
│ │ ├── flow-3ds-detection.js
433+
│ │ ├── flow-container-ready-handler.js
434+
│ │ ├── flow-field-change-handler.js
435+
│ │ ├── flow-initialization.js
436+
│ │ ├── flow-logger.js
437+
│ │ ├── flow-saved-card-handler.js
438+
│ │ ├── flow-state.js
439+
│ │ ├── flow-terms-prevention.js
440+
│ │ └── flow-updated-checkout-guard.js
271441
│ └── css/
272442
│ └── flow.css
273443
├── includes/ # Core functionality
@@ -286,6 +456,7 @@ checkout-com-unified-payments-api/
286456
- WooCommerce 3.0+
287457
- PHP 7.3+
288458
- SSL Certificate (required for production)
459+
- Tested up to WordPress 6.7.0 and WooCommerce 8.3.1
289460

290461
## Support
291462

@@ -296,18 +467,14 @@ For support and integration help:
296467

297468
## License
298469

299-
MIT License
470+
GPL v2 or later
300471

301472
## Changelog
302473

303-
### Version 5.0.0
304-
- Initial Flow integration release
305-
- Complete Flow Web Components integration
306-
- Saved cards functionality
307-
- 3D Secure support
308-
- Webhook queue system
309-
- Enhanced order management
310-
- Comprehensive validation and error handling
474+
### Version 5.0.1
475+
- Flow module refactor for stability and 3DS return handling
476+
- Webhook duplicate detection and improved matching
477+
- Checkout styling updates for payment method title spacing
311478

312479
## Documentation
313480

0 commit comments

Comments
 (0)