Unlock seamless payment solutions by integrating Lovable with Adyen. Follow our step-by-step guide for secure, efficient checkout integration.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Since Lovable doesn’t provide a terminal, you must manually add the necessary dependencies by creating a file named package.json in the project root (if it doesn’t exist) with the following content. This registers Adyen’s checkout library and Axios for HTTP calls:
{
"dependencies": {
"adyen-checkout": "latest",
"axios": "latest"
}
}
Place this file in the root directory of your Lovable project so that when the project initializes, these dependencies are recognized.
Next, create a new TypeScript file named adyenConfig.ts in a new folder called config (or in the root if you prefer). This file will hold the Adyen API keys and merchant information:
export const adyenConfig = {
apiKey: 'YOURADYENAPI_KEY',
merchantAccount: 'YOURMERCHANTACCOUNT',
environment: 'test' // Change to 'live' when ready for production
};
Ensure you replace YOURADYENAPIKEY and YOURMERCHANT_ACCOUNT with your actual Adyen account details.
Now, create a new file called adyenService.ts in a folder named services. This service encapsulates the logic for communicating with the Adyen API. Insert the following TypeScript code into that file:
import axios from 'axios';
import { adyenConfig } from '../config/adyenConfig';
interface PaymentSessionResponse {
sessionData: string;
// Add further fields returned by Adyen if needed
}
/**
- Creates a new payment session with Adyen.
-
- @param amount - The payment amount in minor units (e.g., cents)
- @param currency - The currency code (e.g., EUR, USD)
- @returns A promise that resolves with the payment session data
*/
export async function createPaymentSession(amount: number, currency: string): Promise<PaymentSessionResponse> {
const requestData = {
amount: {
value: amount,
currency: currency
},
merchantAccount: adyenConfig.merchantAccount,
reference: 'ORDER-' + new Date().getTime(), // Example reference
returnUrl: 'https://yourdomain.com/checkout/result'
};
try {
const response = await axios.post(
(adyenConfig.environment === 'live'
? 'https://live-checkout-test.adyen.com/v68/sessions'
: 'https://checkout-test.adyen.com/v68/sessions'),
requestData,
{
headers: {
'Content-Type': 'application/json',
'X-API-Key': adyenConfig.apiKey
}
}
);
return response.data;
} catch (error) {
throw new Error('Unable to create payment session: ' + error);
}
}
Place this file under a new folder called services so that you can manage your service integrations separately.
Locate the main file where your checkout or payment logic exists. In Lovable projects this might be your main TypeScript file for handling business logic. Insert the following code snippet at the beginning of that file to import and use the Adyen service:
import { createPaymentSession } from './services/adyenService';
// This function is an example of how to trigger the Adyen checkout process.
async function initiateCheckout() {
try {
// Example: setting an amount of 1000 (e.g., €10.00 if using cents) in EUR
const sessionResponse = await createPaymentSession(1000, 'EUR');
console.log('Payment session created successfully:', sessionResponse);
// Insert logic to forward sessionResponse.sessionData to Adyen Checkout UI
// For example, you may call AdyenCheckout initialization code here.
} catch (error) {
console.error('Error during checkout:', error);
}
}
// Bind the initiateCheckout function to your UI event, for instance:
document.getElementById('checkoutButton')?.addEventListener('click', initiateCheckout);
Ensure that this code is inserted where your project handles checkout events. The checkoutButton element should exist in your UI so users can trigger the payment process.
If your Lovable project includes a front-end where you need to display the Adyen Checkout, add the following snippet to your HTML file where you include your JavaScript. Insert it inside your HTML’s <head> or right before the closing </body> tag:
<!-- Include Adyen Checkout Library via CDN -->
<script src="https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/5.24.0/adyen.js"></script>
<link rel="stylesheet" href="https://checkoutshopper-live.adyen.com/checkoutshopper/sdk/5.24.0/adyen.css" />
Adjust the library version or environment URL as needed. This snippet ensures that the Adyen Checkout UI resources are available to your project.
Once the above files and code snippets are added, your integration is complete. Review the following points:
package.json file is placed at the root so that dependency management recognizes the added libraries.adyenConfig.ts file must contain your real Adyen API credentials.adyenService.ts file encapsulates all API calls to Adyen and can be expanded if further endpoints are needed.Adyen Checkout CDN snippet in your HTML to load the checkout resources in the browser.initiateCheckout) into your event handlers so that users can initiate the payment process.With these steps, your Lovable project is now integrated with Adyen using TypeScript.
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.