<?php

namespace DigitalApps\PaymentsForAdyen;

defined('ABSPATH') || exit;

/** Build stable partner application information for Checkout API requests. */
final class Adyen_Application_Info
{
	const EXTERNAL_PLATFORM_NAME = 'Digital Apps';
	const MERCHANT_APPLICATION_NAME = 'Digital Apps Payments for Adyen';
	const PAYMENT_SOURCE_NAME = 'Adyen Web';
	const PAYMENT_SOURCE_VERSION = '6.43.0';

	/**
	 * Return values that satisfy Adyen's application-information constraints.
	 *
	 * @return array
	 */
	public static function build()
	{
		$information = [
			'externalPlatform' => [
				'name' => self::EXTERNAL_PLATFORM_NAME,
			],
			'merchantApplication' => [
				'name' => self::MERCHANT_APPLICATION_NAME,
				'version' => defined('DIGITALAPPS_PAYMENTS_FOR_ADYEN_VERSION') ? DIGITALAPPS_PAYMENTS_FOR_ADYEN_VERSION : 'unknown',
			],
			'adyenPaymentSource' => [
				'name' => self::PAYMENT_SOURCE_NAME,
				'version' => self::PAYMENT_SOURCE_VERSION,
			],
		];

		return $information;
	}

	/**
	 * Add application information to a supported Checkout API request body.
	 *
	 * @param array $body Request body.
	 * @return array
	 */
	public static function add_to(array $body)
	{
		$body['applicationInfo'] = self::build();
		return $body;
	}
}
