Skip to content

Commit b0b6c46

Browse files
authored
Merge pull request #1175 from imgbot/backup_queue_update
chore: added backup message for cancelled subscription
2 parents c2cfffb + b659e0d commit b0b6c46

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

Common/Messages/BackupMessage.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class BackupMessage
66

77
public string SaleType { get; set; }
88

9+
public string BillingCycle { get; set; }
10+
911
public int Price { get; set; }
1012
}
1113
}

CompressImagesFunction/host.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
},
77
"extensions": {
88
"queues": {
9-
"batchSize": 2
9+
"batchSize": 2,
10+
"maxDequeueCount" : 2,
11+
"newBatchThreshold" : 1
1012
}
1113
}
1214
}

WebHook/Model/Hook.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,15 @@ public class MarketplacePurchase
336336
public Account account { get; set; }
337337

338338
public Plan plan { get; set; }
339+
public string billing_cycle { get; set; }
339340
public bool? on_free_trial { get; set; }
340341
}
341342

342343
public class Plan
343344
{
344345
public int id { get; set; }
345346
public int monthly_price_in_cents { get; set; }
347+
public int yearly_price_in_cents { get; set; }
346348
}
347349
}
348350
}

WebHook/WebHookFunction.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,12 +360,20 @@ private static async Task<string> ProcessMarketplacePurchaseAsync(Hook hook, Clo
360360
}
361361
}
362362

363+
var price = hook.marketplace_purchase.plan.monthly_price_in_cents / 100;
364+
365+
if (hook.marketplace_purchase.billing_cycle == "yearly")
366+
{
367+
price = hook.marketplace_purchase.plan.yearly_price_in_cents / 100;
368+
}
369+
363370
await backupMessages.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(
364371
new BackupMessage
365372
{
366373
PlanId = hook.marketplace_purchase.plan.id,
367-
Price = hook.marketplace_purchase.plan.monthly_price_in_cents / 100,
368-
SaleType = recurrentSale
374+
Price = price,
375+
SaleType = recurrentSale,
376+
BillingCycle = hook.marketplace_purchase.billing_cycle
369377
})));
370378
}
371379

@@ -387,6 +395,26 @@ await marketplaceTable.ExecuteAsync(TableOperation.InsertOrMerge(new Marketplace
387395
return hook.action;
388396
case "cancelled":
389397
await marketplaceTable.DropRow(hook.marketplace_purchase.account.id, hook.marketplace_purchase.account.login);
398+
if (KnownGitHubs.Plans.ContainsKey(hook.marketplace_purchase.plan.id) &&
399+
KnownGitHubs.Plans[hook.marketplace_purchase.plan.id] != 0)
400+
{
401+
var price = hook.marketplace_purchase.plan.monthly_price_in_cents / 100;
402+
403+
if (hook.marketplace_purchase.billing_cycle == "yearly")
404+
{
405+
price = hook.marketplace_purchase.plan.yearly_price_in_cents / 100;
406+
}
407+
408+
await backupMessages.AddMessageAsync(new CloudQueueMessage(JsonConvert.SerializeObject(
409+
new BackupMessage
410+
{
411+
PlanId = hook.marketplace_purchase.plan.id,
412+
Price = price,
413+
SaleType = "cancelled",
414+
BillingCycle = hook.marketplace_purchase.billing_cycle
415+
})));
416+
}
417+
390418
logger.LogInformation("ProcessMarketplacePurchaseAsync/cancelled {PlanId} for {Owner}", hook.marketplace_purchase.plan.id, hook.marketplace_purchase.account.login);
391419
return "cancelled";
392420
default:

0 commit comments

Comments
 (0)