pronamic / wp-pronamic-pay-woocommerce

WooCommerce driver for the WordPress payment processing library.
http://www.wp-pay.org/extensions/woocommerce/
6 stars 2 forks source link

No customer and payment lines #37

Closed remcotolsma closed 1 year ago

rvdsteege commented 1 year ago

The customer is not set because the payment is not recognized as the first payment in https://github.com/pronamic/wp-pay-core/blob/b20133ecec3b72d2ca9fab58b6b693f93edf3063/src/Subscriptions/SubscriptionsModule.php#L118-L133. Therefore, SubscriptionHelper::complement_subscription_by_payment( $subscription, $payment ) is not called and the customer is not 'complemented' in the subscription.

I think we could simply call $subscription->set_customer( $payment->get_customer() ) in the WooCommerce gateway to resolve this. But additionally, the incorrect period of the first payment (which causes the payment not being recognized as the first payment) is also a point of attention:

Scherm­afbeelding 2023-06-07 om 14 51 21

This seems to be caused by the next payment date being set on the subscription, before a new period is added. In development, I have resolved this by temporarily setting the next payment date to the current date (as is usually the case when starting subscriptions), but this is not really a nice solution.

https://github.com/pronamic/wp-pronamic-pay-woocommerce/blob/f21bf0b8b83e0c5682a9b3825356d8b423714e59/src/Gateway.php#L385-L400

// Add subscription and period.
$next_payment_date = $subscription->get_next_payment_date();

$subscription->set_next_payment_date( new \DateTimeImmutable() );

$period = $subscription->new_period();

$subscription->set_next_payment_date( $next_payment_date );