Skip to content

Commit fed5fcb

Browse files
committed
allow users to configure plugin
1 parent a6dd87d commit fed5fcb

23 files changed

Lines changed: 9297 additions & 106 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ dist/
1111
.env.local
1212
.env.*.local
1313

14+
# Test app
15+
test-app/node_modules/
16+
test-app/.env
17+
test-app/dist/
18+
1419
# IDE
1520
.vscode/
1621
.idea/

CLAUDE.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ A WordPress/WooCommerce plugin that adds stablecoin payment support (USDC, USDT)
4747
1. Customer selects "Pay with Stablecoin" at checkout
4848
2. `ThirdwebCheckout.tsx` renders the CheckoutWidget with order total
4949
3. Customer connects wallet (MetaMask/Coinbase/WalletConnect) or pays with card
50-
4. Payment completes on-chain → thirdweb webhook fires to `/wp-json/thirdweb-wc/v1/webhook`
51-
5. PHP verifies transaction and marks WooCommerce order complete
50+
4. Payment completes on-chain → CheckoutWidget fires `onSuccess` callback with transaction data
51+
5. React component captures transaction hash and passes it to WooCommerce
52+
6. PHP verifies transaction on-chain via RPC and marks order complete
5253

5354
## Build Commands
5455

@@ -80,9 +81,8 @@ Settings at: WooCommerce → Settings → Payments → Stablecoin Payment
8081

8182
- **thirdweb Client ID**: From thirdweb dashboard
8283
- **Seller Wallet**: Address to receive payments
83-
- **Blockchain Network**: Base, Ethereum, Arbitrum, Polygon, Optimism
84-
- **Token Address**: USDC/USDT contract (optional, defaults to native token)
85-
- **Webhook Secret**: For verifying webhook signatures
84+
- **Chain ID**: Blockchain network chain ID (default: 8453 for Base). Supports any EVM chain
85+
- **Token Address**: USDC/USDT contract for the selected chain (optional, defaults to native token)
8686

8787
## CheckoutWidget Props Reference
8888

@@ -94,10 +94,9 @@ Settings at: WooCommerce → Settings → Payments → Stablecoin Payment
9494
seller="0x..." // Merchant wallet address
9595
tokenAddress="0x..." // USDC/USDT contract (optional)
9696
paymentMethods={['crypto', 'card']} // Enabled payment methods
97-
onSuccess={handleSuccess} // Success callback
97+
onSuccess={handleSuccess} // Success callback - receives Status[] with transaction data
9898
onError={handleError} // Error callback
9999
onCancel={handleCancel} // Cancel callback
100-
purchaseData={{ orderId, source }} // Passed to webhook for order matching
101100
theme="light" // UI theme
102101
supportedTokens={{...}} // Tokens users can pay with
103102
/>
@@ -117,13 +116,13 @@ Settings at: WooCommerce → Settings → Payments → Stablecoin Payment
117116
- WooCommerce checkout blocks use React on frontend (not PHP server-rendered)
118117
- `@woocommerce/blocks-registry` provides `registerPaymentMethod()` API
119118
- `getSetting('thirdweb_stablecoin_data')` retrieves PHP config in React
120-
- Webhook endpoint must be publicly accessible for thirdweb to call
119+
- Transaction hash captured from CheckoutWidget's `onSuccess` callback
121120
- Transaction verification happens server-side via RPC for security
122121

123122
## TODO
124123

125124
- [ ] Add refund support via thirdweb API
126-
- [ ] Implement proper webhook signature verification
127125
- [ ] Add transaction receipt email with block explorer link
128126
- [ ] Support multiple tokens per checkout
129127
- [ ] Add test mode toggle for testnet payments
128+
- [ ] Enhanced on-chain transaction verification (amount, recipient validation)

README.md

