Esc
Start typing to search...

Payment Operations

Payment Operations Overview #

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

Withholding Tax Use Reminder #


1. CreatePayment #

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

Endpoint #

TEST:

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

PROD:

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

Request Parameters #

{
  "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
  }
}

Parameter Details #

Basic Parameters #
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
Card Information (bankCard) #
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)
Installment Information #
ParameterTypeRequiredDescription
installmentIntegerNumber of installments (1 = single payment)
isFetchInstallmentsBooleanFetch installment info from Paynkolay?
encodedValueStringEncoded value from FetchPaymentInstallments
Seller List (sellerList) #
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
Discounts and Fees #
ParameterTypeRequiredDescription
shippingCostBigDecimalShipping fee
otherAmountBigDecimalOther fees
mpDiscountAmountBigDecimalMarketplace discount amount
totalDiscountAmountBigDecimalTotal discount amount
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)

Response #

Successful Response #

{
  "data": {
    "refCode": "REF123456789",
    "trxCode": "ORDER_12345",
    "form": "PGh0bWw+...3D HTML Form Base64..."
  },
  "success": true,
  "responseCode": "200",
  "responseMessage": "SUCCESS"
}

Response Parameters #

ParameterTypeDescription
refCodeStringPaynkolay reference code
trxCodeStringYour transaction code
formStringBase64 encoded HTML form (filled in 3D transactions)

3D Secure Transaction Flow #

sequenceDiagram
    participant Client as Müşteri Tarayıcı
    participant Your as Sizin Sunucu
    participant PNK as Paynkolay
    participant Bank as Banka 3D

    Client->>Your: Ödeme Formu Gönder
    Your->>PNK: CreatePayment (isThreeD=true)
    PNK->>Your: form (Base64 HTML)
    Your->>Your: Base64 Decode
    Your->>Client: HTML Form Render
    Client->>Bank: 3D Doğrulama
    Bank->>Client: SMS/OTP
    Client->>Bank: Kod Gir
    Bank->>Your: callbackUrl'e POST
    Your->>Your: Hash Doğrula
    Your->>Client: Sonuç Sayfası

3D Form Processing #

// Yanıttaki form'u decode et
const response = await createPayment(paymentData);

if (response.success && response.data.form) {
  // Base64 decode
  const htmlForm = Buffer.from(response.data.form, 'base64').toString('utf-8');

  // HTML'i müşteriye göster
  res.send(htmlForm);
}

Callback Handling #

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;

  // Hash doğrula
  // verifyCallbackHash fonksiyonu detayları için: Hash Hesaplama sayfası
  if (!verifyCallbackHash(req.body, apiSecretKey)) {
    return res.status(400).send('Invalid hash');
  }

  // Başarılı ödeme
  if (responseCode === '00' || responseCode === '0000') {
    // Siparişi onayla
    updateOrderStatus(trxCode, 'PAID');
  } else {
    // Hata durumu
    updateOrderStatus(trxCode, 'FAILED');
  }

  res.status(200).send('OK');
});

2. GetPaymentStatus #

Queries the status of a payment transaction.

Endpoint #

TEST:

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

PROD:

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

Request #

{
  "refCode": "REF123456789",
  "trxCode": "ORDER_12345"
}

Response #

{
  "data": [
    {
      "trxStatus": "SUCCESS",
      "trxCode": "ORDER_12345",
      "refCode": "REF123456789",
      "trxType": "SALES",
      "trxAmount": 150.00,
      "trxCurrency": "TRY"
    }
  ],
  "success": true,
  "responseCode": "200",
  "responseMessage": "SUCCESS"
}

Status Codes #

CodeDescription
SUCCESSSuccessful transaction
PENDINGTransaction in progress
FAILEDFailed transaction
CANCELLEDCancelled
REFUNDEDRefunded

3. GetStoredCardList #

Lists stored cards belonging to a customer.

Endpoint #

TEST:

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

PROD:

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

Request #

{
  "mpCode": "MP12345",
  "apiSecretKey": "sx_value",
  "mpCustomerKey": "12345678901",
  "apiKey": "calculated_api_key"
}

