[Help] How can i update user credit($) when user hang up?

hi there,

i need help. I am using asterisk from source and using SIP. I am creating a web interface for users to view their outstanding credit. My webserver is seperate from the asterisk server. My problem is the creadit on the web interface does not show the real time amount right after the user hangs up. the user can only see the amount update when he tries to call again.

i have 3 AGI scripts thats being called when a user initiates a call.

first is “pre” pre calculates the amount of time a user can call base on his credit. (maxTimetoCall = credit / chargePerMinute)

second it goes to “recon” updates the credit base on the time consumed. (credit = credit - (CDR(billsec) / 60) * chargePerMinute)

-at this point the user ring the number. Dial(SIP/xxx)

when the user hangs up the third script executes.

third “post” posts the chargePerMinute of the call to the database.
(chargePerMinute = xxxxCountry-WhereTheUserIsPlacingACall)

it is obvious here that the first call did not reflect on the credit. However when the user calls again thats the time the “recon” updates the credit.

is there a better way todo this?

thanks

sounds like post isnt running. try adding the post script to the ‘h’ extension in whatever context you are in, that way it will run when every call is hung up…

iron,

the post script is actually attached to the ‘h’ extension. everytime the user hungs up it goes to the post script.

ah, as i recall sometimes variables get lost when going to ‘h’…
you could also put another copy of the script after the Dial() entry…

or if the script is going off CDR its possible the CDR isnt getting written until after ‘h’ executes… you could do System() to call a shell script that forks and then runs the finish script after a few seconds (getting the account # from a command line argument)…

i can picture out what you mean… ill try that and let you know how it is coming along.

thanks

Hi,

I had this problem when trying to do processing in ‘h’ with an AGI. I was using Asterisk 1.2.12, so I had to apply this patch:

voip-info.org/wiki/index.php … +extension

but its fixed now in Asterisk 1.4.

So after I applied this patch, the CDR and other values werea available.

I’m sure you know this, but to see output from your AGI put debugs statements in them and connect to asterisk with asterisk -cvvvvvvvvvv

:smile: