Skip to content
This repository was archived by the owner on Mar 15, 2018. It is now read-only.

Commit 3ee43d6

Browse files
committed
require user to log in to install a paid app with price "0.00" to record+generate receipt (bug 889501)
1 parent 70116e8 commit 3ee43d6

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

hearth/media/js/buttons.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ define('buttons',
4747

4848
tracking.trackEvent(
4949
'Click to install app',
50-
product.payment_required ? 'paid' : 'free',
50+
product.receipt_required ? 'paid' : 'free',
5151
product.name + ':' + product.id,
5252
$('.button.product').index($button)
5353
);
@@ -76,7 +76,7 @@ define('buttons',
7676

7777
tracking.trackEvent(
7878
'Successful app install',
79-
product.payment_required ? 'paid' : 'free',
79+
product.receipt_required ? 'paid' : 'free',
8080
product.name + ':' + product.id,
8181
$('.button.product').index($button)
8282
);

hearth/media/js/install.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,20 @@ define('install',
2222
z.apps[product.manifest_url].launch();
2323
tracking.trackEvent(
2424
'Launch app',
25-
product.payment_required ? 'Paid' : 'Free',
25+
product.receipt_required ? 'Paid' : 'Free',
2626
product.slug
2727
);
2828
});
2929

3030
var installHandler = _handler(startInstall);
3131

3232
function startInstall(product) {
33-
if (product.payment_required && !user.logged_in()) {
33+
// TODO: Have the API possibly return this (bug 889501).
34+
product.receipt_required = premium_type != 'free' && premium_type != 'free-inapp';
35+
36+
// If we have a premium app (even if it's '$0.00'), require the user
37+
// to first log so we can record the purchase and generate a receipt.
38+
if (product.receipt_required && !user.logged_in()) {
3439
console.log('Install suspended; user needs to log in');
3540
return login.login().done(function() {
3641
startInstall(product);
@@ -41,7 +46,7 @@ define('install',
4146
}
4247

4348
console.log('Starting app installation');
44-
if (product.payment_required) {
49+
if (product.receipt_required) {
4550
return purchase(product);
4651
} else {
4752
return install(product);
@@ -105,9 +110,9 @@ define('install',
105110

106111
var def = defer.Deferred();
107112
// NOTE: We don't want to check `payment_required` because
108-
// even a paid app with a price of '0.00' should still hit the
113+
// even a paid app with a price of '$0.00' should still hit the
109114
// API endpoint for receipt creation (bug 886568).
110-
requests.post(urls.api.url('record_' + (product.price == null ? 'free' : 'paid')),
115+
requests.post(urls.api.url('record_' + (product.receipt_required ? 'paid' : 'free')),
111116
post_data).done(function(response) {
112117
if (response.error) {
113118
$('#pay-error').show().find('div').text(response.error);

hearth/media/js/payments/payments.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ define('payments/payments',
5959
}
6060

6161
function beginPurchase(product) {
62-
if (!product) return;
62+
if (!product || !product.payment_required) return;
6363
var $def = defer.Deferred();
6464

6565
console.log('Initiating transaction');

0 commit comments

Comments
 (0)