Sync data from Stripe manually created subscription

EDITED to explain myself better :slight_smile:

Hello

There is a customer that have an active subscription in Stripe. He cancelled the suscription from the site and the subscription was correctly cancelled in Stripe.

I comment this in order to explain that the user account is correctly linked to Stripre but with non actived subscriptions.

Once the subscription was cancelled in both sides, I have created a subscription manually in Stripe and I have copied Customer and Sub ID to S2Member to S2Member.

I also have asigned the correct subscription level to customer.

I hope this will be enought to vinculate the Stipe Subsction with the S2member subscription in order, for example, to allow user to cancell it

Do you think this will work.

I have realized that in the customer page doesn’t appear the “Next payment” information.

Do you know if it’s possible to sync or import this info from Stripe?

Thanks!

1 Like

Hi Carlos.

It sounds like you did enough: added to the user’s profile the gateway, customer ID and subscr ID.

What are you using to get the next payment, and is it working for other customers?

:slight_smile:

Hi

I use [s2Eot /]

oh… And it’s working for other customers. :smile:

I have tried resending some hooks from Stripe but it didn’t work

Okay.

It seems that s2 is not being able to retrieve that customer’s subscription details to calculate the next payment time.

What do your logs (s2’s and Stripe’s) say? Anything related to the customer or subscr IDs? WP Admin > s2Member > Log Files and https://dashboard.stripe.com/logs

I haven’t seen any thing of intereset.

S2member logging is deactivated. I can activate it but I don’t know how to force S2Member to get next payment time info.

In Stripre, i can’t see any interesting thing about this customer in the log files.

I think the point is… When does S2Member tries to get the Next Payment Time of a subscription that was created manually in stripe and not from S2member?

Regards

s2 Member doesn’t connect to Stripe just because you added stripe details to the user account.

The s2Eot shortcode will try to figure out the Next Payment Time if there isn’t an EOT time in that user’s profile. To do that, it’ll try getting the user’s Stripe subscription details with the IDs from his profile.

So s2 will connect to the Stripe API when the s2Eot shortcode is used for that user. That would be logged in the Stripe logs on their side, and if you enabled s2’s logging, also on s2’s side.

So I’d like to know what those logs say, to help me understand what could be the reason that you don’t get a Next Payment Time for that user.

:slight_smile:

Hi Cristian, thanks for your support.

I have activated the logs and opened the page wheres EOT info is showed.

I attach de Stripe Log in S2member. There is no entry in Stripe in the logs for this event.

------------------------ STRIPE-API.LOG -------------------------

I have replaced some texts like MySite
I have replaced all IDs by xxxxxxxxxIDok or similar if i have found it in Stripe
I have replaced something like “si_–NofFoundInStripe-ID” if I haven’t found thar ID in Stripe

I have realiced that [days_until_due] is returning blank.

