I Make one code for create order in magento programmatically. - paypal-sandbox

it's work fine but when i used Payment Method as "paypal_express" it redirect Error like : PayPal gateway has rejected request. Invalid token (#10410: Invalid token)
Give Proper Suggestion how to solve it.
My Code Like :
$ch = curl_init();
$clientId = "******";
$secret = "*******";
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
//curl_setopt($ch, CURLOPT_HTTPAUTH, true);
$result = curl_exec($ch);
if(empty($result))die("Error: No response.");
else
{
$json = json_decode($result);
$type = $json->token_type;
$token = $type." ".$json->access_token;
$proId = $this->getRequest()->getParam('payid');
//$proId1 = "PAY-6PY01870PN0146745KZTHFDY";
$proUrl = "https://api.sandbox.paypal.com/v1/payments/payment/".$proId;
$headers = array(
"Content-type: application/json",
"Authorization: ".$token,
);
curl_setopt($ch, CURLOPT_URL, $proUrl);
//curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPGET, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$orderResult = curl_exec($ch);
$json = json_decode($orderResult);
$PayerID = $json->payer->payer_info->payer_id;
$PayerEmail = $json->payer->payer_info->email;
$PayerStatus = $json->payer->status;
$Merchant = $json->transactions[0]->related_resources[0]->sale->protection_eligibility;
$TransactionId = $json->transactions[0]->related_resources[0]->sale->id;
// echo $json->state."<br>";
// echo $json->payer->payment_method."<br>";
}
curl_close($ch);
/* End Access Token */
$userid = $this->getRequest()->getParam('userid');
$firstname = $this->getRequest()->getParam('firstname');
$lastname = $this->getRequest()->getParam('lastname');
$telephone = $this->getRequest()->getParam('telephone');
$street[0] = $this->getRequest()->getParam('street');
$city = $this->getRequest()->getParam('city');
$region_id = $this->getRequest()->getParam('region_id');
$region = $this->getRequest()->getParam('region');
$country_id = $this->getRequest()->getParam('country_id');
$postcode = $this->getRequest()->getParam('postcode');
$shippingmethod = $this->getRequest()->getParam('shippingmethod');
$shippingprice = $this->getRequest()->getParam('shippingprice');
$paymentmethod = $this->getRequest()->getParam('payment');
$email = $this->getRequest()->getParam('email');
$productId = $this->getRequest()->getParam('product_id');
$qty = $this->getRequest()->getParam('qty');
$websiteId = Mage::app()->getWebsite()->getId();
$optionValue = $this->getRequest()->getParam('optionvalue');
//echo "pro".$productId."--wty--".$qty."--op--".$optionValue;die();
$store = Mage::app()->getStore();
$customerAccountNo = $userid;
if($customerAccountNo)
{
// load customer object
$customerObj = Mage::getModel('customer/customer')->load($customerAccountNo);
// assign this customer to quote object, before any type of magento order, first create quote.
$quoteObj = Mage::getModel('sales/quote')->assignCustomer($customerObj);
$quoteObj = $quoteObj->setStoreId(Mage::app()->getStore()->getId());
// product id
$productId = 1781;
$productModel = Mage::getModel('catalog/product');
$productObj = $productModel->load($productId);
// for simple product
if ($productObj->getTypeId() == 'simple')
{
$quoteObj->addProduct($productObj , 1);
// for downloadable product
}
else if ($productObj->getTypeId() == 'downloadable')
{
$params = array();
$links = Mage::getModel('downloadable/product_type')->getLinks( $productObj );
$linkId = 0;
foreach ($links as $link) {
$linkId = $link->getId();
}
$params['product'] = $productId;
$params['qty'] = $qty;
$params['links'] = array($linkId);
$request = new Varien_Object();
$request->setData($params);
$quoteObj->addProduct($productObj , $request);
}
elseif ($productObj->getTypeId() == 'configurable')
{
$optionValue = $this->getRequest()->getParam('optionvalue');
$param = array(
'product' => $productId,
'super_attribute' => array(
184 => 50
),
'qty' => 2
);
$quoteObj->addProduct($productObj,new Varien_Object($param));
}
// sample billing address
$billingAddress = array
(
'email' => $email,
'firstname' => $firstname,
'lastname' => $lastname,
'telephone' => $telephone,
'street' => $street[0],
'country_id' => $country_id,
'city' => $city,
'postcode' => $postcode ,
'region_id' => $region_id,
'region' => $region,
'customer_address_id' => NULL,
);
$quoteBillingAddress = Mage::getModel('sales/quote_address');
$quoteBillingAddress->setData($billingAddress);
$quoteObj->setBillingAddress($quoteBillingAddress);
//if product is not virtual
if (!$quoteObj->getIsVirtual())
{
$shippingAddress = $billingAddress;
$quoteShippingAddress = Mage::getModel('sales/quote_address');
$quoteShippingAddress->setData($shippingAddress);
$quoteObj->setShippingAddress($quoteShippingAddress);
// fixed shipping method
$quoteObj->getShippingAddress()->setShippingMethod('ups_03');
$quoteObj->getShippingAddress()->setCollectShippingRates(true);
$quoteObj->getShippingAddress()->collectShippingRates();
$quoteObj->getShippingAddress()->setPaymentMethod('paypal_express');
}
$quoteObj->collectTotals();
$quoteObj->save();
$transaction = Mage::getModel('core/resource_transaction');
if ($quoteObj->getCustomerId())
{
$transaction->addObject($quoteObj->getCustomer());
}
$transaction->addObject($quoteObj);
$quoteObj->reserveOrderId();
$quotePaymentObj = $quoteObj->getPayment();
$quotePaymentObj->setMethod('paypal_express');
$quoteObj->setPayment($quotePaymentObj);
$convertQuoteObj = Mage::getSingleton('sales/convert_quote');
if ($quoteObj->getIsVirtual())
{
$orderObj = $convertQuoteObj->addressToOrder($quoteObj->getBillingAddress());
}
else
{
$orderObj = $convertQuoteObj->addressToOrder($quoteObj->getShippingAddress());
}
$orderPaymentObj = $convertQuoteObj->paymentToOrderPayment($quotePaymentObj);
$orderObj->setBillingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getBillingAddress()));
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
if (!$quoteObj->getIsVirtual())
{
$orderObj->setShippingAddress($convertQuoteObj->addressToOrderAddress($quoteObj->getShippingAddress()));
}
// set payment options
$orderObj->setPayment($convertQuoteObj->paymentToOrderPayment($quoteObj->getPayment()));
$items=$quoteObj->getAllItems();
foreach ($items as $item)
{
//#var $item Mage_Sales_Model_Quote_Item
$orderItem = $convertQuoteObj->itemToOrderItem($item);
if ($item->getParentItem()) {
$orderItem->setParentItem($orderObj->getItemByQuoteItemId($item->getParentItem()->getId()));
}
$orderObj->addItem($orderItem);
}
$orderObj->setCanShipPartiallyItem(false);
$totalDue = $orderObj->getTotalDue();
$transaction->addObject($orderObj);
$transaction->addCommitCallback(array($orderObj, 'place'));
$transaction->addCommitCallback(array($orderObj, 'save'));
try
{
$transaction->save();
} catch (Exception $e){
echo $e->getMessage();
//Mage::throwException('Order Cancelled Bad Response from Credit Authorization.');
}
$orderObj->sendNewOrderEmail();
Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order'=>$orderObj, 'quote'=>$quoteObj));
$quoteObj->setIsActive(0);
$quoteObj->save();
}

