twillio - hot get the price of a number? - twilio

I need to get the price of each phone number, as it was in their "Buy a number" page https://www.twilio.com/user/account/phone-numbers/search
Variable $number do not contain such info.
$numbers = $client->account->available_phone_numbers->getList('US', 'Local', array(
"AreaCode" => "510"
));
foreach($numbers->available_phone_numbers as $number) {
echo $number->phone_number;
}

Ricky from Twilio here.
You can access pricing information using our Pricing API. This will let you query by country:
$client = new Pricing_Services_Twilio($AccountSid, $AuthToken);
$country = $client->phoneNumberCountries->get("US");
foreach ($country->phone_number_prices as $p) {
echo $p->number_type . " " . $p->current_price . "\n";
}
You can then use that information to properly assign the pricing with numbers you retrieve with the Available Phone Numbers API call.

Related

Woocommerce order complete secondary email retrieved from account meta data key value

Scenario: A customer buys any product and upon order completion an additional email gets sent to a stored value in the users meta data.
My meta field is stored in the database as follows:
Table: wp_usermeta
Column: meta_key = iconic-register-email
Column: meta_value = X
I need to retrieve the meta_value based on the meta_key Column iconic-register-email.
My code thus far:
(To be placed in the function.php file of the child theme)
add_filter( 'woocommerce_email_recipient_new_order', 'new_order_conditional_email_recipient', 10, 2 );
function new_order_conditional_email_recipient( $recipient, $order ) {
// Get the order ID (retro compatible)
$order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
// Get the custom field value (with the right $order_id)
$my_field_name = get_post_meta($order_id, 'my_field_name', true);
if ($my_field_name == "empolyee1#company.com")
$recipient .= ', empolyee1#company.com';
elseif ($my_field_name == "empolyee2#company.com")
$recipient .= ', empolyee2#company.com';
return $recipient;
}
I am not getting any errors but I am also not getting any emails. I tried replacing
$my_field_name = get_post_meta($order_id, 'my_field_name', true);
with
$my_field_name = get_post_meta($order_id, 'iconic-register-email', true);
but that did not work.
In an effort to minimize static coding of each email address to be matched in code below:
if ($my_field_name == "empolyee1#company.com")
is there a way to call the $recipient based off of the meta_value = X

Sending an email based on two cell inputs in Google Sheets

I'm fairly new here so apologies for asking a possibly stupid question.
I'm trying to get Google Sheets to send an email based on the information in columns B and O
Here is my code thus far...
function confirmationEmail(e) {
var sheet = SpreadsheetApp.getActiveSheet(BIKE2)
var orderNumber = e.values[2];
var subject = "Order is Ready to be Confirmed";
var body = "An order from the bike shop is ready to be confirmed! Order Number: " + orderNumber;
if (e.values[14] == NOT NULL);
if (e.values[1] == 'Order Entry');
MailApp.sendEmail("dylan.bassett#activesportsinc.com", subject, body)
}
Currently when I try to run the code I get an error saying:
"Missing ) after condition. (line 6, file "Confirmation Emails")"
I'm not sure how far off I am here, I was able to get a similar code to work without a condition but things got dicey when I started trying to tell it when to do things.
Any help is appreciated! I'm sure this is a rookie problem :)
I assume your using a form Submit. I don't send much email so not sure about the syntax for that but BIKE2 needs to be in quotes and the semicolons after the if's are not wanted. So try this.
function confirmationEmail(e) {
var sheet = SpreadsheetApp.getActiveSheet('BIKE2')
var orderNumber = e.values[2];
var subject = "Order is Ready to be Confirmed";
var body = "An order from the bike shop is ready to be confirmed! Order Number: " + orderNumber;
if (e.values[14] && e.values[1] == 'Order Entry')
{
MailApp.sendEmail("dylan.bassett#activesportsinc.com", subject, body);
}
}

How can i bind parameter in zf2 tablegateway

How can i bind parameter in zend framework 2 using tablegateway, here is the code i am using
$adapter = $this->tableGateway->getAdapter();
$result = $adapter->query(
"SELECT * "
. "FROM TABLE "
. "WHERE SOME_ID = $SOME "
. "AND STATUS = 1 "
);
$dataSource = $result->execute();
$statement = $dataSource->getResource();
$result = $statement->fetchAll(\PDO::FETCH_OBJ);
please suggest me a secure query builder code
You are trying to bind parameter in Adapter not in TableGateway.
It can be done on many ways, but example that you post
$id = 123;
$res = $adapter->query(
"SELECT * FROM TABLE WHERE SOME_ID = ? AND STATUS = 1", [$id]
);
var_dump($res->current());
There is a second parameter in function query() which is
#param string|array|ParameterContainer $parametersOrQueryMode
So you can play little bit with this option(s)... also check function Zend\Db\Adapter\Adapter::query();
Easier way is to use TableGateway:
$res = $this->tableGateway->select(['SOME_ID' => $id]);
$res->current(); // than you can use also toArray(), current(), etc.

Adding new Mantis status but ran out of enumeration values

