Skip to content

Commit

Permalink
7.5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianojsjr committed Apr 7, 2022
1 parent 5f2e530 commit 90028ef
Show file tree
Hide file tree
Showing 25 changed files with 2,066 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ tsconfig.tsbuildinfo

# Generated files
*.js.flow
*.d.ts
*.js
!IamExample
!jest.config.js
!babel.config.js
Expand Down
4 changes: 2 additions & 2 deletions RNIap.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Pod::Spec.new do |s|
s.name = "RNIap"
s.version = package['version']
s.summary = package['description']
s.homepage = "https://github.com/dooboolab/react-native-iap"
s.homepage = "https://github.com/amigoapp/react-native-iap"
s.license = "MIT"
s.author = package['author']
s.platforms = { :ios => "9.0", :tvos => "9.0" }
s.source = { :git => "https://github.com/dooboolab/react-native-iap.git", :tag => "#{s.version}" }
s.source = { :git => "https://github.com/amigoapp/react-native-iap.git", :tag => "#{s.version}" }
s.source_files = "ios/*.{h,m}"
s.requires_arc = true

Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './src';
import * as iap from './src/iap';
export default iap;
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './src';
import * as iap from './src/iap';
export default iap;
2 changes: 2 additions & 0 deletions ios/RNIapIos.m
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ - (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)

