npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

paytr-node

v1.0.1

Published

Node.js integration for PayTR payment gateway

Downloads

19

Readme

PayTR Node.js Integration Module

npm version GitHub license npm downloads

A comprehensive Node.js integration module for PayTR payment gateway. Supports all PayTR payment APIs including iFrame API, Direct API, and Link API.

Türkçe açıklamalar için aşağıya bakın

Features

  • iFrame API integration
  • Direct API integration
  • Link API integration
  • Card Storage and Payments with Saved Cards
  • Recurring Payments
  • BIN Inquiry
  • Installment Rate Queries
  • Refund Operations
  • Order Status Queries
  • Transaction List
  • Payment Reports
  • Platform Transfers (Marketplace)
  • EFT/Bank Transfer support

Installation

npm install paytr-node

Quick Start

Configuration

const PayTR = require('paytr-node');

const paytr = new PayTR({
  merchantId: 'YOUR_MERCHANT_ID',
  merchantKey: 'YOUR_MERCHANT_KEY', 
  merchantSalt: 'YOUR_MERCHANT_SALT',
  testMode: true // true for test mode, false for live mode
});

iFrame API Payment

const token = await paytr.iframe.createToken({
  userIp: '192.168.1.1',
  merchantOid: 'ORDER_123',
  email: 'customer@example.com',
  paymentAmount: '10000', // 100.00 TL = 10000
  userName: 'John Doe',
  userAddress: 'Customer Address',
  userPhone: '05001234567',
  merchantOkUrl: 'https://yoursite.com/success',
  merchantFailUrl: 'https://yoursite.com/fail',
  userBasket: [
    ['Product 1', '5000', 1], // Product name, price (50.00 TL), quantity
    ['Product 2', '5000', 1]
  ]
});

// Use token.token to show the payment page

HTML iframe usage:

<script src="https://www.paytr.com/js/iframeResizer.min.js"></script>
<iframe src="https://www.paytr.com/odeme/guvenli/<?php echo $token['token']; ?>" id="paytriframe" frameborder="0" scrolling="no" style="width:100%;"></iframe>
<script>iFrameResize({}, '#paytriframe');</script>

Direct API Payment

const result = await paytr.direct.createPayment({
  userIp: '192.168.1.1',
  merchantOid: 'ORDER_123',
  email: 'customer@example.com',
  paymentAmount: '10000', // 100.00 TL = 10000
  cardOwner: 'John Doe',
  cardNumber: '4355084355084358',
  cardExpireMonth: '12',
  cardExpireYear: '30',
  cardCvc: '000',
  installmentCount: '0', // Single payment
  userName: 'John Doe',
  userAddress: 'Customer Address',
  userPhone: '05001234567',
  merchantOkUrl: 'https://yoursite.com/success',
  merchantFailUrl: 'https://yoursite.com/fail',
  userBasket: [
    ['Product 1', '5000', 1],
    ['Product 2', '5000', 1]
  ]
});

// Process payment result

Express.js Example

const express = require('express');
const bodyParser = require('body-parser');
const PayTR = require('paytr-node');

const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

// PayTR configuration
const paytr = new PayTR({
  merchantId: 'YOUR_MERCHANT_ID',
  merchantKey: 'YOUR_MERCHANT_KEY',
  merchantSalt: 'YOUR_MERCHANT_SALT',
  testMode: true
});

// Create payment page
app.post('/create-payment', async (req, res) => {
  try {
    const merchantOid = `ORDER_${Date.now()}`;
    const userIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
    
    const result = await paytr.iframe.createToken({
      userIp: userIp,
      merchantOid: merchantOid,
      email: req.body.email || 'customer@example.com',
      paymentAmount: req.body.amount || '10000',
      userName: req.body.name || 'John Doe',
      userAddress: req.body.address || 'Customer Address',
      userPhone: req.body.phone || '05001234567',
      merchantOkUrl: `${req.protocol}://${req.get('host')}/success`,
      merchantFailUrl: `${req.protocol}://${req.get('host')}/fail`,
      userBasket: [
        [req.body.productName || 'Product', req.body.amount || '10000', 1]
      ]
    });

    res.send(`
      <html>
        <head>
          <title>PayTR Payment</title>
          <script src="https://www.paytr.com/js/iframeResizer.min.js"></script>
        </head>
        <body>
          <h1>Payment Page</h1>
          <iframe src="https://www.paytr.com/odeme/guvenli/${result.token}" id="paytriframe" frameborder="0" scrolling="no" style="width: 100%;"></iframe>
          <script>iFrameResize({}, '#paytriframe');</script>
        </body>
      </html>
    `);
  } catch (error) {
    res.status(500).send(`Error: ${error.message}`);
  }
});

