app/Http/Controllers/ShopifyController.php
// Comman function to perform different shopify curl operations (GET/POST/DELETE)
Comman function to perform different shopify curl operations (GET/POST/DELETE)
Comman function to perform different shopify curl operations ( GET / POST / DELETE )
public function curlRequestShopify($org_id,$method,$target_url,$postData=''){
			$res = array();
			$accountdetails = $this->getSFCredentials($org_id);
			if( $accountdetails ){
				$domain = base64_decode($accountdetails->domain);
				$access_token = base64_decode($accountdetails->access_token);
				$url = 'https://'.$domain.'/admin/api/2021-01/'.$target_url;
				if($method=='POST'){
					$curl = curl_init();
					curl_setopt_array($curl, array(
					  CURLOPT_URL => $url,
					  CURLOPT_RETURNTRANSFER => true,
					  CURLOPT_ENCODING => '',
					  CURLOPT_MAXREDIRS => 10,
					  CURLOPT_TIMEOUT => 0,
					  CURLOPT_FOLLOWLOCATION => true,
					  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
					  CURLOPT_CUSTOMREQUEST => 'POST',
					  CURLOPT_POSTFIELDS =>$postData,
					  CURLOPT_HTTPHEADER => array(
						'Content-Type: application/json',
						'X-Shopify-Access-Token: '.$access_token
					  ),
					));
					$result = curl_exec($curl);
					if (curl_errno($curl)) {
						echo 'Error:' . curl_error($curl);
					}
					$info = curl_getinfo($curl);
					curl_close ($curl);
					$result_data = json_decode($result,true);
					$res['status_code'] = $info['http_code'];
					$res['result_data'] = $result_data;
				}else if($method=='DELETE'){
					$curl = curl_init();
					curl_setopt_array($curl, array(
					  CURLOPT_URL => $url,
					  CURLOPT_RETURNTRANSFER => true,
					  CURLOPT_ENCODING => '',
					  CURLOPT_MAXREDIRS => 10,
					  CURLOPT_TIMEOUT => 0,
					  CURLOPT_FOLLOWLOCATION => true,
					  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
					  CURLOPT_CUSTOMREQUEST => 'DELETE',
					  CURLOPT_HTTPHEADER => array(
						'Content-Type: application/json',
						'X-Shopify-Access-Token: '.$access_token
					  ),
					));
					$result = curl_exec($curl);
					if (curl_errno($curl)) {
						echo 'Error:' . curl_error($curl);
					}
					$info = curl_getinfo($curl);
					curl_close ($curl);
					$result_data = json_decode($result,true);
					$res['status_code'] = $info['http_code'];
					$res['result_data'] = $result_data;
				}else if($method=='GET'){
					$curl = curl_init();
					curl_setopt_array($curl, array(
					  CURLOPT_URL => $url,
					  CURLOPT_RETURNTRANSFER => true,
					  CURLOPT_ENCODING => '',
					  CURLOPT_MAXREDIRS => 10,
					  CURLOPT_TIMEOUT => 0,
					  CURLOPT_FOLLOWLOCATION => true,
					  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
					  CURLOPT_CUSTOMREQUEST => 'GET',
					  CURLOPT_HTTPHEADER => array(
						'Content-Type: application/json',
						'X-Shopify-Access-Token: '.$access_token
					  ),
					));
					$result = curl_exec($curl);
					if (curl_errno($curl)) {
						echo 'Error:' . curl_error($curl);
					}
					$info = curl_getinfo($curl);
					curl_close ($curl);
					$result_data = json_decode($result,true);
					$res['status_code'] = $info['http_code'];
					$res['result_data'] = $result_data;
				}else if($method=='PUT'){
					$curl = curl_init();
					curl_setopt_array($curl, array(
					  CURLOPT_URL => $url,
					  CURLOPT_RETURNTRANSFER => true,
					  CURLOPT_ENCODING => '',
					  CURLOPT_MAXREDIRS => 10,
					  CURLOPT_TIMEOUT => 0,
					  CURLOPT_FOLLOWLOCATION => true,
					  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
					  CURLOPT_CUSTOMREQUEST => 'PUT',
					  CURLOPT_POSTFIELDS =>$postData,
					  CURLOPT_HTTPHEADER => array(
						'Content-Type: application/json',
						'X-Shopify-Access-Token: '.$access_token
					  ),
					));
					$result = curl_exec($curl);
					if (curl_errno($curl)) {
						echo 'Error:' . curl_error($curl);
					}
					$info = curl_getinfo($curl);
					curl_close ($curl);
					$result_data = json_decode($result,true);
					$res['status_code'] = $info['http_code'];
					$res['result_data'] = $result_data;
				}
				return $res;
			}else{
				echo "send error mail";
			}
		}
