Process attached order when payment is refunded

@param ServiceResponse $response
@return void
166238
public function onRefunded($response)
    {
        $order = $this->owner->Invoice();

        if ($order->exists()) {
            $order->markRefunded();
            $order->write();
        }
    }
1085875
public function getPayPalResponse()
    {
        $service = $this->getPayPalService();
        $request = $this->getPayPalRequest();

        return $service->refundTransaction($request);
    }
1235072
public function bind($response) {
		$this->_response = $response;
		$this->_response->headers += $this->_headers;

		foreach ($this->_queue as $message) {
			$this->_write($message);
		}
	}
478399
protected function finish(Response $response)
    {
        if ($this->requestedResultsLocale !== '') {
            $this->getLocalization()->popActiveContext();
        }
        if (!$response->headers->has('X-Frame-Options')) {
            $response->headers->set('X-Frame-Options', 'DENY');
        }
        if (!$response->headers->has('Access-Control-Allow-Origin')) {
            $config = $this->app->make('community_translation/config');
            $response->headers->set('Access-Control-Allow-Origin', (string) $config->get('options.api.accessControlAllowOrigin'));
        }

        return $response;
    }
960976
private function _createTransaction(array $response)
    {
        $model = new Transaction();
        $model->setId($response['id']);
        $model->setAmount($response['amount']);
        $model->setOriginAmount($response['origin_amount']);
        $model->setStatus($response['status']);
        $model->setDescription($response['description']);
        $model->setLivemode($response['livemode']);
        $model->setRefunds($this->_handleRecursive($response['refunds'], 'refund'));
        $model->setCurrency($response['currency']);
        $model->setCreatedAt($response['created_at']);
        $model->setUpdatedAt($response['updated_at']);
        $model->setResponseCode($response['response_code']);
        $model->setShortId($response['short_id']);
        $model->setInvoices($response['invoices']);
        $model->setPayment($this->_convertResponseToModel($response['payment'], "payment"));
        $model->setClient($this->_convertResponseToModel($response['client'], "client"));
        $model->setPreauthorization($this->_convertResponseToModel($response['preauthorization'], "preauthorization"));
        $model->setFees($response['fees']);
        $model->setAppId($response['app_id']);

        if (isset($response[Transaction::RESPONSE_FIELD_SHIPPING_ADDRESS])) {
            $model->setShippingAddress(
                $this->_convertResponseToModel(
                    $response[Transaction::RESPONSE_FIELD_SHIPPING_ADDRESS],
                    AbstractAddress::TYPE_SHIPPING
                )
            );
        }

        if (isset($response[Transaction::RESPONSE_FIELD_BILLING_ADDRESS])) {
            $model->setBillingAddress(
                $this->_convertResponseToModel(
                    $response[Transaction::RESPONSE_FIELD_BILLING_ADDRESS],
                    AbstractAddress::TYPE_BILLING
                )
            );
        }

        if (isset($response[Transaction::RESPONSE_FIELD_ITEMS])) {
            $model->setItems($this->_handleRecursive($response[Transaction::RESPONSE_FIELD_ITEMS], 'item'));
        }

        return $model;
    }
1256103
public function prepareForResponse(Response $response) {
		$this->jsonPayload = new JsonPayload($this->data);
		$this->jsonPayload->prepareForResponse($response);
	}
726538
public function decorateResponse(Request $request, Response $response)
    {
        if ($request->headers->has(self::ORIGIN_REQUEST_HEADER)) {
            $request->headers->set('referer', $request->headers->get(self::ORIGIN_REQUEST_HEADER));
        }

        $this->setTurbolinksLocationHeaderFromSession($request, $response);

        if ($response->isRedirect() && $response->headers->has(self::ORIGIN_RESPONSE_HEADER)) {
            $this->redirectTo($request, $response);
        }

        $this->modifyStatusCode($request, $response);
    }
1306141
private function authorization_from($response)
  {
      if (isset($response['TRANSACTIONID'])) {
          return $response['TRANSACTIONID'];
      }
      if (isset($response['AUTHORIZATIONID'])) {
          return $response['AUTHORIZATIONID'];
      }
      if (isset($response['REFUNDTRANSACTIONID'])) {
          return $response['REFUNDTRANSACTIONID'];
      }

      return false;
  }
211000
protected function handleResponse(Response $response)
    {
        $statusCode = $response->getStatusCode();

        switch ($statusCode) {
            case 401:
                $response = $this->processNotAuthorized();
                break;
        }

        return $response;
    }
