Closed rvdsteege closed 3 years ago
I suggest we introduce two new actions:
pronamic_pay_pre_create_payment
pronamic_pay_pre_create_subscriptions
We use these like this:
\add_action( 'pronamic_pay_pre_create_payment', function( $payment ) {
// Complement payment.
self::complement_payment( $payment );
} );
\add_action( 'pronamic_pay_pre_create_subscription', function( $subscription ) {
SubscriptionHelper::complement_subscription( $subscription );
SubscriptionHelper::complement_subscription_dates( $subscription );
} );
We only have to figure out where and how to call this:
SubscriptionHelper::complement_subscription_by_payment( $subscription, $payment );
Maybe something like this:
\add_action( 'pronamic_pay_pre_create_payment', function( $payment ) {
foreach ( $payment->get_subscriptions() as $subscription ) {
if ( $subscription->is_first_payment( $payment ) ) {
SubscriptionHelper::complement_subscription_by_payment( $subscription, $payment );
}
}
} );
We should remove all calls like:
$this->plugin->subscriptions_data_store->create( $subscription ); // $subscription->save()
$pronamic_ideal->payments_data_store->create( $payment ); // $payment->save();
@rvdsteege Thoughts?
A new recurring payment creates a duplicate subscription.
Should we use
$subscription->save()
instead of$this->plugin->subscriptions_data_store->create( $subscription )
?