Getresponse lookup contact to see if exists - php

I have this code to find a contact in GetResponse to see if it exists.
The first part (getting the campaign) works, but getting the contact fails in an exception: Request have return error: Invalid params:
<?php
$jsonfile = 'jsonrpcclient.php';
if (file_exists($jsonfile))
{
require_once $jsonfile;
$api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$api_url = 'http://api2.getresponse.com';
$client = new jsonRPCClient($api_url);
$result = NULL;
// Get campaign
try
{
$result = $client->get_campaigns(
$api_key,
array (
'name' => array ( 'EQUALS' => 'my_customer_list' )
)
);
}
catch (Exception $e)
{
die($e->getMessage());
}
$campaigns = array_keys($result);
$CAMPAIGN_ID = array_pop($campaigns);
// Lookup contact
try
{
$result = $client->get_contacts(
$api_key,
array (
'campaigns' => $CAMPAIGN_ID,
'email' => $track_order_email
)
);
}
catch (Exception $e)
{
die($e->getMessage());
}
}
else
{
echo "Json include file NOT found";
}
?>
Any help would be appreciated in formatting the get_contacts parameters.

As I explained here: Getresponse API 2 (Adding Custom fields and contacts using PHP)
both of your parameters should be formatted differently.
Instead of:
array (
'campaigns' => $CAMPAIGN_ID,
'email' => $track_order_email
)
it should be:
array (
'campaigns' => array( $CAMPAIGN_ID ),
'email' => array( 'EQUALS' => $track_order_email )
)
Good luck! :)

Related

An error occurred: 40030: Customer Not Found, using UsaEpay soap API

Hi Stackoverflow community,
I am attempting to implement the "convertPaymentMethodToToken" method from USAePay soap api documentations. For the function to work, it is required to fetch the customer number from the UsaEpay acct, and it generates a Method ID through a "getCustomer" request, that will be used for the conversion. However, the implementation works only for a single customer and fails when I try to process multiple customers at once. The error message I receive is: "An error occurred while fetching details of customer 'customer1': 40030: Customer Not Found......".
I have a large customer database of over 20,000 customers, and my goal is to convert each of their payment methods to tokens efficiently, without having to perform individual conversions for each customer. The USAePay documentation only provides information on how to implement the feature for a single customer.
here is my code by getting Method ID for a single customer
<?php
$wsdl = "https://secure.usaepay.com/soap/gate/INBGTWZC/usaepay.wsdl";
$sourceKey = "your soruce key";
$pin = "1234";
function getClient($wsdl) {
return new SoapClient($wsdl, array(
'trace' => 1,
'exceptions' => 1,
'stream_context' => stream_context_create(
array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)
)
));
}
function getToken($sourceKey, $pin) {
$seed = time() . rand();
return array(
'SourceKey' => $sourceKey,
'PinHash' => array(
'Type' => 'sha1',
'Seed' => $seed,
'HashValue' => sha1($sourceKey . $seed . $pin)
),
'ClientIP' => $_SERVER['REMOTE_ADDR']
);
}
$client = getClient($wsdl);
$token = getToken($sourceKey, $pin);
try {
$custnum='customer number';
print_r($client->getCustomer($token,$custnum));
} catch (Exception $e) {
// Code to handle the exception
echo "An error occurred: " . $e->getMessage();
}
?>
and here the successful response I get back (with the Method ID included)
Successful response.
here Is the code I'm trying it to do with multiple customers
<?php
$wsdl = "https://sandbox.usaepay.com/soap/gate/43R1QPKU/usaepay.wsdl";
$sourceKey = "your api key";
$pin = "1234";
function getClient($wsdl) {
return new SoapClient($wsdl, array(
'trace' => 1,
'exceptions' => 1,
'stream_context' => stream_context_create(
array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
)
)
));
}
function getToken($sourceKey, $pin) {
$seed = time() . rand();
return array(
'SourceKey' => $sourceKey,
'PinHash' => array(
'Type' => 'sha1',
'Seed' => $seed,
'HashValue' => sha1($sourceKey . $seed . $pin)
),
'ClientIP' => $_SERVER['REMOTE_ADDR']
);
}
$client = getClient($wsdl);
$token = getToken($sourceKey, $pin);
$custnums = array();
for ($i = 1; $i <= 3; $i++) {
$custnums[] = 'customer' . $i;
}
$methodIDs = array();
foreach ($custnums as $custnum) {
try {
$result = $client->getCustomer($token, $custnum);
$methodID = $result[0]->MethodID;
$methodIDs[] = $methodID;
error_log("Method ID for customer $custnum: $methodID");
} catch (Exception $e) {
echo " An error occurred: " . $e->getMessage();
}
}
?>
I've already been working on it all day,
Can anyone help me with this?
Thanks in advance