// Payment callback handler
app.post('/payment-callback', (req, res) => {
  try {
    const isValid = paytr.iframe.validateHash(req.body);
    
    if (isValid) {
      const { merchant_oid, status } = req.body;
      
      if (status === 'success') {
        console.log(`Order confirmed: ${merchant_oid}`);
        // Update order in database
      } else {
        console.log(`Order rejected: ${merchant_oid}`);
        // Cancel order in database
      }
      
      res.send('OK');
    } else {
      res.status(400).send('Invalid hash');
    }
  } catch (error) {
    res.status(500).send('Error');
  }
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Complete Documentation

For detailed documentation of all features, visit our GitHub repository.

License

MIT License


PayTR Node.js Entegrasyon Modülü

npm version GitHub license npm downloads

PayTR ödeme geçidi için kapsamlı bir Node.js entegrasyon modülüdür. iFrame API, Direct API ve Link API dahil olmak üzere PayTR'nin tüm ödeme API'lerini destekler.

Özellikler

  • iFrame API entegrasyonu
  • Direct API entegrasyonu
  • Link API entegrasyonu
  • Kart Saklama ve Kayıtlı Kart ile Ödeme
  • Tekrarlayan Ödemeler
  • BIN Sorgulama
  • Taksit Oranları Sorgulama
  • İade İşlemleri
  • Durum Sorgulama
  • İşlem Listesi
  • Ödeme Raporu
  • Platform Transfer (Pazaryeri)
  • EFT/Havale desteği

Kurulum

npm install paytr-node

Hızlı Başlangıç

Yapılandırma

const PayTR = require('paytr-node');

const paytr = new PayTR({
  merchantId: 'MERCHANT_ID',
  merchantKey: 'MERCHANT_KEY', 
  merchantSalt: 'MERCHANT_SALT',
  testMode: true // Test modu için true, canlı mod için false
});

iFrame API ile Ödeme

const token = await paytr.iframe.createToken({
  userIp: '192.168.1.1',
  merchantOid: 'SIPARIS_123',
  email: 'musteri@example.com',
  paymentAmount: '10000', // 100.00 TL = 10000
  userName: 'Ahmet Yılmaz',
  userAddress: 'Müşteri Adresi',
  userPhone: '05001234567',
  merchantOkUrl: 'https://siteniz.com/basarili',
  merchantFailUrl: 'https://siteniz.com/basarisiz',
  userBasket: [
    ['Ürün 1', '5000', 1], // Ürün adı, fiyat (50.00 TL), adet
    ['Ürün 2', '5000', 1]
  ]
});

// token.token kullanılarak ödeme sayfası gösterilir

HTML iframe kullanımı:

<script src="https://www.paytr.com/js/iframeResizer.min.js"></script>
<iframe src="https://www.paytr.com/odeme/guvenli/<?php echo $token['token']; ?>" id="paytriframe" frameborder="0" scrolling="no" style="width:100%;"></iframe>
<script>iFrameResize({}, '#paytriframe');</script>

Direct API ile Ödeme

const result = await paytr.direct.createPayment({
  userIp: '192.168.1.1',
  merchantOid: 'SIPARIS_123',
  email: 'musteri@example.com',
  paymentAmount: '10000', // 100.00 TL = 10000
  cardOwner: 'Ahmet Yılmaz',
  cardNumber: '4355084355084358',
  cardExpireMonth: '12',
  cardExpireYear: '30',
  cardCvc: '000',
  installmentCount: '0', // Tek çekim
  userName: 'Ahmet Yılmaz',
  userAddress: 'Müşteri Adresi',
  userPhone: '05001234567',
  merchantOkUrl: 'https://siteniz.com/basarili',
  merchantFailUrl: 'https://siteniz.com/basarisiz',
  userBasket: [
    ['Ürün 1', '5000', 1],
    ['Ürün 2', '5000', 1]
  ]
});

// result ile ödeme sonucu işlenir

Express.js Örneği

const express = require('express');
const bodyParser = require('body-parser');
const PayTR = require('paytr-node');

const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

// PayTR yapılandırması
const paytr = new PayTR({
  merchantId: 'MERCHANT_ID',
  merchantKey: 'MERCHANT_KEY',
  merchantSalt: 'MERCHANT_SALT',
  testMode: true
});

// Ödeme sayfası oluştur
app.post('/odeme-olustur', async (req, res) => {
  try {
    const merchantOid = `SIPARIS_${Date.now()}`;
    const userIp = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
    
    const result = await paytr.iframe.createToken({
      userIp: userIp,
      merchantOid: merchantOid,
      email: req.body.email || 'musteri@example.com',
      paymentAmount: req.body.tutar || '10000',
      userName: req.body.isim || 'Ahmet Yılmaz',
      userAddress: req.body.adres || 'Müşteri Adresi',
      userPhone: req.body.telefon || '05001234567',
      merchantOkUrl: `${req.protocol}://${req.get('host')}/basarili`,
      merchantFailUrl: `${req.protocol}://${req.get('host')}/basarisiz`,
      userBasket: [
        [req.body.urunAdi || 'Ürün', req.body.tutar || '10000', 1]
      ]
    });

    res.send(`
      <html>
        <head>
          <title>PayTR Ödeme</title>
          <script src="https://www.paytr.com/js/iframeResizer.min.js"></script>
        </head>
        <body>
          <h1>Ödeme Sayfası</h1>
          <iframe src="https://www.paytr.com/odeme/guvenli/${result.token}" id="paytriframe" frameborder="0" scrolling="no" style="width: 100%;"></iframe>
          <script>iFrameResize({}, '#paytriframe');</script>
        </body>
      </html>
    `);
  } catch (error) {
    res.status(500).send(`Hata: ${error.message}`);
  }
});

// Ödeme bildirimi işleyici
app.post('/odeme-bildirimi', (req, res) => {
  try {
    const isValid = paytr.iframe.validateHash(req.body);
    
    if (isValid) {
      const { merchant_oid, status } = req.body;
      
      if (status === 'success') {
        console.log(`Sipariş onaylandı: ${merchant_oid}`);
        // Siparişi veritabanında güncelle
      } else {
        console.log(`Sipariş reddedildi: ${merchant_oid}`);
        // Siparişi veritabanında iptal et
      }
      
      res.send('OK');
    } else {
      res.status(400).send('Geçersiz hash');
    }
  } catch (error) {
    res.status(500).send('Hata');
  }
});

app.listen(3000, () => {
  console.log('Sunucu 3000 portunda çalışıyor');
});

Tüm Dökümanlar

Tüm özelliklerin detaylı dökümentasyonu için GitHub repomuzu ziyaret edin.

Lisans

MIT Lisansı