protected function cancelOrder($id, $user_id = false) { $order_details = $this->getOrder($id, true); // if we send a user id, make sure that user matches the order if ($user_id) { if ($user_id != $order_details['user_id']) { return false; } } switch ($order_details['connection_type']) { case 'com.paypal': $pp = new PaypalSeed($order_details['user_id'], $order_details['connection_id']); $refund_details = $pp->doRefund($order_details['service_transaction_id'], 'This order was cancelled by the seller.'); // check initial refund success if (!$refund_details) { return false; } else { // make sure the refund went through fully, return false if not if (isset($refund_details['REFUNDINFO'])) { if ($refund_details['REFUNDINFO']['REFUNDSTATUS'] == 'none') { return false; } } $this->editOrder($id, false, 1, "Cancelled " . date("F j, Y, g:i a T") . "\n\n" . $order_details['notes']); $this->editTransaction($order_details['transaction_id'], false, false, false, false, false, false, false, 'refunded'); return true; // NOTE: // we aren't restocking physical goods for a few reasons: // 1. cancellations should be less common than sales // 2. lack of inventory is a common reason to cancel, restocking makes it worse // 3. manually re-adding stock isn't hard // 4. if an order is a return of damaged goods, you won't restocking // 5. f**k it } break; default: return false; } }