Exemplo n.º 1
0
 function authorizenet($passphrase, $organization_id = 1)
 {
     $this->load->model('billing_model');
     $this->load->model('settings_model');
     // the login name for your authorize.net api
     $auth_api_login = '';
     // the transaction key for your authorize.net gateway
     $auth_transaction_key = '';
     $billingdate = date("Y-m-d");
     $user = "******";
     /*--------------------------------------------------------------------*/
     // Create the billing data
     /*--------------------------------------------------------------------*/
     // determine the next available batch number
     $batchid = $this->billing_model->get_nextbatchnumber();
     echo "Batch ID: {$batchid}<p>\n";
     echo "Billing Date: {$billingdate}<p>\n";
     echo "Organization ID: {$organization_id}<p>\n";
     $totalall = 0;
     // for a single date run
     // Add creditcard taxes and services to the bill
     $numtaxes = $this->billing_model->add_taxdetails($billingdate, NULL, 'creditcard', $batchid, $organization_id);
     $numservices = $this->billing_model->add_servicedetails($billingdate, NULL, 'creditcard', $batchid, $organization_id);
     echo "Credit Cards:: {$numtaxes} " . lang('added') . ", \n\t\t\t{$numservices} " . lang('added') . "<p>\n";
     // Add prepaycc taxes and services to the bill
     $numpptaxes = $this->billing_model->add_taxdetails($billingdate, NULL, 'prepaycc', $batchid, $organization_id);
     $numppservices = $this->billing_model->add_servicedetails($billingdate, NULL, 'prepaycc', $batchid, $organization_id);
     echo "Pre-Pay: " . lang('creditcard') . ": {$numpptaxes} " . lang('added') . ", \n\t\t\t{$numppservices} " . lang('added') . "<p>\n";
     // Update Reruns to the bill
     $numreruns = $this->billing_model->update_rerundetails($billingdate, $batchid, $organization_id);
     echo "{$numreruns} " . lang('rerun') . "<p>\n";
     $totalall = $numreruns + $numservices + $numtaxes + $numpptaxes + $numppservices + $totalall;
     // show message if no records have been found
     if ($totalall == 0) {
         echo "<b>No Records Found<b><p>\n";
     } else {
         // create billinghistory
         $this->billing_model->create_billinghistory($batchid, 'creditcard', $user);
         /*--------------------------------------------------------------------*/
         // print the credit card billing to a file
         /*--------------------------------------------------------------------*/
         // select the info from general to get the ccexport variable order
         $myccvarresult = $this->billing_model->ccexportvars($organization_id);
         $ccexportvarorder = $myccvarresult['ccexportvarorder'];
         $exportprefix = $myccvarresult['exportprefix'];
         // convert the $ccexportvarorder &#036; dollar signs back to actual dollar signs and &quot; back to quotes
         $ccexportvarorder = str_replace("&#036;", "\$", $ccexportvarorder);
         $ccexportvarorder = str_replace("&quot;", "\\\"", $ccexportvarorder);
         // query the batch for the invoices to do
         $result = $this->billing_model->get_recent_invoice_numbers($batchid);
         foreach ($result as $myresult) {
             // get the invoice data to process now
             $invoice_number = $myresult['recent_invoice_number'];
             $myinvresult = $this->billing_model->get_invoice_data($invoice_number);
             $user = $myinvresult['h_created_by'];
             $mydate = $myinvresult['h_billing_date'];
             $mybilling_id = $myinvresult['b_id'];
             $billing_name = $myinvresult['b_name'];
             $billing_company = $myinvresult['b_company'];
             $billing_street = $myinvresult['b_street'];
             $billing_city = $myinvresult['b_city'];
             $billing_state = $myinvresult['b_state'];
             $billing_zip = $myinvresult['b_zip'];
             $billing_acctnum = $myinvresult['b_acctnum'];
             $billing_ccnum = $myinvresult['b_ccnum'];
             $billing_ccexp = $myinvresult['b_ccexp'];
             $billing_fromdate = $myinvresult['h_from_date'];
             $billing_todate = $myinvresult['h_to_date'];
             $billing_payment_due_date = $myinvresult['h_payment_due_date'];
             $precisetotal = $myinvresult['h_total_due'];
             $encrypted_creditcard_number = $myinvresult['b_enc_ccnum'];
             // get the absolute value of the total
             $abstotal = abs($precisetotal);
             // don't bill them if the amount is less than or equal to zero
             if ($precisetotal > 0) {
                 echo "account num: {$billing_acctnum}\n";
                 echo "ccnum: {$billing_ccnum}\n";
                 echo "ccexp: {$billing_ccexp}\n";
                 echo "Amount: {$precisetotal}\n";
                 // write the encrypted_creditcard_number to a temporary file
                 // and decrypt that file to stdout to get the CC
                 // select the path_to_ccfile from settings
                 $path_to_ccfile = $this->settings_model->get_path_to_ccfile();
                 // open the file
                 $cipherfilename = "{$path_to_ccfile}/ciphertext.tmp";
                 $cipherhandle = fopen($cipherfilename, 'w') or die("cannot open {$cipherfilename}");
                 // write the ciphertext we want to decrypt into the file
                 fwrite($cipherhandle, $encrypted_creditcard_number);
                 // close the file
                 fclose($cipherhandle);
                 // destroy the output array before we use it again
                 unset($decrypted);
                 $gpgcommandline = $this->config->item('gpg_decrypt') . " {$cipherfilename}";
                 // load the encryption helper for use when calling gpg things
                 $this->load->helper('encryption');
                 $decrypted = decrypt_command($gpgcommandline, $passphrase);
                 // if there is a gpg error, stop here
                 if (substr($decrypted, 0, 5) == "error") {
                     die("Credit Card Encryption Error: {$decrypted} " . lang('billingid') . ": {$mybilling_id}");
                 }
                 // set the billing_ccnum to the decrypted_creditcard_number
                 $decrypted_creditcard_number = $decrypted;
                 $billing_ccnum = $decrypted_creditcard_number;
                 //Send charge to authorize.net
                 $charge_result = $this->authorizenet_charge_card("CC", $billing_ccnum, $billing_ccexp, $precisetotal, "Bill for Account #: " . $billing_acctnum, $invoice_number, $billing_name, NULL, $billing_street, $billing_state, $billing_zip, "1", $auth_api_login, $auth_transaction_key);
                 $response_array = explode("|", $charge_result);
                 switch ($response_array[0]) {
                     case 1:
                         echo "Transaction Approved<p>\n";
                         $this->authorizenet_card_approved($response_array[4], $mybilling_id, $billing_ccnum, $billing_ccexp, $charge_result, $precisetotal, "creditcard", "");
                         break;
                     case 2:
                         echo "Transaction Declined<p>\n";
                         $this->authorizenet_card_declined($response_array[4], $mybilling_id, $billing_ccnum, $billing_ccexp, $charge_result, $precisetotal, "creditcard", "");
                         break;
                     case 3:
                         echo "Transaction Error<p>\n";
                         $this->authorizenet_card_declined($response_array[4], $mybilling_id, $billing_ccnum, $billing_ccexp, $charge_result, $precisetotal, "creditcard", "");
                         break;
                     case 4:
                         echo "Hold For Review<p>\n";
                         $this->authorizenet_card_declined($response_array[4], $mybilling_id, $billing_ccnum, $billing_ccexp, $charge_result, $precisetotal, "creditcard", "");
                         break;
                 }
             }
         }
         // end while
     }
     // end if totalall
     // individual elements of the array could be accessed to read certain response
     // fields.  For example, response_array[0] would return the Response Code,
     // response_array[2] would return the Response Reason Code.
     // for a list of response fields, please review the AIM Implementation Guide
 }
