i'm tracking AdWords Conversion through a WPCF7. Since on_sent_ok doesen't work anymore, I found a workaround:
// Contact Conversion-Tracker
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'example.com./thank-you/';
}, false );
</script>
<?php
}
Now there is a function in my functions.php where I send requests via the wpcf7 to salesforce:
// Lead 2 Salesforce
add_action( 'wpcf7_before_send_mail', 'editData' );
function editData( $cf7 ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
$first_name = $posted_data["Vorname"];
$last_name = $posted_data["Nachname"];
$Tel = $posted_data["Tel"];
$mobile = $posted_data["mobile"];
$email = $posted_data["email"];
$message = $posted_data["message"];
$post_items[] = 'oid=00000000000';
$post_items[] = 'first_name=' . $first_name;
$post_items[] = 'last_name=' . $last_name;
$post_items[] = 'email=' . $email;
$post_items[] = 'phone=' . $Tel;
$post_items[] = 'mobile=' . $mobile;
$post_items[] = 'description=' . $message;
$post_items[] = 'lead_source=Contact form';
$post_items[] = 'company=not there';
$post_items[] = 'Anliegen__c=​Contact';
$post_items[] = 'Work together';
$post_string = implode ('&', $post_items);
// Create a new cURL resource
$ch = curl_init();
if (curl_error($ch) != "")
{
// error handling
}
$con_url = 'salesforce.com/servlet/servlet.WebToLead?
encoding=UTF-8';
curl_setopt($ch, CURLOPT_URL, $con_url);
// Set the method to POST
curl_setopt($ch, CURLOPT_POST, 1);
// Pass POST data
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_string);
curl_exec($ch); // Post to Salesforce
curl_close($ch); // close cURL resource
}}
// End Lead 2 Salesforce
Now these two functins seem to not work together properly. Since I added the first function where the redirect happens, no new leads will be added to my Salesforce.
Thank you in advance.
Related
I'm new to wordpress and would like to generate leads on odoo crm. I would like to send the form data in contact us form to odoo via a post request. I'm currently using wpforms plugin.
<?php
add_action( 'wpcf7_mail_sent', 'action__wpcf7_mail_sent' );
function action__wpcf7_mail_sent( $contact_form ) {
$title = $contact_form->title();
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
}
function post_to_url( $url, $data ) {
$fields = '';
foreach( $data as $key => $value ) {
$fields .= $key . '=' . $value . '&';
}
rtrim( $fields, '&' );
$timeout = 30;
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_HEADER, 0);
curl_setopt ($post, CURLOPT_TIMEOUT, $timeout);
curl_setopt ($post, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5)));
curl_setopt ($post, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($post, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($post, CURLOPT_POST, true);
curl_setopt($post, CURLOPT_POSTFIELDS, ($fields));
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($post, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($post);
curl_close($post);
}
if ( 'your contact form title' == $title ) {
//you will get data in $posted_data variable
//echo "<pre>"; print_r($posted_data);
$data = $posted_data;
$final_url = "your_api_url";
post_to_url( $final_url, $data );
}
}
try using this hook wpcf7_mail_sent
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 );
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();
}
I try to add an event to the calendar. I've created a proper application in google console, got ID's, Secret's and so. I even get the ID of created event, but this event is not visible in Calendar dashboard.
session_start();
require_once dirname(__FILE__).'google-api-php-client/src/Google_Client.php';
require_once dirname(__FILE__).'google-api-php-client/src/contrib/Google_CalendarService.php';
ini_set('display_errors', 1);
define('CLIENT_ID','XXX');
define('SERVICE_ACCOUNT_NAME','XXX');
define('KEY_FILE',dirname(__FILE__).'API Project-XXX.p12');
$client = new Google_Client();
$client->setApplicationName("Kalendarz");
$client->setUseObjects(true); //IF USING SERVICE ACCOUNT (YES)
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(SERVICE_ACCOUNT_NAME,array('https://www.googleapis.com/auth/calendar'),$key));
$client->setClientId(CLIENT_ID);
$cal = new Google_CalendarService($client);
$calList = $cal->calendarList->listCalendarList();
print "<h1>Calendar List</h1><pre>" . print_r($calList, true) . "</pre>";
if (isset($_GET['logout']))
{
unset($_SESSION['token']);
}
if (isset($_GET['code']))
{
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] .
$_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token']))
{
$client->setAccessToken($_SESSION['token']);
}
// Creates a test event
$event = new Google_Event();
$event->setSummary('Appointment2');
$event->setLocation('Somewhere2');
$start = new Google_EventDateTime();
$start->setDateTime('2014-10-11T10:00:00.000-01:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime('2014-10-11T10:25:00.000-01:00');
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
//$attendee1->setEmail('XXX');
//$attendees = array($attendee1);
//$event->attendees = $attendee1;
//echo "<pre>";
//var_dump($cal);
$createdEvent = $cal->events->insert('primary', $event);
echo $createdEvent->getId();
/*
$event = new Google_Event();
$event = $service->events->get("XXX", $evID);
echo $event->getSummary();
*/
And the result is:
Google_CalendarList Object
(
[etag] => "1412846388446000"
[__itemsType:protected] => Google_CalendarListEntry
[__itemsDataType:protected] => array
[items] => Array
(
)
[kind] => calendar#calendarList
[nextPageToken] =>
[nextSyncToken] => 00001412846388446000
)
arkd3j1j8ilgi71p6pdp242gp0
I think your event was successfully created and its event id is arkd3j1j8ilgi71p6pdp242gp0 ;)
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'