Skip to content

Commit

Permalink
Payment refund amount is non-nullable.
Browse files Browse the repository at this point in the history
  • Loading branch information
rvdsteege committed Mar 30, 2023
1 parent 4bf8242 commit ea2f0e9
Showing 1 changed file with 40 additions and 42 deletions.
82 changes: 40 additions & 42 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,54 +717,52 @@ public function update_payment( Payment $payment ) {
*/
$refunded_amount = $payment->get_refunded_amount();

if ( null === $refunded_amount ) {
return;
}

$refunded_amount_value = $refunded_amount->get_value();

$entry_refunded_amount_value = (float) \gform_get_meta( $entry_id, 'pronamic_pay_refunded_amount' );

if ( $entry_refunded_amount_value < $refunded_amount_value ) {
$diff_amount = $refunded_amount->subtract( new Money( $entry_refunded_amount_value ) );
if ( $entry_refunded_amount_value >= $refunded_amount_value ) {
return;
}

$result = $this->addon->refund_payment(
$entry,
[
// The Gravity Forms payment add-on callback feature uses the action ID to prevent processing an action twice.
'id' => '',
'type' => 'refund_payment',
/**
* Unfortunately we don't have a specific transaction ID for this refund at this point.
*
* @link https://en.wikipedia.org/wiki/%C3%98
* @link https://unicode-table.com/en/2205/
*/
'transaction_id' => '',
'entry_id' => $entry_id,
'amount' => $diff_amount->get_value(),
/**
* Override the default Gravity Forms payment status.
*
* @link https://github.com/wp-premium/gravityforms/blob/2.4.20/includes/addon/class-gf-payment-addon.php#L1910-L1912
*/
'payment_status' => $refunded_amount->get_value() < $total_amount->get_value() ? 'PartlyRefunded' : 'Refunded',
/**
* Override the default Gravity Forms payment refund note.
*
* @link https://github.com/wp-premium/gravityforms/blob/2.4.20/includes/addon/class-gf-payment-addon.php#L1920-L1922
*/
'note' => \sprintf(
/* translators: %s: refunded amount */
\__( 'Payment has been (partially) refunded. Amount: %s.', 'pronamic_ideal' ),
$diff_amount->format_i18n()
),
]
);
$diff_amount = $refunded_amount->subtract( new Money( $entry_refunded_amount_value ) );

if ( true === $result ) {
\gform_update_meta( $entry_id, 'pronamic_pay_refunded_amount', $refunded_amount_value );
}
$result = $this->addon->refund_payment(
$entry,
[
// The Gravity Forms payment add-on callback feature uses the action ID to prevent processing an action twice.
'id' => '',
'type' => 'refund_payment',
/**
* Unfortunately we don't have a specific transaction ID for this refund at this point.
*
* @link https://en.wikipedia.org/wiki/%C3%98
* @link https://unicode-table.com/en/2205/
*/
'transaction_id' => '',
'entry_id' => $entry_id,
'amount' => $diff_amount->get_value(),
/**
* Override the default Gravity Forms payment status.
*
* @link https://github.com/wp-premium/gravityforms/blob/2.4.20/includes/addon/class-gf-payment-addon.php#L1910-L1912
*/
'payment_status' => $refunded_amount->get_value() < $total_amount->get_value() ? 'PartlyRefunded' : 'Refunded',
/**
* Override the default Gravity Forms payment refund note.
*
* @link https://github.com/wp-premium/gravityforms/blob/2.4.20/includes/addon/class-gf-payment-addon.php#L1920-L1922
*/
'note' => \sprintf(
/* translators: %s: refunded amount */
\__( 'Payment has been (partially) refunded. Amount: %s.', 'pronamic_ideal' ),
$diff_amount->format_i18n()
),
]
);

if ( true === $result ) {
\gform_update_meta( $entry_id, 'pronamic_pay_refunded_amount', $refunded_amount_value );
}
}

Expand Down

0 comments on commit ea2f0e9

Please sign in to comment.