Skip to content

Payment Operations

With the marketplace payment system, you can accept card payments from end users and distribute these payments to sellers and the marketplace according to their commissions.

On this page you will learn about the following operations:

  • Creating payments (3D and non-3D)
  • Querying payment status
  • Fetching stored card list
  • Fetching installment information
  • Updating commission

Initiates a new payment transaction. Used for both 3D Secure and non-3D transactions.

TEST:

POST https://apitest.paynkolay.com.tr/marketplace/v1/payment/create

PROD:

POST https://api.paynkolay.com.tr/marketplace/v1/payment/create
{
"apiKey": "calculated_api_key",
"apiSecretKey": "sx_value",
"bankCard": {
"cardHolder": "AHMET YILMAZ",
"cardNumber": "4546711234567894",
"cvv": "123",
"expiryMonth": "12",
"expiryYear": "2026",
"isThreeD": true,
"registerCard": false
},
"installment": 2,
"isFetchInstallments": false,
"encodedValue": null,
"trxCurrency": "TRY",
"trxAmount": 150.00,
"trxCode": "ORDER_12345",
"trxType": "SALES",
"callbackUrl": "https://yoursite.com/payment-callback",
"sellerList": [
{
"sellerExternalId": "SELLER_001",
"commissionRate": null,
"commissionAmount": null,
"mpCost": null,
"trxAmount": 100.00,
"withholdingTax": 0.80,
"sellerDiscountAmount": 0.00
},
{
"sellerExternalId": "SELLER_002",
"trxAmount": 50.00,
"withholdingTax": 0.40,
"sellerDiscountAmount": 0.00
}
],
"shippingCost": 0.00,
"otherAmount": 0.00,
"mpDiscountAmount": 0.00,
"totalDiscountAmount": 0.00,
"marketplaceCode": "MP12345",
"customerCardInfo": {
"mpCustomerKey": "12345678901",
"cardAlias": null,
"cardTranId": null,
"cardToken": null
}
}
ParameterTypeRequiredDescription
apiKeyStringKey generated with hash calculation
apiSecretKeyStringSX value
trxCurrencyStringCurrency code (TRY, USD, EUR)
trxAmountBigDecimalTotal transaction amount
trxCodeStringTransaction tracking code (your own reference)
trxTypeStringTransaction type: SALES
callbackUrlStringURL where 3D result will be posted
marketplaceCodeStringMarketplace code
ParameterTypeRequiredDescription
cardHolderString✅*Name on card (Optional for stored card)
cardNumberString✅*Card number (Optional for stored card)
cvvString✅*CVV code (Optional for stored card)
expiryMonthString✅*Expiry month (Optional for stored card)
expiryYearString✅*Expiry year (Optional for stored card)
isThreeDBooleanUse 3D Secure?
registerCardBooleanStore card? (Only for 3D transactions)
ParameterTypeRequiredDescription
installmentIntegerNumber of installments (1 = single payment)
isFetchInstallmentsBooleanFetch installment info from Pay N Kolay?
encodedValueStringEncoded value from FetchPaymentInstallments
ParameterTypeRequiredDescription
sellerExternalIdStringSeller’s external ID
trxAmountBigDecimalTransaction amount for seller
commissionRateBigDecimalCustom commission rate (outside profile)
commissionAmountBigDecimalCalculated commission amount
mpCostBigDecimalTransaction fee
withholdingTaxBigDecimalWithholding tax amount
sellerDiscountAmountBigDecimalSeller discount amount
ParameterTypeRequiredDescription
shippingCostBigDecimalShipping fee
otherAmountBigDecimalOther fees
mpDiscountAmountBigDecimalMarketplace discount amount
totalDiscountAmountBigDecimalTotal discount amount
Customer Card Information (customerCardInfo)
Section titled “Customer Card Information (customerCardInfo)”
ParameterTypeRequiredDescription
mpCustomerKeyString✅*Customer identifier (ID/Mobile/Passport) - Required for card storage
cardAliasStringCard alias (for storage)
cardTranIdStringStored card ID (for payment with stored card)
cardTokenStringStored card token (for payment with stored card)
{
"data": {
"refCode": "REF123456789",
"trxCode": "ORDER_12345",
"form": "PGh0bWw+...3D HTML Form Base64..."
},
"success": true,
"responseCode": "200",
"responseMessage": "SUCCESS"
}
ParameterTypeDescription
refCodeStringPay N Kolay reference code
trxCodeStringYour transaction code
formStringBase64 encoded HTML form (filled in 3D transactions)
sequenceDiagram
participant Client as Customer Browser
participant Your as Your Server
participant PNK as Pay N Kolay
participant Bank as Bank 3D
Client->>Your: Submit Payment Form
Your->>PNK: CreatePayment (isThreeD=true)
PNK->>Your: form (Base64 HTML)
Your->>Your: Base64 Decode
Your->>Client: HTML Form Render
Client->>Bank: 3D Verification
Bank->>Client: SMS/OTP
Client->>Bank: Enter Code
Bank->>Your: POST to callbackUrl
Your->>Your: Validate Hash
Your->>Client: Result Page
// Decode the form in the response
const response = await createPayment(paymentData);
if (response.success && response.data.form) {
// Base64 decode
const htmlForm = Buffer.from(response.data.form, 'base64').toString('utf-8');
// Show HTML to customer
res.send(htmlForm);
}

