<?php
/**
 * Apple Pay refund response.
 *
 * @package flo-checkout
 */

namespace Flo_Checkout\Gateways\Apple_Pay\Responses;

use Flo_Checkout\Gateways\Shift4_APM\Responses\Abstract_Response_Gateway_Payment;

defined( 'ABSPATH' ) || exit;

/**
 * Class Apple_Pay_Refund_Response.
 */
class Apple_Pay_Refund_Response extends Abstract_Response_Gateway_Payment {


	/**
	 * {@inheritDoc}
	 */
	public function process(): Apple_Pay_Refund_Response {
		parent::process();

		$this->log(
			'Apple Pay refund response.',
			array(
				'order_id' => $this->order->get_id(),
				'response' => $this->request_response_model->get_body(),
			)
		);

		return $this->update_order();
	}


	/**
	 * Update order.
	 *
	 * @return self
	 */
	protected function update_order(): self {
		$this->order->add_order_note(
			__( 'Payment refunded.', 'flo-checkout-plugin' ) . '<br>' .
			__( 'Payment method', 'flo-checkout-plugin' ) . ': ' . $this->payment_response->payment_method->get_name() . '<br>' .
			__( 'Request ID', 'flo-checkout' ) . ': ' . $this->payment_response->request_id . '<br>' .
			__( 'Transaction ID', 'flo-checkout' ) . ': ' . $this->payment_response->transaction_id . '<br>' .
			__( 'Transaction time', 'flo-checkout' ) . ': ' . $this->payment_response->transaction_time . '<br>' .
			__( 'Amount', 'flo-checkout' ) . ': ' . $this->payment_response->amount->get_display_amount()
		);

		$this->order->save();

		return $this;
	}
}
