@nakamura-123/pages 0.1.50 → 0.1.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/component/Coin/CoinFnc.d.ts +2 -1
- package/dist/component/Coin/CoinFnc.js +45 -24
- package/dist/component/Coin/CoinPageComponent.d.ts +4 -4
- package/dist/component/Coin/CoinPageComponent.js +5 -7
- package/dist/component/Coin/ReceiptFnc.d.ts +2 -2
- package/dist/component/Coin/ReceiptFnc.js +16 -9
- package/dist/page/CoinPage.js +3 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import RNIap, { ProductPurchase } from "
|
|
1
|
+
import RNIap, { ProductPurchase, Purchase } from "expo-iap";
|
|
2
2
|
import { Storage } from "@nakamura-123/types";
|
|
3
3
|
export declare const initializeIAP: (paymentItems: string[] | undefined, setProducts: (products: RNIap.Product[]) => void, setLoading: (loading: boolean) => void) => Promise<void>;
|
|
4
4
|
export declare const handlePurchase: (productId: string, dispatch: (action: any) => void) => Promise<ProductPurchase | null>;
|
|
5
5
|
export declare const restorePurchases: (dispatch: (action: any) => void, isAlert?: boolean) => Promise<Storage.Receipt[] | null>;
|
|
6
6
|
export declare const updateAllFreeState: (receipt: Storage.Receipt | null) => (dispatch: any, getState: any) => void;
|
|
7
|
+
export declare const getAndroidPurchaseState: (purchase: Purchase) => "paid" | "canceled" | "waiting";
|
|
@@ -36,9 +36,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.updateAllFreeState = exports.restorePurchases = exports.handlePurchase = exports.initializeIAP = void 0;
|
|
39
|
+
exports.getAndroidPurchaseState = exports.updateAllFreeState = exports.restorePurchases = exports.handlePurchase = exports.initializeIAP = void 0;
|
|
40
40
|
var react_native_1 = require("react-native");
|
|
41
|
-
var
|
|
41
|
+
var expo_iap_1 = require("expo-iap");
|
|
42
42
|
var stores_1 = require("@nakamura-123/stores");
|
|
43
43
|
var ReceiptFnc_1 = require("./ReceiptFnc");
|
|
44
44
|
// const { pushCoinLog, pushCoinError, pushCoinWarn } = errorAction;
|
|
@@ -49,14 +49,14 @@ var initializeIAP = function (paymentItems, setProducts, setLoading) { return __
|
|
|
49
49
|
switch (_a.label) {
|
|
50
50
|
case 0:
|
|
51
51
|
_a.trys.push([0, 5, 6, 7]);
|
|
52
|
-
return [4 /*yield*/, (0,
|
|
52
|
+
return [4 /*yield*/, (0, expo_iap_1.initConnection)()];
|
|
53
53
|
case 1:
|
|
54
54
|
result = _a.sent();
|
|
55
55
|
console.log("IAP Connection Initialized: ", result);
|
|
56
56
|
itemSkus = paymentItems || [];
|
|
57
57
|
console.log("Item SKUs: ", itemSkus);
|
|
58
58
|
if (!(itemSkus.length > 0)) return [3 /*break*/, 3];
|
|
59
|
-
return [4 /*yield*/, (0,
|
|
59
|
+
return [4 /*yield*/, (0, expo_iap_1.requestProducts)({ skus: itemSkus })];
|
|
60
60
|
case 2:
|
|
61
61
|
productList = _a.sent();
|
|
62
62
|
console.log("Product List: ", productList);
|
|
@@ -80,16 +80,15 @@ var initializeIAP = function (paymentItems, setProducts, setLoading) { return __
|
|
|
80
80
|
exports.initializeIAP = initializeIAP;
|
|
81
81
|
// 11. 購入処理
|
|
82
82
|
var handlePurchase = function (productId, dispatch) { return __awaiter(void 0, void 0, void 0, function () {
|
|
83
|
-
var
|
|
83
|
+
var purchase, receipt, isValid, err_2;
|
|
84
84
|
return __generator(this, function (_a) {
|
|
85
85
|
switch (_a.label) {
|
|
86
86
|
case 0:
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
_a.trys.push([0, 5, , 6]);
|
|
88
|
+
return [4 /*yield*/, (0, expo_iap_1.requestPurchase)({
|
|
89
|
+
request: { ios: { sku: productId }, android: { skus: [productId] } },
|
|
90
|
+
})];
|
|
89
91
|
case 1:
|
|
90
|
-
_a.trys.push([1, 6, , 7]);
|
|
91
|
-
return [4 /*yield*/, (0, react_native_iap_1.requestPurchase)(params)];
|
|
92
|
-
case 2:
|
|
93
92
|
purchase = _a.sent();
|
|
94
93
|
// dispatch(pushCoinLog({ title: "Purchase", log: purchase }));
|
|
95
94
|
if (Array.isArray(purchase))
|
|
@@ -113,16 +112,17 @@ var handlePurchase = function (productId, dispatch) { return __awaiter(void 0, v
|
|
|
113
112
|
// );
|
|
114
113
|
throw new Error("購入検証に失敗しました");
|
|
115
114
|
}
|
|
116
|
-
if (!(react_native_1.Platform.OS === "android" &&
|
|
115
|
+
if (!(react_native_1.Platform.OS === "android" &&
|
|
116
|
+
(0, exports.getAndroidPurchaseState)(purchase) === "waiting")) return [3 /*break*/, 2];
|
|
117
117
|
alert("手続きが完了しました。支払いが完了したら、このページにある「以前購入した方はこちらから復元」をタップしてください。");
|
|
118
|
-
return [3 /*break*/,
|
|
119
|
-
case
|
|
120
|
-
case
|
|
118
|
+
return [3 /*break*/, 4];
|
|
119
|
+
case 2: return [4 /*yield*/, (0, expo_iap_1.finishTransaction)({ purchase: purchase, isConsumable: false })];
|
|
120
|
+
case 3:
|
|
121
121
|
_a.sent();
|
|
122
122
|
alert("購入が完了しました!");
|
|
123
|
-
_a.label =
|
|
124
|
-
case
|
|
125
|
-
case
|
|
123
|
+
_a.label = 4;
|
|
124
|
+
case 4: return [2 /*return*/, purchase]; // 成功時に購入データを返す
|
|
125
|
+
case 5:
|
|
126
126
|
err_2 = _a.sent();
|
|
127
127
|
// エラー処理を整理
|
|
128
128
|
// dispatch(
|
|
@@ -130,7 +130,7 @@ var handlePurchase = function (productId, dispatch) { return __awaiter(void 0, v
|
|
|
130
130
|
// );
|
|
131
131
|
alert("購入に失敗しました。\nしばらく時間を置いた後、もう一度実行してみてください。もしそれでも購入できない場合は「よくある質問」をご確認いただくか、必要に応じて「お問い合わせフォーム」からご連絡ください。");
|
|
132
132
|
return [2 /*return*/, null]; // 失敗時はnullを返す
|
|
133
|
-
case
|
|
133
|
+
case 6: return [2 /*return*/];
|
|
134
134
|
}
|
|
135
135
|
});
|
|
136
136
|
}); };
|
|
@@ -143,9 +143,10 @@ var restorePurchases = function (dispatch, isAlert) { return __awaiter(void 0, v
|
|
|
143
143
|
case 0:
|
|
144
144
|
_a.trys.push([0, 8, , 9]);
|
|
145
145
|
console.log("restorePurchases");
|
|
146
|
-
return [4 /*yield*/, (0,
|
|
146
|
+
return [4 /*yield*/, (0, expo_iap_1.getAvailablePurchases)()];
|
|
147
147
|
case 1:
|
|
148
148
|
purchases = _a.sent();
|
|
149
|
+
// const purchases: Purchase[] = await getAvailablePurchases();
|
|
149
150
|
console.log("purchases", purchases);
|
|
150
151
|
receipts = [];
|
|
151
152
|
_i = 0, purchases_1 = purchases;
|
|
@@ -158,8 +159,8 @@ var restorePurchases = function (dispatch, isAlert) { return __awaiter(void 0, v
|
|
|
158
159
|
dispatch((0, exports.updateAllFreeState)(receipt));
|
|
159
160
|
receipts.push(receipt);
|
|
160
161
|
}
|
|
161
|
-
if (!
|
|
162
|
-
return [4 /*yield*/, (0,
|
|
162
|
+
if (!checkIsAcknowledgedAndroid(purchase)) return [3 /*break*/, 4];
|
|
163
|
+
return [4 /*yield*/, (0, expo_iap_1.finishTransaction)({ purchase: purchase, isConsumable: false })];
|
|
163
164
|
case 3:
|
|
164
165
|
_a.sent();
|
|
165
166
|
_a.label = 4;
|
|
@@ -211,7 +212,27 @@ var updateAllFreeState = function (receipt) { return function (dispatch, getStat
|
|
|
211
212
|
}
|
|
212
213
|
}; };
|
|
213
214
|
exports.updateAllFreeState = updateAllFreeState;
|
|
214
|
-
//
|
|
215
|
-
var
|
|
216
|
-
|
|
215
|
+
// 93. purchaseStateAndroidの判定(0: 支払済み, 1: キャンセル, 2: 支払い待ち)
|
|
216
|
+
var getAndroidPurchaseState = function (purchase) {
|
|
217
|
+
if (purchase.platform === "ios") {
|
|
218
|
+
return "paid";
|
|
219
|
+
}
|
|
220
|
+
switch (purchase.purchaseStateAndroid) {
|
|
221
|
+
case 0:
|
|
222
|
+
return "paid";
|
|
223
|
+
case 1:
|
|
224
|
+
return "canceled";
|
|
225
|
+
case 2:
|
|
226
|
+
return "waiting";
|
|
227
|
+
default:
|
|
228
|
+
return "paid";
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
exports.getAndroidPurchaseState = getAndroidPurchaseState;
|
|
232
|
+
// 94. Androidの後払いアイテムの承認をするか否か
|
|
233
|
+
var checkIsAcknowledgedAndroid = function (purchase) {
|
|
234
|
+
if (purchase.platform === "ios")
|
|
235
|
+
return true; // iOSでは常に承認済み
|
|
236
|
+
return ((0, exports.getAndroidPurchaseState)(purchase) === "paid" &&
|
|
237
|
+
!purchase.isAcknowledgedAndroid);
|
|
217
238
|
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import
|
|
2
|
+
import { type Product } from "expo-iap";
|
|
3
3
|
import { Nav } from "@nakamura-123/types";
|
|
4
4
|
import { Comment } from "./AppReviews";
|
|
5
5
|
interface Props {
|
|
6
6
|
navigation: Nav.NavigationProp<"Coin">;
|
|
7
7
|
comments: Comment[];
|
|
8
|
-
products:
|
|
8
|
+
products: Product[];
|
|
9
9
|
onPurchase: (productId: string) => void;
|
|
10
10
|
onRestore: () => void;
|
|
11
11
|
loading: boolean;
|
|
12
12
|
isAllfreePaid: boolean;
|
|
13
13
|
}
|
|
14
|
-
declare const
|
|
15
|
-
export default
|
|
14
|
+
declare const CoinPageComponent: React.FC<Props>;
|
|
15
|
+
export default CoinPageComponent;
|
|
@@ -12,7 +12,7 @@ var Recommend_1 = __importDefault(require("./Recommend"));
|
|
|
12
12
|
var AppReviews_1 = __importDefault(require("./AppReviews"));
|
|
13
13
|
var WaitingPayBanner_1 = __importDefault(require("./WaitingPayBanner"));
|
|
14
14
|
var react_i18next_1 = require("react-i18next");
|
|
15
|
-
var
|
|
15
|
+
var CoinPageComponent = function (_a) {
|
|
16
16
|
var navigation = _a.navigation, comments = _a.comments, products = _a.products, onPurchase = _a.onPurchase, onRestore = _a.onRestore, loading = _a.loading, isAllfreePaid = _a.isAllfreePaid;
|
|
17
17
|
var t = (0, react_i18next_1.useTranslation)().t;
|
|
18
18
|
var isAndroid = react_native_1.Platform.OS === "android";
|
|
@@ -25,12 +25,10 @@ var CoinPage = function (_a) {
|
|
|
25
25
|
<WaitingPayBanner_1.default currentPage="coin"/>
|
|
26
26
|
|
|
27
27
|
{products.map(function (product, index) {
|
|
28
|
-
var name = isAndroid ? product.
|
|
29
|
-
var price = product.
|
|
28
|
+
var name = isAndroid ? product.displayName : product.title;
|
|
29
|
+
var price = product.displayPrice;
|
|
30
30
|
var title = "".concat(name, " ").concat(price);
|
|
31
|
-
return (<common_1.RectangleCard key={index} title={title} note={product.description} left={<common_1.IconInCircle name="gift"/>} color={isAllfreePaid ? "ltBlack" : "blue"} onPress={function () {
|
|
32
|
-
return isAllfreePaid ? null : onPurchase(product.productId);
|
|
33
|
-
}}/>);
|
|
31
|
+
return (<common_1.RectangleCard key={index} title={title} note={product.description} left={<common_1.IconInCircle name="gift"/>} color={isAllfreePaid ? "ltBlack" : "blue"} onPress={function () { return (isAllfreePaid ? null : onPurchase(product.id)); }}/>);
|
|
34
32
|
})}
|
|
35
33
|
<react_native_1.View style={styles.txtContainer}>
|
|
36
34
|
<common_1.MyText fsize="sm" color="gray">
|
|
@@ -71,4 +69,4 @@ var styles = react_native_1.StyleSheet.create({
|
|
|
71
69
|
alignItems: "center",
|
|
72
70
|
},
|
|
73
71
|
});
|
|
74
|
-
exports.default =
|
|
72
|
+
exports.default = CoinPageComponent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Purchase } from "expo-iap";
|
|
2
2
|
import { Storage } from "@nakamura-123/types";
|
|
3
3
|
type Receipt = Storage.Receipt;
|
|
4
|
-
export declare const unifyReceipt: (receipt:
|
|
4
|
+
export declare const unifyReceipt: (receipt: Purchase) => Receipt | null;
|
|
5
5
|
export declare const validatePurchaseClientSide: (receipt: string | undefined, platform: "ios" | "android") => boolean;
|
|
6
6
|
export {};
|
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validatePurchaseClientSide = exports.unifyReceipt = void 0;
|
|
4
|
-
var react_native_1 = require("react-native");
|
|
5
4
|
// 01. レシートの形式を統一
|
|
6
5
|
var unifyReceipt = function (receipt) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
if (receipt.platform === "android")
|
|
7
|
+
return {
|
|
8
|
+
transactionId: receipt.transactionId || "",
|
|
9
|
+
productId: receipt.productId,
|
|
10
|
+
transactionDate: Number(receipt.transactionDate),
|
|
11
|
+
receipt: receipt.purchaseToken || "",
|
|
12
|
+
isPaid: receipt.purchaseStateAndroid === 0,
|
|
13
|
+
};
|
|
14
|
+
else
|
|
15
|
+
return {
|
|
16
|
+
transactionId: receipt.transactionId || "",
|
|
17
|
+
productId: receipt.productId,
|
|
18
|
+
transactionDate: Number(receipt.transactionDate),
|
|
19
|
+
receipt: receipt.transactionReceipt || "",
|
|
20
|
+
isPaid: true, // iOSでは即時完了
|
|
21
|
+
};
|
|
15
22
|
};
|
|
16
23
|
exports.unifyReceipt = unifyReceipt;
|
|
17
24
|
// 02. レシートの検証
|
package/dist/page/CoinPage.js
CHANGED
|
@@ -65,7 +65,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
65
65
|
var react_1 = __importStar(require("react"));
|
|
66
66
|
var react_redux_1 = require("react-redux");
|
|
67
67
|
var stores_1 = require("@nakamura-123/stores");
|
|
68
|
-
|
|
68
|
+
// import RNIap, { endConnection } from "react-native-iap";
|
|
69
|
+
var expo_iap_1 = require("expo-iap");
|
|
69
70
|
var CoinPageComponent_1 = __importDefault(require("../component/Coin/CoinPageComponent"));
|
|
70
71
|
var CoinFnc_1 = require("../component/Coin/CoinFnc");
|
|
71
72
|
var ReceiptFnc_1 = require("../component/Coin/ReceiptFnc");
|
|
@@ -84,7 +85,7 @@ var CoinPage = function (_a) {
|
|
|
84
85
|
(0, CoinFnc_1.initializeIAP)(items, setProducts, setLoading);
|
|
85
86
|
// アンマウント時に接続を終了
|
|
86
87
|
return function () {
|
|
87
|
-
(0,
|
|
88
|
+
(0, expo_iap_1.endConnection)();
|
|
88
89
|
};
|
|
89
90
|
}, []);
|
|
90
91
|
// 02.購入時の処理の実行
|