When the 3D transaction is completed, the following data will be POSTed to your callbackUrl:

app.post('/payment-callback', (req, res) => {
const {
trxCode,
trxAmount,
authAmount,
commissionRate,
authCode,
bankMessage,
installment,
responseMessage,
referenceCode,
currencyCode,
hash,
responseCode,
commissionAmount,
timestamp,
issuerBankCode,
installmentFeeRate,
installmentFeeAmount,
cardType,
paymentSystem
} = req.body;
// Validate hash
const calculatedHash = calculateCallbackHash({
timestamp,
referenceCode,
trxCode,
authAmount,
responseCode
}, apiSecretKey);
if (calculatedHash !== hash) {
return res.status(400).send('Invalid hash');
}
// Successful payment
if (responseCode === '00' || responseCode === '0000') {
// Confirm order
updateOrderStatus(trxCode, 'PAID');
} else {
// Error status
updateOrderStatus(trxCode, 'FAILED');
}
res.status(200).send('OK');
});

Queries the status of a payment transaction.

TEST:

POST https://apitest.paynkolay.com.tr/marketplace/v1/payment/status

PROD:

POST https://api.paynkolay.com.tr/marketplace/v1/payment/status
{
"refCode": "REF123456789",
"trxCode": "ORDER_12345"
}
{
"data": [
{
"trxStatus": "SUCCESS",
"trxCode": "ORDER_12345",
"refCode": "REF123456789",
"trxType": "SALES",
"trxAmount": 150.00,
"trxCurrency": "TRY"
}
],
"success": true,
"responseCode": "200",
"responseMessage": "SUCCESS"
}
CodeDescription
SUCCESSSuccessful transaction
PENDINGTransaction in progress
FAILEDFailed transaction
CANCELLEDCancelled
REFUNDEDRefunded

Lists stored cards belonging to a customer.

TEST:

POST https://apitest.paynkolay.com.tr/marketplace/v1/payment/storedCardList

PROD:

POST https://api.paynkolay.com.tr/marketplace/v1/payment/storedCardList
{
"mpCode": "MP12345",
"apiSecretKey": "sx_value",
"mpCustomerKey": "12345678901",
"apiKey": "calculated_api_key"
}
{
"data": {
"cardTotalCount": 2,
"storedCardList": [
{
"cardToken": "token_abc123",
"cardTranId": "tran_xyz789",
"cardMaskedPan": "454671******7894",
"cardIssuer": "Akbank",
"cardType": "Credit",
"cardBrand": "VISA",
"cardAlias": "My Work Card"
},
{
"cardToken": "token_def456",
"cardTranId": "tran_uvw321",
"cardMaskedPan": "540061******1234",
"cardIssuer": "İş Bankası",
"cardType": "Debit",
"cardBrand": "MASTERCARD",
"cardAlias": "Personal Card"
}
]
},
"success": true,
"responseCode": "200",
"responseMessage": "SUCCESS"
}
// First, fetch stored cards
const cards = await getStoredCardList({
mpCode: 'MP12345',
apiSecretKey: 'sx',
mpCustomerKey: '12345678901',
apiKey: calculateApiKey()
});
// Show cards to user, let them choose
const selectedCard = cards.data.storedCardList[0];
// Payment with stored card
await createPayment({
// ... other parameters
bankCard: {
isThreeD: true,
registerCard: false
// Card details are NOT SENT
},
customerCardInfo: {
mpCustomerKey: '12345678901',
cardTranId: selectedCard.cardTranId, // OR
cardToken: selectedCard.cardToken
}
});

Fetches installment options from Pay N Kolay.

TEST:

POST https://apitest.paynkolay.com.tr/marketplace/v1/payment/fetchInstallments

PROD:

