// Unit price $refundAmount += $dbOrderItem->quantity * $dbItem->price; $Gresponse->log->LogResponse("refund subtotal: " . $refundAmount); //set item unique id $Gresponse->log->LogResponse("Set Merchant Id" . $dbItem->id); $gitem->SetMerchantItemId($dbItem->id); array_push($itemsToCancel, $gitem); } } if (count($itemsToCancel) > 0) { //Compare total quantity of order items with cancel items to update order status $orderItems = db_getOrderItems($dborder->id); $Gresponse->log->LogResponse("From " . count($orderItems) . " items, " . count($itemsToCancel) . " will be cancelled"); $response = $Grequest->SendRefundOrder($dborder->ordernumber, $refundAmount, "Items could not be processed in Quota System. The most common reason " . "is that there were not enough resources to satisfy this request", "Contact the administrator for further details."); $response = $Grequest->SendCancelItems($dborder->ordernumber, $itemsToCancel, "Items could not be processed in Quota System. The most common reason " . "is that there were not enough resources to satisfy this request"); db_setOrderRefund($dborder->id, $dborder->refund + $refundAmount); } break; case 'PAYMENT_DECLINED': $Gresponse->log->LogResponse("Canceling order " . $data[$root]['google-order-number']['VALUE']); $response = $Grequest->SendCancelOrder($data[$root]['google-order-number']['VALUE'], "Payment Declined", "Contact Google Checkout for further details."); $Grequest->SendBuyerMessage($data[$root]['google-order-number']['VALUE'], "Sorry, your payment has been declined", true); $Gresponse->log->LogResponse("Response: " . array_to_json($response)); break; case 'CANCELLED': $Gresponse->log->LogResponse("Cancelled " + $data[$root]['google-order-number']['VALUE']); $order = db_getOrderByOrderNumber($data[$root]['google-order-number']['VALUE']); cancelTransaction($order->id); $orderItems = db_getOrderItems($orderid); foreach ($orderItems as $orderItem) { db_cancelOrderItem($orderid, $orderItem->itemid);
} $dbOrderItems = db_getOrderItems($orderid); $assignmentsResponse = cancelTransaction($orderid); //print_r($assignmentResponse); //print_r($dbOrderItems); $i = 0; foreach ($dbOrderItems as $dbOrderItem) { $ar = $assignmentsResponse[$i++]; $subtotal = $dbOrderItem['quantity'] * $dbOrderItem['unitprice']; $partialRefund = $subtotal * $ar->percentageReturned / 100; $refundAmount = $refundAmount + $partialRefund; } //Google checkout orders if ($dbOrder_payment) { if ($refundAmount > 0) { db_setOrderRefund($dbOrder_id, $dbOrder_refund + $refundAmount); //Refund total or partial item price /*jh NOTE: Discussed with Dr. Sadjadi on 7/6/2015 that we will not use the google request methods for now. $gresponse = $Grequest->SendRefundOrder($dbOrder_ordernumber,$refundAmount, "Order has been refunded by the store administrator.". "Contact the administrator for further details."); if($gresponse[0]==200){ //If the refund amount is not the total of the orderItem, //item cannot be cancelled $gresponse = $Grequest->SendCancelOrder($dbOrder_ordernumber, "Order has been cancelled by the store.". "Contact the administrator for further details."); if($gresponse[0]==200){