Response #

{
  "data": {
    "cardTotalCount": 2,
    "storedCardList": [
      {
        "cardToken": "token_abc123",
        "cardTranId": "tran_xyz789",
        "cardMaskedPan": "454671******7894",
        "cardIssuer": "Akbank",
        "cardType": "Credit",
        "cardBrand": "VISA",
        "cardAlias": "İş Kartım"
      },
      {
        "cardToken": "token_def456",
        "cardTranId": "tran_uvw321",
        "cardMaskedPan": "540061******1234",
        "cardIssuer": "İş Bankası",
        "cardType": "Debit",
        "cardBrand": "MASTERCARD",
        "cardAlias": "Kişisel Kart"
      }
    ]
  },
  "success": true,
  "responseCode": "200",
  "responseMessage": "SUCCESS"
}

Payment with Stored Card #

// Önce saklı kartları çek
const cards = await getStoredCardList({
  mpCode: 'MP12345',
  apiSecretKey: 'sx',
  mpCustomerKey: '12345678901',
  apiKey: calculateApiKey()
});

// Kullanıcıya kartları göster, seçim yaptır
const selectedCard = cards.data.storedCardList[0];

// Saklı kart ile ödeme
await createPayment({
  // ... diğer parametreler
  bankCard: {
    isThreeD: true,
    registerCard: false
    // Kart bilgileri GÖNDERİLMEZ
  },
  customerCardInfo: {
    mpCustomerKey: '12345678901',
    cardTranId: selectedCard.cardTranId,  // VEYA
    cardToken: selectedCard.cardToken
  }
});

4. FetchPaymentInstallments #

Fetches installment options from Paynkolay.

Endpoint #

TEST:

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

PROD:

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

Request #

{
  "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

Response #

{
  "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"
}

Installment Selection and Payment #

// 1. Taksit seçeneklerini çek
const installments = await fetchPaymentInstallments({
  mpCode: 'MP12345',
  apiSecretKey: 'sx',
  cardNumber: cardNumber.substring(0, 8),
  amount: 1000.00
});

// 2. Kullanıcıya taksit seçeneklerini göster
installments.data.paymentInstallments.forEach(inst => {
  console.log(`${inst.installment} Taksit: ${inst.installmentAmount} TL`);
});

// 3. Kullanıcı seçim yaptı (örn: 2 taksit)
const selectedInstallment = installments.data.paymentInstallments[1];

// 4. Ödemeyi oluştur
await createPayment({
  // ... diğer parametreler
  installment: selectedInstallment.installment,
  isFetchInstallments: true,
  encodedValue: selectedInstallment.encodedValue
});

5. UpdatePaymentCommission #

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

Endpoint #

TEST:

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

PROD:

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

Request #

{
  "mpCode": "MP12345",
  "refCode": "REF123456789",
  "trxCode": "ORDER_12345",
  "sellerList": [
    {
      "sellerExternalId": "SELLER_001",
      "commissionAmount": 5.00,
      "trxAmount": 100.00,
      "withholdingTax": 0.80,
      "sellerDiscountAmount": 0.00
    }
  ]
}

Response #

{
  "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"
}

Complete Payment Flow Example #

class MarketplacePayment {
  async processPayment(orderData) {
    try {
      // 1. Taksit seçeneklerini çek
      const installments = await this.fetchInstallments(
        orderData.cardNumber,
        orderData.amount
      );

      // 2. Stopaj hesapla
      const sellers = orderData.items.map(item => ({
        sellerExternalId: item.sellerId,
        trxAmount: item.price,
        withholdingTax: this.calculateWithholdingTax(item.priceWithoutVAT),
        sellerDiscountAmount: item.sellerDiscount || 0
      }));

      // 3. ApiKey hesapla
      const apiKey = this.calculateApiKey(
        orderData.orderId,
        orderData.amount,
        'TRY',
        'SALES'
      );

      // 4. Ödeme oluştur
      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. 3D form'u göster
      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 stopaj
  }
}

Next Steps #

After learning about payment operations: