This file is indexed.

/usr/share/payui/qml/payui.qml is in pay-ui 15.10+16.04.20160324.1-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/*
 * Copyright 2014-2016 Canonical Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; version 3.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import QtQuick 2.4
import QtQuick.LocalStorage 2.0
import Ubuntu.Components 1.3
import Ubuntu.Components.Popups 1.3
import Ubuntu.OnlineAccounts 0.1
import Ubuntu.OnlineAccounts.Client 0.1
import payui 0.1
import "ui"

/*!
    states:
        - add-payment
        - buy-interaction
        - checkout
        - online-accounts
        - error
*/

MainView {
    id: mainView
    // objectName for functional testing purposes (autopilot-qt5)
    objectName: "payui"

    // NOTE: Must match the gettext domain for translations.
    applicationName: "pay-service"

    /*
     This property enables the application to change orientation
     when the device is rotated. The default is false.
    */
    // automaticOrientation: true

    width: units.gu(100)
    height: units.gu(75)

    property bool loading: false
    property bool purchasing: false
    property bool recentLogin: false
    property bool cancellable: true
    property string suggestedCurrency: "USD"

    backgroundColor: "transparent"

    onStateChanged: {
        mainView.backgroundColor = "white";
    }

    AccountServiceModel {
        id: accounts
        provider: "ubuntuone"
    }

    Setup {
        id: setup
        applicationId: "pay-service"
        providerId: "ubuntuone"

        onFinished: {
            mainView.recentLogin = true;
            mainView.showLoading();
            purchase.checkCredentials();
        }
    }

    Purchase {
        id: purchase

        onItemDetailsObtained: {
            suggestedCurrency = currency;
            checkout.itemIcon = icon;
            checkout.itemTitle = title;
            checkout.itemSubtitle = publisher;
            checkout.price = formatted_price;
            purchase.getPaymentTypes(currency);
        }

        onPaymentTypesObtained: {
            mainView.recentLogin = mainView.recentCredentials();
            checkout.beforeTimeout = mainView.recentLogin;

            // Check for selected payment, and keep it selected if so.
            if (checkout.hasSelectedPayment) {
                for (var i=0; i < payments.length; i++) {
                    if (payments[i].paymentId == checkout.paymentId &&
                        payments[i].backendId == checkout.backendId) {
                            payments[i].preferred = true;
                    } else {
                        payments[i].preferred = false;
                    }
                }
            }
            checkout.model = payments;
            checkout.hasPayments = payments.length != 0;
            checkout.setSelectedItem();

            mainView.state = "checkout";
            checkout.visible = true;

            hideLoading();
        }

        onNoPreferredPaymentMethod: {
            checkout.hasPreferredPayment = false;
            var values = mainView.getLastPayment();
            var backendid = values[0];
            var paymentid = values[1];
            if (backendid != "" && paymentid != "") {
                checkout.hasStoredPayment = true;
            }
        }

        onPasswordValid: {
            hideLoading();
            // Reset password and otp to not keep them in memory.
            checkout.password = "";
            checkout.otp = "";
        }

        onBuyItemFailed: {
            hideLoading();
            purchaseErrorDialog.open = true;
        }

        onBuyItemSucceeded: {
            purchase.quitSuccess();
        }

        onBuyInterationRequired: {
            webkit.title = i18n.tr("Finish Purchase");
            webkit.url = url;
            mainView.state = "buy-interaction";
            pageStack.push(webkit);
        }

        onError: {
            hideLoading();
            serverErrorDialog.open = true;
        }

        onAuthenticationError: {
            mainView.recentLogin = false;
            if (pageStack.currentPage == checkout) {
                mainView.hideLoading();
                checkout.showErrorMessage(i18n.tr("Incorrect Password, please try again."));
            } else {
                mainView.state = "online-accounts";
                setup.exec();
            }
        }

        onCredentialsFound: {
            mainView.recentLogin = mainView.recentCredentials();
            checkout.beforeTimeout = mainView.recentLogin;

            if (mainView.state == "online-accounts") {
                purchase.checkItemPurchased();
            } else if (!mainView.purchasing && mainView.state != "buy-interaction") {
                purchase.getItemDetails();
            }
        }

        onItemNotPurchased: {
            purchase.getItemDetails();
        }

        onCredentialsNotFound: {
            mainView.recentLogin = false;
            if (mainView.state == "online-accounts") {
                purchase.quitCancel();
            } else {
                mainView.state = "online-accounts";
                setup.exec();
            }
        }

        onLoginError: {
            mainView.recentLogin = false;
            mainView.hideLoading();
            checkout.showErrorMessage(message);
        }

        onTwoFactorAuthRequired: {
            mainView.hideLoading();
            checkout.showTwoFactor();
        }

        onCertificateFound: {
            checkout.certificate = cert
        }
    }

    function showLoading() {
        if (!mainView.loading) {
            mainView.loading = true;
            PopupUtils.open(loadingDialogContainer);
        }
    }

    function hideLoading() {
        mainView.purchasing = false;
        mainView.loading = false;
        mainView.cancellable = true;
    }

    function createDB() {
        var db = LocalStorage.openDatabaseSync("PayUI", "1.0", "PayUI Credentials Date", 100);
        db.transaction(
            function(tx) {
                // Create the database if it doesn't already exist
                tx.executeSql('CREATE TABLE IF NOT EXISTS PayUIPayment(backendid TEXT, paymentid TEXT)');
            }
        )
    }

    function recentCredentials() {
        var valid = false;
        var date = purchase.getTokenUpdated();
        var currentDate = new Date();
        var msec = currentDate - date;
        var mm = Math.floor(msec / 1000 / 60);
        if (mm < 15) {
            valid = true;
        }
        return valid;
    }

    function getLastPayment() {
        var backendid = "";
        var paymentid = "";
        var db = LocalStorage.openDatabaseSync("PayUI", "1.0", "PayUI Credentials Date", 100);
        db.transaction(
            function(tx) {
                var rs = tx.executeSql('SELECT * FROM PayUIPayment');
                if (rs.rows.length > 0) {
                    backendid = rs.rows.item(0).backendid;
                    paymentid = rs.rows.item(0).paymentid;
                }
            }
        )
        return [backendid, paymentid];
    }

    function updatePayment(backendid, paymentid) {
        var db = LocalStorage.openDatabaseSync("PayUI", "1.0", "PayUI Credentials Date", 100);
        db.transaction(
            function(tx) {
                var rs = tx.executeSql('SELECT * FROM PayUIPayment');
                if (rs.rows.length > 0) {
                    tx.executeSql('UPDATE PayUIPayment SET backendid = "' + backendid + '", paymentid = "' + paymentid + '"');
                } else {
                    tx.executeSql('INSERT INTO PayUIPayment VALUES(?, ?)', [backendid, paymentid]);
                }
            }
        )
    }

    ErrorDialog {
        id: purchaseErrorDialog
        title: i18n.tr("Purchase failed")
        message: i18n.tr("The purchase couldn't be completed.")

        onRetry: {
            mainView.state = "error";
            mainView.showLoading();
            purchase.getItemDetails();
        }

        onClose: {
            purchase.quitCancel();
        }
    }

    ErrorDialog {
        id: serverErrorDialog
        title: i18n.tr("Error contacting the server")
        message: i18n.tr("Do you want to try again?")

        onRetry: {
            mainView.state = "error";
            mainView.showLoading();
            purchase.getItemDetails();
        }

        onClose: {
            purchase.quitCancel();
        }
    }

    ErrorDialog {
        id: creditCardErrorDialog
        title: i18n.tr("Adding Credit Card failed")
        message: i18n.tr("Do you want to try again?")

        onRetry: {
            mainView.state = "error";
            mainView.showLoading();
            purchase.getItemDetails();
        }

        onClose: {
            purchase.quitCancel();
        }
    }

    Component {
         id: loadingDialogContainer

         Dialog {
             id: loadingDialog
             title: mainView.purchasing ? i18n.tr("Processing Purchase") : i18n.tr("Loading")
             text: i18n.tr("Please wait…")
             ActivityIndicator {
                 running: mainView.loading ? true : false
                 width: parent.width

                 onRunningChanged: {
                     if(!running) {
                         PopupUtils.close(loadingDialog);
                     }
                 }
             }

             Button {
                 objectName: "buttonCancelLoading"
                 text: i18n.tr("Cancel")
                 color: UbuntuColors.orange
                 visible: mainView.cancellable
                 onClicked: {
                     PopupUtils.close(loadingDialog);
                     purchase.quitCancel();
                 }
             }
         }
    }

    PageStack {
        id: pageStack
        objectName: "pageStack"

        Component.onCompleted: {
            showLoading();
            mainView.createDB();
            purchase.checkCredentials();
        }

        onCurrentPageChanged: {
            if (pageStack.currentPage == checkout) {
                mainView.state = "checkout";
            }
        }

        CheckoutPage {
            id: checkout
            objectName: "pageCheckout"
            visible: false
            account: accounts

            onCancel: {
                purchase.quitCancel();
            }

            onBuy: {
                mainView.recentLogin = mainView.recentCredentials();
                checkout.beforeTimeout = mainView.recentLogin;

                // Pass it on.
                checkout.hasSelectedPayment = true;
                checkout.backendId = backendId;
                checkout.paymentId = paymentId;

                mainView.purchasing = true;
                mainView.cancellable = false;
                showLoading();
                if (!checkout.hasPreferredPayment) {
                    mainView.updatePayment(backendId, paymentId);
                }

                if (mainView.recentLogin) {
                    purchase.buyItem(email, "", "", suggestedCurrency, paymentId, backendId, mainView.recentLogin);
                } else {
                    purchase.buyItem(email, password, otp, suggestedCurrency, paymentId, backendId, mainView.recentLogin);
                }
            }

            onAddCreditCard: {
                webkit.title = i18n.tr("Add Payment");
                webkit.url = purchase.getAddPaymentUrl(suggestedCurrency);
                mainView.state = "add-payment";
                pageStack.push(webkit);
            }
        }

        UbuntuPurchaseWebkit {
            id: webkit
            visible: false

            onPurchaseFailed: {
                pageStack.pop();
                hideLoading();
                purchaseErrorDialog.open = true;
            }

            onPurchaseCancelled: {
                hideLoading();
                if (mainView.state == "add-payment") {
                    mainView.state = "checkout";
                    pageStack.pop();
                } else {
                    purchase.quitCancel();
                }
            }

            onPurchaseSucceeded: {
                if (mainView.state == "add-payment") {
                    showLoading();
                    pageStack.pop();
                    purchase.getPaymentTypes(suggestedCurrency);
                } else {
                    purchase.quitSuccess();
                }
            }

            onLoading: {
                if (value) {
                    showLoading();
                } else {
                    hideLoading();
                }
            }
        }
    }

    Rectangle {
        id: lockIconPlace
        width: units.gu(7)
        height: units.gu(7)
        anchors {
            right: parent.right
            top: parent.top
        }
        visible: false
    }
}