Simple Membership Plugin › Forums › Simple Membership Plugin › PPCP renewals saved with empty member_id (4.7.2 fallback has no effect)
- This topic has 1 reply, 2 voices, and was last updated 1 month ago by
admin.
-
AuthorPosts
-
October 16, 2026 at 10:43 am #32383
freetiermorioka555
Participant## Summary
When a PayPal PPCP subscription is started by a visitor who is not logged in, the button’s custom field contains no
swpm_id. Every laterPAYMENT.SALE.COMPLETEDwebhook then reuses that stored custom value, so each recurring payment is saved in the payments table with an emptymember_id. I noticed that 4.7.2 adds a fallback for this, and I think it is very close to working. Below I describe why it cannot take effect yet, and a few ways it could be completed.## Environment
– Plugin: Simple Membership
– Versions checked: 4.4.3 (in production) and 4.7.2 (source reviewed)
– Gateway: PayPal, PPCP subscriptions (button typepp_subscription_new), REST webhooks## What happens
1. The payment button adds
swpm_idto the custom field only if the visitor is logged in at the time the button is rendered.
2. If a visitor subscribes while logged out, the custom field has noswpm_id. For an existing member,swpm_handle_subsc_signup_stand_alone()identifies the member by the payer email and updates the account correctly. So the member account itself is fine and does not end up incomplete.
3. That custom string is stored in theswpm_transactionsCPT. Every laterPAYMENT.SALE.COMPLETEDevent reads it back throughget_original_custom_value_from_transactions_cpt(). As far as I can tell, nothing in the plugin updates that stored value afterwards.
4. As a result,save_txn_record()writes a payment row with an emptymember_idfor every payment, for as long as the subscription continues.## Why the 4.7.2 fallback does not take effect
4.7.2 adds a fallback in
save_txn_record():`php
// classes/class.swpm-transactions.php (4.7.2, lines 31-35)
$txn_data[‘member_id’] = isset ( $custom_var[‘swpm_id’] ) ? $custom_var[‘swpm_id’] : ”;
if( empty( $txn_data[‘member_id’] ) ){
$txn_data[‘member_id’] = isset ( $ipn_data[‘member_id’] ) ? $ipn_data[‘member_id’] : ”;
}
`The value is also set on the other side:
`php
// ipn/swpm_handle_subsc_ipn.php (4.7.2, line 513)
$ipn_data[‘member_id’] = $swpm_id;
`However, that function receives
$ipn_databy value:`php
// ipn/swpm_handle_subsc_ipn.php (4.7.2, line 491)
function swpm_update_member_subscription_start_date_if_applicable( $ipn_data ) {
`Because PHP passes arrays by value, the assignment inside the function does not reach the caller. The PayPal webhook handler also does not use a return value:
`php
// lib/paypal/class-swpm-paypal-webhook-event-handler.php (4.7.2, lines 192-195)
swpm_update_member_subscription_start_date_if_applicable( $ipn_data );
…
SwpmTransactions::save_txn_record( $ipn_data, array() );
`So when
save_txn_record()runs,$ipn_data['member_id']is still unset, and recurring payments for PPCP subscriptions continue to be saved with an emptymember_id. I may be reading this wrong, but this is what the 4.7.2 source suggests.For reference, the admin payments list already has a similar fallback. When
member_idis empty, it looks the member up fromsubscr_id(classes/admin-includes/class.swpm-payments-list-table.php, around line 57). The same idea could be applied on the save side.## Why this matters
Because the payment rows are not linked to a member in the database, anything that relies on
member_id(lookups, reports, aggregation) misses them. In practice, we have to link these payments by hand after receiving support requests.## Suggested fix
Any one of these should be enough:
– Make
swpm_update_member_subscription_start_date_if_applicable()take$ipn_databy reference (&$ipn_data), or have it return the modified array and use that in the caller.
– Alternatively, as a last resort insave_txn_record(), look the member up fromsubscr_id. The function already callsSwpmMemberUtils::get_user_by_subsriber_id( $subscr_id )a few lines later (forextra_info), so the lookup logic already exists.
– Once the member is known, update the custom value stored in theswpm_transactionsCPT, so that all later recurring payments are handled correctly automatically.
– If asubscr_idfallback is added, it may need to handle the case where several member records share the samesubscr_id. In our environment we have seen a small number of such duplicates.Thank you for your work on the plugin and for the 4.7.2 improvement in this area. Happy to share sanitized log excerpts if useful.
October 17, 2026 at 6:54 am #32389admin
KeymasterThank you. I will look into it and apply a fix.
-
AuthorPosts
- You must be logged in to reply to this topic.