//------------------------------------------------------------------------------------ //npm install --save axios moment dotenv const axios = require("axios"); const moment = require("moment"); require('dotenv').config() //------------------------------------------------------------------------------------ /* BEFORE RUNNING THIS EXAMPLE: * Set CONNECTFI_CLIENTID, CONNECTFI_PASSWORD, and CONNECTFI_BASE_URL in an .env file (Speak to a support representative to be issued client credentials and URL after receiving access to the sandbox.) * Set UNIQUE_CUSTOMER_REFERENCE_ID, UNIQUE_CARD_REFERENCE_ID, and UNIQUE_SSN each to a unique identifier. */ const CONNECTFI_CLIENTID = process.env.CONNECTFI_CLIENTID; const CONNECTFI_PASSWORD = process.env.CONNECTFI_PASSWORD; const CONNECTFI_BASE_URL = process.env.CONNECTFI_BASE_URL; const UNIQUE_CUSTOMER_REFERENCE_ID = "exampleCustRef1022"; //Update this value so that it is a unique ID before running const UNIQUE_CARD_REFERENCE_ID = "exampleRef1022"; //Update this value so that it is a unique ID before running const UNIQUE_SSN = "000000022"; //Update this value so that it is unique before running //Customer created in your client sandbox instance with the trigger SSN 666989698 (used for credit requests) //If defined, the CREDIT_CUSTOMERID will be used for all requests where a customerId is required const CREDIT_CUSTOMERID = undefined; //"cstap_1234567890ABCDEFabcdef"; //------------------------------------------------------------------------------------ //Get Authorization Token /* All other requests must have a valid authorization token in the request headers, so your first request in any workflow should be to /auth/get-token in order to receive an authorization token. A valid token should be included in the headers of all subsequent requests. */ async function getAuthToken() { const data = { "user": { "login": `${CONNECTFI_CLIENTID}`, "password": `${CONNECTFI_PASSWORD}` } }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/auth/get-token`, headers: { 'Content-Type': "application/json" }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Create (Customer) /* After you have received an authorization token, you may then initialize a customer. */ async function initCustomer(authToken, reference) { const data = { "customerReference": reference, //reference must be unique "customerType": "individual", "customer": { "firstName": "John", "lastName": "Doe", "gender": "M", "email": "your_email_address@email.sample", "phones": [ { "type": "MOBILE", "countryDialingCode": "01", "phoneNumber": "5555555555" } ], "dateOfBirth": "1969-08-04", "citizenshipCountryCodeA3": "USA", "addresses": [ { "type": "PRIMARY", "addressLine1": "123 Main Str.", "addressLine2": "apt 1", "city": "Harrisburg", "stateCode": "PA", "postalCode": "12345", "countryCodeA3": "USA" } ], "identificationDocuments": [ { "type": "SSN", "value": UNIQUE_SSN, // The SSN 666989698 is a trigger value to allow the customer to pass a credit check if desired "issuanceCountryCodeA3": "USA" }, { "type": "DRIVING LICENSE", "value": "PA99999999", "issuanceCountryCodeA3": "USA", "issuanceRegion": "PA", "expiryDate": "2029-12-28" } ] } }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/customer/init`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Add vAccount /* You may add a vAccount (virtual account) through a POST request to ibis/account/add. The vAccount that is created can be used both as a bank account (using the account number and routing number) and similar to a debit card (using the cFiAccountId that is issued in place of the cFiCardId where applicable). The cFiAccountId can be used to make requests to the following debit card related endpoints: /ibis/card/activate, /ibis/card/cardholder-profile, /ibis/card/status, /ibis/card/list (will include all cards and vAccounts for the specified customer), /ibis/financial/funds-credit, /ibis/financial/funds-debit, /ibis/financial/card-to-card, and /ibis/inquiry/transaction-history */ async function addVAccount(authToken, customerId, reference) { const data = { "customerId": customerId, //received when initializing the customer with /customer/init, "reference": reference, //reference must be unique "profile": { "accountHolderId": customerId } }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/account/add`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Add Debit Card /* You may add a Debit Card through a POST request to /ibis/debit-card/add. */ async function addDebitCard(authToken, customerId, reference) { const data = { "customerId": customerId, //received when initializing the customer with /customer/init, "reference": reference, //reference must be unique "cardProgramId": "d_gpr_test", "profile": { "occupation": "Student", "nameOnCard": "JOLEEN KAPSCH" } }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/debit-card/add`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Credit Application /* You may initialize a credit application through a POST request to /ibis/credit-card/application. When initializing the customer, the SSN 666989698 is a trigger value to allow the customer to pass a credit check if desired. Since customer SSNs must be unique, only one customer may be created in the client sandbox instance using the trigger SSN 666989698. This customer should be used for all requests involving individual credit applications or credit card issuing. */ async function creditApplication(authToken, customerId) { const data = { "customerId": customerId, //received when initializing the customer with /customer/init "employer": "ABC123 Inc", "totalAnnualIncome": 50000, "totalAnnualIncomeCurrency": "USD" }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/credit-card/application`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Get Application /* You may retrieve the details of a credit application through a GET request to /ibis/credit-card/application/:applicationId. */ async function getApplication(authToken, applicationId) { const config = { method: 'GET', url: `${CONNECTFI_BASE_URL}/ibis/credit-card/application/${applicationId}`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required } }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Add Credit Card /* You may add a Credit Card through a POST request to /ibis/credit-card/add. */ async function addCreditCard(authToken, customerId, applicationId, reference) { const data = { "customerId": customerId, //received when initializing the customer with /customer/init "reference": reference, //reference must be unique "cardProgramId": "Evolve_Test", "applicationId": applicationId, "profile": { "occupation": "Student", "nameOnCard": "John Testman" }, "creditLimit": 1500, "creditLimitCurrency": "USD" }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/credit-card/add`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Activate Card /* Activate a card that has been issued through a POST request to /ibis/card/activate. */ async function activateCard(authToken, cFiCardId) { const data = { "cFiCardId": cFiCardId }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/card/activate`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Get Card Auth Data /* The POST /ibis/card/get-auth-data endpoint can be used to retrieve the CVV/CVC card security code for the specified card. The connectFi API uses tokenization to redact the CVV/CVC card security code while in our system and does not store the security code or card PAN at any point. It is your (the client's) responsibility to ensure that sensitive card data is redacted when being handled in your system. */ async function getCardAuthData(authToken, cFiCardId) { const data = { "cFiCardId": cFiCardId }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/card/get-auth-data`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Sync Cardholder Profile /* The POST /ibis/card/sync-profile endpoint can be used to sync the current customer profile details stored in connectFi to the relevant card profile at the card processor. After the email, addresses, and/or phones of an individual customer have been updated in connectFi using the /customer/update endpoint, then the updated information should be synced with any relevant accounts and/or cards that have been issued through /ibis endpoints. */ async function syncCardholderProfile(authToken, customerId, cFiCardId) { const data = { "customerId": customerId, "cFiCardId": cFiCardId }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/card/sync-profile`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Set PIN /* Set the card PIN through a POST request to /ibis/card/set-pin. */ async function setPIN(authToken, cFiCardId) { const data = { "cFiCardId": cFiCardId, "pin": "1234" }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/card/set-pin`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Check PIN /* Check the card PIN through a POST request to /ibis/card/check-pin. */ async function checkPIN(authToken, cFiCardId) { const data = { "cFiCardId": cFiCardId, "pin": "1234" }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/card/check-pin`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Check Status /* Check the card status through a POST request to /ibis/card/status. */ async function checkStatus(authToken, cFiCardId) { const data = { "cFiCardId": cFiCardId }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/card/status`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Set Status /* Set the card status through a POST request to /ibis/card/set-status. */ async function setStatus(authToken, cFiCardId, status) { const data = { "cFiCardId": cFiCardId, "statusCode": status }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/card/set-status`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Cardholder Profile /* Retrieve the cardholder profile through a POST request to /ibis/card/cardholder-profile. */ async function cardholderProfile(authToken, cFiCardId) { const data = { "cFiCardId": cFiCardId }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/card/cardholder-profile`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //List Cards/Accounts /* List all cards and vAccounts belonging to a specified customer through a POST request to /ibis/card/list. */ async function list(authToken, customerId) { const data = { "customerId": customerId }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/card/list`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Credit /* Post a credit transaction through a POST request to /ibis/financial/funds-credit. */ async function creditTransaction(authToken, cFiCardId, amount) { const data = { "reference": `cT${UNIQUE_CARD_REFERENCE_ID}`, //reference must be unique "cFiCardId": cFiCardId, "description": "Credit transaction (add funds to card)", "amount": amount, "currency": "USD" }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/financial/funds-credit`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Debit /* Post a debit transaction through a POST request to /ibis/financial/funds-debit. */ async function debitTransaction(authToken, cFiCardId, amount) { const data = { "reference": `dT${UNIQUE_CARD_REFERENCE_ID}`, //reference must be unique "cFiCardId": cFiCardId, "description": "Debit transaction (subtract funds from card)", "amount": amount, "currency": "USD" }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/financial/funds-debit`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Card-to-Card /* Post a card-to-card transaction through a POST request to /ibis/financial/card-to-card. cardFromId and cardToId must have been created using the same card program ID. The cardFromId card must have funds loaded prior to transferring funds through a card-to-card transaction request. */ async function c2cTransaction(authToken, cFiCardId1, cFiCardId2, amount) { const data = { "reference": `c2c${UNIQUE_CARD_REFERENCE_ID}`, //reference must be unique "cardFromId": cFiCardId1, "cardToId": cFiCardId2, "description": "Card-to-card transaction", "amount": amount, "currency": "USD" }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/financial/card-to-card`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Retrieve Transaction /* Retrieve a specified transaction through a POST request to /ibis/financial/retrieve. */ async function retrieveTransaction(authToken, cFiFundsId) { const data = { "cFiFundsId": cFiFundsId }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/financial/retrieve`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Transaction History /* Retrieve the transaction history for a specified card through a POST request to /ibis/inquiry/transaction-history. */ async function transactionHistory(authToken, cFiCardId) { const data = { "cFiCardId": cFiCardId, "dateFrom": `${moment(new Date()).add(-1, "day").format("YYYY-MM-DD")}`, "dateTo": `${moment(new Date()).format("YYYY-MM-DD")}` }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/inquiry/transaction-history`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Reverse Transaction /* Reverse a previous card-to-card transaction through a POST request to /ibis/financial/reversal. */ async function reverseTransaction(authToken, cFiFundsId) { const data = { "cFiFundsId": cFiFundsId }; const config = { method: 'POST', url: `${CONNECTFI_BASE_URL}/ibis/financial/reversal`, headers: { 'Content-Type': "application/json", 'x-connectfi-token': authToken //previously obtained authorization token is required }, data }; let result; try { result = await axios.request(config); if (result.status === 200) { return Promise.resolve(result.data.data); } } catch (err) { console.log({ errCode: err.code, responseStatus: err.response && err.response.status, data: err.response && JSON.stringify(err.response.data) }); } } //------------------------------------------------------------------------------------ //Run the walkthrough async function cardsWalkthrough() { //Get Authorization Token console.log(`Start /auth/get-token example.\n`); const authObject = await getAuthToken(); let authToken = undefined; if (authObject) { console.log(`Successfully obtained authorization: ${JSON.stringify(authObject)}\n`); authToken = authObject.token; console.log(`Authorization token: ${authToken}\n`); } else { console.log(`Error getting authorization token\n`) } console.log(`End /auth/get-token example.\n`); //Create (Customer) console.log(`Start /customer/init example.\n`); let customerId = undefined; let customerInitResult; if (authToken) { customerInitResult = await initCustomer(authToken, UNIQUE_CUSTOMER_REFERENCE_ID); } else { console.log(`Authorization token is required. Customer not initialized.\n`) } if (customerInitResult) { customerId = CREDIT_CUSTOMERID || customerInitResult.customerId; console.log(`Successfully created customer: ${JSON.stringify(customerInitResult)}\n`); } console.log(`End /customer/init example.\n`); //Add Account console.log(`Start /ibis/account/add example.\n`); let addAccountResult; if (authToken && customerId) { addAccountResult = await addVAccount(authToken, customerId, `vA${UNIQUE_CARD_REFERENCE_ID}`); } else { console.log(`Authorization token and customerId are required.\n`) } if (addAccountResult) { console.log(`Successfully added a vAccount to customer: ${JSON.stringify(addAccountResult)}\n`); } console.log(`End /ibis/account/add example.\n`); //Add Debit Card console.log(`Start /ibis/debit-card/add example.\n`); let addDebitCardResult1; let debitCFiCardId1; if (authToken && customerId) { addDebitCardResult1 = await addDebitCard(authToken, customerId, `DC1${UNIQUE_CARD_REFERENCE_ID}`); } else { console.log(`Authorization token and customerId are required.\n`) } if (addDebitCardResult1) { debitCFiCardId1 = addDebitCardResult1.cFiCardId; console.log(`Successfully added debit card to customer: ${JSON.stringify(addDebitCardResult1)}\n`); } console.log(`End /ibis/debit-card/add example.\n`); //Add Debit Card 2 (for use with card-to-card transfer) console.log(`Start /ibis/debit-card/add example 2.\n`); let addDebitCardResult2; let debitCFiCardId2; if (authToken && customerId) { addDebitCardResult2 = await addDebitCard(authToken, customerId, `DC2${UNIQUE_CARD_REFERENCE_ID}`); } else { console.log(`Authorization token and customerId are required.\n`) } if (addDebitCardResult2) { debitCFiCardId2 = addDebitCardResult2.cFiCardId; console.log(`Successfully added debit card to customer: ${JSON.stringify(addDebitCardResult2)}\n`); } console.log(`End /ibis/debit-card/add example 2.\n`); if (CREDIT_CUSTOMERID || customerInitResult.customer.identificationDocuments[0].last4 === "9698") { //Start Credit Application console.log(`Start /ibis/credit-card/application example.\n`); let creditApplicationResult; let applicationId; if (authToken && customerId) { creditApplicationResult = await creditApplication(authToken, customerId); } else { console.log(`Authorization token and customerId are required.\n`) } if (creditApplicationResult) { applicationId = creditApplicationResult.applicationId; console.log(`Successfully created a credit application for customer: ${JSON.stringify(creditApplicationResult)}\n`); } console.log(`End /ibis/credit-card/application example.\n`); //Get Credit Application console.log(`Start /ibis/credit-card/application/:applicationId example.\n`); let getCreditApplicationResult; if (authToken && applicationId) { getCreditApplicationResult = await getApplication(authToken, applicationId); } else { console.log(`Authorization token and applicationId are required.\n`) } if (getCreditApplicationResult) { console.log(`Successfully retrieved credit application: ${JSON.stringify(getCreditApplicationResult)}\n`); } console.log(`End /ibis/credit-card/application/:applicationId example.\n`); //Add Credit Card console.log(`Start /ibis/credit-card/add example.\n`); let addCreditCardResult; if (authToken && applicationId && customerId) { addCreditCardResult = await addCreditCard(authToken, customerId, applicationId, `CC${UNIQUE_CARD_REFERENCE_ID}`); } else { console.log(`Authorization token, customerId, and applicationId are required.\n`) } if (addCreditCardResult) { console.log(`Successfully added a credit card to the specified customer: ${JSON.stringify(addCreditCardResult)}\n`); } console.log(`End /ibis/credit-card/add example.\n`); } else { console.log("To include credit application and credit card requests in the walkthrough,"); console.log(`you must have a customer defined using the trigger SSN: 666989698\n`); console.log("Use the trigger SSN to initialize a new customer. Or, if such a customer"); console.log(`exists, store the customerId in the CREDIT_CUSTOMERID variable.\n`); } //Activate Debit Card console.log(`Start /ibis/card/activate example.\n`); let activateCardResult; if (authToken && debitCFiCardId1) { activateCardResult = await activateCard(authToken, debitCFiCardId1); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (activateCardResult) { console.log(`Successfully activated card: ${JSON.stringify(activateCardResult)}\n`); } console.log(`End /ibis/card/activate example.\n`); //Get Card Auth Data console.log(`Start /ibis/card/get-auth-data example.\n`); let getCardAuthDataResult; if (authToken && debitCFiCardId1) { getCardAuthDataResult = await getCardAuthData(authToken, debitCFiCardId1); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (getCardAuthDataResult) { console.log(`Successfully retrieved card auth data: ${JSON.stringify(getCardAuthDataResult)}\n`); } console.log(`End /ibis/card/get-auth-data example.\n`); //Sync Cardholder Profile console.log(`Start /ibis/card/sync-profile example.\n`); let syncCardholderProfileResult; if (authToken && debitCFiCardId1 && customerId) { syncCardholderProfileResult = await syncCardholderProfile(authToken, customerId, debitCFiCardId1); } else { console.log(`Authorization token, customerId, and cFiCardId are required.\n`) } if (syncCardholderProfileResult) { console.log(`Successfully synced profile data: ${JSON.stringify(syncCardholderProfileResult)}\n`); } console.log(`End /ibis/card/sync-profile example.\n`); //Set Card PIN console.log(`Start /ibis/card/set-pin example.\n`); let setPINResult; if (authToken && debitCFiCardId1) { setPINResult = await setPIN(authToken, debitCFiCardId1); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (setPINResult) { console.log(`Successfully set card PIN: ${JSON.stringify(setPINResult)}\n`); } console.log(`End /ibis/card/set-pin example.\n`); //Check Card PIN console.log(`Start /ibis/card/check-pin example.\n`); let checkCardPINResult; if (authToken && debitCFiCardId1) { checkCardPINResult = await checkPIN(authToken, debitCFiCardId1); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (checkCardPINResult) { console.log(`Successfully checked card PIN: ${JSON.stringify(checkCardPINResult)}\n`); } console.log(`End /ibis/card/check-pin example.\n`); //Check Card Status console.log(`Start /ibis/card/status example.\n`); let checkCardStatusResult; if (authToken && debitCFiCardId1) { checkCardStatusResult = await checkStatus(authToken, debitCFiCardId1); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (checkCardStatusResult) { console.log(`Successfully retrieved card status: ${JSON.stringify(checkCardStatusResult)}\n`); } console.log(`End /ibis/card/status example.\n`); //Set Card Status "I" console.log(`Start /ibis/card/set-status example - Inactive.\n`); let setCardStatusResult; if (authToken && debitCFiCardId1) { setCardStatusResult = await setStatus(authToken, debitCFiCardId1, "I"); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (setCardStatusResult) { console.log(`Successfully set card status: ${JSON.stringify(setCardStatusResult)}\n`); } console.log(`End /ibis/card/set-status example - Inactive.\n`); //Set Card Status "B" console.log(`Start /ibis/card/set-status example - Active.\n`); if (authToken && debitCFiCardId1) { setCardStatusResult = await setStatus(authToken, debitCFiCardId1, "B"); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (setCardStatusResult) { console.log(`Successfully set card status: ${JSON.stringify(setCardStatusResult)}\n`); } console.log(`End /ibis/card/set-status example - Active.\n`); //Get Cardholder Profile console.log(`Start /ibis/card/cardholder-profile example.\n`); let cardholderProfileResult; if (authToken && debitCFiCardId1) { cardholderProfileResult = await cardholderProfile(authToken, debitCFiCardId1); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (cardholderProfileResult) { console.log(`Successfully retrieved cardholder profile: ${JSON.stringify(cardholderProfileResult)}\n`); } console.log(`End /ibis/card/cardholder-profile example.\n`); //List Cards/Accounts console.log(`Start /ibis/card/list example.\n`); let listResult; if (authToken && customerId) { listResult = await list(authToken, customerId); } else { console.log(`Authorization token and customerId are required.\n`) } if (listResult) { console.log(`Successfully retrieved list of cards and accounts: ${JSON.stringify(listResult)}\n`); } console.log(`End /ibis/card/list example.\n`); //Credit Transaction console.log(`Start /ibis/financial/funds-credit example.\n`); let creditTransactionResult; if (authToken && debitCFiCardId1) { creditTransactionResult = await creditTransaction(authToken, debitCFiCardId1, 30.00); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (creditTransactionResult) { console.log(`Successfully credited funds: ${JSON.stringify(creditTransactionResult)}\n`); } console.log(`End /ibis/financial/funds-credit example.\n`); //Debit Transaction console.log(`Start /ibis/financial/funds-debit example.\n`); let debitTransactionResult; if (authToken && debitCFiCardId1) { debitTransactionResult = await debitTransaction(authToken, debitCFiCardId1, 1.01); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (debitTransactionResult) { console.log(`Successfully debited funds: ${JSON.stringify(debitTransactionResult)}\n`); } console.log(`End /ibis/financial/funds-debit example.\n`); //Card-to-Card Transaction console.log(`Start /ibis/financial/card-to-card example.\n`); let c2cTransactionResult; let transactionId = undefined; if (authToken && debitCFiCardId1 && debitCFiCardId2) { c2cTransactionResult = await c2cTransaction(authToken, debitCFiCardId1, debitCFiCardId2, 20.00); } else { console.log(`Authorization token, cFiCardId1, and cFiCardId2 are required.\n`) } if (c2cTransactionResult) { transactionId = c2cTransactionResult.cFiFundsId; console.log(`Successfully transferred funds card-to-card: ${JSON.stringify(c2cTransactionResult)}\n`); } console.log(`End /ibis/financial/card-to-card example.\n`); //Retrieve Transaction console.log(`Start /ibis/financial/retrieve example.\n`); let retrieveTransactionResult; if (authToken && transactionId) { retrieveTransactionResult = await retrieveTransaction(authToken, transactionId); } else { console.log(`Authorization token and cFiFundsId are required.\n`) } if (retrieveTransactionResult) { console.log(`Successfully retrieved transaction details: ${JSON.stringify(retrieveTransactionResult)}\n`); } console.log(`End /ibis/financial/retrieve example.\n`); //Reverse Transaction console.log(`Start /ibis/financial/reversal example.\n`); let reverseTransactionResult; if (authToken && transactionId) { reverseTransactionResult = await reverseTransaction(authToken, transactionId); } else { console.log(`Authorization token and cFiFundsId are required.\n`) } if (reverseTransactionResult) { console.log(`Successfully reversed transaction: ${JSON.stringify(reverseTransactionResult)}\n`); } console.log(`End /ibis/financial/reversal example.\n`); //Transaction History console.log(`Start /ibis/inquiry/transaction-history example.\n`); let transactionHistoryResult; if (authToken && debitCFiCardId1) { transactionHistoryResult = await transactionHistory(authToken, debitCFiCardId1); } else { console.log(`Authorization token and cFiCardId are required.\n`) } if (transactionHistoryResult) { console.log(`Successfully retrieved transaction history: ${JSON.stringify(transactionHistoryResult)}\n`); } console.log(`End /ibis/inquiry/transaction-history example.\n`); } if (process.env.CONNECTFI_CLIENTID && process.env.CONNECTFI_PASSWORD && process.env.CONNECTFI_BASE_URL) { cardsWalkthrough(); } else { console.log("Before running the walkthrough, set the required .env variables."); }