-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunTest.js
More file actions
194 lines (175 loc) · 5.21 KB
/
runTest.js
File metadata and controls
194 lines (175 loc) · 5.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
const PayMaya = require('./index');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// PayMaya istemcisi
const paymaya = new PayMaya({
publicKey: 'pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah',
secretKey: 'sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl',
environment: 'SANDBOX'
});
// Menü
function showMenu() {
console.log('\n==== PAYMAYA TEST MENÜSÜ ====');
console.log('1. Ödeme Sayfası Oluştur');
console.log('2. Fatura Oluştur');
console.log('3. Webhook Ayarla');
console.log('4. Test Bilgilerini Göster');
console.log('0. Çıkış');
rl.question('\nLütfen bir seçenek girin (0-4): ', async (answer) => {
switch(answer) {
case '1':
await createCheckout();
break;
case '2':
await createInvoice();
break;
case '3':
await setupWebhooks();
break;
case '4':
showTestInfo();
break;
case '0':
console.log('Programdan çıkılıyor...');
rl.close();
return;
default:
console.log('Geçersiz seçenek!');
}
// Ana menüye dön
setTimeout(showMenu, 1000);
});
}
// Ödeme Sayfası Oluştur
async function createCheckout() {
console.log('\n=== ÖDEME SAYFASI OLUŞTURULUYOR ===');
const checkoutData = {
totalAmount: {
value: 100.00,
currency: 'PHP',
},
buyer: {
firstName: 'John',
lastName: 'Doe',
contact: {
phone: '+639123456789',
email: 'john.doe@example.com'
},
shippingAddress: {
line1: '123 Test Street',
city: 'Manila',
state: 'Metro Manila',
zipCode: '1234',
countryCode: 'PH'
},
billingAddress: {
line1: '123 Test Street',
city: 'Manila',
state: 'Metro Manila',
zipCode: '1234',
countryCode: 'PH'
}
},
items: [
{
name: 'Test Product',
quantity: 1,
code: 'TST01',
description: 'Test ürün',
amount: {
value: 100.00
},
totalAmount: {
value: 100.00
}
}
],
redirectUrl: {
success: 'https://www.example.com/success',
failure: 'https://www.example.com/failure',
cancel: 'https://www.example.com/cancel'
},
requestReferenceNumber: 'REF-' + Date.now()
};
try {
const result = await paymaya.checkout.create(checkoutData);
console.log('Ödeme sayfası oluşturuldu!');
console.log('Ödeme URL\'si:', result.redirectUrl);
console.log('Checkout ID:', result.checkoutId);
} catch (error) {
console.error('Hata:', error.message);
}
}
// Fatura Oluştur
async function createInvoice() {
console.log('\n=== FATURA OLUŞTURULUYOR ===');
const invoiceData = {
totalAmount: {
value: 150.00,
currency: 'PHP',
},
buyer: {
firstName: 'John',
lastName: 'Doe',
contact: {
phone: '+639123456789',
email: 'john.doe@example.com'
}
},
title: 'Test Faturası',
description: 'Test fatura açıklaması',
redirectUrl: {
success: 'https://www.example.com/success',
failure: 'https://www.example.com/failure'
},
requestReferenceNumber: 'INV-' + Date.now(),
expiryDate: new Date(Date.now() + (7 * 24 * 60 * 60 * 1000)).toISOString() // 7 gün sonra
};
try {
const result = await paymaya.invoice.create(invoiceData);
console.log('Fatura oluşturuldu!');
console.log('Fatura URL\'si:', result.redirectUrl);
console.log('Fatura ID:', result.id);
} catch (error) {
console.error('Hata:', error.message);
}
}
// Webhook Ayarla
async function setupWebhooks() {
console.log('\n=== WEBHOOK AYARLANIYOR ===');
try {
// Mevcut webhook'ları listele
const webhooks = await paymaya.webhooks.list();
console.log('Mevcut Webhook\'lar:', webhooks);
// Yeni webhook ekle
const webhook = {
name: 'CHECKOUT_SUCCESS',
callbackUrl: 'https://www.example.com/webhook/success'
};
const result = await paymaya.webhooks.register(webhook);
console.log('Webhook eklendi:', result);
} catch (error) {
console.error('Hata:', error.message);
}
}
// Test bilgilerini göster
function showTestInfo() {
console.log('\n=== TEST BİLGİLERİ ===');
console.log('Sandbox API Keys:');
console.log('Public Key: pk-Z0OSzLvIcOI2UIvDhdTGVVfRSSeiGStnceqwUE7n0Ah');
console.log('Secret Key: sk-X8qolYjy62kIzEbr0QRK1h4b4KDVHaNcwMYk39jInSl');
console.log('\nTest Kartları:');
console.log('MASTERCARD: 5123456789012346, 12/2025, CVV: 111');
console.log('MASTERCARD (3DS): 5453010000064154, 12/2025, CVV: 111, 3DS Şifre: secbarry1');
console.log('VISA: 4123450131001381, 12/2025, CVV: 123, 3DS Şifre: mctest1');
console.log('\nMaya E-wallet Test Hesabı:');
console.log('Kullanıcı Adı: 09193890579');
console.log('Şifre: Password@1');
console.log('OTP: 123456');
}
// Programı başlat
console.log('PayMaya Sandbox Test Programı');
showMenu();