<commit_before><?php

/**
 * Payment DataObject
 *
 * This class is used for storing a payment amount, and it's status of being
 * paid or not, and the gateway used to make payment.
 *
 * @package payment
 */
final class Payment extends DataObject{

	private static $db = array(
		'Gateway' => 'Varchar(50)', //this is the omnipay 'short name'
		'Money' => 'Money', //contains Amount and Currency
		'Status' => "Enum('Created,Authorized,Captured,Refunded,Void','Created')",
		'Identifier' => 'Varchar'
	);

	private static $has_many = array(
		'Messages' => 'PaymentMessage'
	);

	private static $defaults = array(
		'Status' => 'Created'
	);

	private static $casting = array(
		"Amount" => "Decimal"
	);

	private static $summary_fields = array(
		'Money' => 'Money',
		'GatewayTitle' => 'Gateway',
		'PaymentStatus' => 'Status',
		'Created.Nice' => 'Created'
	);

	private static $indexes = array(
		'Identifier' => true,
	);

	private static $default_sort = "\"Created\" DESC, \"ID\" DESC";

	public function getCMSFields() {
		$fields = new FieldList(
			TextField::create("MoneyValue", _t("Payment.MONEY", "Money"), $this->dbObject('Money')->Nice()),
			TextField::create("GatewayTitle", _t("Payment.GATEWAY", "Gateway"))
		);
		$fields = $fields->makeReadonly();
		$fields->push(
			GridField::create("Messages", _t("Payment.MESSAGES", "Messages"), $this->Messages(),
				GridFieldConfig_RecordViewer::create()
			)
		);

		$this->extend('updateCMSFields', $fields);

		return $fields;
	}

	/**
	 * Change search context to use a dropdown for list of gateways.
	 */
	public function getDefaultSearchContext() {
		$context = parent::getDefaultSearchContext();
		$fields = $context->getSearchFields();

		$fields->removeByName('Gateway');
		$fields->insertAfter(DropdownField::create('Gateway', _t('Payment.GATEWAY', 'Gateway'),
			GatewayInfo::get_supported_gateways()
		)->setHasEmptyDefault(true), 'Money');

		// create a localized status dropdown for the search-context
		$fields->insertAfter(DropdownField::create('Status', _t('Payment.db_Status', 'Status'),
			$this->getStatusValues()
		)->setHasEmptyDefault(true), 'Gateway');

		// update "money" to localized title
		$fields->fieldByName('Money')->setTitle(_t('Payment.MONEY', 'Money'));

		$context->addFilter(new PartialMatchFilter('Gateway'));

		return $context;
	}

	/**
	 * Set gateway, amount, and currency in one function.
	 * @param  string $gateway   omnipay gateway short name
	 * @param  float $amount     monetary amount
	 * @param  string $currency the currency to set<commit_msg>Remove `Created` field from payment-admin filter dialogue.<commit_after><?php

/**
 * Payment DataObject
 *
 * This class is used for storing a payment amount, and it's status of being
 * paid or not, and the gateway used to make payment.
 *
 * @package payment
 */
final class Payment extends DataObject{

	private static $db = array(
		'Gateway' => 'Varchar(50)', //this is the omnipay 'short name'
		'Money' => 'Money', //contains Amount and Currency
		'Status' => "Enum('Created,Authorized,Captured,Refunded,Void','Created')",
		'Identifier' => 'Varchar'
	);

	private static $has_many = array(
		'Messages' => 'PaymentMessage'
	);

	private static $defaults = array(
		'Status' => 'Created'
	);

	private static $casting = array(
		"Amount" => "Decimal"
	);

	private static $summary_fields = array(
		'Money' => 'Money',
		'GatewayTitle' => 'Gateway',
		'PaymentStatus' => 'Status',
		'Created.Nice' => 'Created'
	);

	private static $indexes = array(
		'Identifier' => true,
	);

	private static $default_sort = "\"Created\" DESC, \"ID\" DESC";

	public function getCMSFields() {
		$fields = new FieldList(
			TextField::create("MoneyValue", _t("Payment.MONEY", "Money"), $this->dbObject('Money')->Nice()),
			TextField::create("GatewayTitle", _t("Payment.GATEWAY", "Gateway"))
		);
		$fields = $fields->makeReadonly();
		$fields->push(
			GridField::create("Messages", _t("Payment.MESSAGES", "Messages"), $this->Messages(),
				GridFieldConfig_RecordViewer::create()
			)
		);

		$this->extend('updateCMSFields', $fields);

		return $fields;
	}

	/**
	 * Change search context to use a dropdown for list of gateways.
	 */
	public function getDefaultSearchContext() {
		$context = parent::getDefaultSearchContext();
		$fields = $context->getSearchFields();

		$fields->removeByName('Gateway');
		$fields->removeByName('Created');
		$fields->insertAfter(DropdownField::create('Gateway', _t('Payment.GATEWAY', 'Gateway'),
			GatewayInfo::get_supported_gateways()
		)->setHasEmptyDefault(true), 'Money');

		// create a localized status dropdown for the search-context
		$fields->insertAfter(DropdownField::create('Status', _t('Payment.db_Status', 'Status'),
			$this->getStatusValues()
		)->setHasEmptyDefault(true), 'Gateway');

		// update "money" to localized title
		$fields->fieldByName('Money')->setTitle(_t('Payment.MONEY', 'Money'));

		$context->addFilter(new PartialMatchFilter('Gateway'));

		return $context;
	}

	/**
	 * Set gateway, amount, and currency in one function.
	 * @param  string $gateway   omnipay gateway short name
	 * @param  float $amount     monetary amount
	 * @param  string $currency the currency to set
{'fraction_non_alphanumeric': 0.164968275331667, 'fraction_numerical': 0.0007690828686791001, 'mean_word_length': 4.735391400220507, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1642392', 'n_tokens_mistral': 1760, 'n_tokens_neox': 1599, 'n_words': 408}