Error code 410 when polling Skyscanner flight live prices - php

I am polling live prices from the Skyscanner API. Although I receive the session_key and although I am immediately polling the results I am getting a 410 (Gone) response header with an empty body. It used to work fine from my localhost environment but not on my live server anymore.
Has anybody experienced this before and can maybe give me a hint what the issue could be?
$url_api = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/";
$api_key = "XXX"; // Not shown here
$data = array('apiKey' => $api_key, 'country' => 'DE', 'currency' => 'EUR',
'locale' => 'de-DE', 'originplace' => 'HAM', 'destinationplace' => 'AMS', 'cabinclass' => 'economy', 'outbounddate' => '2017-01-27',
'inbounddate' => '2017-01-30' , 'locationschema' => 'Iata', 'groupPricing' => true);
$httpdata = http_build_query($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_api);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $httpdata);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
$response = curl_exec($ch);
curl_close($ch);
$headers = get_headers_from_curl_response($response);
$url = $headers['Location']."?apiKey=".$api_key."&stops=0";
echo $url;
return;

Related

Json received = false

I am using ci framework, and i try to create notification using
onesignal API. I have hosted the website using https. But why my JSON
received is always false using onesignal API, but if i test using
postman it runs fine without error.
This is my code
function send_message($id, $nama) {
$content = array(
"en" => $nama
);
$heading =array(
"en" => $id
);
$fields = array(
'app_id' => "2cd5ad24-a2d9-4e7d-ac66-7494cebd8e84",
'included_segments' => array(
'Active Users'
),
'contents' => $content,
'headings' => $heading,
'url' => "https://esop.matahariled.com"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Authorization: Basic MDQ0NjY0ZmYtZjQ2Yi00ODVmLTkzZjgtZmVkZDBkODk0MDFl'
));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_CAINFO, $_SERVER['DOCUMENT_ROOT']."/cacert.pem");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}

MailChimp API subscribe in PHP

I'm incredibly rusty but trying to change the email product used on a website. I've been reading through some previously answered questions and have the below code.
The page is progressing, adding the user to the site database but not the MailChimp list. Where am I falling down?
$apikey = 'api key-us16';
$auth = base64_encode( 'user:'.$apikey );
$data = array(
'apikey' => $apikey,
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => $firstname
)
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://us16.api.mailchimp.com/3.0/lists/mylistid/members/');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);

Sending Push Notifications via OneSignal using PHP

