Example Applications
Learn by example with our reference implementations and sample applications that demonstrate common ZenPay integrations.
Sample Projects
These complete applications demonstrate best practices for integrating ZenPay into your projects. All examples are available on GitHub with step-by-step setup instructions.
E-commerce Store
React + Node.js implementation
SaaS Dashboard
Next.js + TypeScript implementation
Mobile Payments
React Native implementation
Code Snippets
For targeted implementations, explore these code snippets that showcase specific features of the ZenPay API.
One-time Checkout
Create a basic checkout form for one-time payments:
// Create a payment intent on your server
const paymentIntent = await zenpay.paymentIntents.create({
amount: 1999,
currency: 'usd',
payment_method_types: ['card'],
});
// Pass the client secret to your frontend
res.send({
clientSecret: paymentIntent.client_secret
});
// Then on your frontend
const {error, paymentIntent} = await zenpay.confirmCardPayment(
clientSecret,
{
payment_method: {
card: cardElement,
billing_details: {
name: 'Jenny Rosen',
},
},
}
);
if (error) {
// Show error to your customer
} else if (paymentIntent.status === 'succeeded') {
// Show success message
}
Subscription Setup
Create a subscription with a free trial:
// Create a customer
const customer = await zenpay.customers.create({
email: 'customer@example.com',
payment_method: 'pm_card_visa',
invoice_settings: {
default_payment_method: 'pm_card_visa',
},
});
// Create a subscription with a 14-day trial
const subscription = await zenpay.subscriptions.create({
customer: customer.id,
items: [
{ price: 'price_premium_monthly' },
],
trial_period_days: 14,
});
// Check subscription status
console.log(subscription.status); // 'trialing'
Getting Started with Examples
Follow these steps to run any example application locally:
Clone the repository
git clone https://github.com/zenpay/example-ecommerce.git cd example-ecommerce
Set up environment variables
Create a .env
file based on the provided .env.example
:
ZENPAY_PUBLIC_KEY=pk_test_... ZENPAY_SECRET_KEY=sk_test_... WEBHOOK_SECRET=whsec_...
Install dependencies and run
npm install npm run dev
Next Steps
After exploring the example applications, learn how to test your integration: