pronamic / wp-pronamic-pay

The Pronamic Pay plugin allows you to easily accept payments with payment methods like credit card, iDEAL, Bancontact and Sofort through a variety of payment providers on your WordPress website.
https://pronamicpay.com
34 stars 14 forks source link

Review use case `$subscription->get_first_payment()` #240

Closed remcotolsma closed 2 years ago

remcotolsma commented 2 years ago

$subscription->get_first_payment() could result in an empty result as first payments are deleted, which may be confusing.

I noticed we already have a $subscription->get_first_payment() function: https://github.com/pronamic/wp-pay-core/blob/adec7dcd1acab7e0268fad27f1021c390a04b535/src/Subscriptions/Subscription.php#L578-L602

It's implemented like this:

    /**
     * Get the first payment of this subscription.
     *
     * @return Payment|null
     */
    public function get_first_payment() {
        if ( null === $this->id ) {
            return null;
        }

        // Query arguments to get first payment.
        $args = array(
            'posts_per_page' => 1,
            'orderby'        => 'post_date',
            'order'          => 'ASC',
        );

        $first_payment = get_pronamic_payments_by_meta( '_pronamic_payment_subscription_id', $this->id, $args );

        if ( ! empty( $first_payment ) ) {
            return $first_payment[0];
        }

        return null;
    }

If the first payment is deleted it will return the second subscription payment?

Is it a good idea to keep track of the first payment in the subscription object?

subscription {
    "first_payment": {
        "$ref": "..."
    }
}

If the first payment has been removed, we can assume that it concerns a follow-up payment?

Originally posted by @remcotolsma in https://github.com/pronamic/wp-pronamic-pay/issues/228#issuecomment-934321232

remcotolsma commented 2 years ago

Removed in https://github.com/pronamic/wp-pay-core/commit/464a35c21fad87ddcaf344cb592f494520df1059.