@blockbolt/boltpay-client
Version:
BoltPay SDK for E-Commerce
74 lines (73 loc) • 2.65 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyPayment = void 0;
const superagent_1 = __importDefault(require("superagent"));
const index_1 = require("../utils/index");
const verifyPayment = async (verifyPayments) => {
const onHashTransaction = async (randomKey) => {
const getNetwork = verifyPayments.network;
const getTxnDigest = verifyPayments.digest;
const networkUrl = getNetwork == "testnet"
? index_1.RPC_TESTNET
: getNetwork == "devnet"
? index_1.RPC_DEVNET
: index_1.RPC_MAINNET;
const data = {
jsonrpc: "2.0",
id: 1,
method: "sui_getTransactionBlock",
params: [
getTxnDigest,
{
showInput: true,
showEffects: true,
},
],
};
try {
const res = await superagent_1.default.post(networkUrl).send(data);
if (res && res.body && res.body.error) {
return index_1.STATUS_106;
}
if (res && res.body && res.body.result) {
const { transaction } = res.body.result;
const { effects } = res.body.result;
if (transaction &&
transaction.data.transaction.inputs.length === 4 &&
transaction.data.transaction.inputs[2].value === randomKey.toString()) {
if (effects &&
effects.status &&
effects.status.status === "success") {
return index_1.STATUS_101;
}
else if (effects &&
effects.status &&
effects.status.status === "failure") {
return index_1.STATUS_102;
}
}
else {
return index_1.STATUS_104;
}
}
}
catch (error) {
return `${error}`;
}
};
if (verifyPayments &&
verifyPayments.network !== null &&
verifyPayments !== undefined &&
verifyPayments.digest !== null &&
verifyPayments.digest !== undefined) {
const ts = await onHashTransaction(index_1.ITEM_UNIQUE_KEY);
return ts;
}
else {
return index_1.STATUS_105;
}
};
exports.verifyPayment = verifyPayment;