|
| 1 | +--- |
| 2 | +title: Migration to v2.8.6 |
| 3 | +sidebar_label: v2.8.6 Migration |
| 4 | +sidebar_position: 2 |
| 5 | +--- |
| 6 | + |
| 7 | +# Migration Guide for v2.8.6 |
| 8 | + |
| 9 | +This version introduces a significant naming convention change for platform-specific functions to improve code clarity and maintainability. |
| 10 | + |
| 11 | +## Breaking Changes |
| 12 | + |
| 13 | +### Platform-Specific Function Naming |
| 14 | + |
| 15 | +All platform-specific functions now have consistent suffixes: |
| 16 | + |
| 17 | +- **iOS functions**: Use `IOS` suffix |
| 18 | +- **Android functions**: Use `Android` suffix |
| 19 | +- **Common functions**: No suffix |
| 20 | + |
| 21 | +### iOS Function Changes |
| 22 | + |
| 23 | +| Old Name | New Name | |
| 24 | +|----------|----------| |
| 25 | +| `buyPromotedProduct` | `requestPurchaseOnPromotedProductIOS` | |
| 26 | +| `sync` | `syncIOS` | |
| 27 | +| `isEligibleForIntroOffer` | `isEligibleForIntroOfferIOS` | |
| 28 | +| `subscriptionStatus` | `subscriptionStatusIOS` | |
| 29 | +| `currentEntitlement` | `currentEntitlementIOS` | |
| 30 | +| `latestTransaction` | `latestTransactionIOS` | |
| 31 | +| `showManageSubscriptions` | `showManageSubscriptionsIOS` | |
| 32 | +| `beginRefundRequest` | `beginRefundRequestIOS` | |
| 33 | +| `isTransactionVerified` | `isTransactionVerifiedIOS` | |
| 34 | +| `getTransactionJws` | `getTransactionJwsIOS` | |
| 35 | +| `getReceiptData` | `getReceiptIOS` | |
| 36 | +| `presentCodeRedemptionSheet` | `presentCodeRedemptionSheetIOS` | |
| 37 | +| `getAppTransaction` | `getAppTransactionIOS` | |
| 38 | + |
| 39 | +### Android Function Changes |
| 40 | + |
| 41 | +| Old Name | New Name | |
| 42 | +|----------|----------| |
| 43 | +| `acknowledgePurchase` | `acknowledgePurchaseAndroid` | |
| 44 | +| `consumeProduct` | `consumeProductAndroid` | |
| 45 | + |
| 46 | +### New Functions Added |
| 47 | + |
| 48 | +- `getPendingTransactionsIOS()` - Get pending transactions on iOS |
| 49 | +- `clearTransactionIOS()` - Clear a specific transaction on iOS |
| 50 | + |
| 51 | +## Deprecated Functions |
| 52 | + |
| 53 | +The following functions are deprecated and will be removed in v2.9.0: |
| 54 | + |
| 55 | +### `getPurchaseHistories()` |
| 56 | +- **Reason**: This function just calls `getAvailablePurchases()` internally |
| 57 | +- **Migration**: Use `getAvailablePurchases()` instead |
| 58 | + |
| 59 | +```tsx |
| 60 | +// Before |
| 61 | +const histories = await getPurchaseHistories(); |
| 62 | + |
| 63 | +// After |
| 64 | +const purchases = await getAvailablePurchases(); |
| 65 | +``` |
| 66 | + |
| 67 | +### `buyPromotedProductIOS()` |
| 68 | +- **Reason**: Renamed for consistency |
| 69 | +- **Migration**: Use `requestPurchaseOnPromotedProductIOS()` instead |
| 70 | + |
| 71 | +```tsx |
| 72 | +// Before |
| 73 | +await buyPromotedProductIOS(); |
| 74 | + |
| 75 | +// After |
| 76 | +await requestPurchaseOnPromotedProductIOS(); |
| 77 | +``` |
| 78 | + |
| 79 | +### `disable()` |
| 80 | +- **Reason**: Observer management is now automatic |
| 81 | +- **Migration**: Remove calls to this function - it's no longer needed |
| 82 | + |
| 83 | +## Migration Examples |
| 84 | + |
| 85 | +### Using the useIAP Hook |
| 86 | + |
| 87 | +```tsx |
| 88 | +// Before |
| 89 | +import { useIAP } from 'expo-iap'; |
| 90 | + |
| 91 | +const MyComponent = () => { |
| 92 | + const { |
| 93 | + buyPromotedProductIOS, |
| 94 | + getPurchaseHistories |
| 95 | + } = useIAP(); |
| 96 | + |
| 97 | + // ... |
| 98 | +}; |
| 99 | + |
| 100 | +// After |
| 101 | +import { useIAP } from 'expo-iap'; |
| 102 | + |
| 103 | +const MyComponent = () => { |
| 104 | + const { |
| 105 | + requestPurchaseOnPromotedProductIOS, |
| 106 | + getAvailablePurchases |
| 107 | + } = useIAP(); |
| 108 | + |
| 109 | + // ... |
| 110 | +}; |
| 111 | +``` |
| 112 | + |
| 113 | +### Direct Function Imports |
| 114 | + |
| 115 | +```tsx |
| 116 | +// Before |
| 117 | +import { |
| 118 | + isEligibleForIntroOffer, |
| 119 | + acknowledgePurchase, |
| 120 | + getPurchaseHistories |
| 121 | +} from 'expo-iap'; |
| 122 | + |
| 123 | +// After |
| 124 | +import { |
| 125 | + isEligibleForIntroOfferIOS, |
| 126 | + acknowledgePurchaseAndroid, |
| 127 | + getAvailablePurchases |
| 128 | +} from 'expo-iap'; |
| 129 | +``` |
| 130 | + |
| 131 | +### Platform-Specific Code |
| 132 | + |
| 133 | +```tsx |
| 134 | +import { Platform } from 'react-native'; |
| 135 | +import { |
| 136 | + acknowledgePurchaseAndroid, |
| 137 | + clearTransactionIOS |
| 138 | +} from 'expo-iap'; |
| 139 | + |
| 140 | +const finishPurchase = async (purchase: Purchase) => { |
| 141 | + if (Platform.OS === 'ios') { |
| 142 | + // iOS-specific function with IOS suffix |
| 143 | + await clearTransactionIOS(); |
| 144 | + } else if (Platform.OS === 'android') { |
| 145 | + // Android-specific function with Android suffix |
| 146 | + await acknowledgePurchaseAndroid({ token: purchase.purchaseToken }); |
| 147 | + } |
| 148 | +}; |
| 149 | +``` |
| 150 | + |
| 151 | +## Benefits of the New Naming Convention |
| 152 | + |
| 153 | +1. **Clarity**: Function names immediately indicate platform compatibility |
| 154 | +2. **Type Safety**: Better TypeScript support with platform-specific types |
| 155 | +3. **Maintainability**: Easier to identify and manage platform-specific code |
| 156 | +4. **Consistency**: All platform-specific functions follow the same pattern |
| 157 | + |
| 158 | +## Need Help? |
| 159 | + |
| 160 | +If you encounter any issues during migration: |
| 161 | + |
| 162 | +1. Check the [API documentation](/docs/api) for updated function signatures |
| 163 | +2. Review the [example app](https://github.com/hyochan/expo-iap/tree/main/example) for usage patterns |
| 164 | +3. Open an issue on [GitHub](https://github.com/hyochan/expo-iap/issues) if you need assistance |
0 commit comments