Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong message issue when the user has canceled the subscription #122

Open
kjnanda opened this issue Nov 18, 2019 · 1 comment
Open

Wrong message issue when the user has canceled the subscription #122

kjnanda opened this issue Nov 18, 2019 · 1 comment
Assignees
Labels
Milestone

Comments

@kjnanda
Copy link

kjnanda commented Nov 18, 2019

Upon canceling the subscription, the user is getting the mail notification for cancel subscription which tell the user that You have canceled the subscription which is ✅

But the Dashboard shows this message(screenshot) which is completely misleading.
We are conveying different information in mail and dashboard. This should be fixed.

The users are clueless about what action needs to be performed in this scenario as he himself is not aware that it is cause of cancel subscription event.

Transcoder_‹krupa_dev5_rt_gw—_WordPress

@Pathan-Amaankhan
Copy link
Member

Hello @gagan0123,

Every time the page loads we fire the following function & update the rt-transcoding-usage key in our options table.

public function update_usage( $key ) {
$usage_url = trailingslashit( $this->transcoding_api_url ) . 'usage/' . $key;
if ( function_exists( 'vip_safe_wp_remote_get' ) ) {
$usage_page = vip_safe_wp_remote_get( $usage_url, '', 3, 3 );
} else {
$usage_page = wp_safe_remote_get( $usage_url ); // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.wp_remote_get_wp_remote_get
}
if ( ! is_wp_error( $usage_page ) ) {
$usage_info = json_decode( $usage_page['body'] );
} else {
$usage_info = null;
}
update_site_option( 'rt-transcoding-usage', array( $key => $usage_info ) );
return $usage_info;
}

If we are having a subscription then we get the following response, which is later saved in our options table.

"499b3375698cf000135d390f6729780b" => [
    "status"     => 1, 
    "product"    => "162172",
    "price_id"   => "1", 
    "expires"    => "2023-03-03 23:59:59", 
    "valid_from" => "2023-01-31 00:00:00", 
    "msg"        => "Authorized", 
    "usage"      => 0,
    "plan"       => [
        "id"              => "162172-1", 
	"name"            => "FREE", 
	"description"     => "", 
	"status"          => 1, 
	"price_per_month" => 0, 
	"bandwidth"       => 10, 
	"filesize"        => 0.1953125, 
	"overcharge"      => 0, 
	"expires"         => "2023-03-03 23:59:59", 
	"plan_slug"       => "free" 
    ],
    "used"       => 0, 
    "total"      => 5368709120, 
    "sub_status" => 1,
    "remaining"  => 5368709120,
]

Whereas if there is no subscription attached to our API key then we get the following result, which is later saved in our options table. (This happens if we are having an API key saved in our DB but the subscription in it has expired or canceled).

"499b3375698cf000135d390f6729780b" => [ 
    "status" => "error", 
    "msg"    => "Subscription is not active.", 
]

This way we are checking the status of our API key on every visit to our admin.

Now while displaying the usage widget on our admin page we are having a condition that should give us a false when our subscription is expired or canceled.

}
if ( ! empty( $api_key ) ) {
if ( $usage_details && isset( $usage_details[ $api_key ]->status ) && $usage_details[ $api_key ]->status ) {

But as there is no specific check for status !== error we are unable to go in else condition i.e.

} else {
$content .= '<div class="error below-h2"><p>' . esc_html__( 'Your API key is not valid or is expired.', 'transcoder' ) . '</p></div>';
}

So, the conclusion is,
By adding a condition that checks our status we can resolve the above bug...


After updating the condition we will be getting the following results:

Screenshot 2023-01-31 at 8 39 54 PM

Please let me know if this approach sounds good & we can go ahead.

cc: @aviral-mittal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants