function cancelTransaction($orderid) { //Get orde details $order = db_getOrderById($orderid); $user = db_getUserById($order->userid); $orderItems = db_getOrderItems($orderid); //Prepare request for the quota system cancel call $assignments = array(); foreach ($orderItems as $orderItem) { $item = db_getItem($orderItem->itemid); $type = $item->type; if ($type == "ITEM") { $assignment = array("creditTypeId" => $item->referenceid, "quantity" => $orderItem->quantity, "purchaseId" => $order->ordernumber, "active" => !$orderItem->cancelled); array_push($assignments, $assignment); } else { if ($type == "PACKAGE") { //Get package items $packageitems = db_getPackageItems($item->id); //Initialize array to send a ws request for package items only with rollback true $packageItemsArr = array(); //Save items in request array foreach ($packageitems as $packageitem) { $item = db_getItem($packageitem->itemid); $quantity = $orderItem->quantity * $packageitem->quantity; $assignment = array("creditTypeId" => $item->referenceid, "quantity" => $quantity, "purchaseId" => $order->ordernumber . "" . $orderItem->itemid, "active" => !$orderItem->cancelled); array_push($assignments, $assignment); } } } } //call web service $response = ws_cancelQuotaAssignment($assignments); $assignmentsResponse = array(); if (!is_array($response)) { array_push($assignmentsResponse, $response); } else { $assignmentsResponse = array_merge($assignmentsResponse, $response); } return $assignmentsResponse; }
$i = 0; foreach ($packageItems as $pi) { $percentageReturned = $assignmentsResponse[$i++]->percentageReturned; //jh NOTE: this is tied to the above call!! $subtotal = $pi['quantity'] * $dbOrderItem['quantity'] * $pi['price']; $partialRefund = $subtotal * $percentageReturned / 100; $refundAmount = $refundAmount + $partialRefund; // echo "subtotal ".$subtotal; // echo "partial refund ".$partialRefund; // echo "refund subtotal ".$refundAmount; } // echo "refund total ".$refundAmount; } else { $assignment = array("creditTypeId" => $dbItem_referenceid, "quantity" => $dbOrderItem['quantity'], "purchaseId" => $dbOrder_ordernumber, "active" => !$dbOrderItem['cancelled']); array_push($assignmentsRequest, $assignment); $assignmentResponse = ws_cancelQuotaAssignment($assignmentsRequest); // print_r($assignmentResponse); $percentageReturned = $assignmentResponse->percentageReturned; $subtotal = $dbOrderItem->quantity * $dbItem->price; $refundAmount = $subtotal * $percentageReturned / 100; // echo "subtotal ".$subtotal; // echo "refund ".$refundAmount; } //Google checkout order items if ($dbOrder_payment) { if ($refundAmount > 0) { /*jh NOTE: Discussed with Dr. Sadjadi on 7/6/2015 that we will not use the google request methods for now. $itemToCancel = array(); //create a google item $gitem = new GoogleItem($dbItem->name, // Item name