// TEST ENV -----------
const PAYGATEWAY_URL = "https://payin.payserv.net/"; // Sandbox
const NOTIFICATION_URL = `https://test-api.buildhubware.com/api/v.1/paynamics/webhooks`; // Test
const MERCHANT_ID = "00000006032419CD91C0";
const M_KEY = "1179E53D83E9B94C89D89D3A61B7BE0F";
const BA_USERNAME = "buildhub^$*";
const BA_PASSWORD = "pHkMl&D#4mFY";
const MP_URL = "https://test.buildhubware.com";
// TEST ENV -----------

// STAGING ENV -----------
// const PAYGATEWAY_URL = "https://payin.payserv.net/"; // Sandbox
// const NOTIFICATION_URL = `https://staging-api.buildhubware.com/api/v.1/paynamics/webhooks`; // Staging
// const MERCHANT_ID = "00000006032419CD91C0";
// const M_KEY = "1179E53D83E9B94C89D89D3A61B7BE0F";
// const BA_USERNAME = "buildhub^$*";
// const BA_PASSWORD = "pHkMl&D#4mFY";
// const MP_URL = "https://staging.buildhubware.com";
// STAGING ENV -----------

// PRODUCTION ENV -----------
// const PAYGATEWAY_URL = "https://payin.paynamics.net/"; // Production
// const NOTIFICATION_URL = `https://api.buildhubware.com/api/v.1/paynamics/webhooks`; // Production
// const MERCHANT_ID = "0000002904241450B797";
// const M_KEY = "3561A6B2F4F4378B89B4F2F60942BEB4";
// const BA_USERNAME = "buildhbprd*^!";
// const BA_PASSWORD = "ELG@7xBqrv";
// const MP_URL = "https://buildhub.ph";
// PRODUCTION ENV -----------

// CONSTANTS
const PAYNAMICS_TRANSACTION_REQUEST = "paygate/transactions/";
const authHeader = btoa(`${BA_USERNAME}:${BA_PASSWORD}`);
const urlEndpoint = `${PAYGATEWAY_URL}${PAYNAMICS_TRANSACTION_REQUEST}`;
const collectionMethod = "single_pay";
const paymentNotificationStatus = "1";
const paymentNotificationChannel = "1";
const currency = "PHP";

const paynamicsService = async (orderForm, paynamicsPaymentInfo) => {
  try {
    const encodedReferenceNo = btoa(orderForm.referenceNo);
    const responseUrl = `${MP_URL}/payment/web-hooks?ref=${encodedReferenceNo}`;

    const paymentMethodCode = paynamicsPaymentInfo?.pCode;
    const pChannel =
      paymentMethodCode !== "creditcard"
        ? paynamicsPaymentInfo?.pChannel
        : "gpap_cc_ph";

    const paymentAction =
      paymentMethodCode !== "nonbank_otc" ? "url_link" : "direct_otc";

    // Shipping and Billing
    const billingAddress1 = paynamicsPaymentInfo?.billingInfo?.address;
    const billingCity = paynamicsPaymentInfo?.billingInfo?.city;
    const billingState = paynamicsPaymentInfo?.billingInfo?.state;
    const billingCountry = paynamicsPaymentInfo?.billingInfo?.country;
    const billingZip = paynamicsPaymentInfo?.billingInfo?.zip;

    // Customer Info
    const firstName = paynamicsPaymentInfo?.customerInfo?.firstName;
    const lastName = paynamicsPaymentInfo?.customerInfo?.lastName;
    const middleName = paynamicsPaymentInfo?.customerInfo?.middleName;
    const email = orderForm?.customerInfo?.email;
    const phone = "";
    const mobile = "";
    const dob = "";
  } catch (err) {
    return { error: err };
  }
};
