"use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0});exports.verify2CheckoutSignature=exports.generate2CheckoutSignature=exports.get2CheckoutApiUrl=exports.use2Checkout=void 0;const crypto_1=__importDefault(require("crypto")),error_1=require("@b/utils/error"),TWOCHECKOUT_MERCHANT_CODE=process.env.APP_2CHECKOUT_MERCHANT_CODE,TWOCHECKOUT_SECRET_KEY=process.env.APP_2CHECKOUT_SECRET_KEY,TWOCHECKOUT_ACCOUNT_REFERENCE=process.env.APP_2CHECKOUT_ACCOUNT_REFERENCE,use2Checkout=()=>{if(!TWOCHECKOUT_MERCHANT_CODE||!TWOCHECKOUT_SECRET_KEY)throw(0,error_1.createError)({statusCode:500,message:"2Checkout credentials are not set in environment variables."});return{merchantCode:TWOCHECKOUT_MERCHANT_CODE,secretKey:TWOCHECKOUT_SECRET_KEY,accountReference:TWOCHECKOUT_ACCOUNT_REFERENCE||"",isProduction:"production"===process.env.NODE_ENV}};exports.use2Checkout=use2Checkout;const get2CheckoutApiUrl=()=>"https://api.2checkout.com";exports.get2CheckoutApiUrl=get2CheckoutApiUrl;const generate2CheckoutSignature=(e,t)=>{const r=Object.keys(e).sort();let o="";r.forEach(t=>{null!==e[t]&&void 0!==e[t]&&(o+=`${t}${e[t]}`)});return crypto_1.default.createHmac("sha256",t).update(o).digest("hex")};exports.generate2CheckoutSignature=generate2CheckoutSignature;const verify2CheckoutSignature=(e,t,r)=>(0,exports.generate2CheckoutSignature)(e,r)===t;exports.verify2CheckoutSignature=verify2CheckoutSignature;