From ed7823f57716022a3cd00c2c84f7763e5e526760 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 22 Feb 2015 05:39:17 -0800 Subject: [PATCH] Allow subscriptions to decline to generate an invoice Summary: This is a useful capability in Phacility for disabled/suspended instances. Test Plan: Used `bin/phortune invoice` to invoice a disabled instance, saw it decline to invoice. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Differential Revision: https://secure.phabricator.com/D11837 --- .../phortune/storage/PhortuneSubscription.php | 7 +++++++ .../subscription/PhortuneSubscriptionImplementation.php | 7 +++++++ .../phortune/worker/PhortuneSubscriptionWorker.php | 8 +++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/applications/phortune/storage/PhortuneSubscription.php b/src/applications/phortune/storage/PhortuneSubscription.php index b18a8718f0..cc839adbea 100644 --- a/src/applications/phortune/storage/PhortuneSubscription.php +++ b/src/applications/phortune/storage/PhortuneSubscription.php @@ -207,6 +207,13 @@ final class PhortuneSubscription extends PhortuneDAO $end_epoch); } + public function shouldInvoiceForBillingPeriod($start_epoch, $end_epoch) { + return $this->getImplementation()->shouldInvoiceForBillingPeriod( + $this, + $start_epoch, + $end_epoch); + } + public function getPurchaseName( PhortuneProduct $product, PhortunePurchase $purchase) { diff --git a/src/applications/phortune/subscription/PhortuneSubscriptionImplementation.php b/src/applications/phortune/subscription/PhortuneSubscriptionImplementation.php index b94b245df8..ad5126cf65 100644 --- a/src/applications/phortune/subscription/PhortuneSubscriptionImplementation.php +++ b/src/applications/phortune/subscription/PhortuneSubscriptionImplementation.php @@ -22,6 +22,13 @@ abstract class PhortuneSubscriptionImplementation { $start_epoch, $end_epoch); + public function shouldInvoiceForBillingPeriod( + PhortuneSubscription $subscription, + $start_epoch, + $end_epoch) { + return true; + } + public function getCartName( PhortuneSubscription $subscription, PhortuneCart $cart) { diff --git a/src/applications/phortune/worker/PhortuneSubscriptionWorker.php b/src/applications/phortune/worker/PhortuneSubscriptionWorker.php index 272be2c5a2..233eb5dccb 100644 --- a/src/applications/phortune/worker/PhortuneSubscriptionWorker.php +++ b/src/applications/phortune/worker/PhortuneSubscriptionWorker.php @@ -8,6 +8,13 @@ final class PhortuneSubscriptionWorker extends PhabricatorWorker { $range = $this->getBillingPeriodRange($subscription); list($last_epoch, $next_epoch) = $range; + $should_invoice = $subscription->shouldInvoiceForBillingPeriod( + $last_epoch, + $next_epoch); + if (!$should_invoice) { + return; + } + $account = $subscription->getAccount(); $merchant = $subscription->getMerchant(); @@ -21,7 +28,6 @@ final class PhortuneSubscriptionWorker extends PhabricatorWorker { $cart_implementation = id(new PhortuneSubscriptionCart()) ->setSubscription($subscription); - // TODO: This isn't really ideal. It would be better to use an application // actor than the original author of the subscription. In particular, if // someone initiates a subscription, adds some other account managers, and