public function curlRequestShopify ( $ org_id , $ method , $ target_url , $ postData = '' ) { $ res = array ( ) ; $ accountdetails = $ this -> getSFCredentials ( $ org_id ) ; if ( $ accountdetails ) { $ domain = base64_decode ( $ accountdetails -> domain ) ; $ access_token = base64_decode ( $ accountdetails -> access_token ) ; $ url = 'https://' . $ domain . '/admin/api/2021-01/' . $ target_url ; if ( $ method == 'POST' ) { $ curl = curl_init ( ) ; curl_setopt_array ( $ curl , array ( CURLOPT_URL => $ url , CURLOPT_RETURNTRANSFER => true , CURLOPT_ENCODING => '' , CURLOPT_MAXREDIRS => 10 , CURLOPT_TIMEOUT => 0 , CURLOPT_FOLLOWLOCATION => true , CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 , CURLOPT_CUSTOMREQUEST => 'POST' , CURLOPT_POSTFIELDS => $ postData , CURLOPT_HTTPHEADER => array ( 'Content-Type: application/json' , 'X-Shopify-Access-Token: ' . $ access_token ) , ) ) ; $ result = curl_exec ( $ curl ) ; if ( curl_errno ( $ curl ) ) { echo 'Error:' . curl_error ( $ curl ) ; } $ info = curl_getinfo ( $ curl ) ; curl_close ( $ curl ) ; $ result_data = json_decode ( $ result , true ) ; $ res [ 'status_code' ] = $ info [ 'http_code' ] ; $ res [ 'result_data' ] = $ result_data ; } else if ( $ method == 'DELETE' ) { $ curl = curl_init ( ) ; curl_setopt_array ( $ curl , array ( CURLOPT_URL => $ url , CURLOPT_RETURNTRANSFER => true , CURLOPT_ENCODING => '' , CURLOPT_MAXREDIRS => 10 , CURLOPT_TIMEOUT => 0 , CURLOPT_FOLLOWLOCATION => true , CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 , CURLOPT_CUSTOMREQUEST => 'DELETE' , CURLOPT_HTTPHEADER => array ( 'Content-Type: application/json' , 'X-Shopify-Access-Token: ' . $ access_token ) , ) ) ; $ result = curl_exec ( $ curl ) ; if ( curl_errno ( $ curl ) ) { echo 'Error:' . curl_error ( $ curl ) ; } $ info = curl_getinfo ( $ curl ) ; curl_close ( $ curl ) ; $ result_data = json_decode ( $ result , true ) ; $ res [ 'status_code' ] = $ info [ 'http_code' ] ; $ res [ 'result_data' ] = $ result_data ; } else if ( $ method == 'GET' ) { $ curl = curl_init ( ) ; curl_setopt_array ( $ curl , array ( CURLOPT_URL => $ url , CURLOPT_RETURNTRANSFER => true , CURLOPT_ENCODING => '' , CURLOPT_MAXREDIRS => 10 , CURLOPT_TIMEOUT => 0 , CURLOPT_FOLLOWLOCATION => true , CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 , CURLOPT_CUSTOMREQUEST => 'GET' , CURLOPT_HTTPHEADER => array ( 'Content-Type: application/json' , 'X-Shopify-Access-Token: ' . $ access_token ) , ) ) ; $ result = curl_exec ( $ curl ) ; if ( curl_errno ( $ curl ) ) { echo 'Error:' . curl_error ( $ curl ) ; } $ info = curl_getinfo ( $ curl ) ; curl_close ( $ curl ) ; $ result_data = json_decode ( $ result , true ) ; $ res [ 'status_code' ] = $ info [ 'http_code' ] ; $ res [ 'result_data' ] = $ result_data ; } else if ( $ method == 'PUT' ) { $ curl = curl_init ( ) ; curl_setopt_array ( $ curl , array ( CURLOPT_URL => $ url , CURLOPT_RETURNTRANSFER => true , CURLOPT_ENCODING => '' , CURLOPT_MAXREDIRS => 10 , CURLOPT_TIMEOUT => 0 , CURLOPT_FOLLOWLOCATION => true , CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1 , CURLOPT_CUSTOMREQUEST => 'PUT' , CURLOPT_POSTFIELDS => $ postData , CURLOPT_HTTPHEADER => array ( 'Content-Type: application/json' , 'X-Shopify-Access-Token: ' . $ access_token ) , ) ) ; $ result = curl_exec ( $ curl ) ; if ( curl_errno ( $ curl ) ) { echo 'Error:' . curl_error ( $ curl ) ; } $ info = curl_getinfo ( $ curl ) ; curl_close ( $ curl ) ; $ result_data = json_decode ( $ result , true ) ; $ res [ 'status_code' ] = $ info [ 'http_code' ] ; $ res [ 'result_data' ] = $ result_data ; } return $ res ; } else { echo " send error mail " ; } }
Comman function to perform different shopify curl operations (GET/POST/DELETE)
Comman function to perform different shopify curl operations ( GET / POST / DELETE )
// send email to admin to connect their account