Skip to content

Commit

Permalink
dont skip non existent subscriptions on stripe
Browse files Browse the repository at this point in the history
  • Loading branch information
proditis committed Nov 18, 2024
1 parent 386a968 commit 3d9dff6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion backend/modules/sales/commands/CronController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function actionExpireSubscriptions($active = false, $interval = 1440)
foreach ($playerSubs->all() as $rec) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($rec->StripeCompare() !== true) {
if ($rec->StripeCompare(true) !== true) {
printf("Stripe do not agree: %s %s => %s\n", $rec->player->username, $rec->player->email, $rec->subscription_id);
if ($rec->StripeSync() === false) {
printf("Failed to sync and update: %s %s => %s\n", $rec->player->username, $rec->player->email, $rec->subscription_id);
Expand Down
11 changes: 8 additions & 3 deletions backend/modules/sales/models/PlayerSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,20 @@ public static function DeleteInactive(): int
* @return bool - If data are the same or subscription is sub_vip returns true
* @throws Exception|UserException - When stripe error occurs or data problems
*/
public function StripeCompare()
public function StripeCompare($invalid_returns=false): bool
{
if ($this->subscription_id === 'sub_vip')
return true;

$stripe = new \Stripe\StripeClient(\Yii::$app->sys->stripe_apiKey);
$stripe_subscription = $stripe->subscriptions->retrieve($this->subscription_id, []);
try {
$stripe_subscription = $stripe->subscriptions->retrieve($this->subscription_id, []);
} catch (\Stripe\Exception\InvalidRequestException $e) {
return $invalid_returns;
}


if(intval(\Yii::$app->formatter->asTimestamp($this->starting))!==intval($stripe_subscription->current_period_start) || intval(\Yii::$app->formatter->asTimestamp($this->ending))!==intval($stripe_subscription->current_period_end))
if (intval(\Yii::$app->formatter->asTimestamp($this->starting)) !== intval($stripe_subscription->current_period_start) || intval(\Yii::$app->formatter->asTimestamp($this->ending)) !== intval($stripe_subscription->current_period_end))
return false;

if (intval($this->active) !== intval($stripe_subscription->items->data[0]->plan->active) || $this->price_id != $stripe_subscription->items->data[0]->plan->id)
Expand Down

0 comments on commit 3d9dff6

Please sign in to comment.