Retrieve a multiple stripe charges in php

I just want to know if there is way to retrieve charges with multiples charges_id in stripe.
For example in the docs show how to get one charge. But we need get multiple charges. So, we don't want to made a multiple calls to the stripe method retrieve, this is to slow. We dont want to make this:
foreach ($result as $p_key => $payment) {
$charge = $this->CI->stripe_lib->retrieve_charge('ch_......', 'secret_key');
if (isset($charge['charge'])) {
$amount_charged = (float)$charge['charge']->amount / 100;
// echo "<pre>";
// print_r($amount_charged );
// echo "</pre>";
}
}
this is in Codeigniter. And this is the function on the library:
public function retrieve_charge($charge_id, $secret_key) {
$errors = array();
try {
\Stripe\Stripe::setApiKey($secret_key);
$charge = \Stripe\Charge::retrieve($charge_id);
return array('charge' => $charge);
} catch(Stripe_CardError $e) {
$errors = array('error' => false, 'message' => 'Card was declined.', 'e' => $e);
} catch (Stripe_InvalidRequestError $e) {
$errors = array('error' => false, 'message' => 'Invalid parameters were supplied to Stripe\'s API', 'e' => $e);
} catch (Stripe_AuthenticationError $e) {
$errors = array('error' => false, 'message' => 'Authentication with Stripe\'s API failed!', 'e' => $e);
} catch (Stripe_ApiConnectionError $e) {
$errors = array('error' => false, 'message' => 'Network communication with Stripe failed', 'e' => $e);
} catch (Stripe_Error $e) {
$errors = array('error' => false, 'message' => 'Stripe error. Something wrong just happened!', 'e' => $e);
} catch (Exception $e) {
if (isset($e->jsonBody['error']['type']) && $e->jsonBody['error']['type'] == 'idempotency_error') {
$errors = array('error' => false, 'message' => $e->getMessage(), 'e' => $e, 'type' => 'idempotency_error');
} else {
$errors = array('error' => false, 'message' => 'An error has occurred getting customer info.', 'e' => $e);
}
}
return $errors;
}
With this code: \Stripe\Charge::all(["limit" => 3]); returns all charge but in the docs I didn't see if this method returns me also a multiple charges id.
I appreciate all your help.
Thanks and I'm sorry for my english.
Thanks for your question. It seems you have already identified the right method to retrieve multiple charges using the PHP library!
You are correct in that \Stripe\Charge::all(["limit" => 3]) call [0] will return you multiple charges, up to the limit specified in the arguments [1].
In the response to the above request, you will receive an array of charge objects [2], each having an id field [3] that would be the charge ID.
Hope that helps! Please let me know if you have any questions.
Cheers,
Heath
[0] https://stripe.com/docs/api/charges/list?lang=php
[1] https://stripe.com/docs/api/charges/list?lang=php#list_charges-limit
[2] https://stripe.com/docs/api/charges/object?lang=php
[3] https://stripe.com/docs/api/charges/object?lang=php#charge_object-id

Mailchimp API Integration in PHP, FNAME and LNAME not passing

I've been trying to integrate the Mailchimp API in PHP on our website, and I cannot seem to get mailchimp to take the FNAME and the LNAME.
The email always gets passed through to mailchimp and they are added to the list but the names simply don't and are always blank.
Things I have tried:
Using static names such as Dave in place of $_POST[FirstNAME] etc. but still no luck
Using MERGE1 and MERGE2 which are the alternate names for FNAME and LNAME.
Sending the email along with the FNAME and LNAME in the array for merge_vars
Putting the array in directly or as it is below within a variable ($Merge).
require('../MailCHIMP_API_PHP/Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$Mailchimp_Lists = new Mailchimp_Lists( $Mailchimp );
$Merge = array('FNAME' => $_POST[FirstNAME], 'LNAME' => $_POST[LastNAME]);
$subscriber = $Mailchimp_Lists->subscribe( $list_id, array(
'email' => htmlentities($_POST[Email]),
'merge_vars' => $Merge
));
if ( ! empty( $subscriber['leid'] ) ) {
//echo "success";
} else {
//echo "fail";
}
As always there is probably something simple I am missing but I have been staring at this code for so long I obviously can't see it!
This issue was solved so thought I might as well post an answer. Here is the code that works.
require('../MailCHIMP_API_PHP/Mailchimp.php');
$Mailchimp = new Mailchimp( $api_key );
$subscriber = $Mailchimp->call('lists/subscribe',
array(
'id' => $list_id,
'email' => array('email' => htmlentities($_POST[Email])),
'merge_vars' => array('FNAME' => htmlentities($_POST[FirstNAME]), 'LNAME' => htmlentities($_POST[LastNAME])),
'double_optin' => false
));
if ( ! empty( $subscriber['leid'] ) ) {
//echo "success";
} else {
//echo "fail";
}

error in calling soap function in php

how can i get soap data in php from this site
http://www2.rlcarriers.com/freight/shipping-resources/rate-quote-instructions
they have "GetRateQuote(string APIKey, RequestObjects.RateQuoteRequest request)"
this function how can i call this from php soap
$client = new SoapClient('http://api.rlcarriers.com/1.0.1/RateQuoteService.asmx?WSDL');
//print_r($client);
//$result = $client->GetRateQuote('xxxxxxxxxxxxxxxxxxxxxx.......',);
print_r($result);
?>
what should i have to pass in second parameter
Try the following:
$client = new SoapClient("http://api.rlcarriers.com/1.0.1/ShipmentTracingService.asmx?WSDL", array("trace" => 1));
$request = array(
"APIKey" => "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"request" => array(
"TraceNumbers" => array(
0 => "xxxxxxxxx"
),
"TraceType" => "PRO",
"FormatResults" => "true",
"IncludeBlind" => "true",
"OutputFormat" => "Standard"
)
);
try {
$response = $client->TraceShipment($request);
print_r($response);
}
catch (SoapFault $exception) {
print_r($exception);
}

Yahoo Answers API + php Scraper