Related

I am trying to get contact form 7 data to zoho crm ,it is working fine on local host but on live it is giving following error

It is working fine in localhost but when i updating it on live site it giving following error-
{"data":[{"code":"INVALID_DATA","details":{"maximum_length":20,"api_name":"Subscribed_Newsletter"},"message":"invalid data","status":"error"}]}
You can find the reference code below-
add_action('wpcf7_mail_sent','brainium_cf7_api_sender');
function brainium_cf7_api_sender($contact_form){
$title = $contact_form->title;
if( $title === 'Test') {
$submission = WPCF7_Submission::get_instance();
if( $submission ){
$posted_data = $submission->get_posted_data();
$first_name = $posted_data['first-name'];
$last_name = $posted_data['last-name'];
$email = $posted_data['your-email'];
$phone = $posted_data['Phone-no'];
$message = $posted_data['your-message'];
$budget = $posted_data['budget'];
$checkbox = $posted_data['checkbox-37'][0];
$auth = 'xxxxxxxxxxxx';
$refreshToken = "xxxxxxxxxxxx";
//get the last date and time of refresh token generation
//get the access token
$url = "https://accounts.zoho.com/oauth/v2/token";
$query = "refresh_token=xxxxxxxxxxxx&client_id=xxxxxxxxxxxx&client_secret=xxxxxxxxxxxx&grant_type=refresh_token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
$result = curl_exec($ch);
curl_close($ch);
//get the token from the JSON in result
$accessToken = json_decode($result, true);
//echo ($accessToken['access_token']);
//die();
$data = array("First_Name"=>$first_name, "Last_Name"=>$last_name, "Email"=>$email, "Phone"=>$phone, "Description"=>($message), "Budget" => $budget, 'Subscribed_Newsletter' => $checkbox, "Lead_Date"=>$zoho_date, '$gclid'=>$zc_gad);
//$data = json_encode($data);
$encodedData = array();
$encodedData['data'][0] = $data;
//var_dump($data);
//echo(json_encode($encodedData));
//die();
//che
$url ="https://www.zohoapis.com/crm/v2/Leads";
$headers = array(
'Authorization: Zoho-oauthtoken '.$accessToken['access_token'],
'Content-Type:application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($encodedData));
$result = curl_exec($ch);
curl_close($ch);
//echo $result;
// End zoho CRM
$success = true;
$msg = 'Done';
$leadSaving = print_r($result, true);
$leadSaving = $leadSaving . "\r\n" . $email;
$leadSaving = $leadSaving . "\r\n" . "request quote";
file_put_contents("lead-zoho-entry-status.txt", $leadSaving, FILE_APPEND);
file_put_contents("lead-zoho-entry-status.txt", "\r\n\r\n", FILE_APPEND);
}
}
}

scraping data from truecaller

I have 200K phone number and i want to get there city using truecaller , how to do that ?
as you know truecaller has a restriction per requests ,,
somebody do this here :
https://www.phphive.info/324/truecaller-api/
this is mycode :
$cookieFile = dirname(__file__) . DIRECTORY_SEPARATOR . 'cookies';
$no = $users[0];
$url = "https://www.truecaller.com/api/search?type=4&countryCode=sd&q=" . $no;
$ch = curl_init();
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Bearer i03~CNORR-VIOJ2k~Hua_GBt73sKJJmO';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieFile);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
$data = json_decode($data, true);
$name = $data['data'][0]['name'];
$altname = $data['data'][0]['altName'];
$gender = $data['data'][0]['gender'];
$about = $data['data'][0]['about'];
try my npm package truecallerjs
https://www.npmjs.com/package/truecallerjs
const truecallerjs = require('truecallerjs');
var countryCode = "IN"; // Default country code to use.
var installationId = "YOUR INSTALLATION ID";
var phoneNumbers = "+919912345678,+14051234567,+919987654321....." // Phone numbers seperated by comma's
const searchResult = truecallerjs.bulkSearch(phoneNumbers,countryCode,installationId)
searchResult.then(function (response) {
for (let i = 0; i < response.data.length; i++) {
if("undefined" === typeof response.data[i].value.addresses[0].city ) {
console.log(`${response.data[i].key} => Unkown city`);
} else {
console.log(`${response.data[i].key} => `,response.data[i].value.addresses[0].city);
}
}
})
// OUTPUT
// +919912345678 => Andhra Pradesh
// +14051234567 => Unkown city
// +919987654321 => Mumbai
// ...
// ...

Woocommerce CRM connect

I'm trying to connect my Woocommerce to a CRM. They gave me this example code.
My question:
In what file do i need to add this code in Woocommerce.
class SimplicateApi {
public $authentication_key;
public $authentication_secret;
public $api_url;
public function __construct($domain, $key, $secret){
$this->authentication_key = $key;
$this->authentication_secret = $secret;
$this->api_url = 'https://'.$domain.'/api/v2';
}
public function makeApiCall($method, $url, $payload = NULL) {
// Generate the list of headers to always send.
$headers = array(
"User-Agent: simplicate-koppeling",// Sending a User-Agent header is a best practice.
"Authentication-Key: ".$this->authentication_key,
"Authentication-Secret: ".$this->authentication_secret,
"Accept: application/json", // Always accept JSON response.
);
$endpoint = $this->api_url . $url;
$curl = curl_init($endpoint);
switch(strtoupper($method)) {
case "GET":
// Nothing to do, GET is the default and needs no
// extra headers.
break;
case "POST":
// Add a Content-Type header (IMPORTANT!)
$headers[] = "Content-Type: application/json";
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
break;
case "PATCH":
// Add a Content-Type header (IMPORTANT!)
$headers[] = "Content-Type: application/json";
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
break;
case "DELETE":
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
default:
exit;
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if (self::isFailure($httpCode)) {
return array('errorNumber' => $httpCode,
'error' => 'Request returned HTTP error '.$httpCode,
'request_url' => $url);
}
$curl_errno = curl_errno($curl);
$curl_err = curl_error($curl);
if ($curl_errno) {
$msg = $curl_errno.": ".$curl_err;
curl_close($curl);
return array('errorNumber' => $curl_errno,
'error' => $msg);
}
else {
error_log("Response: ".$response);
curl_close($curl);
return json_decode($response, true);
}
}
public static function isFailure($httpStatus){
// Simplistic check for failure HTTP status
return ($httpStatus >= 400);
}
}
$SimplicateApi = new SimplicateApi('yourdomain.simplicate.nl','yourapikey','yourapisecret');
// pepare the payload to create an organization
$org_payload = array(
'name' => $variable_with_organization_name,
'phone' => $variable_with_organization_phone,
'email' => $variable_with_organization_email,
'note' => $variable_with_note,
'relation_type' => array(
'id'=>'' //provide the relationtypeid, f.e. relationtype:796ce0d318a2f5db515efc18bba82b90
),
'visiting_address' => array(
'country_code' => 'NL'
), // can be extented with other address data
'postal_address' => array(
'country_code' => 'NL'
) // can be extented with other address data
);
// add the organization to the CRM
$organization = $SimplicateApi->makeApiCall('POST','/crm/organization',json_encode($org_payload));
And nother question.
How about this part:
// pepare the payload to create an organization
$org_payload = array(
'name' => $variable_with_organization_name,
'phone' => $variable_with_organization_phone,
'email' => $variable_with_organization_email,
'note' => $variable_with_note,
Where do i get these variables from woocommerce?
you need Add custom api route
first technique :
inside woocommerce-ac.php add :
add_action('woocommerce_api_loaded', 'wpc_register_wp_api_endpoints');
function wpc_register_wp_api_endpoints() {
include_once( 'woo-includes/api/v2/class-wc-api-carts.php' );
add_filter('woocommerce_api_classes', 'filter_woocommerce_api_classes', 10, 1);
}
function filter_woocommerce_api_classes($array) {
$cart = array(
'WC_API_Carts',
);
return array_merge($array, $cart);
}
and inside woo-includes/api/v2 add class-wc-api-customs.php; that is done
full details

Payment using Paypal doesn't work after returning from Paypal site

My method of payment with Paypal does not work. After the user arrived on the Paypal page with the description of what he bought, it is directed to my site that says the payment was successful on
http://example.com/Store/ReturnPaypal/?token=EC-8F726826L7777777&PayerID=PEWR9EA
but when I go to my PayPal account, I don't see any extra money
public ActionResult OrderPaypal()
{
string api_paypal = "https://api-3t.paypal.com/nvp?";
string user = "info_api1.example.com";
string pass = "testpass";
string signature = "test.test-test";
string version = "124.0";
string requete = api_paypal + "VERSION=" + version + "&USER=" + user + "&PWD=" + pass + "&SIGNATURE=" + signature;
requete = requete + "&METHOD=SetExpressCheckout" +
"&CANCELURL=" + HttpUtility.UrlEncode("http://example.com/Store/CancelPaypal/") +
"&RETURNURL=" + HttpUtility.UrlEncode("http://example.com/Store/ReturnPaypal/") +
"&AMT=" + SessionData.CurrentOrder.Total.ToString().Replace(',','.') +
"&CURRENCYCODE=EUR" +
"&DESC=" + HttpUtility.UrlEncode("Paiement total:" + SessionData.CurrentOrder.Total+" €") +
"&LOCALECODE=FR" +
"&HDRIMG=" + HttpUtility.UrlEncode("http://example.com/assets/images/home/image_10000.png");
var httpWebRequest = (HttpWebRequest)WebRequest.Create(requete);
WebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
string rep = streamReader.ReadToEnd();
if (!string.IsNullOrEmpty(rep))
{
string[] list = rep.Split('&');
Dictionary<string,string> dicParam = new Dictionary<string,string>();
foreach(string str in list)
{
string key = str.Split('=')[0];
string value = str.Split('=')[1];
dicParam.Add(key, value);
}
if (dicParam["ACK"] == "Success")
return Redirect("https://www.paypal.com/webscr&cmd=_express-checkout&token=" + dicParam["TOKEN"]);
else
{
ViewBag.State = "-1";
return View("ReturnSolution",dicParam["L_SHORTMESSAGE0"]);
}
}
else
{
ViewBag.State = "-1";
return View("ReturnSolution", "Error communication PayPal ");
}
}
}
I do not see you completing the transaction with the DoExpressCheckout call.
It looks like you are doing the SetExpressCheckout which will give you the Payer ID and the Express Checkout token. You get this in the URL:
http://example.com/Store/ReturnPaypal/?token=EC-8F726826L7777777&PayerID=PEWR9EA
token=EC-8F726826L7777777
PayerID=PEWR9EA
This is returned in the URL and is used to complete the DoExpressCheckout call (which I do not see in your code).
Here is a sample script of a SetExpressCheckout and DoExpressCheckout in PHP.
<a href='http://marshalcurrier.com/paypal/ExpressCheckout/custom/SetDo.php'>RESET</a><br>
<form method='post'><input type="text" name="CHARGE" value="1"/><input type="submit" value="Pay Now"/><form>
<?php
session_start();
$PPUSER = 'marshal_api1.clubcovert.com';
$PPPWD = 'LL6NV7TDRB9RFXQ5';
$PPSIG = 'ANc3YRaMB1Tgm9TediH0gENHB02JAksSKWD08wVNN3w3pwHqdBW8Im6y';
function url(){ //PayPal Payment URL (TEST or LIVE)
$url = "https://api-3t.sandbox.paypal.com/nvp";
return $url;
}
function curlCall($nvp){ // Function for Curl Call to PayPal.
$url = url();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($nvp) );
//echo http_build_query($nvp); //Print String
curl_setopt($ch, CURLOPT_URL, $url);
$server_output = curl_exec($ch);
mb_parse_str($server_output, $arr);
return $arr;
}
if(isset($_POST['CHARGE'])){ // SetExpressCheckout Call
$_SESSION['AMT'] = $_POST['CHARGE'];
$nvp = array(
'USER' => $PPUSER,
'PWD' => $PPPWD,
'SIGNATURE' => $PPSIG,
'METHOD' => 'SetExpressCheckout',
'VERSION' => '123',
'PAYMENTREQUEST_0_PAYMENTACTION' => 'SALE',
'PAYMENTREQUEST_0_AMT' => $_POST['CHARGE'],
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
'RETURNURL' => 'http://marshalcurrier.com/paypal/ExpressCheckout/SetDo.php',
'CANCELURL' => 'http://marshalcurrier.com/paypal/ExpressCheckout/SetDo.php',
);
$arr = curlCall($nvp);
echo '<br><br>SetExpressCheckout Call to PayPal:<br><pre>';
print_r ($nvp);
echo '</pre>';
echo 'SetExpressCheckout Server Response:<br><pre>';
print_r ($arr);
echo '</pre>';
echo 'Go To PayPal';
}
if(isset($_GET['PayerID']) && (isset($_POST['CHARGE'])) == false){ // DoExpressCheckoutPayment Call
if (isset($_SESSION['AMT'])){
$AMT = $_SESSION['AMT'];
}else{
$AMT = null;
}
$nvp = array(
'METHOD' => 'DoExpressCheckoutPayment',
'VERSION' => '123',
'USER' => $PPUSER,
'PWD' => $PPPWD,
'SIGNATURE' => $PPSIG,
'PAYERID' => $_GET['PayerID'],
'TOKEN' => $_GET['token'],
'PAYMENTREQUEST_0_PAYMENTACTION' => 'SALE',
'PAYMENTREQUEST_0_AMT' => $AMT,
'PAYMENTREQUEST_0_CURRENCYCODE' => 'USD',
);
$arr = curlCall($nvp);
echo '<br><br>DoExpressCheckoutPayment Call to PayPal:<br><pre>';
print_r ($nvp);
echo '</pre>';
echo 'DoExpressCheckoutPayment Server Response:<br><pre>';
print_r ($arr);
echo '</pre>';
unset($_SESSION['AMT']);
}
?>

Wordpress XML-RPC and featured images

I'm currently developing a plugin for a client that takes an xml feed hourly and posts it into wordpress and I'm having trouble sending the featured image to the post.
I can post to wordpress fine but all my attempts to post the featured image have failed.
<?php
class XMLRPClientWordPress
{
var $XMLRPCURL = "";
var $UserName = "";
var $PassWord = "";
// Constructor
public function __construct($xmlrpcurl, $username, $password)
{
$this->XMLRPCURL = $xmlrpcurl;
$this->UserName = $username;
$this->PassWord = $password;
}
function send_request($requestname, $params)
{
$request = xmlrpc_encode_request($requestname, $params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_URL, $this->XMLRPCURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 1);
$results = curl_exec($ch);
curl_close($ch);
return $results;
}
public function create_post( $title, $body )
{
$title = htmlentities( $title, ENT_NOQUOTES, 'UTF-8' );
$content = array(
'post_category' => array( 18 ), // my category id
'post_type' => 'post',
'post_title' => $title,
'post_content' => $body,
'featured_image_url' => 'http://www.geekologie.com/2009/02/18/scary%20clown.jpg',
);
$params = array( 0, $this->UserName, $this->PassWord, $content );
return $this->send_request( 'wp.newPost', $params );
}
}
$objXMLRPClientWordPress = new XMLRPClientWordPress("xxxx/xmlrpc.php" , "xxxxx" , "xxxx");
$objXMLRPClientWordPress->create_post('Hey Chloe','Hope you like the clown');
?>
Is what i currently have, i've been reading the wordpress patch tickets on this issue but can't seem to figure out how to actually use the new features
Thanks
It should be something like this
'wp_post_thumbnail' => $pictureid
You have to get the ID of uploaded picture into variable and then assign it as a value of 'wp_post_thumbnail' parameter for 'metaWeblog.newPost'

Resources