UNPKG

node-ecpay-aio

Version:

A production-ready ECPay AIO SDK for Node.js with TypeScript support.

172 lines (171 loc) 5.63 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 (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); const yup = __importStar(require("yup")); const InvoiceParamsSchema = yup.object().shape({ RelateNumber: yup .string() .strict() .min(1) .max(30) .required() .matches(/^[\w_\-#$]{0,30}$/), CustomerID: yup .string() .strict() .max(20) .matches(/^[\w_]{0,20}$/), CustomerIdentifier: yup .string() .strict() .length(8) .matches(/^[0-9]+$/, 'must be only digits'), CustomerName: yup .string() .strict() .max(60) .when('Print', { is: '1', then: (schema) => schema.required().min(1), }), CustomerAddr: yup .string() .strict() .max(200) .when('Print', { is: '1', then: (schema) => schema.required().min(1), }), // CustomerPhone 與 CustomerEmail 必須擇一填寫 CustomerPhone: yup .string() .strict() .min(10) .max(20) .matches(/^[0-9]+$/, 'must be only digits') .when('CustomerEmail', { is: (CustomerEmail) => !CustomerEmail, then: (schema) => schema.required(), }), CustomerEmail: yup .string() .strict() .max(200) .email() .when('CustomerPhone', { is: (CustomerPhone) => !CustomerPhone, then: (schema) => schema.required(), }), ClearanceMark: yup .string() .strict() .when('TaxType', { is: '2', then: (schema) => schema.required().oneOf(['1', '2']), }), TaxType: yup.string().strict().required().oneOf(['1', '2', '3', '9']), CarruerType: yup .string() .strict() .when('Print', { is: '1', then: (schema) => schema.notRequired().length(0), }), CarruerNum: yup .string() .strict() .when('CarruerType', { is: (CarruerType) => !CarruerType || CarruerType === '1', then: (schema) => schema.notRequired().length(0), }) .when('CarruerType', { is: (CarruerType) => CarruerType === '2', then: (schema) => schema .required() .length(16) .matches(/[A-Z]{2}[0-9]{14}/), }) .when('CarruerType', { is: (CarruerType) => CarruerType === '3', then: (schema) => schema .required() .length(8) .matches(/^\/[A-Z0-9\s+-.]{7}$/), }), // 若手機條碼中有加號,可能在介接驗證時 發生錯誤,請將加號改為空白字元,產生 驗證碼。 // 若載具編號為手機條碼載具時,請先呼叫 B2C 電子發票介接技術文件手機條碼載驗證 API 進行檢核 Donation: yup .string() .strict() .required() .when('CustomerIdentifier', { is: (CustomerIdentifier) => !CustomerIdentifier, then: (schema) => schema.oneOf(['0', '1']), otherwise: (schema) => schema.oneOf(['0']), }) .when('Print', { is: '1', then: (schema) => schema.notOneOf(['1']), }), LoveCode: yup .string() .strict() .when('Donation', { is: '1', then: (schema) => { return schema .required() .min(3) .max(7) .matches(/^[0-9]+$/, 'must be only digits'); }, }), Print: yup .string() .strict() .required() .when('Donation', { is: '1', then: (schema) => schema.notOneOf(['1']), otherwise: (schema) => schema.oneOf(['0', '1']), }) .when('CustomerIdentifier', { is: (CustomerIdentifier) => !!CustomerIdentifier, then: (schema) => schema.notOneOf(['0']), otherwise: (schema) => schema.oneOf(['0', '1']), }), InvoiceItemName: yup.string().strict().required().min(1).max(100), InvoiceItemCount: yup.string().strict().required().min(1).max(4096), InvoiceItemWord: yup.string().strict().required().min(1).max(4096), InvoiceItemPrice: yup.string().strict().required().min(1).max(4096), InvoiceItemTaxType: yup.string().strict().max(4096), InvoiceRemark: yup.string().strict().max(4096), DelayDay: yup.number().integer().strict().required().min(0).max(15), InvType: yup.string().strict().required().oneOf(['07']), // '07': 一般稅額 }, [ ['CustomerPhone', 'CustomerEmail'], ['Donation', 'Print'], ]); exports.default = InvoiceParamsSchema;