/** * Validate that an incoming rest request is from Twilio * * @param string $failure_message * @return void */ function validate_rest_request($failure_message = 'Could not validate this request. Goodbye.') { $ci =& get_instance(); if ($ci->tenant->type == VBX_Settings::AUTH_TYPE_CONNECT) { return; } if (!OpenVBX::validateRequest()) { $response = new TwimlResponse(); $response->say($failure_message, array('voice' => $ci->vbx_settings->get('voice', $ci->tenant->id), 'language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id))); $response->hangup(); $response->respond(); exit; } }
function accept_or_reject_recording_twiml() { validate_rest_request(); $response = new TwimlResponse(); $digits = clean_digits($this->input->get_post('Digits')); $call_sid = $this->input->get_post('CallSid'); switch ($digits) { case 1: $audioFile = VBX_Audio_File::get(array('recording_call_sid' => $call_sid)); if ($audioFile == null) { trigger_error("That's weird - we can't find the place holder audio file that matches this sid (" . $call_sid . ")"); } else { $audioFile->url = $this->session->userdata('current-recording'); $audioFile->save(); } $response->say('Your recording has been saved.', $this->say_params); $response->hangup(); break; case 2: $response->redirect(site_url('audiofiles/prompt_for_recording_twiml')); default: $response->redirect(site_url('audiofiles/replay_recording_twiml')); break; } return $response->respond(); }
require_once dirname(dirname(dirname(__FILE__))) . '/stripe-php/lib/Stripe.php'; Stripe::setApiKey($settings['api_key']); try { $charge = Stripe_Charge::create(array('card' => $state['card'], 'amount' => $amount, 'currency' => 'usd', 'description' => $description)); if ($charge->paid && true === $charge->paid) { setcookie(PAYMENT_COOKIE); $next = AppletInstance::getDropZoneUrl('success'); if (!empty($next)) { $response->redirect($next); } $response->respond(); die; } } catch (Exception $e) { $error = $e->getCode(); $response->say($e->getMessage(), array('voice' => $ci->vbx_settings->get('voice', $ci->tenant->id), 'voice_language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id))); if (array_key_exists($error, $card_errors)) { $state[PAYMENT_ACTION] = $card_errors[$error]; $response->redirect(); } else { setcookie(PAYMENT_COOKIE); $next = AppletInstance::getDropZoneUrl('fail'); if (!empty($next)) { $response->redirect($next); } $response->respond(); die; } } } setcookie(PAYMENT_COOKIE, json_encode($state), time() + 5 * 60);
$prefs = array('voice' => $ci->vbx_settings->get('voice', $ci->tenant->id), 'language' => $ci->vbx_settings->get('voice_language', $ci->tenant->id)); $response = new TwimlResponse(); if (!empty($orderid)) { $settings = PluginData::get('orders', array('keys' => array(), 'status' => array())); $statusArray = array('shipped' => 'Shipped', 'fullfillment' => 'Sent to Fullfillment', 'processing' => 'Processing'); $s = ''; $keys = $settings->keys; $status = $settings->status; foreach ($keys as $i => $key) { if ($key == $orderid) { $s = $statusArray[$status[$i]]; break; } } if ($s != '') { $response->say("Your order is marked as {$s}.", $prefs); if (AppletInstance::getFlowType() == 'voice') { $next = AppletInstance::getDropZoneUrl('next'); if (!empty($next)) { $response->redirect($next); } } } else { $response->say("We could not find your order.", $prefs); } } elseif ($flow_type == 'voice') { $gather = $response->gather(array('numDigits' => 5)); $gather->say(AppletInstance::getValue('prompt-text'), $prefs); $response->redirect(); } elseif ($flow_type != 'voice') { $response->say(AppletInstance::getValue('prompt-text'));
/** * Handle callback after someone leaves a message * * @return void */ public function add_voice_message() { OpenVBX::addVoiceMessage($this->dial_whom_user_or_group, $_REQUEST['CallSid'], $_REQUEST['From'], $_REQUEST['To'], $_REQUEST['RecordingUrl'], $_REQUEST['RecordingDuration'], $this->transcribe == false); $this->response->say('Your message has been recorded. Goodbye.'); $this->hangup(); }