Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backwards compatibility2 #1906

Merged
merged 3 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion IapExample/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import {storeKit2} from 'react-native-iap';
import {NavigationContainer} from '@react-navigation/native';

import {StackNavigator} from './navigators';

storeKit2();
export const App = () => (
<NavigationContainer>
<StackNavigator />
Expand Down
13 changes: 11 additions & 2 deletions IapExample/src/screens/Products.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, {useEffect, useState} from 'react';
import {ScrollView, StyleSheet, Text, View} from 'react-native';
import {PurchaseError, requestPurchase, Sku, useIAP} from 'react-native-iap';
import {
isIosStorekit2,
PurchaseError,
requestPurchase,
Sku,
useIAP,
} from 'react-native-iap';

import {Box, Button, Heading, Row, State} from '../components';
import {
Expand Down Expand Up @@ -46,7 +52,10 @@ export const Products = () => {
useEffect(() => {
const checkCurrentPurchase = async () => {
try {
if (currentPurchase?.transactionId) {
if (
(isIosStorekit2() && currentPurchase?.transactionId) ||
currentPurchase?.transactionReceipt
) {
await finishTransaction({
purchase: currentPurchase,
isConsumable: true,
Expand Down
41 changes: 25 additions & 16 deletions ios/RNIapIos.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,46 @@ @interface RCT_EXTERN_MODULE (RNIapIos, NSObject)
RCT_EXTERN_METHOD(buyProduct:
(NSString*)sku
andDangerouslyFinishTransactionAutomatically:(BOOL)andDangerouslyFinishTransactionAutomatically
appAccountToken:(NSString*)appAccountToken
quantity:(NSInteger)quantity
withOffer:(NSDictionary*)withOffer
applicationUsername:(NSString*)applicationUsername
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(isEligibleForIntroOffer:
(NSString*)groupID
RCT_EXTERN_METHOD(buyProductWithOffer:
(NSString*)sku
forUser:(NSString*)usernameHash
withOffer:(NSDictionary*)discountOffer
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(currentEntitlement:
RCT_EXTERN_METHOD(buyProductWithQuantityIOS:
(NSString*)sku
quantity:(NSInteger)quantity
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(latestTransaction:
(NSString*)sku
resolve:(RCTPromiseResolveBlock)resolve
RCT_EXTERN_METHOD(clearTransaction:
(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(finishTransaction:
(NSString*)transactionIdentifier
resolve:(RCTPromiseResolveBlock)resolve
RCT_EXTERN_METHOD(clearProducts:
(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(pendingTransactions:
RCT_EXTERN_METHOD(promotedProduct:
(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(sync:
RCT_EXTERN_METHOD(buyPromotedProduct:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(requestReceipt:
(BOOL)refresh
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)
RCT_EXTERN_METHOD(finishTransaction:
(NSString*)transactionIdentifier
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

RCT_EXTERN_METHOD(getPendingTransactions:
(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject)

Expand Down
Loading