@virgodev/iap 1.0.1 → 1.0.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.
|
@@ -66,7 +66,7 @@ import type {
|
|
|
66
66
|
} from "@stripe/stripe-js";
|
|
67
67
|
import api from "@virgodev/bazaar/functions/api";
|
|
68
68
|
import { onMounted, ref } from "vue";
|
|
69
|
-
import { ProductType, useIapStore } from "../
|
|
69
|
+
import { ProductType, useIapStore } from "../index";
|
|
70
70
|
import type { StripeCart } from "../stores/iap";
|
|
71
71
|
|
|
72
72
|
const props = defineProps<{
|
|
@@ -53,14 +53,16 @@ router.beforeResolve(async (to, from, next) => {
|
|
|
53
53
|
await nextTick();
|
|
54
54
|
if (cart && cart.items.length > 0) {
|
|
55
55
|
const item = cart.items[0];
|
|
56
|
-
const
|
|
56
|
+
const transaction = {
|
|
57
57
|
products: [{ id: item.product.id }],
|
|
58
58
|
platform: Platform.STRIPE,
|
|
59
59
|
transactionId: `${to.query.stripe_session_id}`,
|
|
60
60
|
purchaseId: item.product.id,
|
|
61
61
|
finish: function (): void {},
|
|
62
|
-
}
|
|
62
|
+
};
|
|
63
|
+
const result = await iap.verify(transaction);
|
|
63
64
|
if (result) {
|
|
65
|
+
iap.stripeResult = transaction;
|
|
64
66
|
iap.stripeStatus = "verified";
|
|
65
67
|
delete to.query.stripe_session_id;
|
|
66
68
|
}
|
|
@@ -78,6 +80,11 @@ onMounted(() => {});
|
|
|
78
80
|
|
|
79
81
|
function closeDialog(v: boolean): void {
|
|
80
82
|
if (v === false) {
|
|
83
|
+
if (iap.stripeCallback) {
|
|
84
|
+
iap.stripeCallback(undefined);
|
|
85
|
+
}
|
|
86
|
+
iap.stripeCallback = undefined;
|
|
87
|
+
iap.stripeResult = undefined;
|
|
81
88
|
iap.stripeCart = undefined;
|
|
82
89
|
iap.stripeStatus = undefined;
|
|
83
90
|
visible.value = false;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@virgodev/iap",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"main": "./
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"main": "./index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
7
|
},
|
|
@@ -10,14 +10,15 @@
|
|
|
10
10
|
"description": "",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@stripe/stripe-js": "^8.2.0",
|
|
13
|
+
"@virgodev/iap": "^1.0.1",
|
|
13
14
|
"cordova-plugin-purchase": "^13.12.1"
|
|
14
15
|
},
|
|
15
16
|
"peerDependencies": {
|
|
16
|
-
"@virgodev/bazaar": "^1.2.7",
|
|
17
17
|
"@capacitor/app": "^7.1.0",
|
|
18
18
|
"@capacitor/device": "^7.0.2",
|
|
19
|
-
"
|
|
19
|
+
"@virgodev/bazaar": "^1.2.7",
|
|
20
|
+
"pinia": "^3.0.3",
|
|
20
21
|
"primevue": "^4.4.1",
|
|
21
|
-
"
|
|
22
|
+
"vue-router": "^4.6.3"
|
|
22
23
|
}
|
|
23
24
|
}
|
package/stores/iap.ts
CHANGED
|
@@ -6,7 +6,7 @@ import api from "@virgodev/bazaar/functions/api";
|
|
|
6
6
|
import { localRef } from "@virgodev/bazaar/functions/localstorage/localRef";
|
|
7
7
|
import { createStore } from "@virgodev/vue-models/utils/create_store";
|
|
8
8
|
import { defineStore } from "pinia";
|
|
9
|
-
import { computed, ref, shallowRef } from "vue";
|
|
9
|
+
import { computed, ref, shallowRef, watch } from "vue";
|
|
10
10
|
import { useRouter } from "vue-router";
|
|
11
11
|
|
|
12
12
|
export enum ProductType {
|
|
@@ -125,6 +125,9 @@ export const useIapStore = defineStore("iap", () => {
|
|
|
125
125
|
const stripeLoaded = ref(false);
|
|
126
126
|
const stripeCart = localRef<StripeCart | undefined>("stripe-cart", undefined);
|
|
127
127
|
const stripeStatus = ref<undefined | "cart" | "verified">();
|
|
128
|
+
const stripeResult = ref<undefined | Transaction>();
|
|
129
|
+
const stripeCallback =
|
|
130
|
+
ref<(t: Transaction | undefined) => Transaction | undefined>();
|
|
128
131
|
|
|
129
132
|
const storePlatform = computed(() => {
|
|
130
133
|
if (platform.value === "android") {
|
|
@@ -134,6 +137,14 @@ export const useIapStore = defineStore("iap", () => {
|
|
|
134
137
|
}
|
|
135
138
|
});
|
|
136
139
|
|
|
140
|
+
watch(stripeResult, () => {
|
|
141
|
+
if (stripeCallback.value) {
|
|
142
|
+
stripeCallback.value(stripeResult.value);
|
|
143
|
+
stripeCallback.value = undefined;
|
|
144
|
+
stripeResult.value = undefined;
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
|
|
137
148
|
async function initialize(loadProducts: IapProduct[]) {
|
|
138
149
|
products.value = loadProducts;
|
|
139
150
|
|
|
@@ -166,7 +177,7 @@ export const useIapStore = defineStore("iap", () => {
|
|
|
166
177
|
}
|
|
167
178
|
}
|
|
168
179
|
|
|
169
|
-
async function purchaseItem(code: string) {
|
|
180
|
+
async function purchaseItem(code: string): Promise<any | undefined> {
|
|
170
181
|
const product = products.value.find((p) => p.id === code);
|
|
171
182
|
if (product) {
|
|
172
183
|
if (product.platform === Platform.STRIPE) {
|
|
@@ -174,6 +185,9 @@ export const useIapStore = defineStore("iap", () => {
|
|
|
174
185
|
stripeCart.value = {
|
|
175
186
|
items: [{ product, price: product.stripePrice, quantity: 1 }],
|
|
176
187
|
};
|
|
188
|
+
return await new Promise<Transaction | undefined>((resolve) => {
|
|
189
|
+
stripeCallback.value = resolve;
|
|
190
|
+
});
|
|
177
191
|
// this should trigger the <StripePopup /> component
|
|
178
192
|
} else if (
|
|
179
193
|
product.platform === Platform.GOOGLE_PLAY ||
|
|
@@ -269,6 +283,8 @@ export const useIapStore = defineStore("iap", () => {
|
|
|
269
283
|
stripeLoaded,
|
|
270
284
|
stripeCart,
|
|
271
285
|
stripeStatus,
|
|
286
|
+
stripeResult,
|
|
287
|
+
stripeCallback,
|
|
272
288
|
};
|
|
273
289
|
});
|
|
274
290
|
|
/package/{main.ts → index.ts}
RENAMED
|
File without changes
|