on bbbdccd help sign in
unity8/tests/mocks/Ubuntu/Payments/MockPayments.cpp
94 lines 2.2 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include "MockPayments.h"
19#include <QLocale>
22MockPayments::MockPayments(QObject *parent)
23 : QObject(parent)
27QString MockPayments::currency() const
29 return m_currency;
32double MockPayments::price() const
34 return m_price;
37QString MockPayments::storeItemId() const
39 return m_store_item_id;
42QString MockPayments::formattedPrice() const
44 QLocale locale;
45 return locale.toCurrencyString(m_price, m_currency);
48void MockPayments::setCurrency(const QString &currency)
50 if(m_currency != currency) {
51 m_currency = currency;
52 Q_EMIT currencyChanged(currency);
53 Q_EMIT formattedPriceChanged(formattedPrice());
54 }
57void MockPayments::setPrice(const double price)
59 if(m_price != price) {
60 m_price = price;
61 Q_EMIT priceChanged(price);
62 Q_EMIT formattedPriceChanged(formattedPrice());
63 }
66void MockPayments::setStoreItemId(const QString &store_item_id)
68 if (m_store_item_id != store_item_id) {
69 m_store_item_id = store_item_id;
70 Q_EMIT storeItemIdChanged(m_store_item_id);
71 }
73 if (m_store_item_id.isEmpty()) {
74 return;
75 }
78void MockPayments::start()
80 if (m_store_item_id.isEmpty()) {
81 Q_EMIT purchaseError("No item ID supplied.");
82 }
85void MockPayments::process()
87 if (m_store_item_id == "com.example.cancel") {
88 Q_EMIT purchaseCancelled();
89 } else if (m_store_item_id == "com.example.invalid") {
90 Q_EMIT purchaseError("Purchase failed.");
91 } else {
92 Q_EMIT purchaseCompleted();
93 }