UNPKG

@mathrunet/masamune

Version:

Manages packages for the server portion (NodeJS) of the Masamune framework.

130 lines 5.26 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.verifyAndroid = verifyAndroid; const functions = __importStar(require("firebase-functions/v2")); const googleapis_1 = require("googleapis"); /** * Perform Android receipt verification. * * Android の受信確認を実行します。 * * @param {"products" | "subscriptions"} type * Item type(products or subscriptions) * * アイテムの種類(製品またはサブスクリプション) * * @param {String} serviceAccountEmail * The email address of your Google Services account. * * Googleサービスアカウントのメールアドレス。 * * @param {String} serviceAccountPrivateKey * A private key for your Google Services account. * * Googleサービスアカウントのプライベートキー。 * * @param {String} packageName * Application package name. * * アプリケーションのパッケージ名。 * * @param {String} productId * Item ID issued by Google Play. * * GooglePlayで発行されたアイテムID。 * * @param {String} purchaseToken * The purchase token issued at the time of purchase. * * 購入したときに発行された購入トークン。 * * @return {Promise<{ [key: string]: any; }} * Receipt information for the item. * * アイテムの受領情報。 */ function verifyAndroid(_a) { return __awaiter(this, arguments, void 0, function* ({ type, serviceAccountEmail, serviceAccountPrivateKey, packageName, productId, purchaseToken, }) { try { const authClient = new googleapis_1.google.auth.JWT({ email: serviceAccountEmail, key: serviceAccountPrivateKey.replace(/\\n/g, "\n"), scopes: ["https://www.googleapis.com/auth/androidpublisher"] }); const playDeveloperApiClient = googleapis_1.google.androidpublisher({ version: "v3", auth: authClient, }); yield authClient.authorize(); if (type === "products") { const res = yield playDeveloperApiClient.purchases.products.get({ packageName: packageName, productId: productId, token: purchaseToken, }); if (res.status !== 200) { throw new functions.https.HttpsError("not-found", "The validation data is empty."); } return res.data; } else if (type === "subscriptions") { const res = yield playDeveloperApiClient.purchases.subscriptions.get({ packageName: packageName, subscriptionId: productId, token: purchaseToken, }); if (res.status !== 200) { throw new functions.https.HttpsError("not-found", "The validation data is empty."); } return res.data; } } catch (error) { console.log(error); } throw new functions.https.HttpsError("not-found", "The validation data is empty."); }); } //# sourceMappingURL=verify_android.js.map