POST https://api.paynkolay.com.tr/marketplace/v1/payment/fetchInstallments
{
"mpCode": "MP12345",
"apiSecretKey": "sx_value",
"cardNumber": "45467112",
"amount": 1000.00,
"isCardValid": false
}
ParameterTypeRequiredDescription
mpCodeStringMarketplace code
apiSecretKeyStringSX value
cardNumberStringFirst 6-8 digits of card number or full number
amountBigDecimalTransaction amount
isCardValidBooleanIf true, card validity is checked
{
"data": {
"cardScope": "WORLD",
"paymentInstallments": [
{
"installment": 1,
"installmentAmount": 1000.00,
"cardTrxType": "CREDIT",
"bankCode": "0046",
"commissionAmount": 0.00,
"commissionRate": 0.00,
"trxAmount": 1000.00,
"currencyCode": "TRY",
"currencyNumber": "949",
"program": "WORLD",
"cardBankNo": "0046",
"plusInstallment": 0,
"encodedValue": "encoded_value_1"
},
{
"installment": 2,
"installmentAmount": 510.00,
"cardTrxType": "CREDIT",
"bankCode": "0046",
"commissionAmount": 20.00,
"commissionRate": 2.00,
"trxAmount": 1020.00,
"currencyCode": "TRY",
"currencyNumber": "949",
"program": "WORLD",
"cardBankNo": "0046",
"plusInstallment": 0,
"encodedValue": "encoded_value_2"
}
]
},
"success": true,
"responseCode": "200",
"responseMessage": "SUCCESS"
}
// 1. Fetch installment options
const installments = await fetchPaymentInstallments({
mpCode: 'MP12345',
apiSecretKey: 'sx',
cardNumber: cardNumber.substring(0, 8),
amount: 1000.00
});
// 2. Show installment options to user
installments.data.paymentInstallments.forEach(inst => {
console.log(`${inst.installment} Installments: ${inst.installmentAmount} TL`);
});
// 3. User made a selection (e.g., 2 installments)
const selectedInstallment = installments.data.paymentInstallments[1];
// 4. Create payment
await createPayment({
// ... other parameters
installment: selectedInstallment.installment,
isFetchInstallments: true,
encodedValue: selectedInstallment.encodedValue
});

Updates the commission information of a payment transaction. Can only be used within the transaction day.

TEST:

POST https://apitest.paynkolay.com.tr/marketplace/v1/payment/updateCommission

PROD:

POST https://api.paynkolay.com.tr/marketplace/v1/payment/updateCommission
{
"mpCode": "MP12345",
"refCode": "REF123456789",
"trxCode": "ORDER_12345",
"sellerList": [
{
"sellerExternalId": "SELLER_001",
"commissionAmount": 5.00,
"trxAmount": 100.00,
"withholdingTax": 0.80,
"sellerDiscountAmount": 0.00
}
]
}
{
"data": [
{
"mpCode": "MP12345",
"refCode": "REF123456789",
"trxCode": "ORDER_12345",
"trxCurrency": "TRY",
"trxAmount": 100.00,
"trxStatus": "SUCCESS",
"sellerTransactionList": [
{
"sellerName": "Ahmet Yılmaz",
"trxAmount": 100.00,
"trxCurrency": "TRY",
"trxStatus": "SUCCESS",
"pfCommissionRate": 2.50,
"pfCommissionAmount": 2.50,
"mpCommissionRate": 5.00,
"mpCommissionAmount": 5.00,
"mpCost": 0.50,
"trxType": "SALES",
"withholdingTax": 0.80
}
]
}
],
"success": true,
"responseCode": "200",
"responseMessage": "SUCCESS"
}
class MarketplacePayment {
async processPayment(orderData) {
try {
// 1. Fetch installment options
const installments = await this.fetchInstallments(
orderData.cardNumber,
orderData.amount
);
// 2. Calculate withholding tax
const sellers = orderData.items.map(item => ({
sellerExternalId: item.sellerId,
trxAmount: item.price,
withholdingTax: this.calculateWithholdingTax(item.priceWithoutVAT),
sellerDiscountAmount: item.sellerDiscount || 0
}));
// 3. Calculate ApiKey
const apiKey = this.calculateApiKey();
// 4. Create payment
const payment = await this.createPayment({
apiKey,
apiSecretKey: this.apiSecretKey,
bankCard: {
cardHolder: orderData.cardHolder,
cardNumber: orderData.cardNumber,
cvv: orderData.cvv,
expiryMonth: orderData.expiryMonth,
expiryYear: orderData.expiryYear,
isThreeD: true,
registerCard: orderData.saveCard
},
installment: orderData.selectedInstallment,
trxAmount: orderData.amount,
trxCode: orderData.orderId,
trxType: 'SALES',
trxCurrency: 'TRY',
callbackUrl: 'https://yoursite.com/payment-callback',
sellerList: sellers,
marketplaceCode: this.mpCode,
customerCardInfo: {
mpCustomerKey: orderData.customerId
}
});
// 5. Show 3D form
if (payment.data.form) {
const htmlForm = Buffer.from(
payment.data.form,
'base64'
).toString('utf-8');
return { type: '3D_FORM', html: htmlForm };
}
return { type: 'SUCCESS', data: payment.data };
} catch (error) {
console.error('Payment error:', error);
throw error;
}
}
calculateWithholdingTax(amountWithoutVAT) {
return amountWithoutVAT * 0.01; // 1% withholding tax
}
}

After learning about payment operations:

  1. Payment Modifications - Cancel and refund operations
  2. Masterpass Integration - Alternative payment methods
  3. Reporting - Transaction reports