Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show subscription payments that are not linked to a period #131

Closed
remcotolsma opened this issue Jun 14, 2023 · 0 comments · Fixed by #134
Closed

Show subscription payments that are not linked to a period #131

remcotolsma opened this issue Jun 14, 2023 · 0 comments · Fixed by #134

Comments

@remcotolsma
Copy link
Member

remcotolsma commented Jun 14, 2023

At the moment, payments that are connected to a subscription, but not to a specific subscription period, will not be shown with a subscription. This may, for example, concern a payment of €0.01 for a payment method/mandate change. But also WooCommerce Subscriptions renewal payments are no longer linked to a specific subscription period.

$periods = $subscription->get_payments_by_period();

/**
* Get payments by period.
*
* @return array
*/
public function get_payments_by_period() {
$payments = $this->get_payments();
$periods = [];
foreach ( $payments as $payment ) {
// Get period for this subscription.
$period = null;
$payment_periods = $payment->get_periods();
if ( null === $payment_periods ) {
continue;
}
foreach ( $payment_periods as $period ) {
if ( $this->get_id() === $period->get_phase()->get_subscription()->get_id() ) {
break;
}
}
if ( null === $period ) {
continue;
}
// Add period to result.
$start = $period->get_start_date()->getTimestamp();
if ( ! \array_key_exists( $start, $periods ) ) {
$periods[ $start ] = [
'period' => $period,
'payments' => [],
'can_retry' => true,
];
}
// Add payment to result.
$periods[ $start ]['payments'][ $payment->get_date()->getTimestamp() ] = $payment;
if ( \in_array( $payment->get_status(), [ PaymentStatus::OPEN, PaymentStatus::SUCCESS ], true ) ) {
$periods[ $start ]['can_retry'] = false;
}
}
// Sort periods and payments.
\krsort( $periods );
foreach ( $periods as &$period ) {
\ksort( $period['payments'] );
}
return $periods;
}

These periodless payments should be shown with subscriptions.

  1. Payments without period are not listed in the subscription payments meta box.

Originally posted by @rvdsteege in pronamic/wp-pronamic-pay-woocommerce#40 (review)

A little bit related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant