expo-iap 2.3.1-rc.4 → 2.3.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.
Files changed (2) hide show
  1. package/iap.md +38 -20
  2. package/package.json +1 -1
package/iap.md CHANGED
@@ -209,8 +209,8 @@ Transactions map to `Purchase` or `SubscriptionPurchase` with platform-specific
209
209
  Below is a simple example of fetching products and making a purchase with `expo-iap` in a managed workflow, updated to use the new `requestPurchase` signature:
210
210
 
211
211
  ```tsx
212
- import { useEffect, useState } from 'react';
213
- import { Button, Text, View } from 'react-native';
212
+ import {useEffect, useState} from 'react';
213
+ import {Button, Text, View} from 'react-native';
214
214
  import {
215
215
  initConnection,
216
216
  endConnection,
@@ -237,7 +237,7 @@ export default function SimpleIAP() {
237
237
 
238
238
  const purchaseListener = purchaseUpdatedListener(async (purchase) => {
239
239
  if (purchase) {
240
- await finishTransaction({ purchase, isConsumable: true });
240
+ await finishTransaction({purchase, isConsumable: true});
241
241
  alert('Purchase completed!');
242
242
  }
243
243
  });
@@ -252,12 +252,12 @@ export default function SimpleIAP() {
252
252
  const buyItem = async () => {
253
253
  if (!product) return;
254
254
  await requestPurchase({
255
- request: { skus: [product.id] }, // Android expects 'skus'; iOS would use 'sku'
255
+ request: {skus: [product.id]}, // Android expects 'skus'; iOS would use 'sku'
256
256
  });
257
257
  };
258
258
 
259
259
  return (
260
- <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
260
+ <View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
261
261
  <Text>{isConnected ? 'Connected' : 'Connecting...'}</Text>
262
262
  {product ? (
263
263
  <>
@@ -277,7 +277,7 @@ export default function SimpleIAP() {
277
277
  The `useIAP` hook simplifies managing in-app purchases. Below is an example updated to use the new `requestPurchase` signature:
278
278
 
279
279
  ```tsx
280
- import { useEffect, useState } from 'react';
280
+ import {useEffect, useState} from 'react';
281
281
  import {
282
282
  SafeAreaView,
283
283
  ScrollView,
@@ -289,12 +289,20 @@ import {
289
289
  InteractionManager,
290
290
  Alert,
291
291
  } from 'react-native';
292
- import { useIAP } from 'expo-iap';
293
- import type { ProductPurchase, SubscriptionProduct } from 'expo-iap';
292
+ import {useIAP} from 'expo-iap';
293
+ import type {ProductPurchase, SubscriptionProduct} from 'expo-iap';
294
294
 
295
295
  // Define SKUs
296
- const productSkus = ['cpk.points.1000', 'cpk.points.5000', 'cpk.points.10000', 'cpk.points.30000'];
297
- const subscriptionSkus = ['cpk.membership.monthly.bronze', 'cpk.membership.monthly.silver'];
296
+ const productSkus = [
297
+ 'cpk.points.1000',
298
+ 'cpk.points.5000',
299
+ 'cpk.points.10000',
300
+ 'cpk.points.30000',
301
+ ];
302
+ const subscriptionSkus = [
303
+ 'cpk.membership.monthly.bronze',
304
+ 'cpk.membership.monthly.silver',
305
+ ];
298
306
 
299
307
  // Define operations
300
308
  const operations = ['getProducts', 'getSubscriptions'] as const;
@@ -321,7 +329,10 @@ export default function IAPWithHook() {
321
329
 
322
330
  const initializeIAP = async () => {
323
331
  try {
324
- await Promise.all([getProducts(productSkus), getSubscriptions(subscriptionSkus)]);
332
+ await Promise.all([
333
+ getProducts(productSkus),
334
+ getSubscriptions(subscriptionSkus),
335
+ ]);
325
336
  setIsReady(true);
326
337
  } catch (error) {
327
338
  console.error('Error initializing IAP:', error);
@@ -389,7 +400,10 @@ export default function IAPWithHook() {
389
400
  <View style={styles.buttons}>
390
401
  <ScrollView contentContainerStyle={styles.buttonsWrapper} horizontal>
391
402
  {operations.map((operation) => (
392
- <Pressable key={operation} onPress={() => handleOperation(operation)}>
403
+ <Pressable
404
+ key={operation}
405
+ onPress={() => handleOperation(operation)}
406
+ >
393
407
  <View style={styles.buttonView}>
394
408
  <Text>{operation}</Text>
395
409
  </View>
@@ -401,10 +415,10 @@ export default function IAPWithHook() {
401
415
  {!isReady ? (
402
416
  <Text>Loading...</Text>
403
417
  ) : (
404
- <View style={{ gap: 12 }}>
405
- <Text style={{ fontSize: 20 }}>Products</Text>
418
+ <View style={{gap: 12}}>
419
+ <Text style={{fontSize: 20}}>Products</Text>
406
420
  {products.map((item) => (
407
- <View key={item.id} style={{ gap: 12 }}>
421
+ <View key={item.id} style={{gap: 12}}>
408
422
  <Text>
409
423
  {item.title} -{' '}
410
424
  {item.platform === 'android'
@@ -415,20 +429,24 @@ export default function IAPWithHook() {
415
429
  title="Buy"
416
430
  onPress={() =>
417
431
  requestPurchase({
418
- request: item.platform === 'android' ? { skus: [item.id] } : { sku: item.id },
432
+ request:
433
+ item.platform === 'android'
434
+ ? {skus: [item.id]}
435
+ : {sku: item.id},
419
436
  })
420
437
  }
421
438
  />
422
439
  </View>
423
440
  ))}
424
441
 
425
- <Text style={{ fontSize: 20 }}>Subscriptions</Text>
442
+ <Text style={{fontSize: 20}}>Subscriptions</Text>
426
443
  {subscriptions.map((item) => (
427
- <View key={item.id} style={{ gap: 12 }}>
444
+ <View key={item.id} style={{gap: 12}}>
428
445
  <Text>
429
446
  {item.title || item.displayName} -{' '}
430
447
  {item.platform === 'android' && item.subscriptionOfferDetails
431
- ? item.subscriptionOfferDetails[0]?.pricingPhases.pricingPhaseList[0].formattedPrice
448
+ ? item.subscriptionOfferDetails[0]?.pricingPhases
449
+ .pricingPhaseList[0].formattedPrice
432
450
  : item.displayPrice}
433
451
  </Text>
434
452
  <Button
@@ -445,7 +463,7 @@ export default function IAPWithHook() {
445
463
  offerToken: offer.offerToken,
446
464
  })) || [],
447
465
  }
448
- : { sku: item.id },
466
+ : {sku: item.id},
449
467
  type: 'subs',
450
468
  })
451
469
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expo-iap",
3
- "version": "2.3.1-rc.4",
3
+ "version": "2.3.1",
4
4
  "description": "In App Purchase module in Expo",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",