"use strict";function getAuthorizeNetConfig(){const e=process.env.APP_AUTHORIZENET_API_LOGIN_ID,t=process.env.APP_AUTHORIZENET_TRANSACTION_KEY,n="production"===process.env.NODE_ENV?"production":"sandbox",r=process.env.APP_AUTHORIZENET_SIGNATURE_KEY;if(!e||!t)throw(0,error_1.createError)({statusCode:500,message:"Authorize.Net API credentials are not set in environment variables"});return{apiLoginId:e,transactionKey:t,environment:n,signatureKey:r}}function getAuthorizeNetEndpoint(e){return"production"===e?"https://api.authorize.net/xml/v1/request.api":"https://apitest.authorize.net/xml/v1/request.api"}function getAcceptHostedEndpoint(e){return"production"===e?"https://accept.authorize.net/payment/payment":"https://test.authorize.net/payment/payment"}function verifyWebhookSignature(e,t,n){if(!n){console_1.logger.warn("AUTHORIZENET","Signature key not configured, skipping verification");return!0}return`sha512=${crypto.createHmac("sha512",n).update(e).digest("hex").toUpperCase()}`===t}async function makeAuthorizeNetRequest(e,t){const n=getAuthorizeNetEndpoint(t.environment),r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)});if(!r.ok)throw(0,error_1.createError)({statusCode:400,message:`Authorize.Net API request failed: ${r.status} ${r.statusText}`});return await r.json()}function generateHostedPaymentSettings(e){var t;const n=[{settingName:"hostedPaymentReturnOptions",settingValue:JSON.stringify({showReceipt:null!==(t=e.showReceipt)&&void 0!==t&&t,url:e.returnUrl,urlText:"Continue",cancelUrl:e.cancelUrl,cancelUrlText:"Cancel"})},{settingName:"hostedPaymentButtonOptions",settingValue:JSON.stringify({text:"Pay Now"})},{settingName:"hostedPaymentStyleOptions",settingValue:JSON.stringify({bgColor:"#1f2937"})},{settingName:"hostedPaymentPaymentOptions",settingValue:JSON.stringify({cardCodeRequired:!0,showCreditCard:!0,showBankAccount:!1})},{settingName:"hostedPaymentSecurityOptions",settingValue:JSON.stringify({captcha:!1})},{settingName:"hostedPaymentBillingAddressOptions",settingValue:JSON.stringify({show:!0,required:!1})},{settingName:"hostedPaymentShippingAddressOptions",settingValue:JSON.stringify({show:!1,required:!1})},{settingName:"hostedPaymentCustomerOptions",settingValue:JSON.stringify({showEmail:!1,requiredEmail:!1})}];e.iframeCommunicatorUrl&&n.push({settingName:"hostedPaymentIFrameCommunicatorUrl",settingValue:JSON.stringify({url:e.iframeCommunicatorUrl})});return{setting:n}}var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[n]}});Object.defineProperty(e,r,i)}:function(e,t,n,r){void 0===r&&(r=n);e[r]=t[n]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(){var e=function(t){e=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t};return e(t)};return function(t){if(t&&t.__esModule)return t;var n={};if(null!=t)for(var r=e(t),i=0;i<r.length;i++)"default"!==r[i]&&__createBinding(n,t,r[i]);__setModuleDefault(n,t);return n}}();Object.defineProperty(exports,"__esModule",{value:!0});exports.getAuthorizeNetConfig=getAuthorizeNetConfig;exports.getAuthorizeNetEndpoint=getAuthorizeNetEndpoint;exports.getAcceptHostedEndpoint=getAcceptHostedEndpoint;exports.verifyWebhookSignature=verifyWebhookSignature;exports.makeAuthorizeNetRequest=makeAuthorizeNetRequest;exports.generateHostedPaymentSettings=generateHostedPaymentSettings;const crypto=__importStar(require("crypto")),console_1=require("@b/utils/console"),error_1=require("@b/utils/error");