Exemplo n.º 2
0
 function export_card_refunds($organization_id, $path_to_ccfile, $passphrase)
 {
     $myccvarresult = $this->ccexportvars($organization_id);
     $ccexportvarorder = $myccvarresult['ccexportvarorder'];
     $exportprefix = $myccvarresult['exportprefix'];
     // convert the $ccexportvarorder &#036; dollar signs back
     // to actual dollar signs and &quot; back to quotes
     $ccexportvarorder = str_replace("&#036;", "\$", $ccexportvarorder);
     $ccexportvarorder = str_replace("&quot;", "\\\"", $ccexportvarorder);
     // open the file
     $today = date("Y-m-d");
     $filename = "{$path_to_ccfile}" . "/" . "{$exportprefix}" . "refund" . "{$today}.csv";
     $handle = fopen($filename, 'w') or die("cannot open {$filename}");
     // open the file
     // query from billing_details the refunds to do
     $query = "SELECT ROUND(SUM(bd.refund_amount),2) AS RefundTotal, \n            b.id b_id, b.name b_name, b.company b_company, \n            b.street b_street, b.city b_city, \n            b.state b_state, b.zip b_zip, \n            b.account_number b_acctnum, \n            b.creditcard_number b_ccnum, b.encrypted_creditcard_number b_enc_num, \n            b.creditcard_expire b_ccexp, \n            b.from_date b_from_date, \n            b.to_date b_to_date, \n            b.payment_due_date b_payment_due_date,  \n            bd.invoice_number bd_invoice_number, \n            bd.batch bd_batch   \n            FROM billing_details bd\n            LEFT JOIN billing b ON bd.billing_id = b.id \n            LEFT JOIN billing_types bt ON bt.id = b.billing_type \n            WHERE bd.refunded <> 'y' AND bd.refund_amount > 0 \n            AND bt.method = 'creditcard' \n            AND b.organization_id = ? GROUP BY b.id";
     $result = $this->db->query($query, array($organization_id)) or die("export_card_refunds billing_details failed");
     foreach ($result->result_array() as $myresult) {
         $batchid = $myresult['bd_batch'];
         $invoice_number = $myresult['bd_invoice_number'];
         $user = "******";
         $mydate = $today;
         $mybilling_id = $myresult['b_id'];
         $billing_name = $myresult['b_name'];
         $billing_company = $myresult['b_company'];
         $billing_street = $myresult['b_street'];
         $billing_city = $myresult['b_city'];
         $billing_state = $myresult['b_state'];
         $billing_zip = $myresult['b_zip'];
         $billing_acctnum = $myresult['b_acctnum'];
         $billing_ccnum = $myresult['b_ccnum'];
         $billing_ccexp = $myresult['b_ccexp'];
         $billing_fromdate = $myresult['b_from_date'];
         $billing_todate = $myresult['b_to_date'];
         $billing_payment_due_date = $myresult['b_payment_due_date'];
         $precisetotal = $myresult['RefundTotal'];
         $encrypted_creditcard_number = $myresult['b_enc_num'];
         // get the absolute value of the total
         $abstotal = abs($precisetotal);
         // open the file
         $cipherfilename = "{$path_to_ccfile}/ciphertext.tmp";
         $cipherhandle = fopen($cipherfilename, 'w') or die("cannot open {$cipherfilename}");
         // write the ciphertext we want to decrypt into the file
         fwrite($cipherhandle, $encrypted_creditcard_number);
         // close the file
         fclose($cipherhandle);
         //$gpgcommandline = "echo $passphrase | $gpg_decrypt $cipherfilename";
         // destroy the output array before we use it again
         unset($decrypted);
         //$gpgresult = exec($gpgcommandline, $decrypted, $errorcode);
         $gpgcommandline = $this->config->item('gpg_decrypt') . " {$cipherfilename}";
         $decrypted = decrypt_command($gpgcommandline, $passphrase);
         // if there is a gpg error, stop here
         if (substr($decrypted, 0, 5) == "error") {
             die("Credit Card Encryption Error: {$decrypted}");
         }
         // set the billing_ccnum to the decrypted_creditcard_number
         $decrypted_creditcard_number = $decrypted;
         $billing_ccnum = $decrypted_creditcard_number;
         // determine the variable export order values
         eval("\$exportstring = \"{$ccexportvarorder}\";");
         // print the line in the exported data file
         // don't print them to billing if the amount is less than or equal to zero
         $newline = "\"CREDIT\",{$exportstring}\n";
         fwrite($handle, $newline);
         // write to the file
         // mark the refunds as refunded
         $query = "UPDATE billing_details \n                SET refunded = 'y' \n                WHERE refunded <> 'y' AND refund_amount > 0 \n                AND billing_id = ?";
         $detailresult = $this->db->query($query, array($mybilling_id)) or die("update refund details query failed");
     }
     // end while
     // close the file
     fclose($handle);
     // close the file
     $filename = "{$exportprefix}" . "refund" . "{$today}.csv";
     // return the name of the file where the export data is
     return $filename;
 }