@achyutlabsau/vue-payment-gateway 0.0.1

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.
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # Vue Payment Gateway
2
+
3
+ A Vue.js payment gateway library to handle payments with ease.
4
+
5
+ ## Installation
6
+
7
+ To install the library, run the following command:
8
+
9
+ ```bash
10
+ npm install @achyutlabsau/vue-payment-gateway
11
+ ```
12
+
13
+ ## Plugin Initialization
14
+
15
+ To use the payment gateway, you need to initialize the plugin in your Vue app. Here’s an example of how to set it up:
16
+
17
+ ```javascript
18
+ import VuePaymentGateway from "@achyutlabsau/vue-payment-gateway";
19
+
20
+ app.use(VuePaymentGateway, {
21
+ productName: "Pratham Respos", // Name of your product
22
+ productVersion: "3.3.0", // Version of your product
23
+ productVendorName: "Achyutlabs", // Name of the product vendor
24
+ posId: "unique-pos-id", // Unique identifier for the POS system
25
+ posRegisterId: "pos-register-id", // Unique identifier for the POS register
26
+ posRegisterName: "register-name", // Name of the POS register
27
+ posBusinessName: "business name", // Name of the business using the POS system
28
+ tyroApiKey: "tyro-api-key", // API key for Tyro integration
29
+ environment: "development", // Set environment to 'development' or 'production'
30
+ });
31
+ ```
32
+
33
+ > **Note:** Replace the placeholder values with the actual details of your POS system, product, and Tyro API key.
34
+
35
+ ## Using the Payment Gateway
36
+
37
+ This library supports multiple payment providers, such as Tyro, SmartPay, and Linkly. Here’s how to use them in your application.
38
+
39
+ ### Using Tyro
40
+
41
+ To use the Tyro payment gateway, import and initialize it as shown below:
42
+
43
+ ```javascript
44
+ import { useTyro } from "@achyutlabsau/vue-payment-gateway/tyro";
45
+
46
+ const tyro = useTyro();
47
+
48
+ // Example usage
49
+ await tyro.processPayment(amount, options);
50
+ ```
51
+
52
+ ### Using SmartPay
53
+
54
+ To use the SmartPay payment gateway, import and initialize it as shown below:
55
+
56
+ ```javascript
57
+ import { useSmartPay } from "@achyutlabsau/vue-payment-gateway/smartpay";
58
+
59
+ const smartPay = useSmartPay();
60
+
61
+ // Example usage
62
+ await smartPay.processPayment(amount, options);
63
+ ```
64
+
65
+ ### Using Linkly
66
+
67
+ To use the Linkly payment gateway, import and initialize it as shown below:
68
+
69
+ ```javascript
70
+ import { useLinkly } from "@achyutlabsau/vue-payment-gateway/linkly";
71
+
72
+ const linkly = useLinkly();
73
+
74
+ // Example usage
75
+ await linkly.processPayment(amount, options);
76
+ ```
77
+
78
+ ## Payment Method API
79
+
80
+ Each payment provider (Tyro, SmartPay, Linkly) provides methods to process payments. Here are some of the most commonly used methods:
81
+
82
+ ### `processPayment(amount: number, options?: object)`
83
+
84
+ Processes a payment for the specified amount.
85
+
86
+ **Parameters:**
87
+
88
+ - `amount`: The amount to be charged.
89
+ - `options`: (Optional) Additional options for the payment.
90
+
91
+ ### `cancelPayment()`
92
+
93
+ Cancels an ongoing payment.
94
+
95
+ ### `getStatus()`
96
+
97
+ Gets the status of the current payment transaction.
98
+
99
+ > **Note:** The methods may differ slightly between Tyro, SmartPay, and Linkly. Refer to the official documentation of each payment provider for more details.
100
+
101
+ ## Environment Configuration
102
+
103
+ The environment can be set to either `development` or `production`. Make sure to use `development` during testing and switch to `production` in a live environment to ensure security and proper tracking.
104
+
105
+ ```javascript
106
+ app.use(VuePaymentGateway, {
107
+ ...
108
+ environment: "production", // Set to 'production' in a live environment
109
+ });
110
+ ```
111
+
112
+ ## Example Usage
113
+
114
+ Here’s a complete example of how you might use the payment gateway to process a payment with Tyro:
115
+
116
+ ```javascript
117
+ import { useTyro } from "@achyutlabsau/vue-payment-gateway/tyro";
118
+
119
+ const tyro = useTyro();
120
+
121
+ async function handlePayment() {
122
+ try {
123
+ const paymentResult = await tyro.processPayment(100, { currency: "USD" });
124
+ console.log("Payment successful:", paymentResult);
125
+ } catch (error) {
126
+ console.error("Payment failed:", error);
127
+ }
128
+ }
129
+ ```
130
+
131
+ ## Troubleshooting
132
+
133
+ - **Environment Issues**: Make sure `environment` is set correctly (`development` or `production`).
134
+ - **Invalid API Key**: Ensure the Tyro API key is valid and correctly set in the configuration.
135
+ - **Payment Processing Issues**: Check if the payment provider's service is online and available.
136
+
137
+ ## Additional Resources
138
+
139
+ For more details and usage examples, refer to the official documentation or support channels provided by [Achyutlabs](https://achyutlabs.com/).
140
+
141
+ With this guide, you should be able to set up and use the Vue Payment Gateway efficiently to handle payments with Tyro, SmartPay, and Linkly integrations.
@@ -0,0 +1,15 @@
1
+ import axios from "axios";
2
+ const generateTransactionId = () => {
3
+ const timestamp = Date.now().toString();
4
+ const randomComponent = Math.floor(1e3 + Math.random() * 9e3).toString();
5
+ return `${timestamp}${randomComponent}`.slice(0, 16);
6
+ };
7
+ const timeout = (interval = 2e3) => new Promise((resolve) => setTimeout(resolve, interval));
8
+ const isServerError = (status) => status && Number(status) >= 500 && Number(status) <= 599;
9
+ const isNetworkError = (error) => axios.isAxiosError(error) && error.code === "ERR_NETWORK";
10
+ export {
11
+ isServerError as a,
12
+ generateTransactionId as g,
13
+ isNetworkError as i,
14
+ timeout as t
15
+ };
@@ -0,0 +1,35 @@
1
+ import { App } from 'vue';
2
+
3
+ declare const _default: {
4
+ install: (_app: App, options: InstallOptions) => void;
5
+ };
6
+ export default _default;
7
+
8
+ /**
9
+ * Generates a numeric transaction ID with a maximum length of 16 characters.
10
+ * The ID is composed of the current timestamp and a 4-digit random component.
11
+ *
12
+ * @returns {string} A unique numeric transaction ID with a maximum length of 16 characters.
13
+ *
14
+ * @example
15
+ * const transactionId = generateTransactionId();
16
+ * console.log(transactionId); // Output: '1699418999123456'
17
+ */
18
+ export declare const generateTransactionId: () => string;
19
+
20
+ declare interface InstallOptions extends POSConfig {
21
+ environment?: "development" | "production";
22
+ }
23
+
24
+ declare interface POSConfig {
25
+ productName: string;
26
+ productVersion: string;
27
+ productVendorName: string;
28
+ posId: string;
29
+ posRegisterId: string;
30
+ posRegisterName: string;
31
+ posBusinessName: string;
32
+ tyroApiKey: string;
33
+ }
34
+
35
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { s as setState, a as setEnvironment, i as isPluginInitialized } from "./state-0HFa2Xwz.js";
2
+ import { g } from "./index-C8vc_75e.js";
3
+ const install = (_app, options) => {
4
+ setState(options);
5
+ options.environment && setEnvironment(options.environment);
6
+ isPluginInitialized.value = true;
7
+ };
8
+ const VuePaymentGateway = { install };
9
+ export {
10
+ VuePaymentGateway as default,
11
+ g as generateTransactionId
12
+ };
@@ -0,0 +1,390 @@
1
+ declare interface Basket {
2
+ id: string;
3
+ amt: number;
4
+ tax: number;
5
+ dis: number;
6
+ sur: number;
7
+ items: BasketItem[];
8
+ }
9
+
10
+ declare interface BasketItem {
11
+ id: string;
12
+ sku: string;
13
+ qty: number;
14
+ amt: number;
15
+ tax: number;
16
+ dis: number;
17
+ name: string;
18
+ }
19
+
20
+ declare type BooleanishString = "0" | "1";
21
+
22
+ export declare enum CurrencyCodes {
23
+ AustralianDollar = "AUD"
24
+ }
25
+
26
+ export declare interface LinklyAuthPayload {
27
+ /**
28
+ * The secret returned from the cloud pairing process
29
+ */
30
+ secret: string;
31
+ /**
32
+ * The name of the POS requesting the token
33
+ */
34
+ posName: string;
35
+ /**
36
+ * The version of the POS requesting the token
37
+ */
38
+ posVersion: string;
39
+ /**
40
+ * A unique UUID v4 which identifies the POS instance. This value is generated by the POS as a part of the POS deployment settings.
41
+ * e.g. Two registers at the same merchant should supply two different PosId values
42
+ */
43
+ posId: string;
44
+ /**
45
+ * A unique UUID v4 which identifies the POS POS product. This value can be hard coded into the build of the POS.
46
+ * e.g. All merchants using the same POS product should supply the same posVendorId value
47
+ */
48
+ posVendorId: string;
49
+ }
50
+
51
+ export declare interface LinklyAuthResponse {
52
+ /**
53
+ * The token to user for authentication.
54
+ */
55
+ token: string;
56
+ /**
57
+ * The number of seconds until the token expires.
58
+ */
59
+ expirySeconds: number;
60
+ }
61
+
62
+ export declare interface LinklyReprintReceiptRequest {
63
+ Request: {
64
+ /**
65
+ * Two Digit Merchant Code. Defaults to "00" (EFTPOS)
66
+ */
67
+ Merchant?: "00" | "99" | string;
68
+ /**
69
+ * Indicates where the request is to be sent to. Defaults to "00" (EFTPOS)
70
+ */
71
+ Application?: "00" | string;
72
+ /**
73
+ * Indicates if the POS is to receive receipt events.
74
+ */
75
+ ReceiptAutoPrint: ReceiptAutoPrint;
76
+ /**
77
+ * Indicates whether Linkly should cut receipts. Defaults to '0' (DontCut)
78
+ */
79
+ CutReceipt?: BooleanishString;
80
+ /**
81
+ * Indicates whether the receipt should be returned or reprinted. Defaults to '2' (GetLast) '1' is Reprint
82
+ */
83
+ ReprintType?: "2";
84
+ /**
85
+ * The original txnRef of the transaction
86
+ */
87
+ OriginalTxnRef?: string;
88
+ PurchaseAnalysisData?: PurchaseAnalysisData;
89
+ };
90
+ Notification?: Notification_2;
91
+ }
92
+
93
+ /**
94
+ * this will be used but currently not using this
95
+ *
96
+ */
97
+ export declare interface LinklyReprintReceiptResponse {
98
+ sessionId: string;
99
+ responseType: "reprintreceipt";
100
+ response: {
101
+ merchant: string;
102
+ receiptText: string[];
103
+ responseCode: string;
104
+ responseText: string;
105
+ success: boolean;
106
+ };
107
+ }
108
+
109
+ export declare interface LinklyTransactionResponse {
110
+ SessionId: string;
111
+ ResponseType: string;
112
+ Response: {
113
+ TxnType: TransactionTypes;
114
+ Merchant: string;
115
+ CardType: string;
116
+ CardName: string;
117
+ RRN: string;
118
+ DateSettlement: string;
119
+ AmtCash: number;
120
+ AmtPurchase: number;
121
+ AmtTip: number;
122
+ AuthCode: string;
123
+ TxnRef: string;
124
+ Pan: string;
125
+ DateExpiry: string;
126
+ Track2: string;
127
+ AccountType: string;
128
+ TxnFlags: {
129
+ Offline: BooleanishString;
130
+ ReceiptPrinted: BooleanishString;
131
+ CardEntry: string;
132
+ CommsMethod: string;
133
+ Currency: string;
134
+ PayPass: string;
135
+ UndefinedFlag6: string;
136
+ UndefinedFlag7: string;
137
+ };
138
+ BalanceReceived: boolean;
139
+ AvailableBalance: number;
140
+ ClearedFundsBalance: number;
141
+ Success: boolean;
142
+ ResponseCode: ResponseCodes | string;
143
+ ResponseText: string;
144
+ Date: string;
145
+ Catid: string;
146
+ Caid: string;
147
+ Stan: number;
148
+ PurchaseAnalysisData: {
149
+ RFN: string;
150
+ REF: string;
151
+ HRC: string;
152
+ HRT: string;
153
+ };
154
+ };
155
+ }
156
+
157
+ declare interface Notification_2 {
158
+ Uri: string;
159
+ AuthorizationHeader: string;
160
+ }
161
+
162
+ export declare type PinpadPairingResult = {
163
+ success: boolean;
164
+ secret: string;
165
+ message: string;
166
+ };
167
+
168
+ export declare interface PinpadPairPayload {
169
+ /**
170
+ * The Linkly Cloud username
171
+ */
172
+ username: string;
173
+ /**
174
+ * The Linkly Cloud password
175
+ */
176
+ password: string;
177
+ /**
178
+ * The pair code displayed on the PIN pad in "pairing" mode
179
+ */
180
+ pairCode: string;
181
+ }
182
+
183
+ export declare interface PinpadPairResponse {
184
+ /**
185
+ * The non-expiring secret the POS uses to request an auth token
186
+ */
187
+ secret: string;
188
+ }
189
+
190
+ declare interface PurchaseAnalysisData {
191
+ OPR: string;
192
+ AMT: string;
193
+ PCM: string;
194
+ }
195
+
196
+ export declare enum ReceiptAutoPrint {
197
+ /**
198
+ * Return all receipts to the POS in a receipt event. Only supported when async=true.
199
+ */
200
+ ReturnToPOS = "0",
201
+ /**
202
+ * Print all merchant/signature receipts from the PINpad printer, return all other receipts to the POS in the transaction/logon/settlement response.
203
+ */
204
+ MixedPrint = "7",
205
+ /**
206
+ * Print all receipts from the PINpad printer.
207
+ */
208
+ AllReceiptsFromPINPad = "9"
209
+ }
210
+
211
+ export declare enum ResponseCodes {
212
+ /**
213
+ * Transaction / function completed successfully
214
+ */
215
+ APPROVED = "00",
216
+ /**
217
+ * Transaction / function completed successfully
218
+ */
219
+ Approved = "08",
220
+ TXN_CANCELLED = "HD",
221
+ /**
222
+ * The customer account does not have sufficient funds for the transaction
223
+ */
224
+ INSUFFICIENT_FUND = "HB",
225
+ /**
226
+ * Unexpected Error
227
+ */
228
+ GENERAL_DECLINE = "99",
229
+ /**
230
+ * Pinpad is offline
231
+ */
232
+ PINPAD_OFFLINE = "PF"
233
+ }
234
+
235
+ export declare enum TransactionOutcome {
236
+ APPROVED = "APPROVED",
237
+ CANCELLED = "CANCELLED",
238
+ DECLINED = "DECLINED",
239
+ UNKNOWN = "UNKNOWN"
240
+ }
241
+
242
+ export declare type TransactionPayload = Pick<TransactionPostRequest, "AmtPurchase" | "ReceiptAutoPrint" | "CutReceipt">;
243
+
244
+ /**
245
+ * View Documentation - https://www.linkly.com.au/apidoc/REST/#purchase
246
+ */
247
+ export declare interface TransactionPostPayload {
248
+ Request: TransactionPostRequest;
249
+ Notification?: Notification_2;
250
+ }
251
+
252
+ export declare interface TransactionPostRequest {
253
+ Merchant: "00";
254
+ /**
255
+ * Indicated the type of transaction to perform
256
+ */
257
+ TxnType: TransactionTypes;
258
+ /**
259
+ * Left zero filled, amount of sale in cents.
260
+ */
261
+ AmtPurchase: number;
262
+ /**
263
+ * The reference number to attach to the transaction. This will appear on the receipt.
264
+ */
265
+ TxnRef: string;
266
+ /**
267
+ * Code to indicate requested currency. e.g. 'AUD'
268
+ */
269
+ CurrencyCode: CurrencyCodes;
270
+ /**
271
+ * Indicates whether Linkly should cut receipts. Defaults to '0' (Don't Cut)
272
+ */
273
+ CutReceipt?: BooleanishString;
274
+ /**
275
+ * Indicates if the POS is to receive receipt events.
276
+ */
277
+ ReceiptAutoPrint: ReceiptAutoPrint;
278
+ /**
279
+ * Instructs Linkly to perform a card payment
280
+ */
281
+ Application: "00";
282
+ PurchaseAnalysisData?: PurchaseAnalysisData;
283
+ Basket?: Basket;
284
+ }
285
+
286
+ export declare enum TransactionTypes {
287
+ Purchase = "P",
288
+ Refund = "R"
289
+ }
290
+
291
+ export declare const useLinkly: () => {
292
+ pairPinpad: (pairData: PinpadPairPayload) => Promise<PinpadPairingResult>;
293
+ initiatePurchase: (data: TransactionPayload) => Promise<{
294
+ result: TransactionOutcome;
295
+ data: {
296
+ TxnType: TransactionTypes;
297
+ Merchant: string;
298
+ CardType: string;
299
+ CardName: string;
300
+ RRN: string;
301
+ DateSettlement: string;
302
+ AmtCash: number;
303
+ AmtPurchase: number;
304
+ AmtTip: number;
305
+ AuthCode: string;
306
+ TxnRef: string;
307
+ Pan: string;
308
+ DateExpiry: string;
309
+ Track2: string;
310
+ AccountType: string;
311
+ TxnFlags: {
312
+ Offline: "0" | "1";
313
+ ReceiptPrinted: "0" | "1";
314
+ CardEntry: string;
315
+ CommsMethod: string;
316
+ Currency: string;
317
+ PayPass: string;
318
+ UndefinedFlag6: string;
319
+ UndefinedFlag7: string;
320
+ };
321
+ BalanceReceived: boolean;
322
+ AvailableBalance: number;
323
+ ClearedFundsBalance: number;
324
+ Success: boolean;
325
+ ResponseCode: ResponseCodes | string;
326
+ ResponseText: string;
327
+ Date: string;
328
+ Catid: string;
329
+ Caid: string;
330
+ Stan: number;
331
+ PurchaseAnalysisData: {
332
+ RFN: string;
333
+ REF: string;
334
+ HRC: string;
335
+ HRT: string;
336
+ };
337
+ };
338
+ }>;
339
+ initiateRefund: (data: TransactionPayload) => Promise<{
340
+ result: TransactionOutcome;
341
+ data: {
342
+ TxnType: TransactionTypes;
343
+ Merchant: string;
344
+ CardType: string;
345
+ CardName: string;
346
+ RRN: string;
347
+ DateSettlement: string;
348
+ AmtCash: number;
349
+ AmtPurchase: number;
350
+ AmtTip: number;
351
+ AuthCode: string;
352
+ TxnRef: string;
353
+ Pan: string;
354
+ DateExpiry: string;
355
+ Track2: string;
356
+ AccountType: string;
357
+ TxnFlags: {
358
+ Offline: "0" | "1";
359
+ ReceiptPrinted: "0" | "1";
360
+ CardEntry: string;
361
+ CommsMethod: string;
362
+ Currency: string;
363
+ PayPass: string;
364
+ UndefinedFlag6: string;
365
+ UndefinedFlag7: string;
366
+ };
367
+ BalanceReceived: boolean;
368
+ AvailableBalance: number;
369
+ ClearedFundsBalance: number;
370
+ Success: boolean;
371
+ ResponseCode: ResponseCodes | string;
372
+ ResponseText: string;
373
+ Date: string;
374
+ Catid: string;
375
+ Caid: string;
376
+ Stan: number;
377
+ PurchaseAnalysisData: {
378
+ RFN: string;
379
+ REF: string;
380
+ HRC: string;
381
+ HRT: string;
382
+ };
383
+ };
384
+ }>;
385
+ reprintReceipt: (txnRef?: string) => Promise<LinklyReprintReceiptResponse>;
386
+ getTransactionBySessionId: (transactionId: string) => Promise<LinklyTransactionResponse>;
387
+ getLastTransaction: () => Promise<LinklyTransactionResponse>;
388
+ };
389
+
390
+ export { }
package/dist/linkly.js ADDED
@@ -0,0 +1,9 @@
1
+ import { C, R, b, T, a, u } from "./useLinkly-Cj-lTWld.js";
2
+ export {
3
+ C as CurrencyCodes,
4
+ R as ReceiptAutoPrint,
5
+ b as ResponseCodes,
6
+ T as TransactionOutcome,
7
+ a as TransactionTypes,
8
+ u as useLinkly
9
+ };