Skip to content

Commit

Permalink
🐛 Fix react-native-iap method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt committed Nov 9, 2023
1 parent 594a60a commit 40ffc7b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions app/models/iapStore/iap-store.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/* eslint-disable @typescript-eslint/interface-name-prefix */
import { Platform, Alert } from "react-native"
import RNIap, {
import {
Product,
Purchase,
PurchaseError,
getAvailablePurchases,
getProducts,
requestSubscription,
validateReceiptIos,
} from "react-native-iap"

import {
Expand Down Expand Up @@ -55,10 +59,13 @@ export const IAPStoreModel = types
if (receipt) {
// TODO: Validation on Android
if (Platform.OS === "ios") {
const result: any = yield RNIap.validateReceiptIos({
"receipt-data": receipt,
password: self.getConfig("IAP_IOS_SHARED_SECRET"),
}, self.getConfig("IAP_IOS_IS_SANDBOX") === "true")
const result: any = yield validateReceiptIos({
receiptBody: {
"receipt-data": receipt,
password: self.getConfig("IAP_IOS_SHARED_SECRET"),
},
isTest: self.getConfig("IAP_IOS_IS_SANDBOX") === "true",
})
if (result) {
if (result.status === 0) {
self.purchasedSKUs.add(SKU_COM_OICE_MEMBERSHIP)
Expand All @@ -76,7 +83,7 @@ export const IAPStoreModel = types
fetchProducts: flow(function * () {
self.isFetchingProducts = true
try {
self.products = yield RNIap.getProducts([SKU_COM_OICE_MEMBERSHIP])
self.products = yield getProducts({ skus: [SKU_COM_OICE_MEMBERSHIP]})
} catch (error) {
logError(error)
} finally {
Expand All @@ -85,15 +92,15 @@ export const IAPStoreModel = types
}),
requestSubscription: flow(function * (sku: string) {
try {
yield RNIap.requestSubscription(sku, false)
yield requestSubscription({ sku })
} catch (error) {
logError(error)
}
}),
restorePurchases: flow(function * () {
self.isRestoringPurchases = true
try {
const purchases: Purchase[] = yield RNIap.getAvailablePurchases()
const purchases: Purchase[] = yield getAvailablePurchases()
let hasSubscription = false
purchases.forEach(purchase => {
switch (purchase.productId) {
Expand Down

0 comments on commit 40ffc7b

Please sign in to comment.