I am using the following PHP Code to send push notification via One Signal:
function sendMessage(){
$content = array(
"en" => 'English Message'
);
$fields = array(
'app_id' => $appId,
'included_segments' => array('All'),
'data' => array("foo" => "bar"),
'contents' => $content
);
$fields = json_encode($fields);
print("\nJSON sent:\n");
print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic '.$restKey));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$response = sendMessage();
$return["allresponses"] = $response;
$return = json_encode( $return);
print("\n\nJSON received:\n");
print($return);
print("\n");
And I am getting the following response:
JSON sent: {"app_id":null,"included_segments":["All"],"data":{"foo":"bar"},"contents":{"en":"English Message"}} JSON received: "{\"allresponses\":\"{\\\"adm_big_picture\\\":null,\\\"adm_group\\\":null,\\\"adm_group_message\\\":null,\\\"adm_large_icon\\\":null,\\\"adm_small_icon\\\":null,\\\"adm_sound\\\":null,\\\"amazon_background_data\\\":false,\\\"android_accent_color\\\":null,\\\"android_group\\\":null,\\\"android_group_message\\\":null,\\\"android_led_color\\\":null,\\\"android_sound\\\":null,\\\"android_visibility\\\":null,\\\"app_id\\\":\\\"63c6c8f7-694b-4c68-abc1-d820d9bbbec1\\\",\\\"big_picture\\\":null,\\\"buttons\\\":null,\\\"canceled\\\":false,\\\"chrome_big_picture\\\":null,\\\"chrome_icon\\\":null,\\\"chrome_web_icon\\\":\\\"\\\",\\\"chrome_web_image\\\":\\\"\\\",\\\"content_available\\\":false,\\\"contents\\\":{\\\"en\\\":\\\"This is a new message.\\\"},\\\"converted\\\":0,\\\"data\\\":null,\\\"delayed_option\\\":\\\"immediate\\\",\\\"delivery_time_of_day\\\":\\\"4:00 PM\\\",\\\"errored\\\":0,\\\"excluded_segments\\\":[],\\\"failed\\\":0,\\\"firefox_icon\\\":\\\"\\\",\\\"headings\\\":{\\\"en\\\":\\\"New Message\\\"},\\\"id\\\":\\\"8d56f592-8f43-461a-94e8-2fe9922ba844\\\",\\\"include_player_ids\\\":null,\\\"included_segments\\\":[\\\"All\\\"],\\\"ios_badgeCount\\\":null,\\\"ios_badgeType\\\":null,\\\"ios_category\\\":null,\\\"ios_sound\\\":null,\\\"isAdm\\\":false,\\\"isAndroid\\\":false,\\\"isChrome\\\":false,\\\"isChromeWeb\\\":true,\\\"isFirefox\\\":true,\\\"isIos\\\":false,\\\"isSafari\\\":true,\\\"isWP\\\":false,\\\"isWP_WNS\\\":false,\\\"large_icon\\\":null,\\\"priority\\\":null,\\\"queued_at\\\":1492523636,\\\"remaining\\\":0,\\\"send_after\\\":1492523636,\\\"small_icon\\\":null,\\\"successful\\\":3,\\\"tags\\\":null,\\\"filters\\\":null,\\\"template_id\\\":null,\\\"ttl\\\":null,\\\"url\\\":\\\"\\\",\\\"web_buttons\\\":null,\\\"wp_sound\\\":null,\\\"wp_wns_sound\\\":null}\"}"
However the Push Notification is not appearing in the One Signal Dashboard and neither being received by those who subscribed.
Can someone help please :) ?
your mistake is here.
'Authorization: Basic '.$restKey));
Correct one is.....
'Authorization: Basic "'.$restKey."'"));
I am working this code and this is working fine
function SendOneSignalMessage($message,$empid){
// Your code here!
$fields = array(
'app_id' => 'xxxxxxxxxxxxxxxxxx',
'include_player_ids' => [$empid],
'contents' => array("en" =>$message),
'headings' => array("en"=>"etc"),
'largeIcon' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
);
$fields = json_encode($fields);
//print("\nJSON sent:\n");
//print($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
'Authorization: Basic xxxxxxxxxxxxx));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
}

SkyScanner API error when called by PHP

I did exactly as shown in the API documentation
http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingList
but when i call it returns this error
HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server Error Cache-Control: private Content-Type: application/json Date: Sat, 04 Jun 2016 06:23:48 GMT Connection: close Content-Length: 2 {}
and here is my code in PHP
<?
$url = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/';
$data = array('apiKey' => 'de995438234178656329029769192274', 'country' => 'BR', 'currency' => 'BRL',
'locale' => 'pt-BR', 'originplace' => 'SDU-iata', 'destinationplace' => 'GRU-iata', 'outbounddate' => '2016-09-23',
$headers = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8';
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
printf($result);
?>
any idea what is going wrong?
thanks in advance for any kind
So I think the PHP is sending the wrong request type, because the HTTP headers were being sent as an array (so defaults to 'multipart/formdata'). If you use http_build_query on that array, it is sent correctly as 'x-www-form-urlencoded'.
I've tidied things up, removed some duplication in the curl options, and correctly get a 201 response on your example now:
<?
$url = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0/';
$data = array('apiKey' => 'de995438234178656329029769192274', 'country' => 'BR', 'currency' => 'BRL',
'locale' => 'pt-BR', 'originplace' => 'SDU', 'destinationplace' => 'GRU', 'outbounddate' => '2016-09-23', 'locationschema' => 'Iata', 'adults' => 1);
$httpdata = http_build_query($data);
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $httpdata);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
?>
Hope that helps, I'll keep an eye on the thread in case of anything else - feel free to drop us a query or check the FAQs here: https://support.business.skyscanner.net/hc/en-us

