@virgodev/iap 1.0.4 → 1.0.6
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/components/StripeCheckout.vue +18 -9
- package/components/StripePopup.vue +1 -8
- package/package.json +4 -2
- package/stores/iap.ts +14 -0
|
@@ -110,12 +110,9 @@ let checkout: StripeCheckout | null = null;
|
|
|
110
110
|
let loadActionsResult: StripeCheckoutLoadActionsResult | null = null;
|
|
111
111
|
let paymentElement = undefined;
|
|
112
112
|
|
|
113
|
-
watch(
|
|
114
|
-
()
|
|
115
|
-
|
|
116
|
-
getSession();
|
|
117
|
-
}
|
|
118
|
-
);
|
|
113
|
+
watch([() => props.cart, () => iap.stripe.coupon], () => {
|
|
114
|
+
getSession();
|
|
115
|
+
});
|
|
119
116
|
|
|
120
117
|
onMounted(async () => {
|
|
121
118
|
getSession();
|
|
@@ -123,6 +120,7 @@ onMounted(async () => {
|
|
|
123
120
|
|
|
124
121
|
async function getSession() {
|
|
125
122
|
if (iap.stripe.client) {
|
|
123
|
+
messageText.value = "";
|
|
126
124
|
try {
|
|
127
125
|
// Fetch client secret from backend
|
|
128
126
|
const clientSecretResponse = await api({
|
|
@@ -133,6 +131,7 @@ async function getSession() {
|
|
|
133
131
|
sub: props.cart.items.some(
|
|
134
132
|
(i) => i.product.type === ProductType.PAID_SUBSCRIPTION
|
|
135
133
|
),
|
|
134
|
+
coupon_code: iap.stripe.coupon,
|
|
136
135
|
},
|
|
137
136
|
});
|
|
138
137
|
if (clientSecretResponse.ok) {
|
|
@@ -147,10 +146,22 @@ async function getSession() {
|
|
|
147
146
|
// Handle changes to the checkout session
|
|
148
147
|
console.log("session changed:", session);
|
|
149
148
|
});
|
|
149
|
+
checkout.on("error", (error: any) => {
|
|
150
|
+
console.error("Error initializing checkout:", error);
|
|
151
|
+
});
|
|
152
|
+
checkout.on("ready", (...args: any) => {
|
|
153
|
+
console.info("ready?:", args);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
console.log("session created:", sessionResponse.value, checkout);
|
|
150
157
|
|
|
151
158
|
loadActionsResult = await checkout.loadActions();
|
|
152
159
|
|
|
153
|
-
if (
|
|
160
|
+
if (
|
|
161
|
+
loadActionsResult.type === "error" &&
|
|
162
|
+
/^No such payment_page: /.test(loadActionsResult.error.message)
|
|
163
|
+
) {
|
|
164
|
+
} else if (loadActionsResult.type !== "success") {
|
|
154
165
|
showPaymentMessage("Failed to load payment actions");
|
|
155
166
|
}
|
|
156
167
|
|
|
@@ -186,7 +197,6 @@ function setLoading(loading: boolean) {
|
|
|
186
197
|
}
|
|
187
198
|
|
|
188
199
|
async function handleSubmit() {
|
|
189
|
-
console.log("Submitting payment");
|
|
190
200
|
setLoading(true);
|
|
191
201
|
emits("start");
|
|
192
202
|
|
|
@@ -210,7 +220,6 @@ async function handleSubmit() {
|
|
|
210
220
|
}
|
|
211
221
|
|
|
212
222
|
setLoading(false);
|
|
213
|
-
console.log("done Submitting payment");
|
|
214
223
|
}
|
|
215
224
|
</script>
|
|
216
225
|
|
|
@@ -58,14 +58,7 @@ onMounted(() => {});
|
|
|
58
58
|
|
|
59
59
|
function closeDialog(v: boolean): void {
|
|
60
60
|
if (v === false) {
|
|
61
|
-
|
|
62
|
-
iap.stripe.callback(undefined);
|
|
63
|
-
}
|
|
64
|
-
iap.stripe.callback = undefined;
|
|
65
|
-
iap.stripe.result = undefined;
|
|
66
|
-
iap.stripe.cart = undefined;
|
|
67
|
-
iap.stripe.status = undefined;
|
|
68
|
-
iap.stripe.error = undefined;
|
|
61
|
+
iap.stripe.reset();
|
|
69
62
|
visible.value = false;
|
|
70
63
|
}
|
|
71
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@virgodev/iap",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"main": "./index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
@@ -9,9 +9,11 @@
|
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"description": "",
|
|
11
11
|
"dependencies": {
|
|
12
|
+
"@capacitor/core": "^7.4.4",
|
|
12
13
|
"@stripe/stripe-js": "^8.2.0",
|
|
13
14
|
"@virgodev/iap": "^1.0.1",
|
|
14
|
-
"cordova-plugin-purchase": "^13.12.1"
|
|
15
|
+
"cordova-plugin-purchase": "^13.12.1",
|
|
16
|
+
"localforage": "^1.10.0"
|
|
15
17
|
},
|
|
16
18
|
"peerDependencies": {
|
|
17
19
|
"@capacitor/app": "^7.1.0",
|
package/stores/iap.ts
CHANGED
|
@@ -129,6 +129,7 @@ export const useIapStore = defineStore("iap", () => {
|
|
|
129
129
|
const stripeCallback =
|
|
130
130
|
ref<(t: Transaction | undefined) => Transaction | undefined>();
|
|
131
131
|
const stripeError = ref<undefined | string>();
|
|
132
|
+
const stripeCoupon = ref("");
|
|
132
133
|
|
|
133
134
|
const storePlatform = computed(() => {
|
|
134
135
|
if (platform.value === "android") {
|
|
@@ -286,6 +287,17 @@ export const useIapStore = defineStore("iap", () => {
|
|
|
286
287
|
});
|
|
287
288
|
}
|
|
288
289
|
|
|
290
|
+
function reset() {
|
|
291
|
+
if (stripeCallback.value) {
|
|
292
|
+
stripeCallback.value(undefined);
|
|
293
|
+
}
|
|
294
|
+
stripeCallback.value = undefined;
|
|
295
|
+
stripeResult.value = undefined;
|
|
296
|
+
stripeCart.value = undefined;
|
|
297
|
+
stripeStatus.value = undefined;
|
|
298
|
+
stripeError.value = undefined;
|
|
299
|
+
}
|
|
300
|
+
|
|
289
301
|
return {
|
|
290
302
|
products,
|
|
291
303
|
platform,
|
|
@@ -307,6 +319,8 @@ export const useIapStore = defineStore("iap", () => {
|
|
|
307
319
|
result: stripeResult,
|
|
308
320
|
callback: stripeCallback,
|
|
309
321
|
error: stripeError,
|
|
322
|
+
coupon: stripeCoupon,
|
|
323
|
+
reset,
|
|
310
324
|
},
|
|
311
325
|
};
|
|
312
326
|
});
|