[Astpp-commit] SF.net SVN: astpp:[2236] trunk/freeswitch
Brought to you by:
darrenkw
|
From: <dar...@us...> - 2009-02-21 18:37:08
|
Revision: 2236
http://astpp.svn.sourceforge.net/astpp/?rev=2236&view=rev
Author: darrenkw
Date: 2009-02-21 18:36:58 +0000 (Sat, 21 Feb 2009)
Log Message:
-----------
Added the beginning of callingcard support for Freeswitch. A few fixes to the xml generator.
Modified Paths:
--------------
trunk/freeswitch/astpp-fs-xml.pl
Added Paths:
-----------
trunk/freeswitch/astpp-callingcards.pl
Added: trunk/freeswitch/astpp-callingcards.pl
===================================================================
--- trunk/freeswitch/astpp-callingcards.pl (rev 0)
+++ trunk/freeswitch/astpp-callingcards.pl 2009-02-21 18:36:58 UTC (rev 2236)
@@ -0,0 +1,556 @@
+#!/usr/bin/perl
+#
+# ASTPP - Open Source Voip Billing
+#
+# Copyright (C) 2004, Aleph Communications
+#
+# Darren Wiebe (da...@al...)
+#
+# This program is Free Software and is distributed under the
+# terms of the GNU General Public License version 2.
+#############################################################################
+use DBI;
+use POSIX qw(ceil floor);
+use POSIX qw(strftime);
+use Time::HiRes qw( gettimeofday tv_interval );
+use ASTPP;
+use strict;
+our $session;
+
+use vars qw(@output $verbosity $config $astpp_db $cdr_db
+ $ASTPP %stats %input $cc $pricelistinfo $brandinfo $sound @resellerlist $brand);
+$stats{start_time} = [gettimeofday];
+$cc = 0;
+$verbosity = 1;
+require "/usr/local/astpp/astpp-common.pl";
+
+$ASTPP = ASTPP->new;
+$ASTPP->set_verbosity($verbosity); #Tell ASTPP debugging how verbose we want to be.
+
+sub initialize() {
+ $SIG{HUP} = 'ignore_hup'; # We ignore the HUP command that Asterisk sends on a call hangup.
+ $config = &load_config(); # Load /var/lib/astpp/astpp-config.conf
+ $astpp_db = &connect_db( $config, @output );
+ $ASTPP->set_astpp_db($astpp_db);
+ $config = &load_config_db($astpp_db,$config);
+ $brand = "brand"; #$AGI->get_variable("BRAND");
+ if ($brand && $brand ne "") {
+ my $brandinfo = &get_cc_brand($astpp_db, $brand);
+ if ($brandinfo->{reseller}) {
+ $config = &load_config_db_reseller($astpp_db,$config,$brandinfo->{reseller});
+ }
+ $config = &load_config_db_brand($astpp_db,$config,$brand);
+ }
+ $cdr_db = &cdr_connect_db( $config, @output );
+ $ASTPP->set_cdr_db($cdr_db);
+ $sound = &define_sounds($astpp_db);
+}
+
+sub set_in_use() { # Set the "inuse" flag on the calling cards. This prevents multiple people from
+# using the same card.
+ my ( $cardinfo, $status ) = @_;
+ my $sql;
+ $sql =
+ "UPDATE callingcards SET inuse = "
+ . $astpp_db->quote($status)
+ . " WHERE cardnumber = "
+ . $astpp_db->quote( $cardinfo->{cardnumber} );
+ $astpp_db->do($sql);
+}
+
+sub check_card() { # Check a few things before saying the card is ok.
+ my ($cardinfo) = @_;
+ my $now = $astpp_db->selectall_arrayref("SELECT NOW() + 0")->[0][0];
+ $ASTPP->debug( debug => "Present Time: $now",
+ verbosity => $verbosity );
+ $ASTPP->debug( debug => "Expiration Date: $cardinfo->{expiry}",
+ verbosity => $verbosity );
+ $ASTPP->debug( debug => "Valid for Days: $cardinfo->{validfordays}",
+ verbosity => $verbosity );
+ $ASTPP->debug( debug => "First Use: $cardinfo->{firstused}",
+ verbosity => $verbosity );
+ if ( $cardinfo->{inuse} != 0 ) { # If the card is in use then say so and leave.
+ $session->streamFile($sound->{card_inuse});
+ $session->streamFile($sound->{goodbye});
+ &leave($cardinfo);
+ }
+ &set_in_use( $cardinfo, 1 ); # Now the card is in use and nobody else can use it.
+ if ( $cardinfo->{firstused} eq "00000000000000" || $cardinfo->{firstused} eq "0000-00-00 00:00:00" ) { # If "firstused" has not been set, we will set it now.
+ # At the same time we will update the "maint_day" field.
+ my $sql =
+ "UPDATE callingcards SET firstused = NOW() WHERE cardnumber = "
+ . $astpp_db->quote( $cardinfo->{cardnumber} );
+ $ASTPP->debug( debug => $sql,
+ verbosity => $verbosity );
+ $astpp_db->do($sql);
+ $sql =
+ "UPDATE callingcards SET maint_day = DATE_ADD(NOW(), INTERVAL "
+ . "$cardinfo->{maint_fee_days} day) WHERE cardnumber = "
+ . $astpp_db->quote( $cardinfo->{cardnumber} );
+ $ASTPP->debug( debug => $sql,
+ verbosity => $verbosity );
+ if ( $cardinfo->{maint_fee_days} > 0 ) {
+ $astpp_db->do($sql);
+ }
+# $cardinfo = &get_callingcard( $astpp_db, $cardinfo->{cardnumber} );
+ if ( $cardinfo->{validfordays} > 0 ) { #Check if the card is set to expire and deal with that as appropriate.
+ my $sql =
+"UPDATE callingcards SET expiry = DATE_ADD(NOW(), INTERVAL "
+ . " $cardinfo->{validfordays} day) WHERE cardnumber = "
+ . $astpp_db->quote( $cardinfo->{cardnumber} );
+ $ASTPP->debug( debug => $sql,
+ verbosity => $verbosity );
+ $astpp_db->do($sql);
+ $cardinfo = &get_callingcard( $astpp_db, $cardinfo->{cardnumber}, $config );
+ }
+ }
+ elsif ( $cardinfo->{validfordays} > 0 ) {
+ my $now = $astpp_db->selectall_arrayref("SELECT NOW() + 0")->[0][0];
+ $cardinfo->{expiry} = $astpp_db->selectall_arrayref("SELECT DATE_FORMAT('$cardinfo->{expiry}' , '\%Y\%m\%d\%H\%i\%s')")->[0][0];
+ if ( $now >= $cardinfo->{expiry} ) {
+ my $sql =
+ "UPDATE callingcards SET status = 2 WHERE cardnumber = "
+ . $astpp_db->quote( $cardinfo->{cardnumber} );
+ $ASTPP->debug( debug => $sql,
+ verbosity => $verbosity );
+ $astpp_db->do($sql);
+ $sql =
+ "DELETE FROM ani_map WHERE account = "
+ . $astpp_db->quote( $cardinfo->{cardnumber} );
+ $ASTPP->debug( debug => $sql,
+ verbosity => $verbosity );
+ $astpp_db->do($sql);
+ $session->streamFile($sound->{card_has_expired});
+ $session->streamFile($sound->{goodbye});
+ &leave($cardinfo);
+ }
+ }
+ $ASTPP->debug( debug => "Present Time: $now",
+ verbosity => $verbosity );
+ $ASTPP->debug( debug => "Expiration Date: $cardinfo->{expiry}",
+ verbosity => $verbosity );
+ $ASTPP->debug( debug => "Valid for Days: $cardinfo->{validfordays}",
+ verbosity => $verbosity );
+ $ASTPP->debug( debug => "First Use: $cardinfo->{firstused}",
+ verbosity => $verbosity );
+}
+
+sub tell_cost() { #Say how much the call will cost.
+ my ( $numberinfo, $pricelistinfo, $cardinfo ) = @_;
+ if ( $pricelistinfo->{markup} ne "" && $pricelistinfo->{markup} != 0 ) {
+ $ASTPP->debug( debug => "Adding Markup of $pricelistinfo->{markup}",
+ verbosity => $verbosity);
+ $numberinfo->{connectcost} =
+ $numberinfo->{connectcost} *
+ ( ( $pricelistinfo->{markup} / 10000 ) + 1 );
+ $numberinfo->{cost} =
+ $numberinfo->{cost} * ( ( $pricelistinfo->{markup} / 10000 ) + 1 );
+ }
+ if ($config->{calling_cards_rate_announce} == 1) {
+ if ( $numberinfo->{cost} > 0 ) {
+ $session->streamFile($sound->{call_will_cost});
+# $AGI->say_number(ceil($numberinfo->{cost} / 100));
+ $session->streamFile($sound->{currency});
+ my @call_cost = split(/\./, ($numberinfo->{cost} / 100));
+# $AGI->say_number(@call_cost[0]);
+ if (@call_cost[1]) {
+ $session->streamFile($sound->{point});
+# $AGI->say_number(@call_cost[1]);
+ $session->streamFile($sound->{sub_currency});
+ }
+ $session->streamFile($sound->{per});
+ $session->streamFile($sound->{minute});
+ }
+ if ( $numberinfo->{connectcost} > 0 ) {
+ $session->streamFile($sound->{a_connect_charge});
+# $AGI->say_number(ceil($numberinfo->{connectcost} / 100));
+ $session->streamFile($sound->{sub_currency});
+ $session->streamFile($sound->{will_apply});
+ }
+ }
+}
+
+sub timelimit() { #Calculate and say the time limit.
+ my ( $numberinfo, $pricelistinfo, $cardinfo, $phoneno ) = @_;
+ my ( $connectfee, $cost, $timelimit, $available, $maxtime, $balance );
+ # Timelimit is in seconds
+ if ($cc == 0) {
+ $available =
+ ( $cardinfo->{value} - $cardinfo->{used} ) - $numberinfo->{connectfee};
+ $ASTPP->debug( debug => "FUNDS AVAILABLE: $available",
+ verbosity => $verbosity);
+ } elsif ( $cc == 1 ) {
+ $balance = &accountbalance( $astpp_db, $cardinfo->{number} );
+ $balance = ($balance * -1) + ( $cardinfo->{credit_limit});
+ $available = ($balance - $numberinfo->{connectfee}) / 100;
+ }
+ if ( $available > 0 && $numberinfo->{cost} > 0 ) {
+ $timelimit = ( ( $available / $numberinfo->{cost} ) * 60 );
+ }
+ elsif ( $available >= 0 && $numberinfo->{cost} <= 0 ) {
+ $timelimit = $config->{callingcards_max_length};
+ }
+ if ( $timelimit > $config->{callingcards_max_length} ) {
+ $timelimit = $config->{callingcards_max_length};
+ }
+ $ASTPP->debug( debug => "TIMELIMIT: $timelimit",
+ verbosity => $verbosity);
+ if ($brandinfo->{reseller} ne "") {
+ ASTPP->debug( debug => "THIS BRAND BELONGS TO $brandinfo->{reseller}!",
+ verbosity => $verbosity);
+ my $carddata = &get_account( $astpp_db, $brandinfo->{reseller} );
+# ($callstatus, $maxlength) = &max_length($astpp_db, $config, $carddata, $phoneno);
+# my $routeinfo = &get_route( $astpp_db, $config, $phoneno, $carddata->{pricelist},$carddata );
+ my $minimumcharge = $numberinfo->{cost};
+ my $belongs_to_reseller = 1;
+ while ( $belongs_to_reseller == 1 ) {
+ $ASTPP->debug( debug => "FINDING LIMIT FOR: $carddata->{reseller}",
+ verbosity => $verbosity);
+ push @resellerlist, $carddata->{number};
+ $ASTPP->debug( debug => "PUSHING $carddata->{number} ONTO THE LIST OF RESELLERS",
+ verbosity => $verbosity);
+ my ($resellercallstatus, $resellermaxlength) = &max_length($astpp_db, $config, $carddata, $phoneno);
+ my $routeinfo = &get_route( $astpp_db, $config, $phoneno, $carddata->{pricelist}, $carddata, "CC" );
+ if ($resellercallstatus != 1) {
+ $carddata->{reseller} = "";
+ $timelimit = 0;
+ } elsif ($resellermaxlength < $timelimit / 60) {
+ $timelimit = $resellermaxlength * 60;
+ }
+ if ($resellermaxlength < 1 || $routeinfo->{cost} > $minimumcharge ) {
+ $carddata->{reseller} = "";
+ $timelimit = 0;
+ }
+ $ASTPP->debug( debug => "RESELLER Max Length: $resellermaxlength",
+ verbosity => $verbosity);
+ $ASTPP->debug( debug => "RESELLER Call Status: $resellercallstatus",
+ verbosity => $verbosity);
+ if ($carddata->{reseller} && $carddata->{reseller} ne "") {
+ $carddata = &get_account( $astpp_db, $carddata->{reseller} );
+ } else {
+ $belongs_to_reseller = 0;
+ }
+ }
+ } else {
+ $ASTPP->debug( debug => "THIS BRAND DOES NOT BELONG TO A RESELLER!",
+ verbosity => $verbosity);
+ }
+ $ASTPP->debug( debug =>"TIMELIMIT: $timelimit", verbosity => $verbosity);
+ my $minutes = $timelimit / 60;
+ $ASTPP->debug( debug => "MINUTES: $minutes", verbosity => $verbosity);
+ if ($minutes > 0 && $config->{calling_cards_timelimit_announce} == 1) {
+ my $minutes = $timelimit / 60;
+ $minutes = sprintf( "%.0f", $minutes );
+ $session->streamFile($sound->{call_will_last});
+ if ( $minutes == 1 ) {
+# $AGI->say_number($minutes);
+ $session->streamFile($sound->{minute});
+ }
+ elsif ( $minutes > 1 ) {
+# $AGI->say_number($minutes);
+ $session->streamFile($sound->{minutes});
+ }
+ }
+ elsif ($minutes < 1) {
+ $session->streamFile($sound->{not_enough_credit});
+ $session->streamFile($sound->{goodbye});
+ &leave($cardinfo);
+ }
+ $maxtime = $timelimit * 1000;
+
+
+ $timelimit = "\|30\|HL($maxtime:60000:30000)\|Hgj";
+ $ASTPP->debug( debug => "Available: $available",
+ verbosity => $verbosity );
+ $ASTPP->debug( debug => "Balance: $balance", verbosity => $verbosity );
+ $ASTPP->debug( debug => "Max Time: $maxtime", verbosity => $verbosity );
+ return $timelimit;
+}
+
+sub say_balance() { #Calculate and say the card balance.
+ my ($cardinfo) = @_;
+ my ( $connectfee, $cost, $included, $sub_balance, $balance, $main_balance );
+ if ($cc == 0 ) {
+ $balance = $cardinfo->{value} - $cardinfo->{used};
+ } elsif ($cc ==1) {
+ $balance = &accountbalance( $astpp_db, $cardinfo->{number} );
+ $balance = ($balance * -1) + ( $cardinfo->{credit_limit} );
+ }
+ if ( $balance > 0 ) {
+ $balance = $balance / 10000;
+ $balance = sprintf( "%.2f", $balance );
+ $sub_balance = substr( $balance, -2, 2 );
+ $main_balance = substr( $balance, 0, -2 );
+ my $interrupt = $session->playAndGetDigits(1,1,1,0,"#*","$sound->{card_has_balance_of}","$sound->{card_has_balance_of}",'^[0-9]+$');
+ if (!$interrupt || $interrupt eq "" || $interrupt == 0) {
+ if ( $main_balance == 1 ) {
+# $AGI->say_number($main_balance);
+ $session->streamFile($sound->{main_currency});
+ }
+ elsif ( $main_balance > 1 ) {
+# $AGI->say_number($main_balance);
+ $session->streamFile($sound->{main_currency_plural});
+ }
+ if ( $sub_balance == 1 ) {
+# $AGI->say_number($sub_balance);
+ $session->streamFile($sound->{sub_currency});
+ }
+ elsif ( $sub_balance > 1 ) {
+# $AGI->say_number($sub_balance);
+ $session->streamFile($sound->{sub_currency_plural});
+ }
+ }
+ }
+ else {
+ $session->streamFile($sound->{card_is_empty});
+ $session->streamFile($sound->{goodbye});
+ &leave($cardinfo);
+ }
+ return $balance;
+}
+
+sub update_balance() { #Update the available credit on the calling card.
+ my ( $cardinfo, $charge ) = @_;
+ my $sql =
+ "UPDATE callingcards SET used = "
+ . $astpp_db->quote( ($charge) + $cardinfo->{used} )
+ . " WHERE cardnumber = "
+ . $astpp_db->quote( $cardinfo->{cardnumber} );
+ $astpp_db->do($sql);
+}
+sub write_asterisk_cdr() { #Write the cdr record to the asterisk cdr db. This is done so we get a record of the call the callingcard user placed.
+ # This is especially important for resellers and calling cards.
+ my (
+ $reseller, $clid, $destination, $status,
+ $callstart, $answeredtime, $dstchannel, $lastapp, $dialedtime, $uniqueid, $asterisk_time, $cdr_db
+ )
+ = @_;
+ my ($sql);
+ if (!$status) {$status = gettext("N/A"); }
+ $sql = "INSERT INTO cdr (calldate,dst,clid,dstchannel,lastapp,duration,billsec,disposition,accountcode,uniqueid) VALUES("
+ . $astpp_db->quote($asterisk_time) . ", "
+ . $astpp_db->quote($destination) . ", "
+ . $astpp_db->quote($clid) . ", "
+ . $astpp_db->quote($dstchannel) . ", "
+ . $astpp_db->quote($lastapp) . ", "
+ . $astpp_db->quote($dialedtime) . ", "
+ . $astpp_db->quote($answeredtime) . ", "
+ . $astpp_db->quote($status) . ", "
+ . $astpp_db->quote( $reseller ) . ", "
+ . $astpp_db->quote( $uniqueid ) . ")";
+ $cdr_db->do($sql);
+ $session->execute("set", "ANSWEREDTIME=0" );
+ $session->execute("set", "DIALEDTIME=0" );
+ $session->execute("set", "DIALSTATUS=NO ANSWER" );
+}
+
+sub write_cdr() { # Write the callingcardcdr record if this is a calling card.
+ my (
+ $cardinfo, $clid, $destination, $status,
+ $callstart, $charge, $answeredtime
+ )
+ = @_;
+ my ($sql);
+ if (!$status) {$status = gettext("N/A"); }
+ $sql =
+"INSERT INTO callingcardcdrs (cardnumber,clid,destination,disposition,callstart,seconds,"
+ . "debit) VALUES ("
+ . $astpp_db->quote( $cardinfo->{cardnumber} ) . ", "
+ . $astpp_db->quote($clid) . ", "
+ . $astpp_db->quote($destination) . ", "
+ . $astpp_db->quote($status) . ", "
+ . $astpp_db->quote($callstart) . ", "
+ . $astpp_db->quote($answeredtime) . ", "
+ . $astpp_db->quote($charge) . ")";
+ $astpp_db->do($sql);
+ $ASTPP->debug( debug => "$sql", verbosity => $verbosity );
+ $ASTPP->debug( debug => "Resetting CDR Variables", verbosity => $verbosity );
+ $session->execute("set", "ANSWEREDTIME=0" );
+ $session->execute("set", "DIALEDTIME=0" );
+ $session->execute("set", "DIALSTATUS=NO ANSWER" );
+}
+
+
+
+sub leave() { # Prepare everything and then leave the calling card app.
+ my ($cardinfo) = @_;
+ my ($whatnow);
+ my $retries = 0;
+ &set_in_use( $cardinfo, 0 ) if $cc == 0;
+ while ($retries < 3) {
+ $whatnow = $session->playAndGetDigits(1,1,1,$config->{calling_cards_general_input_timeout},"#*","$sound->{astpp_callingcard_menu}","$sound->{astpp_callingcard_menu}",'^[0-9]+$');
+ $ASTPP->debug( debug => "WHAT NEXT = $whatnow ", verbosity => $verbosity );
+ if ($cc == 1) {
+ $session->execute("set", "CARDNUMBER=$cardinfo->{number}" );
+ } else {
+ $session->execute("set", "CARDNUMBER=$cardinfo->{cardnumber}" );
+ }
+ $session->execute("set", "PIN=$cardinfo->{pin}" );
+ if ( $whatnow == 1 ) {
+ $session->execute("set", "NEWCALL=1" );
+ $session->execute("set", "DESTINATION=$stats{destination}" );
+ &exit_program();
+ }
+ elsif ( $whatnow == 2 ) {
+ $session->execute("set", "NEWCALL=1" );
+ $session->execute("set", "DESTINATION=" );
+ &exit_program();
+ }
+ elsif ( $whatnow == 3 ) {
+ $session->streamFile($sound->{goodbye});
+ $session->hangup;
+ } else {
+ $retries++;
+ }
+ }
+ if ($retries == 3) {
+ $session->streamFile($sound->{goodbye});
+ $session->hangup;
+ }
+
+}
+
+sub exit_program() {
+ $stats{total_time} = tv_interval ($stats{start_time});
+ $astpp_db->do("INSERT INTO callingcard_stats(uniqueid,total_time,billable_time) VALUES ("
+ . $astpp_db->quote($stats{uniqueid}) . ","
+ . $astpp_db->quote($stats{total_time}) . ","
+ . $astpp_db->quote($stats{answered_time}) . ")");
+ $stats{total_time} = tv_interval ($stats{start_time});
+ exit(0);
+}
+
+sub print_console() #Dump string to the console
+{
+ my ($output) = @_;
+ freeswitch::consoleLog("ASTPP",$output . "\n");
+}
+
+sub say()
+{
+ my($phrase,$say) = @_;
+ $session->execute("phrase", $phrase ."," . $say );
+}
+
+
+
+################# Program Starts Here #################################
+my ( $cardnum, $pin, $destination, $connectsurcharge, $perminsurcharge, $brand ) =
+ @ARGV;
+my ( $retries, $cardinfo, $numberinfo, $pricelistinfo, @outboundroutes,
+ $callstart );
+$session->answer();
+&initialize;
+return 1 if (! $session->ready());
+
+if ($cardnum && $cardnum ne "") {
+ $ASTPP->debug( debug => "We recieved a cardnumber from the dialplan",verbosity => $verbosity);
+ $cardinfo = &get_callingcard( $astpp_db, $cardnum, $config );
+ if ( !$cardinfo ) {
+ $cardinfo = &get_account_cc( $astpp_db, $cardnum );
+ $cc = 1 if $cardinfo;
+ }
+} else { #We won't play the welcome file when we already have card numbers.
+ $session->streamFile($config->{calling_cards_welcome_file});
+}
+# If $cc == 1 means that we are using an ASTPP account instead of an actual
+# calling card.
+if ( $cardinfo->{status} != 1 || !$cardinfo->{status}) {
+ $retries = 0;
+ while ( $cardinfo->{status} != 1 && $retries < $config->{card_retries} ) {
+ $cardnum = $session->playAndGetDigits($config->{cardlength},$config->{cardlength},1,$config->{calling_cards_number_input_timeout},"#","$sound->{cardnumber}","$sound->{cardnumber}",'^[0-9]+$');
+ $cardinfo = &get_callingcard( $astpp_db, $cardnum, $config );
+ if ( !$cardinfo ) {
+ $cardinfo = &get_account_cc( $astpp_db, $cardnum );
+ $cc = 1 if $cardinfo;
+ }
+ $ASTPP->debug(debug => "CARD BRAND: $cardinfo->{brand} SPECIFIED BRAND: $brand", verbosity => $verbosity);
+ if ($brand && $brand ne "") {
+ $cardinfo = "" if $cardinfo->{brand} ne $brand;
+ }
+ $ASTPP->debug( debug => "ASTPP Number: $cardnum ", verbosity => $verbosity );
+ $ASTPP->debug( debug => "ASTPP Number Status: $cardinfo->{status}", verbosity => $verbosity );
+ if ( $cardinfo->{status} != 1 ) {
+ $session->streamFile($sound->{cardnumber_incorrect});
+ }
+ $retries++;
+ }
+ if ( $cardinfo->{status} != 1 ) {
+ $session->streamFile($sound->{goodbye});
+ exit(1);
+ }
+}
+
+if ( $pin != $cardinfo->{pin} ) {
+ $retries = 0;
+ while ( $cardinfo->{pin} != $pin && $retries < $config->{pin_retries} ) {
+ $pin = $session->playAndGetDigits($config->{pinlength},$config->{pinlength},1,$config->{calling_cards_pin_input_timeout},"#","$sound->{pin}","$sound->{pin}",'^[0-9]+$');
+ if ( $cardinfo->{pin} != $pin ) {
+ $session->streamFile($sound->{pin_incorrect});
+ }
+ $retries++;
+ }
+ if ( $pin != $cardinfo->{pin} ) {
+ $session->streamFile($sound->{pin_incorrect});
+ $session->streamFile($sound->{goodbye});
+ exit(0);
+ }
+}
+&check_card($cardinfo) if $cc == 0;
+my $balance = &say_balance($cardinfo);
+
+# Getting this far means we have a valid card and pin.
+$brandinfo = &get_cc_brand( $astpp_db, $cardinfo->{brand} ) if $cc == 0;
+if ($brandinfo->{reseller}) {
+ $config = &load_config_db_reseller($astpp_db,$config,$brandinfo->{reseller});
+}
+$config = &load_config_db_brand($astpp_db,$config,$cardinfo->{brand});
+$pricelistinfo = &get_pricelist( $astpp_db, $brandinfo->{pricelist} )
+ if $cc == 0;
+$pricelistinfo = &get_pricelist( $astpp_db, $cardinfo->{pricelist} )
+ if $cc == 1;
+if ($destination && $destination ne "" ) {
+ $numberinfo =
+ &get_route( $astpp_db, $config, $destination, $brandinfo->{pricelist}, $cardinfo )
+ if $cc == 0;
+ $numberinfo =
+ &get_route( $astpp_db, $config, $destination, $cardinfo->{pricelist}, $cardinfo )
+ if $cc == 1;
+}
+$retries = 0;
+while ( !$numberinfo->{pattern} && $retries < $config->{number_retries} ) {
+ $destination = $session->playAndGetDigits(4,999,1,$config->{calling_cards_dial_input_timeout},"#","$sound->{destination}","$sound->{destination}",'^[0-9]+$');
+ $numberinfo =
+ &get_route( $astpp_db, $config, $destination, $brandinfo->{pricelist}, $cardinfo );
+ if ( !$numberinfo->{pattern} ) {
+ $session->streamFile($sound->{destination_incorrect});
+ } else {
+ $numberinfo->{cost} = $numberinfo->{cost} + $perminsurcharge if $perminsurcharge ne "";
+ $numberinfo->{connectcost} = $numberinfo->{connectcost} + $connectsurcharge if $connectsurcharge ne "";
+ }
+ $retries++;
+}
+if ( !$numberinfo->{pattern} ) {
+ $session->streamFile($sound->{destination_incorrect});
+ $session->streamFile($sound->{goodbye});
+ $session->hangup();
+ &leave($cardinfo);
+}
+
+# Congratulations, we now have a working card,pin, and phone number.
+$stats{destination} = $destination;
+#&tell_cost( $numberinfo, $pricelistinfo, $cardinfo );
+my $timelimit = &timelimit( $numberinfo, $pricelistinfo, $cardinfo, $destination );
+$session->streamFile($sound->{please_wait_will_connect}) if $config->{calling_cards_connection_prompt} == 1;
+#&dialout( $destination, $timelimit, $numberinfo, $pricelistinfo, $cardinfo, $brandinfo );
+
+
+
+
+
+
+
+
+
+1;
+
Property changes on: trunk/freeswitch/astpp-callingcards.pl
___________________________________________________________________
Added: svn:executable
+ *
Modified: trunk/freeswitch/astpp-fs-xml.pl
===================================================================
--- trunk/freeswitch/astpp-fs-xml.pl 2009-02-21 18:19:44 UTC (rev 2235)
+++ trunk/freeswitch/astpp-fs-xml.pl 2009-02-21 18:36:58 UTC (rev 2236)
@@ -42,7 +42,7 @@
################# Programs start here #######################################
&initialize;
-my ( $xml, $maxlength, $maxmins, $callstatus );
+my ( $xml, $maxlength, $maxmins, $callstatus,$astppdid,$didinfo );
foreach my $param ( param() ) {
$params->{$param} = param($param);
$ASTPP->debug( debug => "$param $params->{$param}" );
@@ -58,6 +58,17 @@
destination_number => $params->{'Caller-Destination-Number'}
);
+# Check to see if this is a DID. If it is we handle it differently.
+#
+ $didinfo = &get_did($astpp_db, $params->{'Caller-Destination-Number'});
+ if ($didinfo->{number}) {
+ $astppdid = "ASTPP-DID";
+ $ASTPP->debug( debug => "This is a call for a DID: ");
+ $params->{variable_accountcode} = $didinfo->{account};
+ }
+
+
+
if ( !$params->{variable_accountcode} ) {
# First we strip off X digits to see if this account is prepending numbers
@@ -130,10 +141,11 @@
my $routeinfo = &get_route(
$astpp_db, $config,
$params->{'Caller-Destination-Number'},
- $carddata->{pricelist}, $carddata
+ $carddata->{pricelist}, $carddata,$astppdid
);
- $ASTPP->debug( debug => "Minimum Charge on call = " . $routeinfo->{cost} );
+ $ASTPP->debug( debug => "Cost: " . $routeinfo->{cost} );
+ $ASTPP->debug( debug => "Pricelist: " . $routeinfo->{pricelist} );
my $minimumcharge = $routeinfo->{cost};
my @reseller_list;
$ASTPP->debug( debug => "CALLSTATUS: $callstatus MAX_LENGTH: $maxlength" );
@@ -213,9 +225,12 @@
my $routeinfo = &get_route(
$astpp_db, $config,
$params->{'Caller-Destination-Number'},
- $carddata->{pricelist}, $carddata
+ $carddata->{pricelist}, $carddata, $astppdid
);
+ if ($astppdid > 0 ) {
+ $ASTPP->debug( debug => "THIS IS A DID CALL: $xml");
+ } else {
# Get the list of routes for the phone number.
my @outboundroutes =
&get_outbound_routes( $astpp_db, $params->{'Caller-Destination-Number'},
@@ -236,6 +251,7 @@
);
}
}
+ }
$xml = $ASTPP->fs_dialplan_xml_footer( xml => $xml );
$ASTPP->debug( debug => $xml );
print $xml;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|