What is wrong with my paypal recurring code

I did everything right, all seem legit, but i don't see any payments made by my dummy user to the merchant:
Is it something in my code:
creating plan:
$req = array(
'USER' => 'bennyrefaelov-facilitator_api1.gmail.com',
'PWD' => 'YWKQ3M3NXBTZQ78U',
'SIGNATURE' => 'AFcWxV21C7fd0v3bYYYRCpSSRl31AuVEFUpBu6N8yXkmFksuwwSiQOW8',
'VERSION' => '98.0',
'METHOD' => 'SetExpressCheckout',
'PAYMENTREQUEST_0_PAYMENTACTION' => 'Mark',
'REQCONFIRMSHIPPING'=>'0',
'NOSHIPPING'=>'1',
'ALLOWNOTE'=>'0',
'SOLUTIONTYPE'=>'Sole',
'LANDINGPAGE'=>'Billing',
'BRANDNAME'=>'MisterSurvey',
'PAYMENTREQUEST_0_AMT'=>'100.00',
'MAXAMT' => '100.00',
'L_BILLINGAGREEMENTDESCRIPTION0' => 'Pay up',
'PAYMENTREQUEST_0_TAXAMT'=>'0',
'PAYMENTREQUEST_0_ITEMAMT'=>'100.00',
'L_BILLINGTYPE0' => 'RecurringPayments',
'PAYMENTREQUEST_0_DESC'=>'An awesome package',
'PAYMENTREQUEST_0_CUSTOM'=>'This is just for fun',
'PAYMENTREQUEST_0_CURRENCYCODE'=>'USD',
'L_PAYMENTREQUEST_0_NUMBER0'=>'itemid1',
'L_PAYMENTREQUEST_0_NAME0'=>'MyItem1',
'L_PAYMENTREQUEST_0_DESC0'=>'basic package',
'L_PAYMENTREQUEST_0_QTY0'=>'1',
'L_PAYMENTREQUEST_0_AMT0'=>'100.00',
'L_PAYMENTREQUEST_0_TAXAMT0'=>'0',
'RETURNURL'=>'http://mistersurveylocal.com:8080/#/pricing',
'CANCELURL'=>'http://mistersurveylocal.com:8080/#/'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($req));
$return = curl_exec($ch);
curl_close($ch);
excute plan (after user agrees)
$token = Input::get('token');
$payerId = Input::get('payerId');
$req = array(
'USER' => 'bennyrefaelov-facilitator_api1.gmail.com',
'PWD' => 'YWKQ3M3NXBTZQ78U',
'SIGNATURE' => 'AFcWxV21C7fd0v3bYYYRCpSSRl31AuVEFUpBu6N8yXkmFksuwwSiQOW8',
'VERSION' => '98.0',
'METHOD' => 'CreateRecurringPaymentsProfile',
'TOKEN'=>$token,
'payerid'=>$payerId,
'PROFILESTARTDATE' =>date('Y-m-d\TH:i:s\Z'),
'TOTALBILLINGCYCLES'=>'12',
'DESC'=>'Pay up',
'BILLINGPERIOD'=>'Month',
'BILLINGFREQUENCY'=>'1',
'AMT'=>'100',
'CURRENCYCODE'=>'USD',
'COUNTRYCODE'=>'US',
'MAXFAILEDPAYMENTS'=>'3'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api-3t.sandbox.paypal.com/nvp');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($req));
$return = curl_exec($ch);
curl_close($ch);
return urldecode($return);
It says it's active, and verified, and the start date is at this moment, why there is no payment made?
is there something missing?
I had the exact same problem. As it turns out, it was an issue with the Sandbox being very slow. After 2 days of troubleshooting and debugging, all the transactions completed and I received all IPN messages related to them.
It's unfortunate, but the solution is simply to wait for them to process. Hopefully live will be much faster.

Categories