Skip to content

Commit

Permalink
backwards compatibility2 (#1906)
Browse files Browse the repository at this point in the history
* Brought back old class, renamed new one

* add switch between versions

* format

Co-authored-by: Andres Aguilar <andres.aguilar@nfl.com>
  • Loading branch information
andresesfm and Andres Aguilar authored Aug 31, 2022
1 parent f797b45 commit 9123ad1
Show file tree
Hide file tree
Showing 8 changed files with 1,376 additions and 327 deletions.
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

0 comments on commit 9123ad1

Please sign in to comment.