@virgodev/iap 1.0.5 → 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.
@@ -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
- () => props.cart,
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 (loadActionsResult.type !== "success") {
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virgodev/iap",
3
- "version": "1.0.5",
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") {
@@ -318,6 +319,7 @@ export const useIapStore = defineStore("iap", () => {
318
319
  result: stripeResult,
319
320
  callback: stripeCallback,
320
321
  error: stripeError,
322
+ coupon: stripeCoupon,
321
323
  reset,
322
324
  },
323
325
  };