ecpay-einvoice-ts
Version:
ECPay e-invoice SDK for TypeScript
97 lines (96 loc) • 3.62 kB
JavaScript
"use strict";
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const index_1 = __importDefault(require("./index"));
describe("綠界開立發票", () => {
const data = `{
"MerchantID": "2000132",
"RelateNumber": "e4323209223",
"CustomerID": "",
"CustomerIdentifier": "",
"CustomerName": "綠界科技股份有限公司",
"CustomerAddr": "106台北市南港區發票一街1號1樓",
"CustomerPhone": "",
"CustomerEmail": "test@ecpay.com.tw",
"ClearanceMark": "1",
"Print": "1",
"Donation": "0",
"LoveCode": "",
"CarrierType": "",
"CarrierNum": "",
"TaxType": "1",
"SalesAmount": 100,
"InvoiceRemark": "發票備註",
"InvType": "07",
"vat": "1",
"Items": [
{
"ItemSeq": 1,
"ItemName": "item01",
"ItemCount": 1,
"ItemWord": "件",
"ItemPrice": 50,
"ItemTaxType": "1",
"ItemAmount": 50,
"ItemRemark": "item01_desc"
},
{
"ItemSeq": 2,
"ItemName": "item02",
"ItemCount": 1,
"ItemWord": "個",
"ItemPrice": 20,
"ItemTaxType": "1",
"ItemAmount": 20,
"ItemRemark": "item02_desc"
},
{
"ItemSeq": 3,
"ItemName": "item03",
"ItemCount": 3,
"ItemWord": "粒",
"ItemPrice": 10,
"ItemTaxType": "1",
"ItemAmount": 30,
"ItemRemark": "item03_desc"
}
]
}`;
const o = JSON.parse(data);
const ecpay = (0, index_1.default)({
MerchantID: "2000132",
HashIV: "q9jcZX8Ib9LM8wYk",
HashKey: "ejCk326UnaZWKisg",
BaseURL: "https://einvoice-stage.ecpay.com.tw",
});
it("issue", () => __awaiter(void 0, void 0, void 0, function* () {
const result = yield ecpay.Issue(o);
console.log(result.DecryptedData);
}));
it("查詢發票", () => __awaiter(void 0, void 0, void 0, function* () {
const r = yield ecpay.GetIssueList({
BeginDate: "2023-10-01", EndDate: "2023-10-19", MerchantID: "2000132", NumPerPage: 200, ShowingPage: 1
});
console.log(r);
const printableInvoice = r.InvoiceData.find(v => v.IIS_Print_Flag === "1");
if (!printableInvoice)
throw new Error("沒有可列印的發票");
const printResult = yield ecpay.InvoicePrint({
InvoiceDate: printableInvoice.IIS_Create_Date.slice(0, 10),
MerchantID: "2000132",
InvoiceNo: printableInvoice.IIS_Number,
});
console.log(printResult);
}));
});