1068315
public function onVoid($response)
    {
        $order = $this->owner->Invoice();

        if ($order->exists()) {
            $order->markCancelled();
            $order->write();
        }
    }
212017
public function respond($response)
	{
		if (
			$this->logger !== null &&
			$this->logger->isHandling(Logger::DEBUG)
		) {
			$this->logger->addDebug(
				'Send response',
				array(
					 'content-type' => $this->contentType,
					 'response'     => ctype_print($response) ? $response : 'base64:' . base64_encode($response)
				)
			);
		}

		ob_start();
		while (ob_end_clean()) {
		}
		header('Content-Type: ' . $this->contentType);
		echo $response;
	}
614073
protected function checkSuccess($response)
    {
        if(!isset($response['ACK'])) {
            $this->_success = false;
            $this->addErrorMessage('ACK key not found in response.');
            return;
        } else if($response['ACK'] == "Success" || $response['ACK'] == "SuccessWithWarning") {
            $this->_success = true;
            return;
        }

        if(isset($response['ERRORS'])) {
            foreach($response['ERRORS'] as $error) {
                if(isset($error['LONGMESSAGE'])) {
                    $this->addErrorMessage($error['LONGMESSAGE']);
                }
            }
        } else {
            $this->addErrorMessage('Unknown error has occurred.');
        }

        $this->_success = false;
    }
321281
public function handle(array $handlingSubject, array $response) {
       
        /** @var $payment Payment */
        $paymentDO  = SubjectReader::readPayment($handlingSubject);
        $payment    = $paymentDO->getPayment();
        $order      = $payment->getOrder();

        if($order->canCreditmemo()) {
            $invoice    = $this->getInvoiceByTransactionId($response['originalId'], $order);
            $amount     = ChargeAmountAdapter::getStoreAmountOfCurrency($response['value'], $response['currency']);

            $creditMemo = $this->creditMemoFactory->createByInvoice($invoice);
            $creditMemo->setBaseGrandTotal($amount);
            $creditMemo->setInvoice($invoice);

            $payment->setCreditmemo($creditMemo);

            $this->orderPaymentRepository->save($payment);
            $this->creditMemoService->refund($creditMemo);
            $this->invoiceRepository->save($invoice);
        }
    }
790425
protected function getPaymentStatus($response)
    {
        switch ($status = Arr::get($response, 'payment_status', 'paid')) {
            case 'Completed':
            case 'Processed':
                return new Status('paid');
            case 'Created':
            case 'Pending':
                return new Status('pending');
            case 'Canceled_Reversal':
                return new Status('canceled');
            case 'Failed':
            case 'Denied':
                return new Status('failed');
            case 'Declined':
                return new Status('declined');
            case 'Expired':
                return new Status('expired');
            case 'Refunded':
                return new Status('refunded');
            case 'Reversed':
                return new Status('charged_back');
            case 'Voided':
                return new Status('voided');
        }
    }
1127599
protected function processTogglResponse($response)
    {
        // We only need to do something if results are paginated
        if ($response->total_count <= 50) {
            return $response->data;
        }

        $reqdata = [];
        $reqdata = json_encode($reqdata);
        $pages = ceil($response->total_count / 50);
        $curr_page = 1;
        $data = $response->data;

        $orig_uri = $this->uri;

        while ($curr_page < $pages) {
            $curr_page++;
            $this->uri .= '&page=' . $curr_page;
            $response = $this->processRequest($reqdata, self::GET);
            $this->_handleError($reqdata, $response);
            foreach ($response->data as $entry) {
                $data[] = $entry;
            }
            $this->uri = $orig_uri;
        }

        return $data;
    }
579105
public function onCaptured($response)
    {
        $order = $this->owner->Invoice();

        if ($order->exists()) {
            $payment_amount = MathsHelper::round($this->owner->getAmount(), 2);
            $order_amount = MathsHelper::round($order->Total, 2);

            // If our payment is the value of the order, mark paid
            // else mark part paid
            if (abs(($payment_amount - $order_amount) / $order_amount) < 0.00001) {
                $order->markPaid();
            } else {
                $order->markPartPaid();
            }

            $order->write();
        }
    }
148646
public static function isCommitSuccess($response)
    {
        //====================================================================//
        // Analyze NuSOAP results
        if (!$response || !isset($response->result) || (true != $response->result)) {
            return false;
        }

        return true;
    }