@achyutlabsau/vue-payment-gateway 0.2.0 → 0.2.2

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 CHANGED
@@ -1,141 +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.
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.
package/dist/mx51.d.ts CHANGED
@@ -4,7 +4,85 @@ import { DefineComponent } from 'vue';
4
4
  import { PublicProps } from 'vue';
5
5
  import { Spi } from '@mx51/spi-client-js';
6
6
 
7
- export declare const PairMX51: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
7
+ /**
8
+ * Attempts to cancel a transaction
9
+ * Be subscribed to TxFlowStateChanged event to see how it goes
10
+ * Wait for the transaction to be finished and then see whether cancellation was successful or not
11
+ *
12
+ **/
13
+ export declare function cancelTransaction(): void;
14
+
15
+ /**
16
+ * Initiates a Get Transaction request
17
+ * Use this when you want to retrieve from one of the last 10 transactions that was processed by the Eftpos
18
+ * Be subscribed to TxFlowStateChanged event to get updates on the process
19
+ *
20
+ * @param posRefId - The unique identifier of the transaction you want to get
21
+ **/
22
+ export declare function getTransaction(posRefId?: string): void;
23
+
24
+ export declare function log(message: string, event?: any): void;
25
+
26
+ export declare const PairMX51: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, HTMLDivElement>;
27
+
28
+ /**
29
+ * Initiates a purchase transaction
30
+ * Be subscribed to TxFlowStateChanged event to get updates on the process
31
+ * Tip and cashout are not allowed simultaneously
32
+ **/
33
+ export declare function purchase({ purchaseAmount, tipAmount, cashoutAmount, promptForCashout, surchargeAmount, }: PurchaseOptions): void;
34
+
35
+ declare interface PurchaseOptions {
36
+ /**
37
+ * The Purchase amount in cents
38
+ */
39
+ purchaseAmount: number;
40
+ /**
41
+ * The Tip amount in cents
42
+ */
43
+ tipAmount: number;
44
+ /**
45
+ * The Cashout amount in cents
46
+ */
47
+ cashoutAmount: number;
48
+ /**
49
+ * Whether to prompt your customer for cashout on the Eftpos
50
+ */
51
+ promptForCashout: boolean;
52
+ /**
53
+ * The Surcharge amount in cents
54
+ */
55
+ surchargeAmount: number;
56
+ }
57
+
58
+ /**
59
+ * Initiates a refund transaction
60
+ * Be subscribed to TxFlowStateChanged event to get updates on the process
61
+ *
62
+ * @param posRefId - A unique identifier for your Refund
63
+ * @param amountCents - The amount in cents
64
+ * @param options - Set custom Header and Footer text for the Receipt
65
+ **/
66
+ export declare function refund({ refundAmount }: {
67
+ refundAmount: number;
68
+ }): void;
69
+
70
+ /**
71
+ * Initiates a Settlement transaction
72
+ * Be subscribed to TxFlowStateChanged event to get updates on the process
73
+ *
74
+ * @param posRefId - A unique identifier for your Settlement
75
+ * @param options - Set custom Header and Footer text for the Receipt
76
+ **/
77
+ export declare function settlement(): void;
78
+
79
+ /**
80
+ * Initiates a Settlement Enquiry transaction
81
+ *
82
+ * @param posRefId - A unique identifier for your Settlement Enquiry
83
+ * @param options - Set custom Header and Footer text for the Receipt
84
+ **/
85
+ export declare function settlementEnquiry(): void;
8
86
 
9
87
  /**
10
88
  * Instantiate the SPI library as an instance object
@@ -16,6 +94,10 @@ export declare const PairMX51: DefineComponent< {}, {}, {}, {}, {}, Component
16
94
  **/
17
95
  export declare const spi: Spi;
18
96
 
97
+ export declare const TransactionDialog: DefineComponent< {}, {
98
+ showDialog: (amount: number) => void;
99
+ }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
100
+
19
101
  export { }
20
102
 
21
103
 