RCT_EXPORT_METHOD(buyProduct:(NSString*)sku
andDangerouslyFinishTransactionAutomatically:(BOOL)finishAutomatically
applicationUsername:(NSString*)applicationUsername
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
pendingTransactionWithAutoFinish = finishAutomatically;
Expand All @@ -158,6 +159,7 @@ - (BOOL)paymentQueue:(SKPaymentQueue *)queue shouldAddStorePayment:(SKPayment *)
[self addPromiseForKey:product.productIdentifier resolve:resolve reject:reject];

SKMutablePayment *payment = [SKMutablePayment paymentWithProduct:product];
payment.applicationUsername = applicationUsername;
[[SKPaymentQueue defaultQueue] addPayment:payment];
} else {
if (hasListeners) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-iap",
"packageManager": "yarn@3.1.1",
"version": "7.5.6",
"version": "7.5.7",
"description": "React Native In App Purchase Module.",
"main": "index.js",
"types": "index.d.ts",
Expand All @@ -20,7 +20,7 @@
},
"repository": {
"type": "git",
"url": "https://github.com/dooboolab/react-native-iap"
"url": "https://github.com/amigoapp/react-native-iap"
},
"keywords": [
"react-native",
Expand Down Expand Up @@ -72,4 +72,4 @@
"ts-jest": "27.0.7",
"typescript": "4.5.2"
}
}
}
1 change: 1 addition & 0 deletions src/__test__/iap.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
59 changes: 59 additions & 0 deletions src/__test__/iap.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { NativeModules } from 'react-native';
import { initConnection } from '../iap';
var rnLib = '../../node_modules/react-native/Libraries';
describe('Google Play IAP', function () {
beforeEach(function () {
jest.mock(rnLib + '/Utilities/Platform', function () { return ({
OS: 'android',
select: function (dict) { return dict.android; },
}); });
});
it("should call init on Google Play's native module but not on Amazon's", function () { return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, initConnection()];
case 1:
_a.sent();
expect(NativeModules.RNIapModule.initConnection).toBeCalled();
expect(NativeModules.RNIapAmazonModule.initConnection).not.toBeCalled();
return [2 /*return*/];
}
});
}); });
});
21 changes: 21 additions & 0 deletions src/hooks/useIAP.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Product, Purchase, PurchaseError, Subscription } from '../types';
import { requestPurchase as iapRequestPurchase, requestSubscription as iapRequestSubscription } from '../iap';
declare type IAP_STATUS = {
connected: boolean;
products: Product[];
promotedProductsIOS: Product[];
subscriptions: Subscription[];
purchaseHistories: Purchase[];
availablePurchases: Purchase[];
currentPurchase?: Purchase;
currentPurchaseError?: PurchaseError;
finishTransaction: (purchase: Purchase, isConsumable?: boolean, developerPayloadAndroid?: string) => Promise<string | void>;
getAvailablePurchases: () => Promise<void>;
getPurchaseHistories: () => Promise<void>;
getProducts: (skus: string[]) => Promise<void>;
getSubscriptions: (skus: string[]) => Promise<void>;
requestPurchase: typeof iapRequestPurchase;
requestSubscription: typeof iapRequestSubscription;
};
export declare function useIAP(): IAP_STATUS;
export {};
140 changes: 140 additions & 0 deletions src/hooks/useIAP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { getPurchaseHistory, finishTransaction as iapFinishTransaction, getAvailablePurchases as iapGetAvailablePurchases, getProducts as iapGetProducts, getSubscriptions as iapGetSubscriptions, requestPurchase as iapRequestPurchase, requestSubscription as iapRequestSubscription, } from '../iap';
import { useCallback } from 'react';
import { useIAPContext } from './withIAPContext';
export function useIAP() {
var _this = this;
var _a = useIAPContext(), connected = _a.connected, products = _a.products, promotedProductsIOS = _a.promotedProductsIOS, subscriptions = _a.subscriptions, purchaseHistories = _a.purchaseHistories, availablePurchases = _a.availablePurchases, currentPurchase = _a.currentPurchase, currentPurchaseError = _a.currentPurchaseError, setProducts = _a.setProducts, setSubscriptions = _a.setSubscriptions, setAvailablePurchases = _a.setAvailablePurchases, setPurchaseHistories = _a.setPurchaseHistories, setCurrentPurchase = _a.setCurrentPurchase, setCurrentPurchaseError = _a.setCurrentPurchaseError;
var getProducts = useCallback(function (skus) { return __awaiter(_this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = setProducts;
return [4 /*yield*/, iapGetProducts(skus)];
case 1:
_a.apply(void 0, [_b.sent()]);
return [2 /*return*/];
}
});
}); }, [setProducts]);
var getSubscriptions = useCallback(function (skus) { return __awaiter(_this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = setSubscriptions;
return [4 /*yield*/, iapGetSubscriptions(skus)];
case 1:
_a.apply(void 0, [_b.sent()]);
return [2 /*return*/];
}
});
}); }, [setSubscriptions]);
var getAvailablePurchases = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = setAvailablePurchases;
return [4 /*yield*/, iapGetAvailablePurchases()];
case 1:
_a.apply(void 0, [_b.sent()]);
return [2 /*return*/];
}
});
}); }, [setAvailablePurchases]);
var getPurchaseHistories = useCallback(function () { return __awaiter(_this, void 0, void 0, function () {
var _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
_a = setPurchaseHistories;
return [4 /*yield*/, getPurchaseHistory()];
case 1:
_a.apply(void 0, [_b.sent()]);
return [2 /*return*/];
}
});
}); }, [setPurchaseHistories]);
var finishTransaction = useCallback(function (purchase, isConsumable, developerPayloadAndroid) { return __awaiter(_this, void 0, void 0, function () {
var err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, 3, 4]);
return [4 /*yield*/, iapFinishTransaction(purchase, isConsumable, developerPayloadAndroid)];
case 1: return [2 /*return*/, _a.sent()];
case 2:
err_1 = _a.sent();
throw err_1;
case 3:
if (purchase.productId === (currentPurchase === null || currentPurchase === void 0 ? void 0 : currentPurchase.productId)) {
setCurrentPurchase(undefined);
}
if (purchase.productId === (currentPurchaseError === null || currentPurchaseError === void 0 ? void 0 : currentPurchaseError.productId)) {
setCurrentPurchaseError(undefined);
}
return [7 /*endfinally*/];
case 4: return [2 /*return*/];
}
});
}); }, [
currentPurchase === null || currentPurchase === void 0 ? void 0 : currentPurchase.productId,
currentPurchaseError === null || currentPurchaseError === void 0 ? void 0 : currentPurchaseError.productId,
setCurrentPurchase,
setCurrentPurchaseError,
]);
return {
connected: connected,
products: products,
promotedProductsIOS: promotedProductsIOS,
subscriptions: subscriptions,
purchaseHistories: purchaseHistories,
availablePurchases: availablePurchases,
currentPurchase: currentPurchase,
currentPurchaseError: currentPurchaseError,
finishTransaction: finishTransaction,
getProducts: getProducts,
getSubscriptions: getSubscriptions,
getAvailablePurchases: getAvailablePurchases,
getPurchaseHistories: getPurchaseHistories,
requestPurchase: iapRequestPurchase,
requestSubscription: iapRequestSubscription,
};
}
21 changes: 21 additions & 0 deletions src/hooks/withIAPContext.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import { Product, Purchase, PurchaseError, Subscription } from '../types';
declare type IAPContextType = {
connected: boolean;
products: Product[];
promotedProductsIOS: Product[];
subscriptions: Subscription[];
purchaseHistories: Purchase[];
availablePurchases: Purchase[];
currentPurchase?: Purchase;
currentPurchaseError?: PurchaseError;
setProducts: (products: Product[]) => void;
setSubscriptions: (subscriptions: Subscription[]) => void;
setPurchaseHistories: (purchaseHistories: Purchase[]) => void;
setAvailablePurchases: (availablePurchases: Purchase[]) => void;
setCurrentPurchase: (currentPurchase: Purchase | undefined) => void;
setCurrentPurchaseError: (currentPurchaseError: PurchaseError | undefined) => void;
};
export declare function useIAPContext(): IAPContextType;
export declare function withIAPContext<T>(Component: React.ComponentType<T>): (props: T) => JSX.Element;
export {};
Loading

0 comments on commit 90028ef

Please sign in to comment.