Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/moizxox/stripe-api-generator/archive/refs/heads/main.zipNo built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.
A small WordPress plugin that creates Stripe Checkout Sessions through a REST API. Configure test and live secret keys in wp-admin, switch modes, and call the endpoint from any button or frontend script.
Install
- Copy this folder to
wp-content/plugins/stripe-api-generator - Activate Stripe API Generator in WordPress
- Open Settings → Stripe API Generator
- Paste your Stripe test and live secret keys
- Generate a Plugin API Key and save
- Set the active Mode (Test or Live)
Endpoint
POST /wp-json/sag/v1/checkout
Headers
| Header | Value |
|---|---|
Content-Type |
application/json |
X-SAG-API-Key |
Your plugin API key from settings |
Body
| Field | Required | Description |
|---|---|---|
amount |
yes | Integer in smallest currency unit (e.g. 2500 = $25.00) |
currency |
yes | 3-letter code, e.g. usd |
product_name |
yes | Line item name shown on Checkout |
quantity |
no | Defaults to 1 |
success_url |
no | Overrides the default success URL |
cancel_url |
no | Overrides the default cancel URL |
customer_email |
no | Prefills email on Checkout |
metadata |
no | Object of string key/value pairs |
Success response
{
"id": "cs_test_...",
"url": "https://checkout.stripe.com/c/pay/cs_test_..."
}
Redirect the customer to url.
Example
fetch('/wp-json/sag/v1/checkout', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-SAG-API-Key': 'your-plugin-api-key'
},
body: JSON.stringify({
amount: 2500,
currency: 'usd',
product_name: 'Custom Service'
})
})
.then((r) => r.json())
.then((data) => {
if (data.url) {
window.location.href = data.url;
} else {
console.error(data);
}
});
Security notes
- Stripe secret keys never leave the server
- Callers must send the plugin API key header
- Keep the plugin API key private (treat it like a password)
- Use Test mode until you are ready for real charges