Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- 2 define("WP_USE_THEMES",true);
- 3 require(__DIR__."/../../../../wp-load.php");
- 4
- 5 $conf = parse_ini_file("../../../../config.ini");
- 6 $servername = $conf['host'];
- 7 $username = $conf['user'];
- 8 $password = $conf['password'];
- 9 $database = $conf['database'];
- 10
- 11 $conn = mysqli_connect($servername, $username, $password,$database);
- 12 $check = 0;
- 13
- 14 // Check connection
- 15 if ($conn->connect_error) {
- 16 die("Database Connection failed: " . $conn->connect_error);
- 17 $check = 1;
- 18 }
- 19
- 20 require_once(__DIR__. '/Requests/library/Requests.php');
- 21 Requests::register_autoloader();
- 22
- 23 // START CODE FROM HERE
- 24 ///////////////////////////////////////////////////////////////////////
- 25
- 26 $oid = $_GET['order_idx'];
- 27 $oiid = $_GET['order_item_idx'];
- 28
- 29 //MAP ORDERID AND USERID
- 30 $result = mysqli_query($conn,"SELECT * FROM orderid_hashkey_map WHERE orderid='$oid'");
- 31 $hash = mysqli_fetch_array($result)['hash'];
- 32 $userid = mysqli_fetch_array($result)['userid'];
- 33 $invoiceid = mysqli_fetch_array($result)['invoiceid'];
- 34
- 35 //MAP CONNECTION DETAILS
- 36 $result1 = mysqli_query($conn,"SELECT * FROM hiveage_connection WHERE userid='$userid'");
- 37 $userhash = mysqli_fetch_array($result1)['userhash'];
- 38 $firstname = mysqli_fetch_array($result1)['firstname'];
- $url = 'https://healthonrent.hiveage.com/api/rinv/'.$hash.'/';
- 44
- 45
- 46
- 47
- 48 $customer = new WC_Order($oid);
- 49 //$customer = new WC_Order('239');
- 50 $email = $customer->billing_email;
- 51 $firstname = $customer->billing_first_name;
- 52 $lastname = $customer->billing_last_name;
- 53 $address = $customer->billing_address_1 . " " .$customer->billing_address_2;
- 54 $city = $customer->billing_city;
- 55 $statename = $customer->billing_state;
- 56 $zipcode = $customer->billing_postcode;
- 57 $country = $customer->shipping_country;
- 58 $phone = $customer->billing_phone;
- 59
- 60 //echo $email. " ". $firstname . " " .$lastname;
- 61
- 62 //GET ORDER DETAILS
- 63 $date_today = date("Y-m-d");
- 64 $get_url = "http://128.199.112.153/wp-content/plugins/orders/rent.php?order_id=".$oid."&date=".$date_today;
- 65 $get_rent_array = file_get_contents($get_url);
- 66 $items = get_object_vars(json_decode($get_rent_array));
- //Create the items array
- 69 $hiveage_item_format = array();
- 70 $i = 0;
- 71 $alop = 0;
- 72 foreach($items as $item_id => $rent_object){
- 73 $rent_det = get_object_vars($rent_object);
- 74 if($item_id != $oiid && $rent_det["rent"]){
- 75 echo $item_id." ".$oiid." INSIDE <br>";
- 76 $alop = 1;
- 77 $hiveage_item_format[$i] = array(
- 78 'date' => $date_today,
- 79 'description' => $rent_det["name"],
- 80 'price' => $rent_det["rent"],
- 81 'quantity' => '1',
- 82 'unit' => 'monthly',
- 83 'sort_order' => $i + 1
- 84 );
- 85 $i++;
- 86 }
- 87 }
- echo "<br><br><br>";
- 91 var_dump($hiveage_item_format);
- 92 echo "<br><br><br>";
- 93 if($alop){
- 94 $data = array(
- 95 'recurring_invoice' => array(
- 96 'id' => $invoiceid,
- 97 'connection' => array(
- 98 'id' => $userid,
- 99 'hash_key' => $userhash,
- 100 'name' => $fname
- 101 ),
- 102 'recurring_method' => 'auto_send',
- 103 'next_billing_date' => $date_today,
- 104 'profile_name' => 'Recurring-Invoice',
- 105 'profile_no' => substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $ length),
- 106 'occurrences' => '0',
- 107 'interval' => '1',
- 108 'interval_unit' => 'months',
- 109 'due_date_options' => '5',
- 110 'hash_key' => $hash,
- 111 'summary' => $oid,
- 112 'note' => $oid,
- 113 'allow_partial_payments' => 'false',
- 114 'send_receipts_automatically' => 'true',
- 115 'currency_iso_code' => 'INR',
- 116 'items' => $hiveage_item_format
- 117 )
- 118 );
- 119 $data = json_encode($data);
- 120 echo $url;
- $headers = array('content-type' => 'application/json');
- 123 $options = array('auth' => array('xxxx', 'xxxx'));
- 124
- 125 if($alop){
- 126 $request = Requests::put($url,$headers,$data,$options);
- 127 //var_dump($request);
- 128 }
- 129 else{
- 130 $request = Requests::delete($url ,$headers,$options );
- 131 }
- 132 var_dump($request);
- 133 }
- 134
- 135 ?>
Add Comment
Please, Sign In to add comment