Skip to content

Commit deb447d

Browse files
committed
patches after testing
1 parent fed5fcb commit deb447d

6 files changed

Lines changed: 72 additions & 48 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,13 @@ After verifying the CheckoutWidget works standalone, test the full plugin integr
196196

197197
3. **Link the plugin** to your WordPress installation:
198198

199+
**Important**: Run these commands from the plugin root directory (where `thirdweb-woocommerce-checkout.php` is located).
200+
199201
**Option A: Symlink (recommended for development)**
200202
```bash
203+
# Make sure you're in the plugin directory first
204+
cd /path/to/woocommerce-thirdweb-checkout
205+
201206
# LocalWP example:
202207
ln -s $(pwd) ~/Local\ Sites/YOUR_SITE/app/public/wp-content/plugins/thirdweb-woocommerce-checkout
203208

@@ -207,7 +212,8 @@ After verifying the CheckoutWidget works standalone, test the full plugin integr
207212

208213
**Option B: Copy files**
209214
```bash
210-
cp -r $(pwd) ~/Local\ Sites/YOUR_SITE/app/public/wp-content/plugins/thirdweb-woocommerce-checkout
215+
# From the plugin directory:
216+
cp -r . ~/Local\ Sites/YOUR_SITE/app/public/wp-content/plugins/thirdweb-woocommerce-checkout
211217
```
212218

213219
4. **Activate the plugin**:

assets/icon.svg

Lines changed: 28 additions & 0 deletions
Loading

includes/class-thirdweb-blocks-support.php

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
<?php
22
/**
33
* WooCommerce Blocks Support for thirdweb Payment Gateway
4-
*
5-
* This enables the payment method to work with the new
4+
*
5+
* This enables the payment method to work with the new
66
* React-based WooCommerce Checkout Blocks
77
*/
88

99
defined('ABSPATH') || exit;
1010

1111
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
1212

13-
/**
14-
* Register the block payment method type
15-
*/
16-
add_action('woocommerce_blocks_payment_method_type_registration', function($payment_method_registry) {
17-
$payment_method_registry->register(new WC_Thirdweb_Blocks_Support());
18-
});
19-
2013
/**
2114
* Block support class
2215
*/
23-
class WC_Thirdweb_Blocks_Support extends AbstractPaymentMethodType {
16+
final class WC_Thirdweb_Blocks_Support extends AbstractPaymentMethodType {
2417

2518
/**
2619
* Payment method name/id
@@ -54,25 +47,30 @@ public function is_active() {
5447
* Register scripts for checkout block
5548
*/
5649
public function get_payment_method_script_handles() {
57-
$asset_path = THIRDWEB_WC_PLUGIN_DIR . 'build/checkout-block.asset.php';
58-
$asset = file_exists($asset_path)
59-
? require($asset_path)
50+
$asset_path = THIRDWEB_WC_PLUGIN_DIR . 'build/index.tsx.asset.php';
51+
$asset = file_exists($asset_path)
52+
? require($asset_path)
6053
: ['dependencies' => [], 'version' => THIRDWEB_WC_VERSION];
6154

55+
// Add WooCommerce block dependencies (they're externals in webpack)
56+
$dependencies = array_merge(
57+
$asset['dependencies'],
58+
[
59+
'wc-blocks-registry',
60+
'wc-settings',
61+
]
62+
);
63+
6264
wp_register_script(
6365
'thirdweb-wc-checkout-block',
64-
THIRDWEB_WC_PLUGIN_URL . 'build/checkout-block.js',
65-
$asset['dependencies'],
66+
THIRDWEB_WC_PLUGIN_URL . 'build/index.tsx.js',
67+
$dependencies,
6668
$asset['version'],
6769
true
6870
);
6971

70-
// Pass PHP config to JavaScript
71-
wp_localize_script(
72-
'thirdweb-wc-checkout-block',
73-
'thirdwebWCConfig',
74-
$this->get_payment_method_data()
75-
);
72+
// Note: get_payment_method_data() is automatically passed to JS by WooCommerce Blocks
73+
// via the getSetting() function, no need to localize manually
7674

7775
return ['thirdweb-wc-checkout-block'];
7876
}

src/checkout-block/ThirdwebCheckout.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const ThirdwebCheckout: React.FC<ThirdwebCheckoutProps> = ({
5858
// Calculate amount in token units (assuming 6 decimals for USDC/USDT)
5959
// WooCommerce sends total in smallest currency unit (cents for USD)
6060
const cartTotalInDollars = billing.cartTotal.value / 100;
61-
61+
6262
// For stablecoins, amount is typically 1:1 with USD
6363
// The CheckoutWidget expects amount as a string
6464
const amount = cartTotalInDollars.toFixed(2);
@@ -162,33 +162,23 @@ export const ThirdwebCheckout: React.FC<ThirdwebCheckoutProps> = ({
162162
chain={chain}
163163
amount={amount}
164164
seller={settings.seller as `0x${string}`}
165-
165+
166166
// Optional: specific token (USDC address)
167-
tokenAddress={settings.tokenAddress as `0x${string}` | undefined}
168-
169-
// Product info (optional - enhances the checkout UI)
170-
name="Order Payment"
171-
description={`Pay ${billing.currency.code} ${amount}`}
172-
167+
// Only pass if it's a valid address, not empty string
168+
{...(settings.tokenAddress && settings.tokenAddress.startsWith('0x')
169+
? { tokenAddress: settings.tokenAddress as `0x${string}` }
170+
: {})}
171+
173172
// Payment methods
174173
paymentMethods={['crypto', 'card']}
175-
174+
176175
// Callbacks
177176
onSuccess={handleSuccess}
178177
onError={handleError}
179178
onCancel={handleCancel}
180179

181180
// Theming
182181
theme="light"
183-
184-
// Supported tokens users can pay WITH (cross-chain)
185-
supportedTokens={{
186-
[settings.chainId]: settings.supportedTokens?.map(t => ({
187-
address: t.address as `0x${string}`,
188-
name: t.symbol,
189-
symbol: t.symbol,
190-
})) || [],
191-
}}
192182
/>
193183
</div>
194184

thirdweb-woocommerce-checkout.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ function thirdweb_wc_init() {
9191
// Load block support for checkout blocks
9292
add_action('woocommerce_blocks_loaded', function() {
9393
require_once THIRDWEB_WC_PLUGIN_DIR . 'includes/class-thirdweb-blocks-support.php';
94+
95+
// Register with blocks payment method registry
96+
add_action('woocommerce_blocks_payment_method_type_registration', function($payment_method_registry) {
97+
$payment_method_registry->register(new WC_Thirdweb_Blocks_Support());
98+
});
9499
});
95100
}
96101
add_action('plugins_loaded', 'thirdweb_wc_init');

webpack.config.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* Webpack configuration for WooCommerce Blocks extension
3-
*
3+
*
44
* Extends @wordpress/scripts default config to handle WooCommerce packages
55
* that are provided by WooCommerce core at runtime.
66
*/
@@ -9,13 +9,10 @@ const defaultConfig = require('@wordpress/scripts/config/webpack.config');
99

1010
module.exports = {
1111
...defaultConfig,
12-
resolve: {
13-
...defaultConfig.resolve,
14-
alias: {
15-
...defaultConfig.resolve?.alias,
16-
'@woocommerce/blocks-registry': require.resolve('./src/mocks/@woocommerce/blocks-registry.js'),
17-
'@woocommerce/settings': require.resolve('./src/mocks/@woocommerce/settings.js'),
18-
},
12+
externals: {
13+
...defaultConfig.externals,
14+
'@woocommerce/blocks-registry': ['wc', 'wcBlocksRegistry'],
15+
'@woocommerce/settings': ['wc', 'wcSettings'],
1916
},
2017
};
2118

0 commit comments

Comments
 (0)