package/dist/mx51.js CHANGED
@@ -1,5 +1,8 @@
1
- import { Spi, TransactionOptions, SuccessState, TransactionType } from "@mx51/spi-client-js";
2
- import { defineComponent, ref, computed, onMounted, resolveComponent, resolveDirective, openBlock, createElementBlock, Fragment, createVNode, withCtx, createElementVNode, createCommentVNode, createBlock, toDisplayString, unref, withDirectives } from "vue";
1
+ import { Spi, TransactionOptions, SuccessState, TransactionType, SpiStatus } from "@mx51/spi-client-js";
2
+ import { defineComponent, ref, computed, onMounted, resolveDirective, openBlock, createElementBlock, createVNode, unref, withCtx, createElementVNode, createCommentVNode, createBlock, toDisplayString, withDirectives } from "vue";
3
+ import { QForm, QSelect, QInput, QCheckbox, QIcon, QBtn, QDialog, QCard, QCardSection, Dialog } from "quasar";
4
+ import { useEventListener } from "@vueuse/core";
5
+ import { v4 } from "uuid";
3
6
  const spiSettings = {
4
7
  posVendorId: "Pratham Respos",
5
8
  // your POS company name/id
@@ -17,12 +20,18 @@ const spiSettings = {
17
20
  signatureFlowOnEftpos: false
18
21
  // signature flow and receipts on terminal instead of POS
19
22
  };
20
- const getTenants = () => {
21
- return Spi.GetAvailableTenants(
22
- spiSettings.posVendorId,
23
- spiSettings.deviceApiKey,
24
- spiSettings.countryCode
25
- );
23
+ const getTenants = async () => {
24
+ try {
25
+ const res = await Spi.GetAvailableTenants(
26
+ spiSettings.posVendorId,
27
+ spiSettings.deviceApiKey,
28
+ spiSettings.countryCode
29
+ );
30
+ return res.Data;
31
+ } catch (error) {
32
+ console.warn(error);
33
+ return [];
34
+ }
26
35
  };
27
36
  const getPairingData = () => {
28
37
  try {
@@ -47,14 +56,11 @@ const spi = new Spi(
47
56
  getSecrets()
48
57
  );
49
58
  spi.SetTenantCode(pairingData.tenantCode ?? "gko");
50
- spi.SetPosInfo(spiSettings.posVendorId, spiSettings.posVersion);
51
- spi.SetDeviceApiKey(spiSettings.deviceApiKey);
52
59
  spi.SetSecureWebSockets(spiSettings.secureWebSockets);
53
60
  spi.Config.PrintMerchantCopy = spiSettings.printMerchantCopyOnEftpos;
54
61
  spi.Config.PromptForCustomerCopyOnEftpos = spiSettings.promptForCustomerCopyOnEftpos;
55
62
  spi.Config.SignatureFlowOnEftpos = spiSettings.signatureFlowOnEftpos;
56
- new TransactionOptions();
57
- spi.Start();
63
+ const receiptOptions = new TransactionOptions();
58
64
  function log(message, event) {
59
65
  if (event) {
60
66
  spi._log.info(`${message} -> `, event);
@@ -148,33 +154,36 @@ function cancelPairing() {
148
154
  log("Pairing cancelled");
149
155
  spi.PairingCancel();
150
156
  }
151
- const _hoisted_1 = { class: "rounded bg-gray-100 p-3" };
152
- const _hoisted_2 = {
157
+ const _hoisted_1$1 = { class: "my-6 w-full max-w-lg rounded-md bg-white p-6 shadow-md" };
158
+ const _hoisted_2$1 = { class: "rounded bg-gray-100 p-3" };
159
+ const _hoisted_3$1 = {
153
160
  key: 0,
154
161
  class: "flex items-center gap-1 font-semibold"
155
162
  };
156
- const _hoisted_3 = {
163
+ const _hoisted_4$1 = {
157
164
  key: 1,
158
165
  class: "flex items-center gap-1 font-semibold"
159
166
  };
160
- const _hoisted_4 = {
167
+ const _hoisted_5$1 = {
161
168
  key: 2,
162
169
  class: "flex items-center gap-1 font-semibold"
163
170
  };
164
- const _hoisted_5 = { class: "text-center font-semibold text-gray-500 uppercase" };
165
- const _hoisted_6 = { class: "py-3 text-center text-2xl font-semibold text-slate-700 uppercase" };
166
- const _hoisted_7 = { class: "text-center font-semibold text-gray-500 uppercase" };
167
- const _sfc_main = /* @__PURE__ */ defineComponent({
171
+ const _hoisted_6 = { class: "text-center font-semibold text-gray-500 uppercase" };
172
+ const _hoisted_7 = { class: "py-3 text-center text-2xl font-semibold text-slate-700 uppercase" };
173
+ const _hoisted_8 = { class: "text-center font-semibold text-gray-500 uppercase" };
174
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
168
175
  __name: "PairMX51",
169
176
  setup(__props) {
170
177
  const tenants = ref([]);
171
178
  const model = ref(false);
172
179
  const pairStatus = ref(spi._currentStatus);
173
- const isPaired = computed(
174
- () => ["PairedConnected", "PairedConnecting"].includes(pairStatus.value)
175
- );
180
+ const isPaired = computed(() => {
181
+ return [SpiStatus.PairedConnected, SpiStatus.PairedConnecting].includes(
182
+ pairStatus.value
183
+ );
184
+ });
176
185
  const pairForm = ref({
177
- posId: "TA",
186
+ posId: "",
178
187
  serialNumber: "",
179
188
  tenantCode: "",
180
189
  eftposAddress: "",
@@ -187,10 +196,26 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
187
196
  message: "Connecting to eftpos",
188
197
  confirmationCode: ""
189
198
  });
190
- document.addEventListener("StatusChanged", (e) => {
199
+ const onPairTerminal = () => {
200
+ pair(pairForm.value);
201
+ };
202
+ const onUnpairTerminal = () => {
203
+ unpair();
204
+ Dialog.create({
205
+ title: "Successfully Unpaired!",
206
+ message: "Unpair the terminal from the device menu if it remains paired."
207
+ });
208
+ };
209
+ onMounted(async () => {
210
+ const res = await getTenants();
211
+ if (res) {
212
+ tenants.value = res;
213
+ }
214
+ });
215
+ useEventListener(document, "StatusChanged", (e) => {
191
216
  pairStatus.value = e.detail;
192
217
  });
193
- document.addEventListener("PairingFlowStateChanged", (e) => {
218
+ useEventListener(document, "PairingFlowStateChanged", (e) => {
194
219
  var _a, _b, _c, _d, _e, _f, _g;
195
220
  model.value = true;
196
221
  pairInfo.value.message = (_a = e == null ? void 0 : e.detail) == null ? void 0 : _a.Message;
@@ -208,37 +233,16 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
208
233
  return;
209
234
  }
210
235
  });
211
- const onPairTerminal = () => {
212
- pair(pairForm.value);
213
- };
214
- const onUnpairTerminal = () => {
215
- unpair();
216
- };
217
- onMounted(async () => {
218
- const res = await getTenants();
219
- if (res.Data) {
220
- tenants.value = res.Data;
221
- }
222
- });
223
236
  return (_ctx, _cache) => {
224
- const _component_QSelect = resolveComponent("QSelect");
225
- const _component_QInput = resolveComponent("QInput");
226
- const _component_QCheckbox = resolveComponent("QCheckbox");
227
- const _component_q_icon = resolveComponent("q-icon");
228
- const _component_q_btn = resolveComponent("q-btn");
229
- const _component_QForm = resolveComponent("QForm");
230
- const _component_q_card_section = resolveComponent("q-card-section");
231
- const _component_q_card = resolveComponent("q-card");
232
- const _component_QDialog = resolveComponent("QDialog");
233
237
  const _directive_close_popup = resolveDirective("close-popup");
234
- return openBlock(), createElementBlock(Fragment, null, [
235
- createVNode(_component_QForm, {
238
+ return openBlock(), createElementBlock("div", _hoisted_1$1, [
239
+ createVNode(unref(QForm), {
236
240
  onSubmit: onPairTerminal,
237
- class: "my-6 w-full max-w-lg space-y-4 rounded-md bg-white p-6 shadow-md"
241
+ class: "space-y-4"
238
242
  }, {
239
243
  default: withCtx(() => [
240
- _cache[10] || (_cache[10] = createElementVNode("div", { class: "font-sans text-lg font-semibold text-gray-600" }, " Mx 51 Terminal Pairing ", -1)),
241
- createVNode(_component_QSelect, {
244
+ _cache[11] || (_cache[11] = createElementVNode("div", { class: "font-sans text-lg font-semibold text-gray-600" }, " Mx 51 Terminal Pairing ", -1)),
245
+ createVNode(unref(QSelect), {
242
246
  disable: isPaired.value,
243
247
  dense: "",
244
248
  class: "my-6",
@@ -254,68 +258,77 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
254
258
  rules: [(v) => !!v || "Please select tenant"],
255
259
  hint: "Choose the Tenant"
256
260
  }, null, 8, ["disable", "modelValue", "options", "rules"]),
257
- createVNode(_component_QInput, {
261
+ createVNode(unref(QInput), {
262
+ disable: isPaired.value,
263
+ dense: "",
264
+ outlined: "",
265
+ modelValue: pairForm.value.posId,
266
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => pairForm.value.posId = $event),
267
+ label: "POS ID",
268
+ rules: [(v) => !!v || "POS ID is required"]
269
+ }, null, 8, ["disable", "modelValue", "rules"]),
270
+ createVNode(unref(QInput), {
258
271
  disable: isPaired.value,
259
272
  dense: "",
260
273
  outlined: "",
261
274
  modelValue: pairForm.value.serialNumber,
262
- "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => pairForm.value.serialNumber = $event),
275
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => pairForm.value.serialNumber = $event),
263
276
  label: "Serial Number",
264
277
  rules: [(v) => !!v || "Serial Number is required"],
265
- hint: "Enter the Serial Number associated with the merchant"
278
+ hint: "Enter the Serial Number associated with the terminal"
266
279
  }, null, 8, ["disable", "modelValue", "rules"]),
267
- createVNode(_component_QInput, {
280
+ createVNode(unref(QInput), {
268
281
  disable: isPaired.value,
269
282
  dense: "",
270
283
  outlined: "",
271
284
  modelValue: pairForm.value.eftposAddress,
272
- "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => pairForm.value.eftposAddress = $event),
285
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => pairForm.value.eftposAddress = $event),
273
286
  label: "Eftpos Address",
274
287
  rules: [(v) => !!v || "Eftpos Address is required"],
275
288
  hint: "Enter the Eftpos Address associated with the merchant"
276
289
  }, null, 8, ["disable", "modelValue", "rules"]),
277
290
  createElementVNode("div", null, [
278
- createVNode(_component_QCheckbox, {
291
+ createVNode(unref(QCheckbox), {
279
292
  label: "Test Mode",
280
293
  modelValue: pairForm.value.testMode,
281
- "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => pairForm.value.testMode = $event),
294
+ "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => pairForm.value.testMode = $event),
282
295
  disable: isPaired.value,
283
296
  dense: ""
284
297
  }, null, 8, ["modelValue", "disable"])
285
298
  ]),
286
- createVNode(_component_QCheckbox, {
299
+ createVNode(unref(QCheckbox), {
287
300
  disable: isPaired.value,
288
301
  dense: "",
289
302
  label: "Auto Address Mode",
290
303
  modelValue: pairForm.value.autoAddressResolution,
291
- "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => pairForm.value.autoAddressResolution = $event)
304
+ "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => pairForm.value.autoAddressResolution = $event)
292
305
  }, null, 8, ["disable", "modelValue"]),
293
- createElementVNode("div", _hoisted_1, [
294
- _cache[9] || (_cache[9] = createElementVNode("div", { class: "text-sm font-medium text-gray-500" }, "Pairing Status", -1)),
295
- pairStatus.value === "PairedConnected" ? (openBlock(), createElementBlock("div", _hoisted_2, [
296
- createVNode(_component_q_icon, {
306
+ createElementVNode("div", _hoisted_2$1, [
307
+ _cache[10] || (_cache[10] = createElementVNode("div", { class: "text-sm font-medium text-gray-500" }, "Pairing Status", -1)),
308
+ pairStatus.value === unref(SpiStatus).PairedConnected ? (openBlock(), createElementBlock("div", _hoisted_3$1, [
309
+ createVNode(unref(QIcon), {
297
310
  name: "check_circle",
298
311
  size: "xs",
299
312
  color: "green"
300
313
  }),
301
- _cache[6] || (_cache[6] = createElementVNode("div", null, "Paired and Connected", -1))
302
- ])) : pairStatus.value === "Unpaired" ? (openBlock(), createElementBlock("div", _hoisted_3, [
303
- createVNode(_component_q_icon, {
314
+ _cache[7] || (_cache[7] = createElementVNode("div", null, "Paired and Connected", -1))
315
+ ])) : pairStatus.value === unref(SpiStatus).Unpaired ? (openBlock(), createElementBlock("div", _hoisted_4$1, [
316
+ createVNode(unref(QIcon), {
304
317
  name: "cancel",
305
318
  size: "xs",
306
319
  color: "red"
307
320
  }),
308
- _cache[7] || (_cache[7] = createElementVNode("div", null, "Unpaired", -1))
309
- ])) : pairStatus.value === "PairedConnecting" ? (openBlock(), createElementBlock("div", _hoisted_4, [
310
- createVNode(_component_q_icon, {
321
+ _cache[8] || (_cache[8] = createElementVNode("div", null, "Unpaired", -1))
322
+ ])) : pairStatus.value === unref(SpiStatus).PairedConnecting ? (openBlock(), createElementBlock("div", _hoisted_5$1, [
323
+ createVNode(unref(QIcon), {
311
324
  name: "check_circle",
312
325
  size: "xs",
313
326
  color: "yellow-8"
314
327
  }),
315
- _cache[8] || (_cache[8] = createElementVNode("div", null, "Paired and trying to connect", -1))
328
+ _cache[9] || (_cache[9] = createElementVNode("div", null, "Paired and trying to connect", -1))
316
329
  ])) : createCommentVNode("", true)
317
330
  ]),
318
- !isPaired.value ? (openBlock(), createBlock(_component_q_btn, {
331
+ !isPaired.value ? (openBlock(), createBlock(unref(QBtn), {
319
332
  key: 0,
320
333
  label: "Pair Terminal",
321
334
  type: "submit",
@@ -324,7 +337,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
324
337
  unelevated: "",
325
338
  "no-caps": "",
326
339
  ripple: false
327
- })) : (openBlock(), createBlock(_component_q_btn, {
340
+ })) : (openBlock(), createBlock(unref(QBtn), {
328
341
  key: 1,
329
342
  label: "Unpair",
330
343
  type: "button",
@@ -339,18 +352,18 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
339
352
  ]),
340
353
  _: 1
341
354
  }),
342
- createVNode(_component_QDialog, {
355
+ createVNode(unref(QDialog), {
343
356
  modelValue: model.value,
344
- "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => model.value = $event),
357
+ "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => model.value = $event),
345
358
  persistent: ""
346
359
  }, {
347
360
  default: withCtx(() => [
348
- createVNode(_component_q_card, { class: "w-full p-3" }, {
361
+ createVNode(unref(QCard), { class: "w-full p-3" }, {
349
362
  default: withCtx(() => [
350
- pairInfo.value.state === "INPROGRESS" ? (openBlock(), createBlock(_component_q_card_section, { key: 0 }, {
363
+ pairInfo.value.state === "INPROGRESS" ? (openBlock(), createBlock(unref(QCardSection), { key: 0 }, {
351
364
  default: withCtx(() => [
352
- createElementVNode("div", _hoisted_5, toDisplayString(pairInfo.value.message), 1),
353
- createVNode(_component_q_btn, {
365
+ createElementVNode("div", _hoisted_6, toDisplayString(pairInfo.value.message), 1),
366
+ createVNode(unref(QBtn), {
354
367
  label: "Cancel",
355
368
  onClick: unref(cancelPairing),
356
369
  color: "primary",
@@ -362,17 +375,17 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
362
375
  }, null, 8, ["onClick"])
363
376
  ]),
364
377
  _: 1
365
- })) : pairInfo.value.state === "CONFIRMATION" ? (openBlock(), createBlock(_component_q_card_section, { key: 1 }, {
378
+ })) : pairInfo.value.state === "CONFIRMATION" ? (openBlock(), createBlock(unref(QCardSection), { key: 1 }, {
366
379
  default: withCtx(() => [
367
- _cache[11] || (_cache[11] = createElementVNode("div", { class: "text-center font-semibold text-gray-500 uppercase" }, " Confirm your pairing code ", -1)),
368
- createElementVNode("div", _hoisted_6, toDisplayString(pairInfo.value.confirmationCode), 1),
369
- _cache[12] || (_cache[12] = createElementVNode("div", { class: "text-center text-sm text-gray-500" }, " Confirm the matching pairing code on the terminal ", -1))
380
+ _cache[12] || (_cache[12] = createElementVNode("div", { class: "text-center font-semibold text-gray-500 uppercase" }, " Confirm your pairing code ", -1)),
381
+ createElementVNode("div", _hoisted_7, toDisplayString(pairInfo.value.confirmationCode), 1),
382
+ _cache[13] || (_cache[13] = createElementVNode("div", { class: "text-center text-sm text-gray-500" }, " Confirm the matching pairing code on the terminal ", -1))
370
383
  ]),
371
384
  _: 1
372
- })) : pairInfo.value.state === "FINISHED" ? (openBlock(), createBlock(_component_q_card_section, { key: 2 }, {
385
+ })) : pairInfo.value.state === "FINISHED" ? (openBlock(), createBlock(unref(QCardSection), { key: 2 }, {
373
386
  default: withCtx(() => [
374
- createElementVNode("div", _hoisted_7, toDisplayString(pairInfo.value.message), 1),
375
- withDirectives(createVNode(_component_q_btn, {
387
+ createElementVNode("div", _hoisted_8, toDisplayString(pairInfo.value.message), 1),
388
+ withDirectives(createVNode(unref(QBtn), {
376
389
  label: "OK",
377
390
  color: "primary",
378
391
  outline: "",
@@ -392,11 +405,239 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
392
405
  ]),
393
406
  _: 1
394
407
  }, 8, ["modelValue"])
395
- ], 64);
408
+ ]);
409
+ };
410
+ }
411
+ });
412
+ function posRefIdGenerator(type) {
413
+ return (/* @__PURE__ */ new Date()).toISOString() + "-" + type + v4();
414
+ }
415
+ function purchase({
416
+ purchaseAmount,
417
+ tipAmount,
418
+ cashoutAmount,
419
+ promptForCashout,
420
+ surchargeAmount
421
+ }) {
422
+ spi.AckFlowEndedAndBackToIdle();
423
+ spi.InitiatePurchaseTxV2(
424
+ posRefIdGenerator("purchase"),
425
+ // posRefId
426
+ purchaseAmount,
427
+ tipAmount,
428
+ cashoutAmount,
429
+ promptForCashout,
430
+ receiptOptions,
431
+ // options
432
+ surchargeAmount
433
+ );
434
+ }
435
+ function refund({ refundAmount }) {
436
+ spi.AckFlowEndedAndBackToIdle();
437
+ spi.InitiateRefundTx(
438
+ posRefIdGenerator("refund"),
439
+ // posRefId
440
+ refundAmount,
441
+ // amountCents
442
+ false,
443
+ receiptOptions
444
+ // options
445
+ );
446
+ }
447
+ function getTransaction(posRefId) {
448
+ if (!posRefId) {
449
+ spi.InitiateGetLastTx();
450
+ } else {
451
+ spi.InitiateGetTx(posRefId);
452
+ }
453
+ }
454
+ function cancelTransaction() {
455
+ spi.CancelTransaction();
456
+ }
457
+ function settlement() {
458
+ spi.AckFlowEndedAndBackToIdle();
459
+ spi.InitiateSettleTx(posRefIdGenerator("settlement"), receiptOptions);
460
+ }
461
+ function settlementEnquiry() {
462
+ spi.AckFlowEndedAndBackToIdle();
463
+ spi.InitiateSettlementEnquiry(
464
+ posRefIdGenerator("settlementEnquiry"),
465
+ receiptOptions
466
+ );
467
+ }
468
+ function overrideTransaction(isSuccess) {
469
+ if (isSuccess) {
470
+ spi.AckFlowEndedAndBackToIdle();
471
+ } else {
472
+ spi.AckFlowEndedAndBackToIdle();
473
+ }
474
+ }
475
+ const _hoisted_1 = { class: "text-center font-semibold text-gray-500 uppercase" };
476
+ const _hoisted_2 = { class: "text-center font-semibold text-gray-500" };
477
+ const _hoisted_3 = { class: "text-center font-semibold text-gray-500" };
478
+ const _hoisted_4 = { class: "grid grid-cols-2 gap-3" };
479
+ const _hoisted_5 = { class: "text-center font-semibold text-gray-500" };
480
+ const _sfc_main = /* @__PURE__ */ defineComponent({
481
+ __name: "TransactionDialog",
482
+ setup(__props, { expose: __expose }) {
483
+ const pairInfo = ref({
484
+ state: "INPROGRESS",
485
+ message: "Processing"
486
+ });
487
+ const model = ref(false);
488
+ const transactionAmount = ref(0);
489
+ document.addEventListener("TxFlowStateChanged", (e) => {
490
+ model.value = true;
491
+ if (e.detail.AttemptingToCancel) {
492
+ pairInfo.value.state = "AWAITING_CANCELLATION";
493
+ pairInfo.value.message = "Please wait";
494
+ }
495
+ if (e.detail.AwaitingSignatureCheck) ;
496
+ else if (e.detail.AwaitingPhoneForAuth) ;
497
+ else if (e.detail.Finished) {
498
+ switch (e.detail.Success) {
499
+ case SuccessState.Success:
500
+ pairInfo.value.state = "SUCCESS";
501
+ switch (e.detail.Type) {
502
+ case TransactionType.Purchase:
503
+ break;
504
+ case TransactionType.Refund:
505
+ break;
506
+ }
507
+ break;
508
+ case SuccessState.Failed:
509
+ const ResponseData = e.detail.Response.Data;
510
+ pairInfo.value.message = ResponseData.error_detail ?? "Failed";
511
+ pairInfo.value.state = "FAILED";
512
+ break;
513
+ case SuccessState.Unknown:
514
+ pairInfo.value.state = "MANUAL_RECOVERY";
515
+ break;
516
+ }
517
+ }
518
+ });
519
+ spi.TransactionUpdateMessage = (e) => {
520
+ pairInfo.value.message = e.Data.display_message_text;
521
+ };
522
+ const showDialog = (amount) => {
523
+ transactionAmount.value = amount;
524
+ pairInfo.value.state = "INPROGRESS";
525
+ pairInfo.value.message = "Processing";
526
+ model.value = true;
527
+ };
528
+ __expose({ showDialog });
529
+ return (_ctx, _cache) => {
530
+ const _directive_close_popup = resolveDirective("close-popup");
531
+ return openBlock(), createBlock(unref(QDialog), {
532
+ modelValue: model.value,
533
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => model.value = $event),
534
+ persistent: ""
535
+ }, {
536
+ default: withCtx(() => [
537
+ createVNode(unref(QCard), { class: "w-96 p-3" }, {
538
+ default: withCtx(() => [
539
+ pairInfo.value.state === "INPROGRESS" ? (openBlock(), createBlock(unref(QCardSection), { key: 0 }, {
540
+ default: withCtx(() => [
541
+ createElementVNode("div", _hoisted_1, " Purchase of $" + toDisplayString(transactionAmount.value) + " in progress... ", 1),
542
+ createElementVNode("div", _hoisted_2, toDisplayString(pairInfo.value.message), 1),
543
+ createVNode(unref(QBtn), {
544
+ label: "Cancel",
545
+ onClick: unref(cancelTransaction),
546
+ color: "primary",
547
+ outline: "",
548
+ class: "!mt-6 !w-full",
549
+ unelevated: "",
550
+ "no-caps": "",
551
+ ripple: false
552
+ }, null, 8, ["onClick"])
553
+ ]),
554
+ _: 1
555
+ })) : pairInfo.value.state === "AWAITING_CANCELLATION" ? (openBlock(), createBlock(unref(QCardSection), { key: 1 }, {
556
+ default: withCtx(() => [
557
+ _cache[3] || (_cache[3] = createElementVNode("div", { class: "text-center font-semibold text-gray-500 uppercase" }, " Attempting to cancel transaction ", -1)),
558
+ createElementVNode("div", _hoisted_3, toDisplayString(pairInfo.value.message), 1)
559
+ ]),
560
+ _: 1
561
+ })) : pairInfo.value.state === "MANUAL_RECOVERY" ? (openBlock(), createBlock(unref(QCardSection), { key: 2 }, {
562
+ default: withCtx(() => [
563
+ _cache[4] || (_cache[4] = createElementVNode("div", { class: "text-center font-semibold text-gray-500 uppercase" }, " Was the transaction successful ", -1)),
564
+ _cache[5] || (_cache[5] = createElementVNode("div", { class: "text-center font-semibold text-gray-500" }, " Check the EFTPOS terminal ", -1)),
565
+ createElementVNode("div", _hoisted_4, [
566
+ createVNode(unref(QBtn), {
567
+ label: "Yes",
568
+ color: "primary",
569
+ onClick: _cache[0] || (_cache[0] = ($event) => unref(overrideTransaction)(true)),
570
+ outline: "",
571
+ class: "!mt-6",
572
+ unelevated: "",
573
+ "no-caps": "",
574
+ ripple: false
575
+ }),
576
+ createVNode(unref(QBtn), {
577
+ label: "No",
578
+ color: "primary",
579
+ outline: "",
580
+ onClick: _cache[1] || (_cache[1] = ($event) => unref(overrideTransaction)(false)),
581
+ class: "!mt-6",
582
+ unelevated: "",
583
+ "no-caps": "",
584
+ ripple: false
585
+ })
586
+ ])
587
+ ]),
588
+ _: 1
589
+ })) : pairInfo.value.state === "SUCCESS" ? (openBlock(), createBlock(unref(QCardSection), { key: 3 }, {
590
+ default: withCtx(() => [
591
+ _cache[6] || (_cache[6] = createElementVNode("div", { class: "text-center font-semibold text-gray-500 uppercase" }, " Transaction Successful ", -1)),
592
+ withDirectives(createVNode(unref(QBtn), {
593
+ label: "OK",
594
+ color: "primary",
595
+ outline: "",
596
+ class: "!mt-6 !w-full",
597
+ unelevated: "",
598
+ "no-caps": "",
599
+ ripple: false
600
+ }, null, 512), [
601
+ [_directive_close_popup]
602
+ ])
603
+ ]),
604
+ _: 1
605
+ })) : pairInfo.value.state === "FAILED" ? (openBlock(), createBlock(unref(QCardSection), { key: 4 }, {
606
+ default: withCtx(() => [
607
+ _cache[7] || (_cache[7] = createElementVNode("div", { class: "text-center font-semibold text-gray-500 uppercase" }, " Transaction Failed ", -1)),
608
+ createElementVNode("div", _hoisted_5, toDisplayString(pairInfo.value.message), 1),
609
+ withDirectives(createVNode(unref(QBtn), {
610
+ label: "OK",
611
+ color: "primary",
612
+ outline: "",
613
+ class: "!mt-6 !w-full",
614
+ unelevated: "",
615
+ "no-caps": "",
616
+ ripple: false
617
+ }, null, 512), [
618
+ [_directive_close_popup]
619
+ ])
620
+ ]),
621
+ _: 1
622
+ })) : createCommentVNode("", true)
623
+ ]),
624
+ _: 1
625
+ })
626
+ ]),
627
+ _: 1
628
+ }, 8, ["modelValue"]);
396
629
  };
397
630
  }
398
631
  });
399
632
  export {
400
- _sfc_main as PairMX51,
633
+ _sfc_main$1 as PairMX51,
634
+ _sfc_main as TransactionDialog,
635
+ cancelTransaction,
636
+ getTransaction,
637
+ log,
638
+ purchase,
639
+ refund,
640
+ settlement,
641
+ settlementEnquiry,
401
642
  spi
402
643
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@achyutlabsau/vue-payment-gateway",
3
3
  "private": false,
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",