quickpos 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+ const crypto = require('crypto');
2
+ const axios = require('axios');
3
+
4
+ class Cryptomus {
5
+ constructor(config) {
6
+ const requiredFields = ['merchantId', 'paymentKey'];
7
+ for (let field of requiredFields) {
8
+ if (!config[field]) throw new Error(`Missing required field: ${field}`);
9
+ }
10
+
11
+ this.merchantId = config.merchantId;
12
+ this.paymentKey = config.paymentKey;
13
+ this.apiUrl = 'https://api.cryptomus.com/v1';
14
+ }
15
+
16
+ createSignature(payload) {
17
+ const data = Buffer.from(JSON.stringify(payload)).toString('base64');
18
+ return crypto.createHash('md5').update(data + this.paymentKey).digest('hex');
19
+ }
20
+
21
+ async createPayment(options) {
22
+ const payload = {
23
+ merchant_id: this.merchantId,
24
+ order_id: options.orderId,
25
+ amount: options.amount,
26
+ currency: options.currency || 'USD',
27
+ network: options.network || 'ETH',
28
+ url_callback: options.callbackUrl,
29
+ url_return: options.returnUrl,
30
+ is_payment_multiple: false,
31
+ lifetime: options.lifetime || 3600,
32
+ to_currency: options.toCurrency || 'ETH'
33
+ };
34
+
35
+ const sign = this.createSignature(payload);
36
+
37
+ try {
38
+ const response = await axios.post(`${this.apiUrl}/payment`, payload, {
39
+ headers: {
40
+ 'merchant': this.merchantId,
41
+ 'sign': sign
42
+ }
43
+ });
44
+ return response.data;
45
+ } catch (error) {
46
+ return error.response.data;
47
+ }
48
+ }
49
+
50
+ async getPaymentStatus(orderId) {
51
+ const payload = {
52
+ merchant_id: this.merchantId,
53
+ order_id: orderId
54
+ };
55
+
56
+ const sign = this.createSignature(payload);
57
+
58
+ try {
59
+ const response = await axios.post(`${this.apiUrl}/payment/status`, payload, {
60
+ headers: {
61
+ 'merchant': this.merchantId,
62
+ 'sign': sign
63
+ }
64
+ });
65
+ return response.data;
66
+ } catch (error) {
67
+ throw new Error(`Payment status query error: ${error.message}`);
68
+ }
69
+ }
70
+
71
+ async testWebhook(payload) {
72
+ const sign = this.createSignature(payload);
73
+
74
+ try {
75
+ const response = await axios.post(`${this.apiUrl}/test-webhook/payment`, payload, {
76
+ headers: {
77
+ 'merchant': this.merchantId,
78
+ 'sign': sign
79
+ }
80
+ });
81
+ return response.data;
82
+ }
83
+ catch (error) {
84
+ throw new Error(`Test webhook error: ${error.message}`);
85
+ }
86
+ }
87
+
88
+ verifyWebhook(payload, signature) {
89
+ if (payload?.sign) delete payload.sign;
90
+ const data = Buffer.from(JSON.stringify(payload)).toString('base64');
91
+ const hash = crypto.createHash('md5').update(data + this.paymentKey).digest('hex');
92
+ return hash === signature;
93
+ }
94
+
95
+ async handleCallback(callbackData) {
96
+ try {
97
+ if (!this.verifyWebhook(callbackData, callbackData.sign)) {
98
+ throw new Error("Cryptomus notification failed: invalid signature");
99
+ }
100
+
101
+ if (callbackData.status === 'paid') {
102
+ return {
103
+ status: 'success',
104
+ orderId: callbackData.order_id,
105
+ uuid: callbackData.uuid,
106
+ amount: parseFloat(callbackData.amount),
107
+ payment_amount: parseFloat(callbackData.payment_amount),
108
+ payment_amount_usd: parseFloat(callbackData.payment_amount_usd),
109
+ currency: callbackData.currency,
110
+ paymentMethod: callbackData.payment_method,
111
+ network: callbackData.network
112
+ };
113
+ } else {
114
+ throw new Error(`Payment failed with status: ${callbackData.status}`);
115
+ }
116
+ } catch (error) {
117
+ throw new Error(`Error in Cryptomus callback handling: ${error.message}`);
118
+ }
119
+ }
120
+ }
121
+
122
+ module.exports = Cryptomus;
package/lib/paytr.js CHANGED
@@ -100,7 +100,8 @@ class PayTR {
100
100
  if (callbackData.status === 'success') {
101
101
  return {
102
102
  status: 'success',
103
- orderId: callbackData.merchant_oid,
103
+ orderId: callbackData.callback_id,
104
+ merchant_oid: callbackData.merchant_oid,
104
105
  amount: parseFloat(callbackData.total_amount) / 100,
105
106
  currency: callbackData.currency,
106
107
  paymentType: callbackData.payment_type
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickpos",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "main": "app.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -23,7 +23,8 @@
23
23
  "paynet",
24
24
  "stripe",
25
25
  "paypal",
26
- "shopier"
26
+ "shopier",
27
+ "cryptomus"
27
28
  ],
28
29
  "repository": {
29
30
  "type": "git",
package/readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # 💳 QuickPos 🚀
2
2
 
3
- QuickPos, farklı ödeme sağlayıcılarını destekleyen güçlü bir ödeme entegrasyon modülüdür. Şu anda PayTR sağlayıcısını desteklemektedir ve gelecekte birçok yeni sağlayıcı ile özellik eklemeyi planlamaktadır. Yol haritamıza göz atarak gelecek özellikleri keşfedebilirsiniz.
3
+ QuickPos, farklı ödeme sağlayıcılarını destekleyen güçlü bir ödeme entegrasyon modülüdür. Şu anda PayTR, Shopier, Cryptomus sağlayıcısını desteklemektedir ve gelecekte birçok yeni sağlayıcı ile özellik eklemeyi planlamaktadır. Yol haritamıza göz atarak gelecek özellikleri keşfedebilirsiniz.
4
4
 
5
5
  ---
6
6
 
@@ -134,6 +134,7 @@ const quickPos = new QuickPos({
134
134
 
135
135
  - PayTR
136
136
  - Shopier
137
+ - Cryptomus
137
138
 
138
139
  ---
139
140
 
@@ -149,6 +150,8 @@ const quickPos = new QuickPos({
149
150
  ### İlerleme Durumu
150
151
 
151
152
  - [x] PayTR entegrasyonu
153
+ - [x] Shopier entegrasyonu
154
+ - [x] Cryptomus entegrasyonu
152
155
  - [ ] İyzico entegrasyonu
153
156
  - [ ] Vallet entegrasyonu
154
157
  - [ ] Shipy entegrasyonu