66 lines
2.3 KiB
JavaScript
66 lines
2.3 KiB
JavaScript
"use strict";
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.transformWhmcsPaymentMethod = transformWhmcsPaymentMethod;
|
|
exports.transformWhmcsPaymentGateway = transformWhmcsPaymentGateway;
|
|
const schema_1 = require("../../schema");
|
|
const raw_types_1 = require("./raw.types");
|
|
const PAYMENT_TYPE_MAP = {
|
|
creditcard: "CreditCard",
|
|
bankaccount: "BankAccount",
|
|
remotecard: "RemoteCreditCard",
|
|
remotebankaccount: "RemoteBankAccount",
|
|
manual: "Manual",
|
|
remoteccreditcard: "RemoteCreditCard",
|
|
};
|
|
function mapPaymentMethodType(type) {
|
|
const normalized = type.trim().toLowerCase();
|
|
return PAYMENT_TYPE_MAP[normalized] ?? "Manual";
|
|
}
|
|
const GATEWAY_TYPE_MAP = {
|
|
merchant: "merchant",
|
|
thirdparty: "thirdparty",
|
|
tokenization: "tokenization",
|
|
manual: "manual",
|
|
};
|
|
function mapGatewayType(type) {
|
|
const normalized = type.trim().toLowerCase();
|
|
return GATEWAY_TYPE_MAP[normalized] ?? "manual";
|
|
}
|
|
function coerceBoolean(value) {
|
|
if (typeof value === "boolean")
|
|
return value;
|
|
if (typeof value === "number")
|
|
return value === 1;
|
|
if (typeof value === "string")
|
|
return value === "1" || value.toLowerCase() === "true";
|
|
return false;
|
|
}
|
|
function transformWhmcsPaymentMethod(raw) {
|
|
const whmcs = raw_types_1.whmcsPaymentMethodRawSchema.parse(raw);
|
|
const paymentMethod = {
|
|
id: whmcs.id,
|
|
type: mapPaymentMethodType(whmcs.payment_type || whmcs.type || "manual"),
|
|
description: whmcs.description,
|
|
gatewayName: whmcs.gateway_name || whmcs.gateway,
|
|
cardLastFour: whmcs.card_last_four,
|
|
expiryDate: whmcs.expiry_date,
|
|
cardType: whmcs.card_type,
|
|
bankName: whmcs.bank_name,
|
|
remoteToken: whmcs.remote_token,
|
|
lastUpdated: whmcs.last_updated,
|
|
isDefault: coerceBoolean(whmcs.is_default),
|
|
};
|
|
return schema_1.paymentMethodSchema.parse(paymentMethod);
|
|
}
|
|
function transformWhmcsPaymentGateway(raw) {
|
|
const whmcs = raw_types_1.whmcsPaymentGatewayRawSchema.parse(raw);
|
|
const gateway = {
|
|
name: whmcs.name,
|
|
displayName: whmcs.display_name || whmcs.name,
|
|
type: mapGatewayType(whmcs.type),
|
|
isActive: coerceBoolean(whmcs.visible),
|
|
configuration: whmcs.configuration,
|
|
};
|
|
return schema_1.paymentGatewaySchema.parse(gateway);
|
|
}
|
|
//# sourceMappingURL=mapper.js.map
|