'async', 'in_footer'=>true ); wp_enqueue_script( 'affiliatly', 'https://static.affiliatly.com/v3/affiliatly.js?affiliatly_code='.esc_html( $id_affiliatly ), array(), '3.2.0', $script_arguments ); return true; } /* * sends the order info to the Affiliatly server when a purchase is completed * $id_affiliatly and $security hash are taken from the plugin's settings page * * @version 3.2.0 * @since 3.2.0 * * @return type Bool. */ function affiliatly_mark_purchase( $id_affiliatly, $order, $price, $security_hash, $coupon_code = '', $skus = array(), $client_email = '' ) { global $affiliatly_root; if( ( ! isset( $_COOKIE['affiliatly_v3'] ) || empty( $_COOKIE['affiliatly_v3'] ) ) && empty( $coupon_code ) && empty( $client_email ) ) { return false; } $cookie_data = isset( $_COOKIE['affiliatly_v3'] ) ? sanitize_text_field( wp_unslash( $_COOKIE['affiliatly_v3'] ) ) : ''; if( !empty($cookie_data) ) { preg_match_all( '/&id_user=([0-9]+)/', $cookie_data, $result ); $id_user = $result[1][0]; preg_match_all( '/id_token=(.+)/', $cookie_data, $result ); $id_hash = isset($result[1][0]) ? $result[1][0] : ''; preg_match_all( '/&aff_uid=([0-9]+)/', $cookie_data, $result ); $id_affiliate = $result[1][0]; } else { $id_affiliate = $id_user = 0; } $id_order = $order; $price = $price; $coupon_code = $coupon_code; $skus = json_encode( $skus ); // preapre the POST data that will be send $post = 'mode=mark_php&id_affiliatly='.$id_affiliatly.'&id_user='.$id_user.'&id_hash='.$id_hash.'&aff_uid='.$id_affiliate; $post .= '&order='.$order.'&price='.$price.'&from=php&hash='.$security_hash.'&coupon_code='.$coupon_code.'&skus='.$skus; $post .= '&client_email='.$client_email; $url_to_listener = $affiliatly_root.'api_request.php'; $result = affiliatly_call( $url_to_listener, $post ); return true; } /* * sends order status updates to Affiliatly * * @version 3.2.0 * @since 3.2.0 * * @return type Bool. */ function affiliatly_order_status( $id_affiliatly, $order, $status, $security_hash ) { global $affiliatly_root; if( empty($security_hash) ) { return false; } $post = 'mode=order_status&id_affiliatly='.$id_affiliatly.'&order='.$order.'&status='.$status.'&from=php&hash='.$security_hash; $url_to_listener = $affiliatly_root.'api_request.php'; return affiliatly_call( $url_to_listener, $post ); } /* * calls the app server to update the price of the order on partial refund status changes * * @version 3.2.0 * @since 3.2.0 * * @return type Bool. */ function affiliatly_price_update( $id_affiliatly, $order, $data, $security_hash ) { global $affiliatly_root; if( empty( $security_hash ) ) { return false; } $post = 'mode=price_update&id_affiliatly='.$id_affiliatly.'&order='.$order.'&data='.json_encode($data).'&from=php&hash='.$security_hash; $url_to_listener = $affiliatly_root.'api_request.php'; return affiliatly_call( $url_to_listener, $post ); } /* * connects to URL using cURL method * * @version 3.2.0 * @since 3.2.0 * * @return type Object. */ function affiliatly_call( $url, $post) { $parameters = array( 'url'=>$url, 'method'=>'POST', 'headers'=>array('Content-Type' => 'application/x-www-form-urlencoded'), 'body'=>$post ); $ch = wp_remote_post( $url, $parameters ); return $ch; } ?>