I have found a php script that would in theorie match my needs, however I cant get it to work and I was wondering if maybe the script is outdated or if I am doing something wrong.
The script looks like this:
<?php
/**
* #package Yahoo Answer
* #author The HungryCoder
* #link http://hungrycoder.xenexbd.com/?p=953
* #version 1.0
* #license GPL, This class does not come with any expressed or implied warranties! Use at your own risks!
*/
class yahooAnswer{
var $appID;
var $searchQuestionURL = 'http://answers.yahooapis.com/AnswersService/V1/questionSearch?';
var $getQuestionURL = 'http://answers.yahooapis.com/AnswersService/V1/getQuestion?';
private $numResults = 10;
private $numStart = 0;
function __construct($appid) {
$this->appID=$appid;
}
function set_numResults($num_results){
$this->numResults = $num_results;
}
/**
* Search for questions for the given keywords. Returned results can be associative array or XML
* #param <string> $kewyord
* #return <string> Returns the results set either in XML format or associative array.
*/
function search_questions($params){
if(!is_array($params)){
throw new Exception('The parameters must be an array!');
}
$defaults = array(
'search_in' => '',
'category_name' => '',
'date_range' => '', //7, 7-30, 30-60, 60-90, more90
'sort' => 'relevance', //relevance, date_desc, date_asc
'type' => 'all',
'output' => 'php',
'results' => $this->numResults,
'start' => $this->numStart,
'region' => 'us',
'appid' => $this->appID,
);
$params = array_merge($defaults,$params);
if(!$params['appid']){
throw new Exception('APP ID is empty!', 404);
}
if(!$params['query']) {
throw new Exception('Query is not set!', '404');
}
$req_params = $this->array2query_string($params);
$url = $this->searchQuestionURL.$req_params;
$results = $this->make_call($url);
if($params['output']=='php'){
$results = unserialize($results);
return $results['Questions'];
}
return $results;
}
/**
* Get all answers of a given question ID
* #param <array> $params keys are: question_id, output, appid
* #return <string> Returns all answers in expected format. default format is php array
*/
function get_question($params){
if(!is_array($params)){
throw new Exception('The parameter must be an array!');
}
$defaults = array(
'question_id' => '',
'output' => 'php',
'appid' => $this->appID,
);
$params = array_merge($defaults,$params);
if(!$params['appid']){
throw new Exception('APP ID is empty!', 404);
}
if(!$params['question_id']) {
throw new Exception('Question ID is not set!', '404');
}
$req_params = $this->array2query_string($params);
$url = $this->getQuestionURL.$req_params;
$results = $this->make_call($url);
if($params['output']=='php'){
$results = unserialize($results);
return $results['Questions'][0];
}
return $results;
}
protected function make_call($url){
if(function_exists('curl_init')){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
$result = curl_exec($ch);
curl_close($ch);
return $result;
} else if(function_exists('file_get_contents')) {
return file_get_contents($url);
} else {
throw new Exception('No method available to contact remote server! We must need cURL or file_get_contents()!', '500');
}
}
protected function array2query_string($array){
if(!is_array($array)) throw new Exception('Parameter must be an array', '500');
$params ='';
foreach($array as $key=>$val){
$params .= "$key=$val&";
}
return $params;
}
}
$appid = 'MYAPPID';
$params = array(
'query' => 'test', //enter your keyword here. this will be searched on yahoo answer
'results' => 2, //number of questions it should return
'type' => 'resolved', //only resolved questiosn will be returned. other values can be all, open, undecided
'output' => 'php', //result will be PHP array. Other values can be xml, json, rss
);
$question_id = 'test'; //without this i get an error "Question ID is not set!"
$yn = new yahooAnswer($appid);
//search questions
try{
$questions = $yn->search_questions($params);
} catch (Exception $e){
echo ($e->getMessage());
}
foreach ($questions as $question) {
//now get the answers for the question_id;
try{
$answers = $yn->get_question(array('question_id'=>$question_id));
echo '<pre>';
print_r($answers);
echo '<pre>';
} catch (Exception $e){
echo($e->getMessage());
}
}
?>
But instead of a valid output I just get this:
Array
(
[id] =>
[type] =>
[Subject] =>
[Content] =>
[Date] =>
[Timestamp] =>
[Link] => http://answers.yahoo.com/question/?qid=
[Category] => Array
(
[id] =>
[content] =>
)
[UserId] =>
[UserNick] =>
[UserPhotoURL] =>
[NumAnswers] =>
[NumComments] =>
[ChosenAnswer] =>
[ChosenAnswererId] =>
[ChosenAnswererNick] =>
[ChosenAnswerTimestamp] =>
[ChosenAnswerAwardTimestamp] =>
)
I have tried it with other keywords, but the result is always the same.
This part $question_id = 'test'; is not included in the official script, but without it I keep getting Question ID is not set!.
I also tried to change it, add it at another place in the script etc. Everything I could think of, but the result was always that array with no information besides the [Link]
Since I got almost zero php experience at all, I am not even where start looking for an error :/ Would be glad if some1 could point me in the right direction!
Regards!
p.s. of course "MYAPPID" is changed to my real yahoo app id.
In order to make this example work, change this line:
$answers = $yn->get_question(array('question_id'=>$question_id));
to:
$answers = $yn->get_question(array('question_id'=>$question['id']));
That change pulls the actual question ID out of the response from search_questions(), and uses it in the call to get_question().

Categories