Lines changed: 161 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,24 +47,53 @@ thirdweb-woocommerce-checkout/
4747
│ ├── index.tsx # React entry point
4848
│ └── ThirdwebCheckout.tsx # CheckoutWidget wrapper
4949
├── build/ # Compiled JS (gitignored)
50+
├── test-app/ # Standalone React test app
5051
├── .env.example # Environment variables template
51-
├── .env # Your environment variables (create from .env.example)
5252
├── package.json
5353
├── tsconfig.json
5454
└── webpack.config.js
5555
```
5656

5757
## Installation & Setup
5858

59-
### 1. Install Dependencies
59+
### For End Users (WordPress Admin)
60+
61+
1. **Download the Plugin**
62+
- Download the latest `thirdweb-woocommerce-checkout.zip` from the releases page
63+
64+
2. **Install via WordPress Admin**
65+
- Go to **WordPress Admin → Plugins → Add New → Upload Plugin**
66+
- Choose the downloaded ZIP file
67+
- Click **Install Now**
68+
- Click **Activate Plugin**
69+
70+
3. **Create thirdweb Account & Project**
71+
- Go to [thirdweb.com/dashboard](https://thirdweb.com/dashboard) to create an account
72+
- Create a new project in your dashboard
73+
- Copy your **Client ID** from the project settings
74+
- Copy your **project wallet address** (this will receive all payments)
75+
76+
4. **Configure Payment Settings**
77+
- Navigate to **WooCommerce → Settings → Payments**
78+
- Find **Stablecoin Payment** and click **Manage**
79+
- Enable the payment method
80+
- Enter your **thirdweb Client ID**
81+
- Enter your **wallet address** to receive payments
82+
- Enter the **Chain ID** for your preferred blockchain (default: 8453 for Base)
83+
- Optionally enter the **Token Address** for USDC/USDT on that chain
84+
- Save changes
85+
86+
### For Developers
87+
88+
#### 1. Install Dependencies
6089

6190
```bash
6291
pnpm install
6392
```
6493

65-
### 2. Configure Environment Variables
94+
#### 2. Configure Environment Variables (Optional)
6695

67-
Copy the example environment file and add your thirdweb Client ID:
96+
For development convenience, you can use a `.env` file:
6897

6998
```bash
7099
cp .env.example .env
@@ -76,26 +105,143 @@ Edit `.env` and add your thirdweb Client ID:
76105
THIRDWEB_CLIENT_ID=your_client_id_here
77106
```
78107

79-
You can get your Client ID from the [thirdweb Dashboard](https://thirdweb.com/dashboard).
108+
This provides a default value in WooCommerce settings but can be overridden in the admin panel.
109+
110+
#### 3. Build the Plugin
111+
112+
For development:
113+
```bash
114+
pnpm run start # Watch mode
115+
```
116+
117+
For production:
118+
```bash
119+
pnpm run build # Build once
120+
```
121+
122+
#### 4. Create Distribution Package
80123

81-
### 3. Build the Plugin
124+
To create a production-ready ZIP for distribution:
82125

83126
```bash
84-
pnpm run build
127+
pnpm run package
85128
```
86129

87-
### 4. Configure in WooCommerce
130+
This creates `dist/thirdweb-woocommerce-checkout.zip` ready for WordPress installation.
131+
132+
## Testing the CheckoutWidget
133+
134+
Before integrating with WordPress, you can test the CheckoutWidget standalone using the React test app.
135+
136+
### Standalone Test App (No WordPress Required)
137+
138+
1. **Navigate to the test app**:
139+
```bash
140+
cd test-app
141+
```
142+
143+
2. **Install dependencies**:
144+
```bash
145+
pnpm install
146+
```
147+
148+
3. **Configure your credentials**:
149+
```bash
150+
cp .env.example .env
151+
```
152+
153+
Edit `.env` with your credentials:
154+
```env
155+
VITE_THIRDWEB_CLIENT_ID=your_client_id_here
156+
VITE_SELLER_WALLET=0xYourWalletAddress
157+
VITE_CHAIN_ID=8453
158+
VITE_TOKEN_ADDRESS=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
159+
VITE_AMOUNT=10.00
160+
```
161+
162+
**Get your credentials**:
163+
- **Client ID**: From [thirdweb.com/dashboard](https://thirdweb.com/dashboard)
164+
- **Wallet Address**: Your project wallet address from thirdweb dashboard
165+
- **Token Address** (optional): USDC on Base `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` or leave empty for native ETH
166+
167+
4. **Run the test app**:
168+
```bash
169+
pnpm dev
170+
```
171+
172+
The app will automatically open at `http://localhost:3000`
173+
174+
5. **Test the payment flow**:
175+
- The CheckoutWidget loads with your configuration
176+
- Connect your wallet (MetaMask, Coinbase Wallet, etc.) or pay with card
177+
- Complete a test payment
178+
- Transaction hash appears on success with block explorer link
179+
- Verify the transaction on [BaseScan](https://basescan.org)
180+
181+
See `test-app/README.md` for more details.
182+
183+
### Local WordPress Testing
184+
185+
After verifying the CheckoutWidget works standalone, test the full plugin integration:
186+
187+
1. **Install WordPress locally** using one of these options:
188+
- [LocalWP](https://localwp.com/) (recommended)
189+
- [MAMP](https://www.mamp.info/)
190+
- Docker with [docker-wordpress](https://hub.docker.com/_/wordpress)
191+
192+
2. **Install WooCommerce**:
193+
```
194+
WordPress Admin → Plugins → Add New → Search "WooCommerce" → Install & Activate
195+
```
196+
197+
3. **Link the plugin** to your WordPress installation:
198+
199+
**Option A: Symlink (recommended for development)**
200+
```bash
201+
# LocalWP example:
202+
ln -s $(pwd) ~/Local\ Sites/YOUR_SITE/app/public/wp-content/plugins/thirdweb-woocommerce-checkout
203+
204+
# MAMP example:
205+
ln -s $(pwd) /Applications/MAMP/htdocs/wordpress/wp-content/plugins/thirdweb-woocommerce-checkout
206+
```
207+
208+
**Option B: Copy files**
209+
```bash
210+
cp -r $(pwd) ~/Local\ Sites/YOUR_SITE/app/public/wp-content/plugins/thirdweb-woocommerce-checkout
211+
```
212+
213+
4. **Activate the plugin**:
214+
- Go to **WordPress Admin → Plugins**
215+
- Find "thirdweb Stablecoin Checkout for WooCommerce"
216+
- Click **Activate**
217+
218+
5. **Configure payment settings**:
219+
- Navigate to **WooCommerce → Settings → Payments**
220+
- Click **Manage** next to "Stablecoin Payment"
221+
- Enter your Client ID, wallet address, chain ID, and token address
222+
- Save changes
223+
224+
6. **Create a test product and complete checkout**:
225+
- Create a simple product in WooCommerce
226+
- Add it to cart and proceed to checkout
227+
- Select "Pay with Stablecoin" as payment method
228+
- Complete the payment flow
88229

89-
1. Go to **WooCommerce → Settings → Payments**
90-
2. Find **Stablecoin Payment** and click **Manage**
91-
3. Enable the payment method
92-
4. Enter your configuration (Client ID will be pre-filled from `.env` if set)
93-
5. Save changes
230+
### Common Token Addresses (Mainnet)
231+
232+
| Chain | Chain ID | USDC | Native Token |
233+
|-------|----------|------|--------------|
234+
| Base | 8453 | `0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913` | ETH |
235+
| Ethereum | 1 | `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48` | ETH |
236+
| Arbitrum | 42161 | `0xaf88d065e77c8cC2239327C5EDb3A432268e5831` | ETH |
237+
| Polygon | 137 | `0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359` | MATIC |
238+
| Optimism | 10 | `0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85` | ETH |
94239

95240
## How It Works
96241

97242
1. **Customer selects "Pay with Stablecoin"** at checkout
98243
2. **CheckoutWidget renders** with order total and merchant wallet
99244
3. **Customer connects wallet** (or pays with card via thirdweb)
100-
4. **Payment completes on-chain** → thirdweb webhook fires
101-
5. **PHP verifies transaction** and marks order complete
245+
4. **Payment completes on-chain** → CheckoutWidget fires `onSuccess` callback
246+
5. **Transaction hash captured** and passed to WooCommerce
247+
6. **PHP verifies transaction** on-chain via RPC and marks order complete

demo/checkout-mockup.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ <h2>Order Summary</h2>
641641
</button>
642642

643643
<p style="text-align: center; margin-top: 16px; font-size: 12px; color: #666;">
644-
🔒 Secure checkout powered by thirdweb
644+
🔒 Secure stablecoin checkout powered by thirdweb
645645
</p>
646646
</div>
647647
</div>

includes/class-thirdweb-payment-gateway.php

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function __construct() {
3939
$this->seller_wallet = $this->get_option('seller_wallet');
4040
$this->chain_id = $this->get_option('chain_id');
4141
$this->token_address = $this->get_option('token_address');
42-
$this->webhook_secret = $this->get_option('webhook_secret');
4342

4443
// Save settings hook
4544
add_action('woocommerce_update_options_payment_gateways_' . $this->id, [$this, 'process_admin_options']);
@@ -72,42 +71,45 @@ public function init_form_fields() {
7271
'client_id' => [
7372
'title' => __('thirdweb Client ID', 'thirdweb-wc'),
7473
'type' => 'text',
75-
'description' => __('Your thirdweb Client ID from the dashboard. Can also be set via .env file as THIRDWEB_CLIENT_ID.', 'thirdweb-wc'),
74+
'description' => sprintf(
75+
__('Get your Client ID from <a href="%s" target="_blank">thirdweb Dashboard</a>. Create a new project if you haven\'t already. Can also be set via .env file for development.', 'thirdweb-wc'),
76+
'https://thirdweb.com/dashboard'
77+
),
7678
'default' => thirdweb_wc_get_env('THIRDWEB_CLIENT_ID', ''),
77-
'desc_tip' => true,
79+
'placeholder' => __('e.g., abc123def456...', 'thirdweb-wc'),
7880
],
7981
'seller_wallet' => [
8082
'title' => __('Seller Wallet Address', 'thirdweb-wc'),
8183
'type' => 'text',
82-
'description' => __('Wallet address to receive payments', 'thirdweb-wc'),
84+
'description' => sprintf(
85+
__('Your project wallet address that will receive all payments. Get this from your <a href="%s" target="_blank">thirdweb project dashboard</a>.', 'thirdweb-wc'),
86+
'https://thirdweb.com/dashboard'
87+
),
8388
'default' => '',
84-
'desc_tip' => true,
89+
'placeholder' => __('0x...', 'thirdweb-wc'),
90+
'custom_attributes' => [
91+
'pattern' => '^0x[a-fA-F0-9]{40}$',
92+
],
8593
],
8694
'chain_id' => [
87-
'title' => __('Blockchain Network', 'thirdweb-wc'),
88-
'type' => 'select',
89-
'description' => __('Select the blockchain to receive payments on', 'thirdweb-wc'),
95+
'title' => __('Chain ID', 'thirdweb-wc'),
96+
'type' => 'text',
97+
'description' => sprintf(
98+
__('The blockchain network chain ID to receive payments on. Default is 8453 (Base). Common chains: 1 (Ethereum), 8453 (Base), 137 (Polygon), 42161 (Arbitrum), 10 (Optimism). See <a href="%s" target="_blank">chainlist.org</a> for more chains.', 'thirdweb-wc'),
99+
'https://chainlist.org'
100+
),
90101
'default' => '8453', // Base
91-
'options' => [
92-
'1' => 'Ethereum Mainnet',
93-
'8453' => 'Base',
94-
'42161' => 'Arbitrum One',
95-
'137' => 'Polygon',
96-
'10' => 'Optimism',
102+
'placeholder' => __('8453', 'thirdweb-wc'),
103+
'custom_attributes' => [
104+
'pattern' => '[0-9]+',
97105
],
98106
],
99107
'token_address' => [
100108
'title' => __('Token Address (Optional)', 'thirdweb-wc'),
101109
'type' => 'text',
102-
'description' => __('USDC/USDT contract address. Leave empty to accept native token (ETH).', 'thirdweb-wc'),
110+
'description' => __('USDC/USDT contract address for the chain above. Make sure the token address matches your selected chain. Leave empty to accept the native token (ETH, MATIC, etc.). Default is USDC on Base (chain 8453).', 'thirdweb-wc'),
103111
'default' => '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base
104-
'desc_tip' => true,
105-
],
106-
'webhook_secret' => [
107-
'title' => __('Webhook Secret', 'thirdweb-wc'),
108-
'type' => 'password',
109-
'description' => __('Secret key for verifying webhook signatures', 'thirdweb-wc'),
110-
'default' => '',
112+
'placeholder' => __('0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', 'thirdweb-wc'),
111113
],
112114
];
113115
}
@@ -214,18 +216,6 @@ private function verify_transaction($tx_hash, $order) {
214216
return true;
215217
}
216218

217-
/**
218-
* Verify webhook signature
219-
*/
220-
public function verify_webhook_signature($payload, $signature) {
221-
if (empty($this->webhook_secret)) {
222-
return true; // Skip if not configured
223-
}
224-
225-
$expected = hash_hmac('sha256', json_encode($payload), $this->webhook_secret);
226-
return hash_equals($expected, $signature);
227-
}
228-
229219
/**
230220
* Get config for frontend
231221
*/

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"scripts": {
77
"build": "wp-scripts build src/checkout-block/index.tsx --output-path=build",
88
"start": "wp-scripts start src/checkout-block/index.tsx --output-path=build",
9+
"package": "pnpm run build && bash scripts/package.sh",
910
"check-engines": "wp-scripts check-engines",
1011
"check-licenses": "wp-scripts check-licenses",
1112
"lint:js": "wp-scripts lint-js",

0 commit comments

Comments
 (0)