I'm finding that I have the following Generic List, and I can see it has items in it, but when I try to run the code, it's not hitting inside the foreach. This is my code:
function SQLQueryWriteToFile([string]$SQLquery, [string]$extractFile)
{
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Server=blah;Database=blah;User ID=blah;Password=blah" #production #I have an error in this so it doesn't connect
$sqlConnection.Open()
if($sqlConnection.State -ne 'Open'){
$global:ErrorStrings.Add("Exception: $("Couldn't connect to DB with connection string given");; ") #this gets hit
}
###
$global:ErrorStrings = New-Object System.Collections.Generic.List[System.String] #System.Object]
$query = "Select blah"
$dir = "C:\blah"
SQLQueryWriteToFile $query $dir
$errorCodeAsString = ""
foreach ($item in $global:ErrorStrings.Members){
$errorCodeAsString += $item #this isn't hit
}
Any idea why it's not finding the error string in my list for the foreach loop, when I can see it's in there looking at $global:ErrorStrings? Based on this foreach list, I'm doing it correctly. I'm having trouble finding examples like what I'm doing. Thanks!
try this:
function SQLQueryWriteToFile([string]$SQLquery, [string]$extractFile)
{
[System.Data.SqlClient.SqlConnection] $sqlConnection=$null
[System.Data.SqlClient.SqlCommand] $command=$null
try
{
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection
$sqlConnection.ConnectionString = "Server=blah;Database=blah;User ID=blah;Password=blah"
$command = New-Object System.Data.SqlClient.SqlCommand
$command.Connection=$sqlConnection
$command.CommandText=$SQLquery
$sqlConnection.Open()
$command.ExecuteNonQuery()
}
catch
{
$global:ErrorStrings.Add($_.Exception.Message)
}
finally
{
if ($sqlConnection -ne $null)
{
$sqlConnection.Close()
$sqlConnection.Dispose()
}
if ($command -ne $null)
{
$command.Dispose()
}
}
}
$global:ErrorStrings = New-Object System.Collections.Generic.List[System.String]
$query = "Select blah"
$dir = "C:\blah"
$global:ErrorStrings.Clear()
SQLQueryWriteToFile $query $dir
$errorCodeAsString=""
for ($i = 0; $i -lt $global:ErrorStrings.Count; $i++)
{
$errorCodeAsString +=$global:ErrorStrings.Item($i)
}
$errorCodeAsString
Website built on OpenCart 3.0.2.0, using the standard (included with OC) payment module for Authorize.net.
Problem #1: need to add Line Items (individual item information) to the transaction.
Problem #2: the Authorize.net AIM PDF reference shows only hardcoded examples, no idea how to turn them into dynamically-generated array.
Problem #3: don't know nearly enough PHP to figure it out on my own.
Here's the current code of authorizenet_aim.php... if anyone can show me how to add line items to this mess, I would really, really appreciate it!
<?php
class ControllerExtensionPaymentAuthorizeNetAim extends Controller {
public function index() {
$this->load->language('extension/payment/authorizenet_aim');
$data['months'] = array();
for ($i = 1; $i <= 12; $i++) {
$data['months'][] = array(
'text' => strftime('%B', mktime(0, 0, 0, $i, 1, 2000)),
'value' => sprintf('%02d', $i)
);
}
$today = getdate();
$data['year_expire'] = array();
for ($i = $today['year']; $i < $today['year'] + 11; $i++) {
$data['year_expire'][] = array(
'text' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i)),
'value' => strftime('%Y', mktime(0, 0, 0, 1, 1, $i))
);
}
return $this->load->view('extension/payment/authorizenet_aim', $data);
}
public function send() {
if ($this->config->get('payment_authorizenet_aim_server') == 'live') {
$url = 'https://secure.authorize.net/gateway/transact.dll';
} elseif ($this->config->get('payment_authorizenet_aim_server') == 'test') {
$url = 'https://test.authorize.net/gateway/transact.dll';
}
//$url = 'https://secure.networkmerchants.com/gateway/transact.dll';
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$data = array();
$data['x_login'] = $this->config->get('payment_authorizenet_aim_login');
$data['x_tran_key'] = $this->config->get('payment_authorizenet_aim_key');
$data['x_version'] = '3.1';
$data['x_delim_data'] = 'true';
$data['x_delim_char'] = '|';
$data['x_encap_char'] = '"';
$data['x_relay_response'] = 'false';
$data['x_first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
$data['x_last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['x_company'] = html_entity_decode($order_info['payment_company'], ENT_QUOTES, 'UTF-8');
$data['x_address'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8');
$data['x_city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
$data['x_state'] = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');
$data['x_zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
$data['x_country'] = html_entity_decode($order_info['payment_country'], ENT_QUOTES, 'UTF-8');
$data['x_phone'] = $order_info['telephone'];
$data['x_customer_ip'] = $this->request->server['REMOTE_ADDR'];
$data['x_email'] = $order_info['email'];
$data['x_description'] = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
$data['x_amount'] = $this->currency->format($order_info['total'], $order_info['currency_code'], 1.00000, false);
$data['x_currency_code'] = $this->session->data['currency'];
$data['x_method'] = 'CC';
$data['x_type'] = ($this->config->get('payment_authorizenet_aim_method') == 'capture') ? 'AUTH_CAPTURE' : 'AUTH_ONLY';
$data['x_card_num'] = str_replace(' ', '', $this->request->post['cc_number']);
$data['x_exp_date'] = $this->request->post['cc_expire_date_month'] . $this->request->post['cc_expire_date_year'];
$data['x_card_code'] = $this->request->post['cc_cvv2'];
$data['x_invoice_num'] = $this->session->data['order_id'];
$data['x_solution_id'] = 'A1000015';
/* Customer Shipping Address Fields */
if ($order_info['shipping_method']) {
$data['x_ship_to_first_name'] = html_entity_decode($order_info['shipping_firstname'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_last_name'] = html_entity_decode($order_info['shipping_lastname'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_company'] = html_entity_decode($order_info['shipping_company'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_address'] = html_entity_decode($order_info['shipping_address_1'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['shipping_address_2'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_city'] = html_entity_decode($order_info['shipping_city'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_state'] = html_entity_decode($order_info['shipping_zone'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_zip'] = html_entity_decode($order_info['shipping_postcode'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_country'] = html_entity_decode($order_info['shipping_country'], ENT_QUOTES, 'UTF-8');
} else {
$data['x_ship_to_first_name'] = html_entity_decode($order_info['payment_firstname'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_last_name'] = html_entity_decode($order_info['payment_lastname'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_company'] = html_entity_decode($order_info['payment_company'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_address'] = html_entity_decode($order_info['payment_address_1'], ENT_QUOTES, 'UTF-8') . ' ' . html_entity_decode($order_info['payment_address_2'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_city'] = html_entity_decode($order_info['payment_city'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_state'] = html_entity_decode($order_info['payment_zone'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_zip'] = html_entity_decode($order_info['payment_postcode'], ENT_QUOTES, 'UTF-8');
$data['x_ship_to_country'] = html_entity_decode($order_info['payment_country'], ENT_QUOTES, 'UTF-8');
}
if ($this->config->get('payment_authorizenet_aim_mode') == 'test') {
$data['x_test_request'] = 'true';
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_PORT, 443);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FORBID_REUSE, 1);
curl_setopt($curl, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data, '', '&'));
$response = curl_exec($curl);
$json = array();
if (curl_error($curl)) {
$json['error'] = 'CURL ERROR: ' . curl_errno($curl) . '::' . curl_error($curl);
$this->log->write('AUTHNET AIM CURL ERROR: ' . curl_errno($curl) . '::' . curl_error($curl));
} elseif ($response) {
$i = 1;
$response_info = array();
$results = explode('|', $response);
foreach ($results as $result) {
$response_info[$i] = trim($result, '"');
$i++;
}
if ($response_info[1] == '1') {
$message = '';
if (isset($response_info['5'])) {
$message .= 'Authorization Code: ' . $response_info['5'] . "\n";
}
if (isset($response_info['6'])) {
$message .= 'AVS Response: ' . $response_info['6'] . "\n";
}
if (isset($response_info['7'])) {
$message .= 'Transaction ID: ' . $response_info['7'] . "\n";
}
if (isset($response_info['39'])) {
$message .= 'Card Code Response: ' . $response_info['39'] . "\n";
}
if (isset($response_info['40'])) {
$message .= 'Cardholder Authentication Verification Response: ' . $response_info['40'] . "\n";
}
if (!$this->config->get('payment_authorizenet_aim_hash') || (strtoupper($response_info[38]) == strtoupper(md5($this->config->get('payment_authorizenet_aim_hash') . $this->config->get('payment_authorizenet_aim_login') . $response_info[7] . $this->currency->format($order_info['total'], $order_info['currency_code'], 1.00000, false))))) {
$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('payment_authorizenet_aim_order_status_id'), $message, false);
} else {
$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('config_order_status_id'));
}
$json['redirect'] = $this->url->link('checkout/success', '', true);
} else {
$json['error'] = $response_info[4];
}
} else {
$json['error'] = 'Empty Gateway Response';
$this->log->write('AUTHNET AIM CURL ERROR: Empty Gateway Response');
}
curl_close($curl);
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
Found the solution.
Path: public_html/catalog/controller/extension/payment/authorizenet_aim.php
Line items:
$products = $this->model_checkout_order->getOrderProducts($this->session->data['order_id']);
$post_string = "";
foreach( $data as $key => $value )
{ $post_string .= "$key=" . urlencode( $value ) . "&"; }
$post_string = rtrim( $post_string, "& " );
$line_items = array();
$index = 1;
foreach ($products as $product) {
$line_items[] = 'item' . $index . '<|>' . $product['name'] . '<|>' . $product['model'] . '<|>' . (int) $product['quantity'] . '<|>' . (int) $product['price'] . '<|>Y';
$index++;
}
foreach( $line_items as $value )
{ $post_string .= "&x_line_item=" . urlencode( $value ); }
Custom Fields:
/* Merchant Defined Fields */
$data['Order'] = $data['x_invoice_num'];
$data['Item_1'] = "";
$data['Model'] = $data['x_description'];
$data['Qty'] = "";
$data['Price'] = $data['x_amount'];
$data['Taxable?'] = "";
I have this script for making subdomain and I want to placed it in the opencart contoller. How to do that and how to make it work with the insert function?
$cpanel_user = 'root';
$cpanel_pass = 'password';
$cpanel_skin = 'x2';
$cpanel_host = 'yourdomain.com';
$subdomain = 'mysubdomain';
$dir = 'public_html/mysubdomain';
$sock = fsockopen($cpanel_host,2082);
if(!$sock) {
print('Socket error');
exit();
}
$pass = base64_encode("$cpanel_user:$cpanel_pass");
$in = "GET /frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$cpanel_host&domain=$subdomain&dir=$dir\r\n";
$in .= "HTTP/1.0\r\n";
$in .= "Host:$cpanel_host\r\n";
$in .= "Authorization: Basic $pass\r\n";
$in .= "\r\n";
fputs($sock, $in);
while (!feof($sock)) {
$result .= fgets ($sock,128);
}
fclose($sock);
I have created a PHP / MySQL based web service. I wrote client.php as mentioned here
and server.php as below:
<?php
require_once("lib/nusoap.php");
$host = $_SERVER['HTTP_HOST'];
$miURL = 'http://'.$host.'/WS-Demo';
$server = new nusoap_server();
$server->configureWSDL('L3M_WebService', $miURL);
$server->wsdl->schemaTargetNamespace=$miURL;
$server->register('getDemoData',
array('fldpara' => 'xsd:Array', 'tblpara' => 'xsd:Array', 'cndpara' => 'xsd:Array'),
array('return' => 'xsd:string'),
$miURL);
function decryptRJ256($string_to_decrypt)
{
$key = 'salt_key - I';
$iv = 'salt_key - II';
$string_to_decrypt = base64_decode($string_to_decrypt);
$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv);
$rtn = rtrim($rtn, "\4");
return($rtn);
}
function encryptRJ256($string_to_encrypt)
{
$key = 'salt_key - I';
$iv = 'salt_key - II';
$rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv);
$rtn = base64_encode($rtn);
return($rtn);
}
function getDemoData($flds, $tbls, $cnds){
$mysqli = new mysqli("localhost", "root", "", "test");
for($i=0;$i< count($flds); $i++) {
$flds[$i] = decryptRJ256($flds[$i]);
}
for($i=0;$i< count($tbls); $i++) {
$tbls[$i] = decryptRJ256($tbls[$i]);
}
for($i=0;$i< count($cnds); $i++) {
$cnds[$i] = decryptRJ256($cnds[$i]);
}
if(! empty($flds)) {
$what = implode(", ", $flds);
} else {
$what = "*";
}
if(! empty($tbls)) {
$from = implode(", ", $tbls);
}else {
$err = 1;
}
if(! empty($cnds)) {
$cond = " WHERE ";
$cond .= $cnds[0] . " = '" . $cnds[1] . "'";
} else {
$cond = "";
}
$sql = "SELECT ".$what." FROM ".$from . $cond;
$rsGetData = $mysqli->query($sql);
$responseData = '<?xml version="1.0" encoding="UTF-8"?>
<L3MDataSets>';
while($rowGetData = $rsGetData->fetch_assoc()) {
$responseData .= '<L3DataSet>';
foreach($rowGetData as $k => $v) {
$responseData .= '<' . $k . '>' . $v . '</' . $k . '>';
}
$responseData .= '</L3DataSet>';
}
$responseData .= '</L3MDataSets>';
$responseData = encryptRJ256($responseData);
$responseString = new soapval('return', 'xsd:string', $responseData );
return $responseData;
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
From the Above code in the getDemoData function, if I remove the while loop, it gives the proper output. But when I put back the while loop it shows me output as "-Error: Response not of type text/xml: text/html" even if the SQL query is correct. I have copied and paste the generated SQL query which works in phpMyAdmin.
In my app. i get user's feed and user's news ticker. With first i have no questions, but with the second i have some troubles. How a can access to the ticker using php?
From my experience the ticker is just a shortened version of a users news feed using "story"
Here is a sample batch request "with only 1 request" i use to display ticker info from a users news feed.
user / home https://developers.facebook.com/docs/reference/api/user/#home
filtering results based on user lists https://developers.facebook.com/docs/reference/fql/stream_filter/
API Request:
<?php
$Ticker = $facebook->api('/me/home?fields=id,story%26'.$access_token.'');
echo '<pre>';
print_r($Ticker);
echo '</pre>';
?>
Batch API Request:
<?php
$Ticker = '/me/home?fields=id,story%26'.$access_token.'';
$queries = array(
array('method' => 'GET', 'relative_url' => ''.$Ticker.'')
);
$batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
$MEticker = json_decode($batchResponse[0]['body'], true);
echo '<pre>';
print_r($MEticker);
echo '</pre>';
?>
Thank you very much! I almost understood! :)
Another way to get ticker:
<?php
$res = $app->facebook->get_friends_news('me',$access_token);
print_r($res);
print "Ticker:"."\r\n";
foreach ($res['data'] as $value){
if (isset($value['story'])){
echo $value['story']."\r\n";
}
}
?>
where
<?php
function get_friends_news($user_id ='me',$token)<br/>
{
$url = $this->url_base_graph.$user_id.'/home?access_token='.$token;
$res = json_decode($this->httpQuery($url),true);
return $res;
}
?>
And:
<?php
function httpQuery($url, $method = 'GET', $post_data = array(), $CONNECTTIMEOUT = 30) {
// type of query
if ($method == 'POST')
$method = 1;
elseif ($method == 'GET')
$method = 0;
if ($this->access_token != false)
$url = $url . 'access_token=' . $this->access_token;
//echo $url;
//traverse array and prepare data for posting (key1=value1)
if (count($post_data)) {
foreach ($post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode('&', $post_items);
} else {
$post_string = '';
}
// echo $url;
//create cURL connection
$curl_connection = curl_init($url);
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, $CONNECTTIMEOUT);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_URL, $url);
curl_setopt($curl_connection, CURLOPT_POST, $method);
//set data to be posted
if ($post_string != '') {
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
}
//perform our request
$result = curl_exec($curl_connection);
//close the connection
curl_close($curl_connection);
return $result;
}?>