Skip to content

Commit

Permalink
Insights email: If Payment due, show an alert to update payment info
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed Jun 26, 2015
1 parent 631986c commit 0cb5c60
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ private function sendDigestSinceWithTemplate($owner, $start, $template, &$option
}
}
} else {
//Check subscription status and show a message if Payment failed
//@TODO Handle Payment due state here as well
//Check subscription status and show a message if Payment failed or due
$logger->logUserInfo("User is not in free trial; check subscription status",
__METHOD__.','.__LINE__);

Expand All @@ -327,20 +326,21 @@ private function sendDigestSinceWithTemplate($owner, $start, $template, &$option
__METHOD__.','.__LINE__);

if (isset($membership_details->subscription_status)
&& $membership_details->subscription_status == 'Payment failed') {
&& ($membership_details->subscription_status == 'Payment failed'
|| $membership_details->subscription_status == 'Payment due')) {

$logger->logUserInfo("Owner has payment failure; include alert in email",
__METHOD__.','.__LINE__);

$payment_failed_copy = array ();
$payment_failed_copy[] = array(
'headline'=>'Oops! Your account needs attention',
'explainer' => "We had a problem processing your last membership payment. "
'explainer' => "We had a problem processing your membership payment. "
."But it's easy to fix."
);
$payment_failed_copy[] = array(
'headline'=>'Uh oh, problem with your subscription...',
'explainer' => "There was a problem processing your last membership payment. "
'explainer' => "There was a problem processing your membership payment. "
."To fix it, update your payment info."
);
$payment_failed_copy[] = array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,49 @@ public function testMandrillHTMLDailyPaymentFailed() {
$owner_builder = null;
}

public function testMandrillHTMLDailyPaymentDue() {
unlink(FileDataManager::getDataPath(Mailer::EMAIL));
$plugin = new InsightsGeneratorPlugin();
$config = Config::getInstance();
$config->setValue('mandrill_api_key','1234');
$config->setValue('thinkupllc_endpoint', 'http://example.com/thinkup/');

$plugin_dao = DAOFactory::getDAO('PluginDAO');
$plugin_id = $plugin_dao->getPluginId($plugin->folder_name);
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$long_ago = date('Y-m-d', strtotime('-7 day'));
$plugin_option_dao->insertOption($plugin_id, 'mandrill_template', $template = 'my_template');
$plugin_option_dao->insertOption($plugin_id, 'last_daily_email', $long_ago);
$options = $plugin_option_dao->getOptionsHash($plugin->folder_name, true);
$builders = self::buildDataForDailyEmailFreeTrial();

$i = 0;
while ($i < 5) {
$owner_builder = FixtureBuilder::build('owners', array('id'=>1, 'full_name'=>'ThinkUp Q. User',
'is_admin'=>1, 'email'=>'paymentdue@example.com', 'is_activated'=>1,
'email_notification_frequency' => 'daily', 'timezone' => 'America/New_York',
'is_free_trial'=>0, 'joined'=>'-'.$i.'d', 'membership_level'=>'Member'));
$this->simulateLogin('paymentdue@example.com');
$plugin->current_timestamp = strtotime('5pm');
//Cycle through the 5 copy options for when a payment fails
TimeHelper::setDayOfYear($i);
$plugin->crawl();
$sent = Mailer::getLastMail();
$merge_vars = array();
$decoded = json_decode($sent);
foreach ($decoded->global_merge_vars as $mv) {
$merge_vars[$mv->name] = $mv->content;
}
$html_email = $merge_vars['insights'];
$this->debug($html_email);
$this->assertPattern('/Update your payment info/', $html_email);
unlink(FileDataManager::getDataPath(Mailer::EMAIL));
$plugin_option_dao->updateOption($options['last_daily_email']->id, 'last_daily_email', $long_ago);
$owner_builder = null;
$i++;
}
}

/**
* Add just enough data to generate an email.
* @return arr FixtureBuilders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public function getSubscriptionStatus($email) {
"email":"paymentfailed@example.com",
"subscription_status":"Payment failed"
}
EOD;
return JSONDecoder::decode($resp);
} elseif ($email == 'paymentdue@example.com') {
$resp = <<<EOD
{
"email":"paymentdue@example.com",
"subscription_status":"Payment due"
}
EOD;
return JSONDecoder::decode($resp);
} elseif ($email == 'paid@example.com') {
Expand Down

0 comments on commit 0cb5c60

Please sign in to comment.