shopier
v1.0.4
Published
Shopier Payment API Gateway for Node.js
Maintainers
Readme
Shopier Node.js
Shopier ödeme sistemi için Node.js/TypeScript kütüphanesi.
Kurulum
npm install shopierKullanım
CommonJS
const {
Shopier,
Buyer,
Address,
ProductType,
WebsiteIndex,
ShopierButtonRenderer
} = require('shopier');
// Shopier instance oluştur
const shopier = new Shopier('API_KEY', 'API_SECRET');
// Alıcı bilgilerini oluştur
const buyer = new Buyer({
id: '101',
name: 'Ahmet',
surname: 'Yılmaz',
email: '[email protected]',
phone: '5551234567',
});
// Adres bilgilerini oluştur
const address = new Address({
address: 'Atatürk Caddesi No: 123',
city: 'İstanbul',
country: 'Türkiye',
postcode: '34000',
});
// Parametreleri ayarla
const params = shopier.getParams();
params.setWebsiteIndex(WebsiteIndex.SITE_1);
params.setBuyer(buyer);
params.setAddress(address);
params.setOrderData('ORDER-12345', '150.00');
params.setProductData('Premium Üyelik', ProductType.DOWNLOADABLE_VIRTUAL);
// HTML çıktısını al
const renderer = new ShopierButtonRenderer(shopier);
const html = shopier.goWith(renderer);ES Modules / TypeScript
import {
Shopier,
Buyer,
Address,
ProductType,
WebsiteIndex,
ShopierButtonRenderer
} from 'shopier';
### Express.js ile Kullanım
```typescript
import express from 'express';
import { Shopier, ShopierResponse, Buyer, Address } from 'shopier';
const app = express();
app.use(express.urlencoded({ extended: true }));
// Ödeme sayfası
app.get('/payment', (req, res) => {
const shopier = new Shopier('API_KEY', 'API_SECRET');
// ... parametreleri ayarla
const html = shopier.go();
res.send(html);
});
// Callback endpoint
app.post('/payment/callback', (req, res) => {
const response = ShopierResponse.fromPostData(req.body);
if (response.hasValidSignature('API_SECRET')) {
// Ödeme başarılı
console.log('Sipariş ID:', response.getPlatformOrderId());
} else {
// Geçersiz imza
res.status(400).send('Invalid signature');
}
});Renderer Tipleri
ShopierButtonRenderer
Shopier temalı buton ile ödeme formu.
const renderer = new ShopierButtonRenderer(shopier);
renderer.setName('Öde'); // Buton metnini değiştirAutoSubmitFormRenderer
Sayfa yüklendiğinde otomatik olarak ödeme sayfasına yönlendirir.
const renderer = new AutoSubmitFormRenderer(shopier);IframeRenderer
Ödeme formunu iframe içinde gösterir.
const renderer = new IframeRenderer(shopier);
renderer.setWidth(600).setHeight(750).setCenter(true);FormRenderer
Basit form render'ı.
const renderer = new FormRenderer(shopier);Para Birimleri
import { Currency } from 'shopier';
params.setCurrency(Currency.TL); // Türk Lirası
params.setCurrency(Currency.USD); // Amerikan Doları
params.setCurrency(Currency.EUR); // EuroDil Seçenekleri
import { Language } from 'shopier';
params.setCurrentLanguage(Language.TR); // Türkçe
params.setCurrentLanguage(Language.EN); // İngilizceÜrün Tipleri
import { ProductType } from 'shopier';
params.setProductData('Ürün', ProductType.REAL); // Fiziksel ürün
params.setProductData('Ürün', ProductType.DOWNLOADABLE_VIRTUAL); // Dijital ürün
params.setProductData('Ürün', ProductType.DEFAULT_TYPE); // VarsayılanAPI Referansı
Shopier
| Metod | Açıklama |
|-------|----------|
| getParams() | ShopierParams instance'ını döndürür |
| go() | Otomatik submit HTML'i döndürür |
| goWith(renderer) | Renderer ile HTML döndürür |
| validateResponse(data) | Yanıt imzasını doğrular |
| calculateSignature() | İmzayı hesaplar |
ShopierParams
| Metod | Açıklama |
|-------|----------|
| setBuyer(buyer) | Alıcı bilgilerini ayarlar |
| setAddress(address) | Hem fatura hem kargo adresini ayarlar |
| setBillingAddress(address) | Fatura adresini ayarlar |
| setShippingAddress(address) | Kargo adresini ayarlar |
| setOrderData(orderId, total, callback?) | Sipariş bilgilerini ayarlar |
| setProductData(name, type?) | Ürün bilgilerini ayarlar |
| setCurrency(currency) | Para birimini ayarlar |
| setCurrentLanguage(language) | Dili ayarlar |
| setWebsiteIndex(index) | Website indexini ayarlar |
ShopierResponse
| Metod | Açıklama |
|-------|----------|
| fromPostData(data) | POST verisinden instance oluşturur |
| hasValidSignature(secret) | İmzayı doğrular |
| isSuccess() | Ödeme başarılı mı? |
| getPlatformOrderId() | Sipariş ID'sini döndürür |
| getPaymentId() | Ödeme ID'sini döndürür |
| getInstallment() | Taksit sayısını döndürür |
Lisans
MIT
