Integrating by adding a Yandex Pay payment link
A payment link is the easiest method to integrate with Yandex Pay that doesn't require frontend integration. With these instructions, you can implement link generation as shown in the demo. To integrate by installing a Yandex Pay button or widget, follow other instructions.
Requirements for connecting
Before getting started, register in the merchant console and set up the test environment.
Instructions for integrating with
To transfer a payment:
- Create a link to the Yandex Pay payment form. When generating a link, specify the available payment methods using
availablePaymentMethods
. - Redirect the user to the
paymentUrl
that will be contained in the response to the order creation request. - Wait for the order payment confirmation using /webhook or polling the method.
Code examples
httpie
Node
Example of generating a payment link using HTTPie:
http POST https://sandbox.pay.yandex.ru/api/merchant/v1/orders \
Authorization:"API-Key a5f49c84-0baa-41e1-814f-6f99746a6987" \
cart:='{}' \
orderId=Order-$RANDOM \
currencyCode=RUB \
availablePaymentMethods:='["CARD", "SPLIT"]' \
redirectUrls:='{"onError": "https://merchant.example/error.html", "onSuccess": "https://merchant.example/success.html"}' \
cart:='{ "total": {"amount": "10"}, "items": [{"productId": "p1", "title": "Yandex Station Mini", "quantity": {"count": 1}, "total": "10"}]}'
Sample merchant backend code written in Node.js:
const https = require("https");
function createOrder(orderId) {
const ORDER_CREATE_URL =
"https://sandbox.pay.yandex.ru/api/merchant/v1/orders";
// In the sandbox environment, the merchant ID is used as the authorization key.
// In the production environment, you need to get an API key in the merchant's console.
const API_KEY = "a5f49c84-0baa-41e1-814f-6f99746a6987";
const orderData = {
// Unique order ID in the merchant's system (a required parameter)
orderId: orderId,
// User cart details
cart: {
// Items in the cart
items: [
{
productId: "3",
total: "15980.00",
title: "Yandex Station mini with a clock, pomegranate red",
quantity: {
count: "2",
},
},
],
// Optional. Data about discounts applied
discounts: [
{
amount: "500",
description: "Discount on the first order",
discountId: "first-order",
},
],
// Total order amount
total: {
amount: "15480.00",
},
},
// Order currency code (ISO 4217)
currencyCode: "RUB",
// Get the Merchant ID in the merchant's console after registration.
merchantId: "a5f49c84-0baa-41e1-814f-6f99746a6987",
// URLs on merchant site to forward the user after the payment
redirectUrls: {
onSuccess: "https://your-site.ru/page/success",
onError: "https://your-site.ru/page/error",
},
// Available payment methods.
// Options:
// - ["SPLIT"] — The form will only support payment via Split
// - ["CARD"] — The form will only support payment by bank card
// - ["SPLIT", "CARD"] — The user will be able to select between the payment methods: by bank card or Split.
availablePaymentMethods: ["CARD", "SPLIT"],
// Order TTL (in seconds)
ttl: 1800,
};
const data = JSON.stringify(orderData);
const requestOptions = {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Api-Key ${API_KEY}`,
},
};
const req = https.request(ORDER_CREATE_URL, requestOptions, (res) => {
let response = [];
res.on("data", (chunk) => {
response.push(chunk);
});
res.on("end", () => {
response = JSON.parse(Buffer.concat(response).toString());
// Send paymentUrl to the frontend
console.log(response.data.paymentUrl);
});
});
req.on("error", (err) => {
console.log("Error: ", err.message);
});
req.write(data);
req.end();
}
createOrder("your-order-id");
What's next
Read the branding rules. If needed, set up transmission of receipts for the Federal Taxation Services, implement order management over the Yandex Pay API in the merchant's backoffice, and enable Split. To let your users pay in two steps, set up two-step payments.