Een geavanceerde Kayana Integration bouwen met RYFT in Node.js
Last updated Mar 13, 2026
Deze gids toont hoe u
Kayana Payments powered by RYFT
integreert met behulp van een
Node.js backend en een frontend (React / Next.js / HTML)
. Betalingsstroom: 1️⃣ Backend maakt een betalingssessie aan 2️⃣ Backend haalt RYFT openbare sleutel op 3️⃣ Frontend laadt RYFT SDK 4️⃣ Frontend initialiseert betaling 5️⃣ Klant voltooit betaling
1. Installeer Afhankelijkheden
npm init -y
npm install express cors node-fetch dotenv
2. Projectstructuur
project
│
├── server.js
├── .env
└── routes
└── payment.js
3. Omgevingsvariabelen
.env maken
PORT=5000
API_KEY=YOUR_API_KEY
PROPERTY_ID=Prop_039f025cdbc74ca9957dbec1b3e193c1
BASE_URL=https://integration.dev.kayana.co.uk
4. Express Server Setup
server.js
const express = require("express");
const cors = require("cors");
require("dotenv").config();
const paymentRoutes = require("./routes/payment");
const app = express();
app.use(cors());
app.use(express.json());
app.use("/api/payment", paymentRoutes);
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
5. Betalingsroutes maken
routes/payment.js
const express = require("express");
const fetch = require("node-fetch");
const router = express.Router();
const BASE_URL = process.env.BASE_URL;
const API_KEY = process.env.API_KEY;
const PROPERTY_ID = process.env.PROPERTY_ID;
//
// Betalingssessie maken
//
router.post("/create-payment", async (req, res) => {
try {
const response = await fetch(`${BASE_URL}/web/payment`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"x-api-key": API_KEY,
type: "business",
},
body: JSON.stringify({
property_id: PROPERTY_ID,
psp_code: "RYFT",
currency_code: "GBP",
amount: 100.5,
customer_email: "customer@example.com",
payment_mode: "CARD",
}),
});
const data = await response.json();
res.status(response.status).json(data);
} catch (error) {
res.status(500).json({
error: "Betalingssessie kon niet worden aangemaakt",
details: error.message,
});
}
});
//
// RYFT openbare sleutel ophalen
//
router.get("/public-key", async (req, res) => {
try {
const response = await fetch(`${BASE_URL}/web/payment/public-key`, {
method: "GET",
headers: {
"x-api-key": API_KEY,
"x-psp-code": "RYFT",
"x-currency-code": "GBP",
type: "business",
},
});
const data = await response.json();
res.json(data);
} catch (error) {
res.status(500).json({
error: "Openbare sleutel kon niet worden opgehaald",
details: error.message,
});
}
});
module.exports = router;
6. Frontend Integration
Laad de RYFT SDK
<script src="https://embedded.ryftpay.com/v2/ryft.min.js"></script>
7. Initialiseer betaling op frontend
async function initPayment() {
// Get public key
const keyRes = await fetch("/api/payment/public-key");
const keyData = await keyRes.json();
const publicKey = keyData.data.public_key;
// Create payment session
const paymentRes = await fetch("/api/payment/create-payment", {
method: "POST",
});
const paymentData = await paymentRes.json();
const clientSecret = paymentData.data.client_secret;
// Initialize RYFT
window.Ryft.init({
publicKey,
clientSecret,
});
}
8. Betaling Voltooien
async function payNow() {
const paymentSession = await window.Ryft.attemptPayment();
if (
paymentSession.status === "Approved" ||
paymentSession.status === "Captured"
) {
alert("Payment Successful");
} else {
alert("Payment Failed");
}
}
9. Testkaarten
| Kaart | Resultaat |
| 4242 4242 4242 4242 | Geslaagd |
| 4000 0025 0000 3155 | 3D Secure |
| 4000 0000 0000 9995 | Geweigerd |
Gebruik:
- Elke toekomstige vervaldatum
- Elke CVC
10. Controlelijst productie
Voordat u live gaat:
Basis-URL wijzigen
https://integration.kayana.co.uk
Productie-API-sleutel gebruiken RYFT PSP inschakelen in Kayana Betalingswebhooks toevoegen
Aanvullende eindpunten voor bestellingen
Aanbevolen flow:
Bestelling maken → Betaling autoriseren ↓ ├── Vastleggen → Succes ├── Annuleren → Betaling annuleren └── Terugbetaling → Na vastlegging
Verificatie
Alle API-verzoeken moeten de volgende headers bevatten:
| Header | Type | Vereist | Beschrijving |
|---|---|---|---|
| x-api-key | String | Ja | Uw API-sleutel |
| type | String | Ja | Moet ingesteld zijn op business |
| Content-Type | String | Ja | Moet application/json zijn |
| x-property-id | String | Ja | eigendoms-ID |
1. Gemaakte betaling vastleggen
Eindpunt
POST /web/payment/capture-authorised-payment
Verzoekparameters
| Veld | Type | Vereist | Beschrijving |
| order_id | String | Ja | Bestelling-ID |
| amount | Number | Ja | Bedrag om vast te leggen |
cURL-voorbeeld
curl --location 'https://integration.dev.kayana.co.uk/web/payment/capture-authorised-payment' \
--header 'Content-Type: application/json' \
--header 'type: business' \
--header 'x-api-key: <YOUR_API_KEY>' \
--data '{
"order_id": "Order_xxx",
"amount": 5
}'
Voorbeeldrespons
{
"status": "success",
"message": "Betaling succesvol vastgelegd",
"data": {
"order_id": "Order_xxx",
"captured_amount": 5
}
}
2. Gemaakte betaling annuleren
Eindpunt
POST /web/payment/cancel-authorised-payment
Verzoekparameters
| Veld | Type | Vereist | Beschrijving |
| order_id | String | Ja | Bestelling-ID |
cURL-voorbeeld
curl --location 'https://integration.dev.kayana.co.uk/web/payment/cancel-authorised-payment?order_id=Order_xxx' \
--header 'Content-Type: application/json' \
--header 'type: business' \
--header 'x-api-key: <YOUR_API_KEY>'
Voorbeeldrespons
{
"status": "success",
"message": "Betaling succesvol geannuleerd"
}
3. Betaling terugbetalen
Eindpunt
POST /web/payment/refund
Verzoekparameters
| Veld | Type | Vereist | Beschrijving |
| order_id | String | Ja | Bestelling-ID |
| amount | Number | Ja | Terugbetalingsbedrag |
cURL-voorbeeld
curl --location --request POST 'https://integration.dev.kayana.co.uk/web/payment/refund?order_id=Order_xxx&amount=0.4' \
--header 'Content-Type: application/json' \
--header 'type: business' \
--header 'x-api-key: <YOUR_API_KEY>'
Voorbeeldrespons
{
"status": "success",
"message": "Terugbetaling verwerkt",
"data": {
"order_id": "Order_xxx",
"refunded_amount": 0.4
}
}
4. Bestelgegevens ophalen
Eindpunt
GET /web/order/fetch-order-details-by-order-id
Verzoekparameters
| Veld | Type | Vereist | Beschrijving |
| order_id | String | Ja | Bestelling-ID |
cURL-voorbeeld
curl --location 'https://integration.dev.kayana.co.uk/web/order/fetch-order-details-by-order-id?order_id=Order_xxx' \
--header 'type: business' \
--header 'x-api-key: <YOUR_API_KEY>'
Voorbeeldrespons
{
"status": "success",
"data": {
"order_id": "Order_xxx",
"status": "captured",
"amount": 5
}
}
Best Practices voor Beveiliging
Nooit blootstellen:
API keys client_secret payment session logs
Altijd:
Bel de Kayana API aan vanaf de backend Gebruik omgevingsvariabelen Valideer betalingsstatus aan serverzijde
Als je wilt, kan ik je ook een veel betere productie-klare versie geven:
- Volledige React + Node.js RYFT integratie
- Juiste betaalcomponent UI
- Webhook verificatie
- Foutafhandeling
- TypeScript versie
Zeg het maar en ik deel een complete real-world productie-implementatie.
Volgende stappen
Als u RYFT als uw Payment Service Provider (PSP) wilt gebruiken, ondersteunt Kayana ook een volledige RYFT-integratieflow. Raadpleeg onze gids over hoe u een geavanceerde Kayana-integratie met Stripe in Node.js bouwt
