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'
Related
I´ve been searching a lot to find a solution but my problem as to do with some understanding of the mechanism, so i was wondering if someone could help me:
At this moment i´m sending push notifications using the REST api from OneSignal and it´s working...but i don´t know how to reach the data sent in order to tell the app to go to a specific place:
My server side:
public function sendMessage(){
$content = array(
"en" => 'Nova Angariação'
);
$hashes_array = array();
array_push($hashes_array, array(
"id" => "like-button",
"text" => "Ver",
"icon" => "http://i.imgur.com/N8SN8ZS.png",
"url" => "https://yoursite.com"
));
$fields = array(
'app_id' => "myAppId",
'included_segments' => array(
'All'
),
'data' => array(
"foo" => "bar"
),
'contents' => $content,
'buttons' => $hashes_array
);
$fields = json_encode($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 my rest key'
));
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);
$resp = curl_exec($ch);
curl_close($ch);
return $resp;
}
Now in my app(i´m using nativescript with OneSignal SDK):
if (application.ios) {
const MyDelegate = /** #class */ (function (_super) {
__extends(MyDelegate, _super);
function MyDelegate() {
return _super !== null && _super.apply(this, arguments) || this;
}
MyDelegate.prototype.applicationDidFinishLaunchingWithOptions = function (app, launchOptions) {
try {
**//i think it´s here where i have to handle the handleNotificationOpened but i don´t know how**
TnsOneSignal.initWithLaunchOptionsAppId(launchOptions, 'my onesignal app key');
}
catch (error) {
console.error('error', error);
}
return true;
};
MyDelegate.ObjCProtocols = [UIApplicationDelegate];
return MyDelegate;
}(UIResponder));
application.ios.delegate = MyDelegate;
}
How do i do this?
Thanks for your time
Regards.
If you want to access the notification data upon app launch, then try this inside applicationDidFinishLaunchingWithOptions
if (launchOptions) {
const userInfo = launchOptions.objectForKey(UIApplicationLaunchOptionsRemoteNotificationKey);
if (userInfo) {
const aps = userInfo.objectForKey("aps");
if (aps !== null) {
// aps will be again a dictionary will have all data for the notification
}
}
}
Between didReceiveRemoteNotification also works, but when application is already in foreground.
This is all I have for now. I am using jQuery.
Also I get this error: PARTNER_AUTHENTICATION_FAILED
jQuery(document).ready(function($){
// console.log('DocuSign Script Loaded!');
var accountId = '404569';
// on button click
$('#upload_submit').click(function(){
// form inputs
// document, emailSubject, status, recipients
var name = $('#upload_name').val();
var email = $('#upload_email').val();
$.post("https://na2.docusign.net/restapi/v2/accounts/" + accountId + "/envelopes", {
},
function (data) {
console.log(data);
});
});
});
Your example code is not providing authentication credentials.
<?php
// Set Authentication information
$email = '';
$password = '';
$integratorKey = '';
function get_url( $email, $password, $integratorKey ) {
// api service point
$url = "https://demo.docusign.net/restapi/v2/login_information";
// construct the authentication header:
$header = "<DocuSignCredentials><Username>" . $email . "</Username><Password>" . $password . "</Password><IntegratorKey>" . $integratorKey . "</IntegratorKey></DocuSignCredentials>";
// STEP 1 - Login (to retrieve baseUrl and accountId)
$curl = curl_init( $url );
curl_setopt( $curl, CURLOPT_HEADER, false );
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_HTTPHEADER, array( "X-DocuSign-Authentication: $header" ) );
$json_response = curl_exec( $curl );
$status = curl_getinfo( $curl, CURLINFO_HTTP_CODE );
if ( $status != 200 ) {
return (['ok' => false, 'errMsg' => "Error calling DocuSign, status is: " . $status]);
}
$response = json_decode( $json_response, true );
// Account ID and Base URL for envelopes API
$accountId = $response["loginAccounts"][0]["accountId"];
$baseUrl = $response["loginAccounts"][0]["baseUrl"];
curl_close( $curl );
return $baseUrl;
}
// Base URL Envelope
$baseUrl = get_url( $email, $password, $integratorKey );
Im trying to post some data to custom api endpoint that i created,
This is what my wordpress custom endpoint code.
register_rest_route( 'api/v1', '/cities', array(
'methods' => 'POST',
'callback' => 'create_city_from_data'
));
And for testing I am trying to return the request like this
function create_city_from_data($req) {
return ['req' => $req];
}
but always i receive empty object as response, whatever i send in payload i didn't receive anything.
My payload is something like this
{ name: 'Hello', population: 565656 }
This is what is received from the request
{"req":{}}
By using below code you can view your payload.
add_action('rest_api_init', function () {
register_rest_route( 'api/v1', '/cities', array(
'methods' => 'POST',
'callback' => 'create_city_from_data'
));
});
function create_city_from_data($req) {
$response['name'] = $req['name'];
$response['population'] = $req['population'];
$res = new WP_REST_Response($response);
$res->set_status(200);
return ['req' => $res];
}
I have used postman to view the POST parameter
By using this function you can see all post of your custom post type in API...
Get All Post in your API Viewer.
Writer URL on your API viewer (e.g. I used Postman json api view, google chrome adon)
Domain-name/wp-json/showFavorites/v2?post_type=hotel
Here 'hotel' is the custom posttype.
Add this function in your functions.php
add_action( 'rest_api_init', 'wp_api_show_favorites_endpoints' );
function wp_api_show_favorites_endpoints() {
register_rest_route( 'showFavorites', '/v2', array(
'methods' => 'GET',
'callback' => 'showFavorites_callback',
));
}
function showFavorites_callback( $request_data ) {
global $wpdb;
$data = array();
$table = 'wp_posts';
$parameters = $request_data->get_params();
$post_type = $parameters['post_type'];
if($post_type!=''){
$re_query = "SELECT * FROM $table where post_type='$post_type'";
$pre_results = $wpdb->get_results($re_query,ARRAY_A);
return $pre_results;
}else{
$data['status']=' false ';
return $data;
}
}
And using this you can post your content from API
// POST All Posts using API
add_action( 'rest_api_init', 'wp_api_add_posts_endpoints' );
function wp_api_add_posts_endpoints() {
register_rest_route( 'addPost', '/v2', array(
'methods' => 'POST',
'callback' => 'addPosts_callback',
));
}
function addPosts_callback( $request_data ) {
global $wpdb;
$data = array();
$table = 'wp_posts';
// Fetching values from API
$parameters = $request_data->get_params();
$user_id = $parameters['user_id'];
$post_type = $parameters['post_type'];
$post_title = $parameters['post_title'];
$the_content = $parameters['the_content'];
$cats = $parameters['cats'];
$the_excerpt = $parameters['the_excerpt'];
$feature_img = $parameters['featured_image'];
// custom meta values
$contact_no = $parameters['contact_no'];
$email = $parameters['email'];
$hotel_url = $parameters['hotel_url'];
if($post_type!='' && $post_title!=''){
// Create post object
$my_post = array(
'post_title' => wp_strip_all_tags( $post_title),
'post_content' => $the_content,
'post_author' => '',
'post_excerpt' => $the_excerpt,
'post_status' => 'publish',
'post_type' => $post_type,
);
$new_post_id = wp_insert_post( $my_post );
function wp_api_encode_acf($data,$post,$context){
$customMeta = (array) get_fields($post['ID']);
$data['meta'] = array_merge($data['meta'], $customMeta );
return $data;
}
if( function_exists('get_fields') ){
add_filter('json_prepare_post', 'wp_api_encode_acf', 10, 3);
}
// Set post categories
$catss = explode(',', $cats);
if (!empty($catss)) {
if ($post_type == 'post') {
wp_set_object_terms( $new_post_id, $catss, 'category', false );
}
else{
wp_set_object_terms( $new_post_id, $catss, 'Categories', false ); // Executes if posttype is other
}
}
// Set Custom Metabox
if ($post_type != 'post') {
update_post_meta($new_post_id, 'contact-no', $contact_no);
update_post_meta($new_post_id, 'email', $email);
update_post_meta($new_post_id, 'hotel-url', $hotel_url);
}
// Set featured Image
$url = $feature_img;
$path = parse_url($url, PHP_URL_PATH);
$filename = basename($path);
$uploaddir = wp_upload_dir();
$uploadfile = $uploaddir['path'] . '/' . $filename;
$contents= file_get_contents($feature_img);
$savefile = fopen($uploadfile, 'w');
chmod($uploadfile, 0777);
fwrite($savefile, $contents);
fclose($savefile);
$wp_filetype = wp_check_filetype(basename($filename), null );
$attachment = array(
'post_mime_type' => $wp_filetype['type'],
'post_title' => $filename,
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $uploadfile );
if ($attach_id) {
set_post_thumbnail( $new_post_id, $attach_id );
}
if ($new_post_id) {
$data['status']='Post added Successfully.';
}
else{
$data['status']='post failed..';
}
}else{
$data['status']=' Please provide correct post details.';
}
return ($data);
}
The object parameter passed into the callback function is a WP_REST_REQUST object and has a get_body() method on it which returns the payload/post body of the HTTP Post Request.
function create_city_from_data(WP_REST_Request $req) {
$body = $req->get_body()
return ['req' => $body];
}
I learnt about this today whilst reading this article
You can also declare the type of object in the method signature in case you need to search the documentation for it (like i have above).
CURL request :
$url = $your_url; // your url should like: http://host.com/wp-json/v1/'.$key
$post_string = json_encode($post_data);// make json string of post data
$ch = curl_init(); //curl initialisation
curl_setopt($ch, CURLOPT_URL, $url); // add url
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // get return value
curl_setopt($ch, CURLOPT_POST, true); // false for GET request
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); // add post data
curl_setopt($crl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($post_string))
);// add header
$output = curl_exec($ch);
curl_close($ch); // close curl
$error = curl_error($ch); // get error
if(!$error){
return json_decode($output);
}else{
return $error;
}
For Handle Request in PLUGIN context :
public static function handle_requests(WP_REST_Request $request){
$return_data = [];
//get GET params
$key = $request['key'];
//get POST values
$post_data = json_decode($request->get_body());
//$return_data = $post_data;
if ( empty( $return_data ) ) {
return new WP_Error( 'error', 'Invalid Request', array( 'status' => 404 ) );
}else{
return $return_data;
}
}
Your WP REST API ACTION :
add_action( 'rest_api_init', function () {
register_rest_route( '/v1', '/(?P<key>[\w]+)', array(
'methods' => ['GET', 'POST'],
'callback' => 'YOUR_CLASS::handle_requests',
'permission_callback' => '__return_true'
) );
} );
//permission_callback need to add for wordpress newer versions.
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
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();
}