I was wondering if you had any thoughts about this issue: We want to add one more status at a specific 'place' between two statuses, but we ran out of enumeration for it.
The enumeration looks like this:
$s_status_enum_string = "10:new,20:feedback,40:confirmed,50:assigned,52:in progress,53:code review pending,54:merge pending, 56:merged, 58:resolved, 60:testing, 70:tested, 90:closed, 91:updating test documentation";
And I want to add a new status between 52 and 53 so that, on the pull-down menu for status, they appear in the desired order.
I tried different things - including changing the .php file definitions then updating the MySQL table's status field in mantis_bug_table, but it messes up all the views and filters.
Any ideas?
The following steps might help you:
Redefine the enumeration string as per your requirements
Prepare a traceability with your current enumeration values
Update the status field in bugs table with the new values
Add the enumeration in config.php
You may have to reset your previous filters. The filter criteria is stored as a serialized string and it's very difficult to modify.
If anyone is having issues with this you need to change the following:
In config_inc.php modify $g_status_enum_string to ennumerate the new statuses as you see fit.
In custom_constants_inc.php make sure to do the same as above.
In the database, run SQL commands such as this:
UPDATE mantisclone.mantis_bug_table SET status=100 WHERE status=10;
to change the actual records for existing status IDs to new ones.
In custom_strings_inc.php modify $s_status_enum_string and input your new statuses. For example one of mine was:
$s_sanity_test_bug_title = "Set Issue Sanity Test";
$s_sanity_test_bug_button = "Issue Sanity Test Pending";
$s_email_notification_title_for_sanity_test = "The following issue is NOW SANITY TEST PENDING";
Finally you'll need a small script to change the existing ennumerated values in mantis_filters_table. This was mine, alter it as you see fit:
<?php
$mantisDB="myMantisDatabaseName";
mysql_connect("localhost", "XXXX", "YYYY") or die("Could not connect: " . mysql_error());
mysql_select_db($mantisDB);
$result = mysql_query("SELECT id, filter_string FROM $mantisDB.mantis_filters_table");
function parseRecord($statusArray)
{
$newStatus = array( "10" => "100",
"20" => "200",
"50" => "300",
"52" => "400",
"53" => "500",
"54" => "540",
"56" => "560",
"58" => "580",
"60" => "600",
"70" => "700",
"75" => "450",
"90" => "900",
"91" => "910"
);
foreach ($statusArray as $key=>$value)
{
if(array_key_exists($value, $newStatus))
{
echo "Found value $value, replacing it with " . $newStatus[$value] . "\n";
$statusArray[$key] = (int)$newStatus[$value];
}
}
}
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$statusID = $row["id"];
$serializedString = $row["filter_string"];
$unserializedArray = unserialize(substr($serializedString,3)); // There's a prepended 'v8#' string in there, don't know why.
parseRecord(&$unserializedArray["hide_status"]);
parseRecord(&$unserializedArray["show_status"]);
$newSerialized = "v8#".serialize($unserializedArray);
// echo $newSerialized;
$changeStatus = mysql_query("UPDATE $mantisDB.mantis_filters_table SET filter_string='$newSerialized' WHERE id=$statusID");
}
mysql_free_result($result);
?>
I hope this works, let me know if you're having any issues.

ZF2 Db\RecordExists - Check additional columns

I have a problem with ZF2 RecordExists method. I will explain my problematic case/scenario.
Table: users
Columns: id, emailaddress, websitename
Sample Records:
1, user1#email.com, 1site.com
2, user2#email.com, 1site.com
3, user3#email.com, 2site.com
4, user4#email.com, 2site.com
5, user5#email.com, 1site.com
6, user6#email.com, 3site.com
7, user7#email.com, 4site.com
I am using the following snippet for already exist condition.
//Check that the email address exists in the database
$validator = new Zend\Validator\Db\RecordExists(
array(
'table' => 'users',
'field' => 'emailaddress'
)
);
if ($validator->isValid($emailaddress)) {
// email address appears to be valid
} else {
// email address is invalid; print the reasons
foreach ($validator->getMessages() as $message) {
echo "$message\n";
}
}
As per the above snippets, user1#email.com cannot register again. Because, that emailaddress is exist in table.
But, i would like to do register with 2site.com. Because, user1#email.com is in 1site.com.
So, user1#email.com cannot register with 1site.com again. But, user1#email.com can register with 2site.com.
How is it possible? Let me know your suggestions.
There are two way to do this.
First using Excluding Record methods
Where you exclude the record of websitename field value.
Zend\Validator\Db\RecordExists and Zend\Validator\Db\NoRecordExists
also provide a means to test the database, excluding a part of the
table, either by providing a where clause as a string, or an array
with the keys “field” and “value”.
$email = 'user#example.com';
$clause = $db->quoteInto('email = ?', $email);
$validator = new Zend\Validator\Db\RecordExists(
array(
'table' => 'users',
'field' => 'username',
'exclude' => $clause
)
);
if ($validator->isValid($username)) {
// username appears to be valid
} else {
// username is invalid; print the reason
$messages = $validator->getMessages();
foreach ($messages as $message) {
echo "$message\n";
}
}
Second by writing your own custom validtor.
You need to extend AbstractDB class and create your own class on directions of RecordExists Class. In your own cust class your can define your own query and pass it to isValid function.
I have created a Custom Validator oposite to Exclude, which is include.
include is reserve word, Now sure if it will work.
check it here
More readings on this
Guidlines 1
Please have look to existing validtor for creating your own custom validatorCustom validator guildline
Chain validator 2

Resources