Woocommerce Checkout function - wordpress

I want to execute below script while doing checkout in woocommerce.
$args = http_build_query(array(
'token' => '*********',
'from' => '****',
'to' => '*******',
'text' => 'Your Order Id is: 9879987 '));
$url = "http://api.sparrowsms.com/v2/sms/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
I didn't find checkout process page.

You need to add a woocommerce_after_checkout_form hook in function.php like below.
add_action( 'woocommerce_after_checkout_form', 'sms_function', 10 );
function sms_function( ) {
$args = http_build_query(array(
'token' => '*********',
'from' => '****',
'to' => '*******',
'text' => 'Your Order Id is: 9879987 '));
$url = "http://api.sparrowsms.com/v2/sms/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
}

Related

I want to add contact form 7 data to zoho crm with custom code in wordpress. I tried but not find any solution

I already added the code on my function.php file by applying zoho crm api but the data is not transferring on ZOHO crm.
I called the data through the access token provided by Zoho crm, then i create API v2 of web API and generate client id and client secret. I don't know where i am making error
Please check and update me where i am making mistake
add_action('wpcf7_mail_sent','brainium_cf7_api_sender');
function brainium_cf7_api_sender(){
$title = $contact_form->title;
if( $title === 'Contact form 1') {
$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-993'];
$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); }
}
}
I tried and getting the following SUCCESS response
{"data":[{"code":"SUCCESS","details":{"Modified_Time":"2022-07-27T17:28:36+05:30","Modified_By":{"name":"Sourav Sinha","id":"1153488000000068001"},"Created_Time":"2022-07-27T17:28:36+05:30","id":"1153488000046560019","Created_By":{"name":"Sourav Sinha","id":"1153488000000068001"}},"message":"record added","status":"success"}]}
youremail#test.com
request quote
This is the code used in functions.php file
add_action('wpcf7_mail_sent','brainium_cf7_api_sender');
function brainium_cf7_api_sender($contact_form){
$title = $contact_form->title;
if( $title === 'Contact form 1') {
$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-194'][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);
}
}
}
<?php
$first_name = 'first-name';
$last_name = 'last-name';
$email = 'youremail#test.com';
$phone = '9876543210';
$message = 'your-message';
$budget = '1000';
$checkbox = '1';
$auth = 'fa738eaef1becee890f8935f65169e99';
$refreshToken = "1000.3c0d5bb96a00e9438d132d94a316a72b.2d5261b7e33c42614c08f1bd4e9a0f1a";
//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);

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);
}
}
}

How to add custom payment getaway in woocommerce using Third Party Rest API

Could you please tell me how we can add a custom payment gateway in WordPress using this PHP file or rest API.
<?php
function ProcessRequest($curl_post_data,$service_url,$proxy,$proxyauth) { $output = ''; $certfile = '/11122333.crt'; $keyfile = '/11122333.key'; $cert_password = ''; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $service_url ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt( $ch, CURLOPT_SSLCERT, getcwd() . $certfile ); curl_setopt( $ch, CURLOPT_SSLKEY, getcwd() . $keyfile ); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_POSTFIELDS, $curl_post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $output = curl_exec($ch); $cblcz = json_decode($output, true ); return $cblcz; }
$proxy =""; $proxyauth =""; $postDatatoken = '{ "password": "***", "userName": "***" }'; $serviceUrltoken =""; $serviceUrltoken= 'https://sandbox.arbdbank.com:7788/transaction/token'; $cblcz = ProcessRequest($postDatatoken,$serviceUrltoken,$proxy,$proxyauth);
$transactionId = $cblcz['transactionId'];
$serviceUrlEcomm = 'https://sandbox.arbdbankbank.com:7788/transaction/createorder';
$curl = curl_init();
$postdataEcomm = '{ "merchantId": "11122333", "amount": "100", "currency": "050", "description": "This is test", "approveUrl": "http://localhost/ARBankPHP_1.0.1/approve.php",
"cancelUrl": "http://localhost/ARBankPHP_1.0.1/cencel.php", "declineUrl": "http://localhost/ARBankPHP_1.0.1/decline.php", "userName": "test", "passWord": "123456Aa", "secureToken": "'.$transactionId.'" }';
$cblEcomm = ProcessRequest($postdataEcomm,$serviceUrlEcomm,$proxy,$proxyauth);
$URL = $cblEcomm['items']['url']; $orderId = $cblEcomm['items']['orderId']; $sessionId = $cblEcomm['items']['sessionId']; $redirectUrl = $URL."?ORDERID=".$orderId."&SESSIONID=".$sessionId;
?>
<form id="PostForm" name="PostForm" action="<?php echo $redirectUrl;?>" method="POST">
</form> <script language='javascript'>var vPostForm = document.PostForm;vPostForm.submit();</script>

How to remove product from collection using shopify api

https://wetion.myshopify.com/admin/collects/.jsonproduct_id=9706757444&collection_id=380751892';
I need to remove a product from the collection.is it possible?
$delete_exist_collect = array();
for($i=0 ; $i < $custom_collectionss ; $i++)
{
$delete_exist_collect = $product_data_collection['custom_collections'][$i]['id'];
$urli = $to_storeurl_shopify.'/admin/collects/.json?product_id='.$response->product->id.'&collection_id='.$delete_exist_collect;
echo $urli;
$newurl = str_replace(" ","",$urli);
$shopcurl = curl_init();
curl_setopt($shopcurl, CURLOPT_URL, $newurl);
curl_setopt($shopcurl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($shopcurl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($shopcurl, CURLOPT_USERPWD,$to_shopify_u_p);
curl_setopt($shopcurl, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($shopcurl, CURLOPT_SSL_VERIFYPEER, false);
$responsee = curl_exec ($shopcurl);
curl_close ($shopcurl);
$product_data_collection = json_decode($responsee,TRUE);
}

Wordpress : Call wp_create_user function from external?

In Wordpress, i want to create New Users from external. I've found this is function in wordpress:
wp_create_user( $username, $password, $email );
So how can i run this function from external call please?
I mean, how to run this function from either:
Via simple URL with GET, like: www.example.com/adduser/?username=james&password=simpletext&email=myemail
Via cURL with POST
.. from external website.
You may try this but also make sure that the listening url has a handler to handle the request in your WordPress end (using GET methof)
function curlAdduser($strUrl)
{
if( empty($strUrl) )
{
return 'Error: invalid Url given';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $strUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
Call the function from external site :
curlAdduser("www.example.com/adduser?username=james&password=simpletext&email=myemail");
Update : using POST method
function curlAdduser($strUrl, $data) {
$fields = '';
foreach($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
$fields = rtrim($fields, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $strUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$return = curl_exec($ch);
curl_close($ch);
return $return;
}
Call the function with data
$data = array(
"username" => "james",
"password" => "simpletext",
"email" => "myemail"
);
curlAdduser("www.example.com/adduser", $data);

Resources