Code Duplication    Length = 28-43 lines in 4 locations

includes/payments/class-give-payment.php 4 locations

@@ 1379-1421 (lines=43) @@
1376
	 *
1377
	 * @return void
1378
	 */
1379
	private function process_refund() {
1380
		$process_refund = true;
1381
1382
		// If the payment was not in publish or revoked status, don't decrement stats as they were never incremented.
1383
		if ( 'publish' != $this->old_status || 'refunded' != $this->status ) {
1384
			$process_refund = false;
1385
		}
1386
1387
		// Allow extensions to filter for their own payment types, Example: Recurring Payments.
1388
		$process_refund = apply_filters( 'give_should_process_refund', $process_refund, $this );
1389
1390
		if ( false === $process_refund ) {
1391
			return;
1392
		}
1393
1394
		/**
1395
		 * Fires before refunding payment.
1396
		 *
1397
		 * @since 1.5
1398
		 *
1399
		 * @param Give_Payment $this Payment object.
1400
		 */
1401
		do_action( 'give_pre_refund_payment', $this );
1402
1403
		$decrease_earnings       = apply_filters( 'give_decrease_store_earnings_on_refund', true, $this );
1404
		$decrease_customer_value = apply_filters( 'give_decrease_customer_value_on_refund', true, $this );
1405
		$decrease_purchase_count = apply_filters( 'give_decrease_customer_purchase_count_on_refund', true, $this );
1406
1407
		$this->maybe_alter_stats( $decrease_earnings, $decrease_customer_value, $decrease_purchase_count );
1408
		$this->delete_sales_logs();
1409
1410
		// @todo: Refresh only range related stat cache
1411
		give_delete_donation_stats();
1412
1413
		/**
1414
		 * Fires after refunding payment.
1415
		 *
1416
		 * @since 1.5
1417
		 *
1418
		 * @param Give_Payment $this Payment object.
1419
		 */
1420
		do_action( 'give_post_refund_payment', $this );
1421
	}
1422
1423
	/**
1424
	 * Process when a payment is set to failed
@@ 1443-1470 (lines=28) @@
1440
	 *
1441
	 * @return void
1442
	 */
1443
	private function process_pending() {
1444
		$process_pending = true;
1445
1446
		// If the payment was not in publish or revoked status, don't decrement stats as they were never incremented.
1447
		if ( 'publish' != $this->old_status || 'pending' != $this->status ) {
1448
			$process_pending = false;
1449
		}
1450
1451
		// Allow extensions to filter for their own payment types, Example: Recurring Payments.
1452
		$process_pending = apply_filters( 'give_should_process_pending', $process_pending, $this );
1453
1454
		if ( false === $process_pending ) {
1455
			return;
1456
		}
1457
1458
		$decrease_earnings       = apply_filters( 'give_decrease_earnings_on_pending', true, $this );
1459
		$decrease_donor_value    = apply_filters( 'give_decrease_donor_value_on_pending', true, $this );
1460
		$decrease_donation_count = apply_filters( 'give_decrease_donors_donation_count_on_pending', true, $this );
1461
1462
		$this->maybe_alter_stats( $decrease_earnings, $decrease_donor_value, $decrease_donation_count );
1463
		$this->delete_sales_logs();
1464
1465
		$this->completed_date = false;
1466
		$this->update_meta( '_give_completed_date', '' );
1467
1468
		// @todo: Refresh only range related stat cache
1469
		give_delete_donation_stats();
1470
	}
1471
1472
	/**
1473
	 * Process when a payment moves to cancelled.
@@ 1480-1507 (lines=28) @@
1477
	 *
1478
	 * @return void
1479
	 */
1480
	private function process_cancelled() {
1481
		$process_cancelled = true;
1482
1483
		// If the payment was not in publish or revoked status, don't decrement stats as they were never incremented.
1484
		if ( 'publish' != $this->old_status || 'cancelled' != $this->status ) {
1485
			$process_cancelled = false;
1486
		}
1487
1488
		// Allow extensions to filter for their own payment types, Example: Recurring Payments.
1489
		$process_cancelled = apply_filters( 'give_should_process_cancelled', $process_cancelled, $this );
1490
1491
		if ( false === $process_cancelled ) {
1492
			return;
1493
		}
1494
1495
		$decrease_earnings       = apply_filters( 'give_decrease_earnings_on_cancelled', true, $this );
1496
		$decrease_donor_value    = apply_filters( 'give_decrease_donor_value_on_cancelled', true, $this );
1497
		$decrease_donation_count = apply_filters( 'give_decrease_donors_donation_count_on_cancelled', true, $this );
1498
1499
		$this->maybe_alter_stats( $decrease_earnings, $decrease_donor_value, $decrease_donation_count );
1500
		$this->delete_sales_logs();
1501
1502
		$this->completed_date = false;
1503
		$this->update_meta( '_give_completed_date', '' );
1504
1505
		// @todo: Refresh only range related stat cache
1506
		give_delete_donation_stats();
1507
	}
1508
1509
	/**
1510
	 * Process when a payment moves to revoked.
@@ 1515-1542 (lines=28) @@
1512
	 * @since  1.5
1513
	 * @return void
1514
	 */
1515
	private function process_revoked() {
1516
		$process_revoked = true;
1517
1518
		// If the payment was not in publish, don't decrement stats as they were never incremented.
1519
		if ( 'publish' != $this->old_status || 'revoked' != $this->status ) {
1520
			$process_revoked = false;
1521
		}
1522
1523
		// Allow extensions to filter for their own payment types, Example: Recurring Payments.
1524
		$process_revoked = apply_filters( 'give_should_process_revoked', $process_revoked, $this );
1525
1526
		if ( false === $process_revoked ) {
1527
			return;
1528
		}
1529
1530
		$decrease_earnings       = apply_filters( 'give_decrease_earnings_on_revoked', true, $this );
1531
		$decrease_donor_value    = apply_filters( 'give_decrease_donor_value_on_revoked', true, $this );
1532
		$decrease_donation_count = apply_filters( 'give_decrease_donors_donation_count_on_revoked', true, $this );
1533
1534
		$this->maybe_alter_stats( $decrease_earnings, $decrease_donor_value, $decrease_donation_count );
1535
		$this->delete_sales_logs();
1536
1537
		$this->completed_date = false;
1538
		$this->update_meta( '_give_completed_date', '' );
1539
1540
		// @todo: Refresh only range related stat cache
1541
		give_delete_donation_stats();
1542
	}
1543
1544
	/**
1545
	 * Used during the process of moving to refunded or pending, to decrement stats