<commit_before><?php defined('SYSPATH') OR die('No direct script access.');

/**
 * Jam behavior for payments which could refund.
 * It would subscribe to the model.after_refund event of the payment
 * and it would create a new purchase_item_refund in the store purchases.
 *
 * @package    Openbuildings\Purchases
 * @author     <NAME> <<EMAIL>>
 * @copyright  2014 OpenBuildings, Inc.
 * @license    http://spdx.org/licenses/BSD-3-Clause
 */
class Kohana_Jam_Behavior_Payment_Refundable extends Jam_Behavior {

	/**
	 * @codeCoverageIgnore
	 */
	public function initialize(Jam_Meta $meta, $name)
	{
		parent::initialize($meta, $name);

		$meta->events()
			->bind(
				'model.after_refund',
				'Jam_Behavior_Payment_Refundable::add_purchase_item_refund'
			);
	}

	public static function add_purchase_item_refund(Model_Payment $payment, Jam_Event_Data $data, Model_Store_Refund $refund)
	{
		$refund->add_purchase_item_refund();
	}
}<commit_msg>Don't add purchase items on failed refund<commit_after><?php defined('SYSPATH') OR die('No direct script access.');

/**
 * Jam behavior for payments which could refund.
 * It would subscribe to the model.after_refund event of the payment
 * and it would create a new purchase_item_refund in the store purchases.
 *
 * @package    Openbuildings\Purchases
 * @author     <NAME> <<EMAIL>>
 * @copyright  2014 OpenBuildings, Inc.
 * @license    http://spdx.org/licenses/BSD-3-Clause
 */
class Kohana_Jam_Behavior_Payment_Refundable extends Jam_Behavior {

	/**
	 * @codeCoverageIgnore
	 */
	public function initialize(Jam_Meta $meta, $name)
	{
		parent::initialize($meta, $name);

		$meta->events()
			->bind(
				'model.after_refund',
				'Jam_Behavior_Payment_Refundable::add_purchase_item_refund'
			);
	}

	public static function add_purchase_item_refund(Model_Payment $payment, Jam_Event_Data $data, Model_Store_Refund $refund)
	{
		if ($refund->transaction_status === Model_Store_Refund::TRANSACTION_REFUNDED)
		{
			$refund->add_purchase_item_refund();
		}
	}
}
{'fraction_non_alphanumeric': 0.11475409836065574, 'fraction_numerical': 0.004967709885742673, 'mean_word_length': 4.673239436619719, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, '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': '6339422', 'n_tokens_mistral': 711, 'n_tokens_neox': 655, 'n_words': 153}