/******************************************************************* * Configuration * * Reads the pin.conf file to determine the database we want. * * Not actually needed here since we use PCM_CONNECT to * open our database connection and get the database # * returned as a by product. But this does illustrate * how to use pin_conf to retrieve conf'ed info. * *******************************************************************/ void sample_read_pin_conf( u_int64 *databasep, pin_errbuf_t *ebufp) { poid_t *db_pdp; int32 err; /*********************************************************** * Clear the error buffer. ***********************************************************/ PIN_ERR_CLEAR_ERR(ebufp); /*********************************************************** * Get the config userid to determine DB. * * Note: This allocates a poid that we must free. ***********************************************************/ pin_conf("-", "userid", PIN_FLDT_POID, (caddr_t *)&(db_pdp), &err); if (err != PIN_ERR_NONE) { ebufp->pin_err = err; return; } *databasep = PIN_POID_GET_DB(db_pdp); PIN_POID_DESTROY(db_pdp, NULL); return; }
/* FUNCTION ***************************************************************** ** Initialise one of the internal ADCs on the LPC23xx/LPC17xx ** *****************************************************************************/ void adc_init_dev (adcDevice_t *device) { /* enable power for ADC converters */ PCONP |= PCADC; switch(device->channel) { case ADC0_0: pin_conf(PORT0,PIN23,PIN_ALT1_FUNC,PIN_NO_PULL); /* AD0 */ break; case ADC0_1: pin_conf(PORT0,PIN24,PIN_ALT1_FUNC,PIN_NO_PULL); /* AD1 */ break; case ADC0_2: pin_conf(PORT0,PIN25,PIN_ALT1_FUNC,PIN_NO_PULL); /* AD2 */ break; case ADC0_3: pin_conf(PORT0,PIN26,PIN_ALT1_FUNC,PIN_NO_PULL); /* AD3 */ break; case ADC0_4: pin_conf(PORT1,PIN30,PIN_ALT3_FUNC,PIN_NO_PULL); /* AD4 */ break; case ADC0_5: pin_conf(PORT1,PIN31,PIN_ALT3_FUNC,PIN_NO_PULL); /* AD5 */ break; default: //ADC_DEBUG_PRINTF((DEBUG_UART, "No regular adc initialised\n")); break; } }
/******************************************************************* * Function bodies. *******************************************************************/ void fm_zonemap_pol_get_lineage_init() { int32 *i_ptr = NULL; int32 error = 0; PIN_HEAP_VAR; PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_init Enter"); /* * Init ProductHashArray */ if (nInitDone == PIN_BOOLEAN_FALSE) { nInitDone = PIN_BOOLEAN_TRUE; /* * initialize the interval */ interval = 3600; /* * read the value of this variable from the pin.conf file. If it * doesn't exist then the default value stays. */ pin_conf("fm_zonemap_pol", "update_interval", PIN_FLDT_INT, (caddr_t *)&i_ptr, &error); if (error == PIN_ERR_NONE) { interval = *i_ptr; } if (i_ptr) { free(i_ptr); } PIN_SET_GLOBAL_HEAP; /* * Init mutex */ MutexInit(HashTableLock); PIN_RESET_GLOBAL_HEAP; } PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "fm_zonemap_pol_get_lineage_init Exit"); }
/******************************************************************* * Main * * This sets up the parameters and then calls the FM. * *******************************************************************/ int main( int argc, char *argv[]) { pcm_context_t *ctxp; pin_flist_t *flistp = NULL; pin_flist_t *a_flistp = NULL; pin_flist_t *r_flistp = NULL; poid_t *acct_pdp = NULL; poid_t *srvc_pdp = NULL; u_int opcode; int64 database; void *vp; char logfile[256]; char *c_ptr = (char *)NULL; char *program; int32 err; pin_errbuf_t ebuf; PIN_ERR_CLEAR_ERR(&ebuf); /* * Logging initialization */ program = basename(argv[0]); PIN_ERR_SET_PROGRAM(program); PIN_ERR_SET_LEVEL(PIN_ERR_LEVEL_WARNING); strcpy(logfile, "default.pinlog"); pin_conf(program, "logfile", PIN_FLDT_STR, (caddr_t *)&(c_ptr), &err); if (c_ptr != (char *)NULL) { pin_strlcpy(logfile, c_ptr, sizeof(logfile)); pin_free(c_ptr); c_ptr = (char *)NULL; } PIN_ERR_SET_LOGFILE(logfile); /* * Check the input. */ if (argc != 3) { usage(argv[0]); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR, "bad # of arguments"); exit(1); } /* * Initialize PCM connection. */ PCM_CONNECT(&ctxp, &database, &ebuf); if (PIN_ERR_IS_ERR(&ebuf)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "pcm_connect error", &ebuf); exit(2); } /* * Create the poid prototype. */ srvc_pdp = PIN_POID_CREATE(database, argv[1], 0, &ebuf); /* * Look up the account. */ flistp = PIN_FLIST_CREATE(&ebuf); vp = (void *)srvc_pdp; PIN_FLIST_FLD_SET(flistp, PIN_FLD_POID, vp, &ebuf); vp = (void *)argv[2]; PIN_FLIST_FLD_SET(flistp, PIN_FLD_LOGIN, vp, &ebuf); opcode = PCM_OP_ACT_FIND; PCM_OP(ctxp, opcode, 0, flistp, &a_flistp, &ebuf); /* * Did we find anything? */ acct_pdp = PIN_FLIST_FLD_GET(a_flistp, PIN_FLD_ACCOUNT_OBJ, 0, &ebuf); if (!PIN_POID_IS_NULL(acct_pdp)) { /* * Advisory (or add confirm?) */ fprintf(stdout, "Deleting Account:\t"); pin_poid_print(acct_pdp, 0, &ebuf); fprintf(stdout, "\n"); /* * Put the real account poid on the flist * (The account_obj field will just be ignored) */ vp = (void *)acct_pdp; PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_POID, vp, &ebuf); /* * Delete the account. */ opcode = PCM_OP_CUST_DELETE_ACCT; PCM_OP(ctxp, opcode, 0, a_flistp, &r_flistp, &ebuf); /* * Did we delete or not? */ if (PIN_ERR_IS_ERR(&ebuf)) { fprintf(stdout, "Account Deletion Error Occurred.\n"); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "op_cust_delete_acct error", &ebuf); } else { fprintf(stdout, "Account Deleted.\n"); } } else { /* * FIND error. */ fprintf(stdout, "Unable to locate Account.\n"); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "op_act_find error", &ebuf); } /* * Close the PCM context. */ PCM_CONTEXT_CLOSE(ctxp, 0, &ebuf); /* * Clean up. */ /* Free local memory. */ PIN_FLIST_DESTROY(flistp, NULL); PIN_FLIST_DESTROY(a_flistp, NULL); PIN_FLIST_DESTROY(r_flistp, NULL); /* No errors. */ return(0); }
/******************************************************************* * MAIN *******************************************************************/ int main( int argc, char *argv[]) { pcm_context_t *ctxp = NULL; pin_errbuf_t ebuf; int64 database; char logfile[256]; char *c_ptr = (char *)NULL; char *program; int32 err; /*********************************************************** * Clear the error buffer (for safety). ***********************************************************/ PIN_ERR_CLEAR_ERR(&ebuf); /*********************************************************** * Logging initialization ***********************************************************/ program = basename(argv[0]); PIN_ERR_SET_PROGRAM(program); PIN_ERR_SET_LEVEL(PIN_ERR_LEVEL_WARNING); strcpy(logfile, "default.pinlog"); pin_conf(program, "logfile", PIN_FLDT_STR, (caddr_t *)&(c_ptr), &err); if (c_ptr != (char *)NULL) { pin_strlcpy(logfile, c_ptr, sizeof(logfile)); pin_free(c_ptr); c_ptr = (char *)NULL; } PIN_ERR_SET_LOGFILE(logfile); /*********************************************************** * Open the database context ***********************************************************/ PCM_CONNECT(&ctxp, &database, &ebuf); /*********************************************************** * Simple Read Object Search. ***********************************************************/ sample_read_obj_search(ctxp, database, &ebuf); /*********************************************************** * Create the service. ***********************************************************/ sample_read_flds_search(ctxp, database, &ebuf); /*********************************************************** * Step search sample. ***********************************************************/ sample_step_search(ctxp, database, &ebuf); /*********************************************************** * See if all went well. ***********************************************************/ if (PIN_ERR_IS_ERR(&ebuf)) { fprintf(stderr, "\nTest Failed, See Log File\n\n"); } else { fprintf(stderr, "\nTest Suceeded\n\n"); } /*********************************************************** * Close the database channel (a formality since we exit). ***********************************************************/ PCM_CONTEXT_CLOSE(ctxp, 0, &ebuf); return(0); }
/******************************************************************* * fm_pymt_pol_spec_collect_commit_cust_dd(): * * Fill the the spec flist for the "commit customer" action. * This routine is for Direct Debit specific. * *******************************************************************/ static void fm_pymt_pol_spec_collect_commit_cust_dd( pcm_context_t *ctxp, int32 flags, pin_flist_t *i_flistp, pin_flist_t *o_flistp, pin_errbuf_t *ebufp) { pin_flist_t *b_flistp = NULL; poid_t *a_pdp = NULL; pin_decimal_t *amount = NULL; int32 *curr = NULL; int32 result = 0; int32 dd_collect_flag = 0; int32 err = 0; void *valp = NULL; if (PIN_ERR_IS_ERR(ebufp)) return; PIN_ERR_CLEAR_ERR(ebufp); /*********************************************************** * Get (and add) the account poid. ***********************************************************/ a_pdp = (poid_t *)PIN_FLIST_FLD_GET(i_flistp, PIN_FLD_POID, 0, ebufp); PIN_FLIST_FLD_SET(o_flistp, PIN_FLD_POID, (void *)a_pdp, ebufp); /*********************************************************** * Set dd_collect flag ***********************************************************/ dd_collect_flag = FM_DD_COLLECT_FLAG_DEFAULT; pin_conf(FM_PYMT_POL, FM_DD_COLLECT_TOKEN, PIN_FLDT_INT, (caddr_t *)&valp, &err); switch (err) { case PIN_ERR_NONE: dd_collect_flag = *((int32 *)valp); free(valp); break; case PIN_ERR_NOT_FOUND: break; default: pin_set_err(ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_SYSTEM_DETERMINATE, err, 0, 0, 0); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "Unable to read dd_collect flag from pin.conf",ebufp); break; } /*********************************************************** * If the flag says not to collect, then skip collection. ***********************************************************/ if (!dd_collect_flag) { result = PIN_BOOLEAN_FALSE; PIN_FLIST_FLD_SET(o_flistp, PIN_FLD_BOOLEAN, (void *)&result, ebufp); goto Done; /********/ } fm_pymt_pol_spec_collect_get_items(ctxp, flags, i_flistp, o_flistp, ebufp); Done: /*********************************************************** * Error? ***********************************************************/ if (PIN_ERR_IS_ERR(ebufp)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "fm_pymt_pol_spec_collect_commit_cust_dd error", ebufp); } return; }
int spi_config(unsigned char param) { unsigned char spi_data; int ret; switch(param) { case SPI_CONF_SPI_MUX_A: /* check FPGA "SPI not in use" flag */ /* set FPGA "SPI is not allowed" flag */ ret = spi_fpga_read(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; spi_data &= ~FPGASPI_PWRCTRL_EN_SPI_MASTER; ret = spi_fpga_write(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; /* set MUX to A */ pin_conf(PORT1,PIN23,PIN_PRIM_FUNC,PIN_PULLUP); /* GBESW_EE_SEL */ gpio_config(PORT1,PIN23,GPIO_OUTPUT,GPIO_SET); /* low = LPC2368 <-> EEPROM */ /* turn on MUX*/ pin_conf(PORT1,PIN24,PIN_PRIM_FUNC,PIN_PULLUP); /* GBESW_EE_DIS */ gpio_config(PORT1,PIN24,GPIO_OUTPUT,GPIO_CLR); /* high = disable */ break; case SPI_CONF_SPI_MUX_B: /* set MUX to B */ pin_conf(PORT1,PIN23,PIN_PRIM_FUNC,PIN_PULLUP); /* GBESW_EE_SEL */ gpio_config(PORT1,PIN23,GPIO_OUTPUT,GPIO_CLR); /* low = LPC2368 <-> EEPROM */ /* turn on MUX */ pin_conf(PORT1,PIN24,PIN_PRIM_FUNC,PIN_PULLUP); /* GBESW_EE_DIS */ gpio_config(PORT1,PIN24,GPIO_OUTPUT,GPIO_CLR); /* high = disable */ /* clear FPGA "SPI is not allowed" flag */ ret = spi_fpga_read(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; spi_data |= FPGASPI_PWRCTRL_EN_SPI_MASTER; ret = spi_fpga_write(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; break; case SPI_CONF_DISABLE_GBESW_EE: pin_conf(PORT1,PIN24,PIN_PRIM_FUNC,PIN_PULLUP); /* GBESW_EE_DIS */ gpio_config(PORT1,PIN24,GPIO_OUTPUT,GPIO_SET); /* high = disable */ ret = spi_fpga_read(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; spi_data |= FPGASPI_PWRCTRL_EN_SPI_MASTER; ret = spi_fpga_write(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; break; case SPI_CONF_EN_GBESW_EE: pin_conf(PORT1,PIN24,PIN_PRIM_FUNC,PIN_PULLUP); /* GBESW_EE_DIS */ gpio_config(PORT1,PIN24,GPIO_OUTPUT,GPIO_CLR); /* high = disable */ ret = spi_fpga_read(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; spi_data &= ~FPGASPI_PWRCTRL_EN_SPI_MASTER; ret = spi_fpga_write(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; break; case SPI_CONF_EN_I2C: ret = spi_fpga_read(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; spi_data |= FPGASPI_PWRCTRL_EN_TEMP_I2C | FPGASPI_PWRCTRL_EN_BPL_I2C | FPGASPI_PWRCTRL_EN_MEZZ_I2C; ret = spi_fpga_write(FPGASPI_PWRCTRL, &spi_data); if(ret != E_OK) return ret; break; default: return E_INVALID; } return E_OK; }
/******************************************************************* * fm_cust_pol_read_config(): * * Read the config file to obtain general purpose config params. * *******************************************************************/ static void fm_cust_pol_read_config( pin_flist_t *r_flistp, pin_flist_t *in_flistp, pin_errbuf_t *ebufp) { FILE *fp = NULL; char *fname = NULL; char *path = NULL; char *access = NULL; char conffile[PIN_MAXPATHLEN]; u_int done = 0; char *key = NULL; char *val = NULL; int32 perr; if (PIN_ERR_IS_ERR(ebufp)) return; PIN_ERR_CLEAR_ERR(ebufp); /************************************************************* * Obtain config_dir directory location *************************************************************/ pin_conf("fm_cust_pol", "config_dir", PIN_FLDT_STR, (caddr_t *)&path, &perr); switch (perr) { case PIN_ERR_NONE: break; default: pin_set_err(ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_INVALID_CONF, 0, 0, perr); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "config_dir configuration error",ebufp); return; } /************************************************************* * Obtain the filename (mecca = aac_source, default otherwise) *************************************************************/ access = (char *)PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_AAC_ACCESS, 1, ebufp); if ((access != (char *)NULL) && (!strcmp(access, PIN_CUST_AAC_ACCESS_MECCAD))) { fname = (char *)PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_AAC_SOURCE, 0, ebufp); } else { fname = "default"; } /************************************************************* * path would never be NULL because we checked the pin_conf error * we check it any way, but no else for pin_set_err *************************************************************/ if (path) { sprintf(conffile, "%s/%s.config", path, fname); /************************************************************* * Open the config_file file for reading *************************************************************/ fp = fopen(conffile, "r"); if(fp == NULL) { sprintf(conffile, "%s/default.config", path); fp = fopen(conffile, "r"); if(fp == NULL) { pin_set_err(ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_FILE_IO, 0, 0, 0); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "error opening config file", ebufp); free(path); return; } } free(path); } /************************************************************* * Read until EOF *************************************************************/ done = 0; while( ! feof(fp) && done != 1) { /********************************************** * read next data line from file, returned * malloc'd strings with key and value **********************************************/ fm_cust_pol_get_config_parse_line(fp, &key, &val, &done, ebufp); if(PIN_ERR_IS_ERR(ebufp)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "Err reading config file", ebufp); goto ErrOut; } if( done != 1) { /*************************************** * Stuff the configuration parameter * into outgoing flist. ***************************************/ fm_cust_pol_get_config_stuff(r_flistp, key, val, ebufp); if(PIN_ERR_IS_ERR(ebufp)) { PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "Err reading config file", ebufp); goto ErrOut; } } /********************************************** * Free memory just malloc'd while parsing line **********************************************/ if(key) free(key); key = NULL; if(val) free(val); val = NULL; } /* End while */ ErrOut: if(key) free(key); if(val) free(val); if(fp) fclose(fp); return; }
/******************************************************************* * Main routine for the PCM_OP_PYMT_POL_PRE_COLLECT command *******************************************************************/ void op_pymt_pol_pre_collect( cm_nap_connection_t *connp, int opcode, int flags, pin_flist_t *in_flistp, pin_flist_t **ret_flistpp, pin_errbuf_t *ebufp) { pcm_context_t *ctxp = connp->dm_ctx; pin_cookie_t cookie = NULL; pin_flist_t *flistp = NULL; pin_flist_t *c_flistp = NULL; pin_flist_t *chkpt_flistp = NULL; pin_flist_t *rc_flistp = NULL; pin_charge_cmd_t *cmdp = NULL; pin_decimal_t *amtp = NULL; poid_t *a_pdp = NULL; double *d_ptr = NULL; char *descr = NULL; int32 *selectp = NULL; int32 elemid = 0; int32 result = 0; int32 err = 0; int32 flag = 0; int32 sflag = 0; int32 rec_id = 0; pin_decimal_t *minimum_pay = NULL; pin_decimal_t *minimum_ref = NULL; pin_flist_t *s_flistp = NULL; pin_flist_t *a_flistp = NULL; pin_flist_t *b_flistp = NULL; pin_flist_t *r_flistp = NULL; poid_t *s_pdp = NULL; int32 *mandate_status = 0; pin_pymt_result_t *statusp = NULL; int32 *resultp = NULL; char vendor_name[256] = {" "}; void *vp = NULL; char *dd_vendorp = NULL; if (PIN_ERR_IS_ERR(ebufp)) return; PIN_ERR_CLEAR_ERR(ebufp); /*********************************************************** * Null out results until we have some. ***********************************************************/ *ret_flistpp = (pin_flist_t *)NULL; /*********************************************************** * Insanity check. ***********************************************************/ if (opcode != PCM_OP_PYMT_POL_PRE_COLLECT) { pin_set_err(ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_SYSTEM_DETERMINATE, PIN_ERR_BAD_OPCODE, 0, 0, opcode); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "bad opcode in op_pymt_pol_pre_collect", ebufp); return; } /*********************************************************** * Debug: What did we get? ***********************************************************/ PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "op_pymt_pol_pre_collect input flist", in_flistp); /*********************************************************** * Get command from very first element of array * note: we cannot rely that it has index [0] or [1] or ... ***********************************************************/ flistp = PIN_FLIST_ELEM_GET_NEXT(in_flistp, PIN_FLD_CHARGES, &elemid, 0, &cookie, ebufp); cmdp = (pin_charge_cmd_t *)PIN_FLIST_FLD_GET(flistp, PIN_FLD_COMMAND, 0, ebufp); /*********************************************************** * Select the list of outstanding checkpoint events. * Checkpoints' existance has sense for following commands only: * authorization, deposit, conditional deposit and refund ***********************************************************/ if (cmdp && ((*cmdp == PIN_CHARGE_CMD_CONDITION) || (*cmdp == PIN_CHARGE_CMD_REFUND) || (*cmdp == PIN_CHARGE_CMD_AUTH_ONLY) || (*cmdp == PIN_CHARGE_CMD_DEPOSIT))) { /*********************************************************** * New algorithm is to search for checkpoint upfront and * pass a flag that indicates that search is done ***********************************************************/ pin_flist_t *b_flistp = NULL; int32 *b_flags = 0; /*********************************************************** * Get checkpoints' flag from very first element of array * note: we cannot rely that it has index [0] or [1] or ... ***********************************************************/ elemid = 0; cookie = NULL; b_flistp = PIN_FLIST_ELEM_GET_NEXT(in_flistp,PIN_FLD_BATCH_INFO, &elemid, 1, &cookie, ebufp); if (b_flistp != 0) { b_flags = (int32*)PIN_FLIST_FLD_GET(b_flistp, PIN_FLD_STATUS_FLAGS, 1, ebufp); } /*********************************************************** * 1. If no flags do checkpoints selection * 2. If flag is not set do checkpoint selection * 3. If flag is set don't perform checkpoint selection ***********************************************************/ if(!((b_flags != 0)&&(*b_flags & PIN_PAYMENT_BATCH_CHKPTS))){ fm_pymt_pol_find_outstanding_chkpts(ctxp, in_flistp, &chkpt_flistp, ebufp); } } /*********************************************************** * Get the minimum charge amount from the pin.conf. If the * entry is missing from the pin.conf assume the default * minimum value of 2.00 ***********************************************************/ pin_conf("fm_pymt_pol", "minimum_payment", PIN_FLDT_NUM, (caddr_t *)&d_ptr, &err); if (d_ptr) { minimum_pay = pbo_decimal_from_double(*d_ptr, ebufp); free(d_ptr); } else { minimum_pay = pbo_decimal_from_str("2.00", ebufp); } /*********************************************************** * Get the minimum refund amount from the pin.conf. If the * entry is missing from the pin.conf assume the default * minimum value of -2.00 ***********************************************************/ pin_conf("fm_pymt_pol", "minimum_refund", PIN_FLDT_NUM, (caddr_t *)&d_ptr, &err); if (d_ptr) { minimum_ref = pbo_decimal_from_double(*d_ptr, ebufp); free(d_ptr); } else { minimum_ref = pbo_decimal_from_str("2.00", ebufp); } /*********************************************************** * Get the dd_vendor value from the pin.conf. ***********************************************************/ pin_conf("cm", "dd_vendor", PIN_FLDT_STR, (caddr_t *)&dd_vendorp, &err); c_flistp = PIN_FLIST_COPY(in_flistp, ebufp); /*********************************************************** * Walk the charges array and check each element. ***********************************************************/ elemid = 0; cookie = NULL; while ((flistp = PIN_FLIST_ELEM_GET_NEXT(c_flistp, PIN_FLD_CHARGES, &elemid, 1, &cookie, ebufp)) != (pin_flist_t *)NULL) { statusp = (pin_pymt_result_t *) PIN_FLIST_FLD_GET(flistp, PIN_FLD_STATUS, 1, ebufp); resultp = (int32 *) PIN_FLIST_FLD_GET(flistp,PIN_FLD_RESULT, 1, ebufp); if((statusp && *statusp >= PIN_PYMT_SUSPENSE && *statusp < PIN_PYMT_FAILED) || (resultp && *resultp == PIN_PAYMENT_RES_FAIL)){ /******************************************* * Do nothing if a payment in suspense *******************************************/ continue; } amtp = (pin_decimal_t *)PIN_FLIST_FLD_GET(flistp, PIN_FLD_AMOUNT, 1, ebufp); cmdp = (pin_charge_cmd_t *)PIN_FLIST_FLD_GET(flistp, PIN_FLD_COMMAND, 0, ebufp); a_pdp = (poid_t *)PIN_FLIST_FLD_GET(flistp, PIN_FLD_ACCOUNT_OBJ,0,ebufp); selectp = (int *)PIN_FLIST_FLD_GET(flistp, PIN_FLD_SELECT_RESULT, 1, ebufp); /*************************************************** * Did PCM_OP_PYMT_SELECT_ITEMS retured OK? ***************************************************/ if (selectp && (*selectp != PIN_SELECT_RESULT_PASS)){ result = PIN_CHARGE_RES_FAIL_SELECT_ITEMS; PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, (void *)&result, ebufp); descr = "Select Items Failed"; PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp); continue; } /*************************************************** * Get the amount for this charge. If the amount to * be charged is 0.0, then don't even bother dealing * with this element. ***************************************************/ if ((amtp && pbo_decimal_compare(amtp, minimum_pay, ebufp) < 0) && (cmdp && ((*cmdp == PIN_CHARGE_CMD_CONDITION) || (*cmdp == PIN_CHARGE_CMD_AUTH_ONLY) || (*cmdp == PIN_CHARGE_CMD_DEPOSIT)))) { result = PIN_CHARGE_RES_FAIL_NO_MIN; PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, (void *)&result, ebufp); descr = "Below Minimum"; PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp); continue; } /*************************************************** * Set the minimum refund to compare. ***************************************************/ if (cmdp && ((*cmdp == PIN_CHARGE_CMD_NONE) && (pbo_decimal_sign(amtp, ebufp) < 0))) { pbo_decimal_negate_assign(minimum_ref, ebufp); } /*************************************************** * If command and amount are not NULL and if the * command is refund or if the commnd is none, but * has a negative amount, check the amount with * the minimum refund. ***************************************************/ if (cmdp && amtp && (((*cmdp == PIN_CHARGE_CMD_REFUND) && (pbo_decimal_compare(amtp, minimum_ref, ebufp) < 0)) || ((*cmdp == PIN_CHARGE_CMD_NONE) && (pbo_decimal_sign(amtp, ebufp) < 0) && (pbo_decimal_compare(amtp, minimum_ref, ebufp) > 0)))) { result = PIN_CHARGE_RES_FAIL_NO_MIN; PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, (void *)&result, ebufp); descr = "Below Minimum"; PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp); continue; } /*************************************************** * If command and amount are not NULL and if the * command is REFUND or if the command is NONE and * its a negative amount, make sure that the account * has sufficient credit balance. If not, set the * RESULT code to be NO_CREDIT_BALANCE. ***************************************************/ if (cmdp && amtp && ((*cmdp == PIN_CHARGE_CMD_REFUND) || ((*cmdp == PIN_CHARGE_CMD_NONE) && (pbo_decimal_sign(amtp, ebufp) < 0)))) { flag = fm_pymt_pol_pre_collect_validate_refund(ctxp, amtp, flistp, ebufp); if (flag == PIN_BOOLEAN_FALSE) { result = PIN_CHARGE_RES_NO_CREDIT_BALANCE; PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, (void *)&result, ebufp); descr = "No credit available"; PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp); } } /*************************************************** * Is there a outstanding checkpoint for this acct? ***************************************************/ if ((chkpt_flistp != (pin_flist_t *)NULL) && cmdp && ((*cmdp == PIN_CHARGE_CMD_CONDITION) || (*cmdp == PIN_CHARGE_CMD_REFUND) || (*cmdp == PIN_CHARGE_CMD_AUTH_ONLY) || (*cmdp == PIN_CHARGE_CMD_DEPOSIT))) { if (fm_pymt_pol_is_chkpt_outstanding(a_pdp, chkpt_flistp, ebufp)) { result = PIN_CHARGE_RES_CHECKPOINT; PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, (void *)&result, ebufp); descr = "Checkpoint Outstanding"; PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp); continue; } } s_flistp = PIN_FLIST_CREATE(ebufp); vp = PIN_FLIST_FLD_GET(flistp, PIN_FLD_ACH, 1, ebufp); if (vp) { vp = PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0, ebufp); PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_POID, vp, ebufp); vp = PIN_FLIST_FLD_GET(flistp, PIN_FLD_ACH, 0, ebufp); if (vp) { rec_id = *(int32 *)vp; } PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_ACH, &rec_id, ebufp); PCM_OP(ctxp, PCM_OP_PYMT_GET_ACH_INFO, sflag, s_flistp, &r_flistp, ebufp); rc_flistp = PIN_FLIST_ELEM_GET(r_flistp, PIN_FLD_RESULTS, 0, 0, ebufp); vp = PIN_FLIST_FLD_GET(rc_flistp, PIN_FLD_NAME, 0, ebufp); memset(vendor_name, 0, sizeof(vendor_name)); if ((vp != (void *)NULL) && strlen(vp)) { strcpy(vendor_name, (char *)vp); } } PIN_FLIST_DESTROY_EX(&s_flistp, NULL); PIN_FLIST_DESTROY_EX(&r_flistp, NULL); /************************************************************* * If Bertelsmann then check the mandate status. *************************************************************/ if (dd_vendorp && !strcasecmp(dd_vendorp, "Bertelsmann") && cmdp && *cmdp != PIN_CHARGE_CMD_RFR && vendor_name && !strcasecmp(vendor_name, "bertelsmann")) { s_flistp = PIN_FLIST_CREATE(ebufp); s_pdp = PIN_POID_CREATE(PIN_POID_GET_DB(a_pdp), "/search/pin", 0, ebufp); PIN_FLIST_FLD_PUT(s_flistp, PIN_FLD_POID, (void *)s_pdp, ebufp); PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_FLAGS, (void *)&sflag, ebufp); PIN_FLIST_FLD_SET(s_flistp, PIN_FLD_TEMPLATE, "select X from /payinfo where F1 = V1 ", ebufp); a_flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_ARGS, 1, ebufp); PIN_FLIST_FLD_SET(a_flistp, PIN_FLD_ACCOUNT_OBJ, a_pdp, ebufp); a_flistp = PIN_FLIST_ELEM_ADD(s_flistp, PIN_FLD_RESULTS, 0, ebufp); b_flistp = PIN_FLIST_ELEM_ADD(a_flistp, PIN_FLD_DD_INFO, 0, ebufp); PIN_FLIST_FLD_SET(b_flistp, PIN_FLD_MANDATE_STATUS, (void *)0, ebufp); PCM_OP(ctxp, PCM_OP_SEARCH, 0, s_flistp, &r_flistp, ebufp); if (r_flistp != (pin_flist_t *)NULL) { a_flistp = PIN_FLIST_ELEM_GET(r_flistp, PIN_FLD_RESULTS, 0, 1, ebufp); b_flistp = PIN_FLIST_ELEM_GET(a_flistp, PIN_FLD_DD_INFO, 0, 1, ebufp); /*********************************************** * Do not allow accounts with the following * mandate_statuses to go to collection. ***********************************************/ mandate_status = PIN_FLIST_FLD_GET(b_flistp, PIN_FLD_MANDATE_STATUS, 1, ebufp); if (!mandate_status || ((*mandate_status != PIN_MANDATE_RECEIVED) && (*mandate_status != PIN_MANDATE_NOT_REQUIRED))) { result = PIN_CHARGE_RES_FAIL_SELECT_ITEMS; PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, (void *)&result, ebufp); descr = "Mandate Outstanding"; PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp); } } /*********************************************** * Clean up. ***********************************************/ PIN_FLIST_DESTROY_EX(&s_flistp, NULL); PIN_FLIST_DESTROY_EX(&r_flistp, NULL); } /*************************************************** * Check the command for this element. ***************************************************/ if (cmdp == NULL) { pin_set_err(ebufp, PIN_ERRLOC_FM, PIN_ERRCLASS_APPLICATION, PIN_ERR_MISSING_ARG, PIN_FLD_COMMAND, elemid, 0); continue; } /*************************************************** * Is it ok? ***************************************************/ switch (*cmdp) { case PIN_CHARGE_CMD_NONE: case PIN_CHARGE_CMD_AUTH_ONLY: case PIN_CHARGE_CMD_CONDITION: case PIN_CHARGE_CMD_DEPOSIT: case PIN_CHARGE_CMD_REFUND: case PIN_CHARGE_CMD_RFR: case PIN_CHARGE_CMD_RESUBMIT: break; default: result = PIN_CHARGE_RES_INVALID_CMD; PIN_FLIST_FLD_SET(flistp, PIN_FLD_RESULT, (void *)&result, ebufp); descr = "Invalid Command"; PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void *)descr, ebufp); } } /*********************************************************** * Clean up. ***********************************************************/ PIN_FLIST_DESTROY_EX(&chkpt_flistp, NULL); pbo_decimal_destroy(&minimum_pay); pbo_decimal_destroy(&minimum_ref); if (dd_vendorp != (char *)NULL) { free(dd_vendorp); dd_vendorp = NULL; } /*********************************************************** * Results. ***********************************************************/ if (PIN_ERR_IS_ERR(ebufp)) { PIN_FLIST_DESTROY_EX(&c_flistp, NULL); PIN_ERR_LOG_EBUF(PIN_ERR_LEVEL_ERROR, "op_pymt_pol_pre_collect error", ebufp); } else { *ret_flistpp = c_flistp; PIN_ERR_CLEAR_ERR(ebufp); PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "op_pymt_pol_pre_collect return flist", *ret_flistpp); } return; }
/******************************************************************* * fm_cust_pol_tax_init() * * Use this policy to load any custom user tax data into an internal * data structure you may have declared in this file. In this default * implementation, the structure will be the Tax_Table global flist. * *******************************************************************/ void fm_cust_pol_tax_init( pcm_context_t *ctxp, pin_flist_t *in_flistp, pin_flist_t **out_flistpp, pin_errbuf_t *ebufp) { int32 errp = 0; void *vp = NULL; char *taxfile = NULL; FILE *fp = NULL; char buf[STR_LEN]; char code[STR_LEN]; char pkg[STR_LEN]; char rate[STR_LEN]; char start_t[STR_LEN]; char end_t[STR_LEN]; char j_level[STR_LEN]; char j_list[STR_LEN]; char descr[STR_LEN]; char rule[STR_LEN]; pin_decimal_t *pct = NULL; pin_decimal_t *npct=NULL; pin_decimal_t *dpct=NULL; int32 len = 0; int32 lvl = 0; int32 trl = 0; int32 elemid = 0; int32 precision = 6; time_t startTm = 0; time_t endTm = 0; pin_flist_t *flistp = NULL; if (PIN_ERR_IS_ERR(ebufp)) return; PIN_ERR_CLEAR_ERR(ebufp); /* Create the return flist */ *out_flistpp = PIN_FLIST_CREATE(ebufp); /* Set the account POID */ vp = PIN_FLIST_FLD_GET(in_flistp, PIN_FLD_POID, 0, ebufp); PIN_FLIST_FLD_SET(*out_flistpp, PIN_FLD_POID, (void *)vp, ebufp); if (Tax_Table == (pin_flist_t*)NULL) { /* Create the flist to hold the tax rates */ Tax_Table = (pin_flist_t*)PIN_FLIST_CREATE(ebufp); PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_DEBUG, "Creating the Tax_Table"); } else { /* the tax table has been initialized */ PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_WARNING, "The Tax_Table has already been created!"); return; /*****/ } /* * Build Tax_Table from external table, which in this * implementation happens to be the same taxcodes_map * file specified in the cm/pin.conf */ /* get the taxcodes_map path from the pin.conf */ pin_conf("fm_rate", "taxcodes_map", PIN_FLDT_STR, (caddr_t*)&taxfile, &errp); if (errp != PIN_ERR_NONE) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR, "taxcodes_map table config error!"); return; /*****/ } /* Let's redefine the taxcodes_map table so that the following * columns: * * # Taxcode Pkg Code1 Code2 Si Wt_code Cmdty_code * # ------- --- ----- ----- ------ ------- ---------- * usage : Q : 01 : 01 : S : : * VAT : U : 4.5 : : : : * * will now become these: * * # Taxcode Pkg Rate Start End Lvl List Desc Rule * # ------- ---- ---- -------- -------- --- ----- ------ ---- * VAT : U : 5.0 : 02/01/01 : 01/31/02 : Fed : GB;FR : VAT-EU : Std * VAT : U : 4.5 : 02/01/02 : 01/31/08 : Fed : GB : VAT-GB : Std * VAT : U : 4.0 : 02/01/02 : 01/31/08 : Fed : FR : VAT-FR : Std */ fp = (FILE*) fopen(taxfile, "r"); free(taxfile); if (fp == (FILE*)NULL) { PIN_ERR_LOG_MSG(PIN_ERR_LEVEL_ERROR, "Failed to open taxcodes_map file!"); goto Done; /********/ } while (fgets(buf, STR_LEN, fp) != NULL) { if (strchr(buf, '#') || *buf == '\n') { /* skip comments and blank lines*/ continue; } /* Strip newline, if it is there */ len = strlen(buf); if (buf[len-1] == '\n') { buf[len-1] = '\0'; } code[0] = pkg[0] = rate[0] = start_t[0] = end_t[0] = '\0'; j_level[0] = j_list[0] = descr[0] = rule[0] = '\0'; /* Parse the line in the taxcodes_map */ fm_cust_pol_parse_map_file(buf, code, pkg, rate, start_t, end_t, j_level, j_list, descr, rule); if (strncmp(pkg, "U", 1) != 0) { /* skip entries other than "user" */ continue; /*******/ } /* Start of validity date */ fm_cust_pol_str_to_time_t(start_t, &startTm, 0); /* End of validity date */ fm_cust_pol_str_to_time_t(end_t, &endTm, 1); /* Jurisdiction level */ if (strncmp("Federal", j_level, 3) == 0) { lvl = PIN_RATE_TAX_JUR_FED; } else if (strncmp("State", j_level, 3) == 0) { lvl = PIN_RATE_TAX_JUR_STATE; } else if (strncmp("County", j_level, 3) == 0) { lvl = PIN_RATE_TAX_JUR_COUNTY; } else if (strncmp("City", j_level, 3) == 0) { lvl = PIN_RATE_TAX_JUR_CITY; } else { lvl = PIN_RATE_TAX_JUR_FED; } /* Tax rule (how to tax) */ if (strncmp(rule, "Std", 3) == 0) { trl = 0; /* standard tax */ } else if (strncmp(rule, "Tax", 3) == 0) { trl = 1; /* tax on tax */ } else if (strncmp(rule, "Fee", 3) == 0) { trl = 2; /* flat fee */ } else if (strncmp(rule, "Inc", 3) == 0) { trl = 3; /* inclusive tax */ } else if (strncmp(rule, "NCS", 3) == 0) { trl = 4; /* non-cumulative standard tax */ } else if (strncmp(rule, "NCT", 3) == 0) { trl = 5; /* non-cumulative tax on tax */ } else if (strncmp(rule, "NCF", 3) == 0) { trl = 6; /* non-cumulative flat fee */ } else if (strncmp(rule, "NCI", 3) == 0) { trl = 7; /* non-cumulative inclusive */ } else { trl = 0; /* default */ } /* Tax rate */ if (trl == 2 || trl == 6) { /* 'rate' is a flat fee */ pct = pbo_decimal_from_str(rate,ebufp); } else { /* 'rate' is a percentage */ npct = pbo_decimal_from_str(rate,ebufp); dpct = pbo_decimal_from_str("100.0",ebufp); pct = pbo_decimal_divide( npct, dpct ,ebufp); } /* Set some defaults */ if (!*j_list) { strcpy(j_list, "*"); } if (!*descr) { strcpy(descr, "No Tax Description"); } flistp = PIN_FLIST_ELEM_ADD(Tax_Table, PIN_FLD_TAXES, elemid++, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_TAX_CODE, (void*)code, ebufp); PIN_FLIST_FLD_PUT(flistp, PIN_FLD_PERCENT,(void*)pbo_decimal_round(pct, (int32)precision,ROUND_HALF_UP,ebufp), ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_START_T, (void*)&startTm, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_END_T, (void*)&endTm, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_TYPE, (void*)&lvl, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_NAME, (void*)j_list, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_DESCR, (void*)descr, ebufp); PIN_FLIST_FLD_SET(flistp, PIN_FLD_TAX_WHEN, (void*)&trl, ebufp); pbo_decimal_destroy(&npct); pbo_decimal_destroy(&dpct); pbo_decimal_destroy(&pct); } /* end while */ fclose(fp); Done: PIN_ERR_LOG_FLIST(PIN_ERR_LEVEL_DEBUG, "Tax Table from taxcodes_map file", Tax_Table); return; }