LOG ENTRY: Tue Mar 9th, 2021 @ precisely 11:24 pm UTC
PHP v7.3.27 :: WordPress v5.6.2 :: s2Member v210208 :: s2Member Pro v210208
Memory 31.18 MB :: Real Memory 12.00 MB :: Peak Memory 32.07 MB :: Real Peak Memory 12.00 MB
mysite.com/wellcomepageOK/
User-Agent: Mozilla/5.0 (Linux; Android 10; Mi A2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.86 Mobile Safari/537.36
-------- Function/Caller: ( get_customer_subscription ) --------
-------- Input vars: ( Tue, 09 Mar 21 23:24:01 +0000 ) --------
Array
(
    [customer_id] => cus_xxxxxxxxIDok
    [subscription_id] => sub_xxxxxxxxxIDok
    [input_time] => 1615332241
)

-------- Output string/vars: ( Tue, 09 Mar 21 23:24:02 +0000 ) --------
Stripe\Subscription Object
(
    [id] => sub_xxxxxxxxxIDok
    [object] => subscription
    [application_fee_percent] => 
    [billing] => charge_automatically
    [billing_cycle_anchor] => 1615213274
    [billing_thresholds] => 
    [cancel_at] => 
    [cancel_at_period_end] => 
    [canceled_at] => 
    [collection_method] => charge_automatically
    [created] => 1615213274
    [current_period_end] => 1617891674
    [current_period_start] => 1615213274
    [customer] => cus_xxxxxxxxIDok
    [days_until_due] => 
    [default_payment_method] => 
    [default_source] => 
    [default_tax_rates] => Array
        (
        )

    [discount] => 
    [ended_at] => 
    [invoice_customer_balance_settings] => Stripe\StripeObject Object
        (
            [consume_applied_balance_on_void] => 1
        )

    [items] => Stripe\Collection Object
        (
            [object] => list
            [data] => Array
                (
                    [0] => Stripe\SubscriptionItem Object
                        (
                            [id] => si_--NofFoundInStripe-ID
                            [object] => subscription_item
                            [billing_thresholds] => 
                            [created] => 1615213275
                            [metadata] => Stripe\StripeObject Object
                                (
                                )

                            [plan] => Stripe\Plan Object
                                (
                                    [id] => price_xxxxxxxxxxxxIDok
                                    [object] => plan
                                    [active] => 1
                                    [aggregate_usage] => 
                                    [amount] => 12000
                                    [amount_decimal] => 12000
                                    [billing_scheme] => per_unit
                                    [created] => 1615213267
                                    [currency] => eur
                                    [interval] => month
                                    [interval_count] => 1
                                    [livemode] => 1
                                    [metadata] => Stripe\StripeObject Object
                                        (
                                        )

                                    [nickname] => 
                                    [product] => prod_xxxxxxxxxIDOk
                                    [tiers] => 
                                    [tiers_mode] => 
                                    [transform_usage] => 
                                    [trial_period_days] => 
                                    [usage_type] => licensed
                                )

                            [price] => Stripe\StripeObject Object
                                (
                                    [id] => price_xxxxxxxxxxxxIDok
                                    [object] => price
                                    [active] => 1
                                    [billing_scheme] => per_unit
                                    [created] => 1615213267
                                    [currency] => eur
                                    [livemode] => 1
                                    [lookup_key] => 
                                    [metadata] => Stripe\StripeObject Object
                                        (
                                        )

                                    [nickname] => 
                                    [product] => prod_xxxxxxxxxIDOk
                                    [recurring] => Stripe\StripeObject Object
                                        (
                                            [aggregate_usage] => 
                                            [interval] => month
                                            [interval_count] => 1
                                            [trial_period_days] => 
                                            [usage_type] => licensed
                                        )

                                    [tiers_mode] => 
                                    [transform_quantity] => 
                                    [type] => recurring
                                    [unit_amount] => 12000
                                    [unit_amount_decimal] => 12000
                                )

                            [quantity] => 1
                            [subscription] => sub_xxxxxxxxxIDok
                            [tax_rates] => Array
                                (
                                )

                        )

                )

            [has_more] => 
            [total_count] => 1
            [url] => /v1/subscription_items?subscription=sub_xxxxxxxxxIDok
        )

    [latest_invoice] => in_xxxxInvoiceIDOk
    [livemode] => 1
    [metadata] => Stripe\StripeObject Object
        (
        )

    [next_pending_invoice_item_invoice] => 
    [pause_collection] => 
    [pending_invoice_item_interval] => 
    [pending_setup_intent] => 
    [pending_update] => 
    [plan] => Stripe\Plan Object
        (
            [id] => price_xxxxxxxxxxxxIDok
            [object] => plan
            [active] => 1
            [aggregate_usage] => 
            [amount] => 12000
            [amount_decimal] => 12000
            [billing_scheme] => per_unit
            [created] => 1615213267
            [currency] => eur
            [interval] => month
            [interval_count] => 1
            [livemode] => 1
            [metadata] => Stripe\StripeObject Object
                (
                )

            [nickname] => 
            [product] => prod_xxxxxxxxxIDOk
            [tiers] => 
            [tiers_mode] => 
            [transform_usage] => 
            [trial_period_days] => 
            [usage_type] => licensed
        )

    [quantity] => 1
    [schedule] => 
    [start] => 1615213274
    [start_date] => 1615213274
    [status] => active
    [tax_percent] => 
    [transfer_data] => 
    [trial_end] => 
    [trial_start] => 
)
LOG ENTRY: Tue Mar 9th, 2021 @ precisely 11:24 pm UTC
PHP v7.3.27 :: WordPress v5.6.2 :: s2Member v210208 :: s2Member Pro v210208
Memory 32.14 MB :: Real Memory 20.00 MB :: Peak Memory 33.83 MB :: Real Peak Memory 20.00 MB
mysite.com/ecr/
User-Agent: Mozilla/5.0 (Linux; Android 10; Mi A2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.86 Mobile Safari/537.36
-------- Function/Caller: ( get_customer_subscription ) --------
-------- Input vars: ( Tue, 09 Mar 21 23:24:11 +0000 ) --------
Array
(
    [customer_id] => cus_xxxxxxxxIDok
    [subscription_id] => sub_xxxxxxxxxIDok
    [input_time] => 1615332251
)

-------- Output string/vars: ( Tue, 09 Mar 21 23:24:11 +0000 ) --------
Stripe\Subscription Object
(
    [id] => sub_xxxxxxxxxIDok
    [object] => subscription
    [application_fee_percent] => 
    [billing] => charge_automatically
    [billing_cycle_anchor] => 1615213274
    [billing_thresholds] => 
    [cancel_at] => 
    [cancel_at_period_end] => 
    [canceled_at] => 
    [collection_method] => charge_automatically
    [created] => 1615213274
    [current_period_end] => 1617891674
    [current_period_start] => 1615213274
    [customer] => cus_xxxxxxxxIDok
    [days_until_due] => 
    [default_payment_method] => 
    [default_source] => 
    [default_tax_rates] => Array
        (
        )

    [discount] => 
    [ended_at] => 
    [invoice_customer_balance_settings] => Stripe\StripeObject Object
        (
            [consume_applied_balance_on_void] => 1
        )

    [items] => Stripe\Collection Object
        (
            [object] => list
            [data] => Array
                (
                    [0] => Stripe\SubscriptionItem Object
                        (
                            [id] => si_--NofFoundInStripe-ID
                            [object] => subscription_item
                            [billing_thresholds] => 
                            [created] => 1615213275
                            [metadata] => Stripe\StripeObject Object
                                (
                                )

                            [plan] => Stripe\Plan Object
                                (
                                    [id] => price_xxxxxxxxxxxxIDok
                                    [object] => plan
                                    [active] => 1
                                    [aggregate_usage] => 
                                    [amount] => 12000
                                    [amount_decimal] => 12000
                                    [billing_scheme] => per_unit
                                    [created] => 1615213267
                                    [currency] => eur
                                    [interval] => month
                                    [interval_count] => 1
                                    [livemode] => 1
                                    [metadata] => Stripe\StripeObject Object
                                        (
                                        )

                                    [nickname] => 
                                    [product] => prod_xxxxxxxxxIDOk
                                    [tiers] => 
                                    [tiers_mode] => 
                                    [transform_usage] => 
                                    [trial_period_days] => 
                                    [usage_type] => licensed
                                )

                            [price] => Stripe\StripeObject Object
                                (
                                    [id] => price_xxxxxxxxxxxxIDok
                                    [object] => price
                                    [active] => 1
                                    [billing_scheme] => per_unit
                                    [created] => 1615213267
                                    [currency] => eur
                                    [livemode] => 1
                                    [lookup_key] => 
                                    [metadata] => Stripe\StripeObject Object
                                        (
                                        )

                                    [nickname] => 
                                    [product] => prod_xxxxxxxxxIDOk
                                    [recurring] => Stripe\StripeObject Object
                                        (
                                            [aggregate_usage] => 
                                            [interval] => month
                                            [interval_count] => 1
                                            [trial_period_days] => 
                                            [usage_type] => licensed
                                        )

                                    [tiers_mode] => 
                                    [transform_quantity] => 
                                    [type] => recurring
                                    [unit_amount] => 12000
                                    [unit_amount_decimal] => 12000
                                )

                            [quantity] => 1
                            [subscription] => sub_xxxxxxxxxIDok
                            [tax_rates] => Array
                                (
                                )

                        )

                )

            [has_more] => 
            [total_count] => 1
            [url] => /v1/subscription_items?subscription=sub_xxxxxxxxxIDok
        )

    [latest_invoice] => in_xxxxInvoiceIDOk
    [livemode] => 1
    [metadata] => Stripe\StripeObject Object
        (
        )

    [next_pending_invoice_item_invoice] => 
    [pause_collection] => 
    [pending_invoice_item_interval] => 
    [pending_setup_intent] => 
    [pending_update] => 
    [plan] => Stripe\Plan Object
        (
            [id] => price_xxxxxxxxxxxxIDok
            [object] => plan
            [active] => 1
            [aggregate_usage] => 
            [amount] => 12000
            [amount_decimal] => 12000
            [billing_scheme] => per_unit
            [created] => 1615213267
            [currency] => eur
            [interval] => month
            [interval_count] => 1
            [livemode] => 1
            [metadata] => Stripe\StripeObject Object
                (
                )

            [nickname] => 
            [product] => prod_xxxxxxxxxIDOk
            [tiers] => 
            [tiers_mode] => 
            [transform_usage] => 
            [trial_period_days] => 
            [usage_type] => licensed
        )

    [quantity] => 1
    [schedule] => 
    [start] => 1615213274
    [start_date] => 1615213274
    [status] => active
    [tax_percent] => 
    [transfer_data] => 
    [trial_end] => 
    [trial_start] => 
)

Thanks for the log entries!

I think I see the problem. Those are missing the metadata s2Member adds to the plan.

Go to one of the subscriptions you sold through s2, open its plan (id will start with s2_plan_) and copy the metadata. Here’s a link to the plan from one of my tests: https://dashboard.stripe.com/test/prices/s2_plan_a97b9b42320d9ke8j4f9df1fe405b417

Screenshot_2021-03-10%20Products%20%E2%80%93%20Cristi%C3%A1n%20L%C3%A1vaque%20%E2%80%93%20Stripe%20%5BTest%5D

Then go edit the subscription you created manually, edit its plan, and add the missing metadata.

Let me know how it goes. :slight_smile:

Thanks…

I did it and didn’t work

I have a guess… May it be that the subscription was created with a monthly period and S2Member requires a period expressed in days?

That could affect another part, but not this. The EOT time calculation uses the current_period_end, which is a timestamp, so the interval unit is not relevant.

Okay, so you added the metadata and it didn’t change the behavior… hmm… Does the plan metadata now show up in the log entry?

s2member/src/includes/classes/utils-users.inc.php

					if(isset($stripe_subscription->plan->metadata->recurring, $stripe_subscription->plan->metadata->recurring_times)
						&& $stripe_subscription->plan->metadata->recurring && $stripe_subscription->plan->metadata->recurring_times <= 0)
					{
						if($stripe_subscription->current_period_end + 1 > $now)
						{
							$time = $stripe_subscription->current_period_end + 1;
							return array('type' => 'next', 'time' => $time, 'tense' => $time <= $now ? 'past' : 'future',
								'debug' => 'The Stripe API says this is the next payment time.');
						}
						return array_merge($empty_response, array('debug' => 'Stripe says no more payments needed from this user.'));
					}

That’s the condition for the block that gives you the next itme. As you can see it’s looking for the metadata recurring (not a non-recurring subscription) and recurring_times (not an installments plan).

So if the metadata for the plan is there, and it gets to that condition, I think it should be giving you the NPT. Are you sure you are not seeing a cache of the page from before making this change?