on db4dbae help sign in
unity8/tests/mocks/Ubuntu/Payments/MockPayments.cpp
95 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)
24 , m_price(0)
28QString MockPayments::currency() const
30 return m_currency;
33double MockPayments::price() const
35 return m_price;
38QString MockPayments::storeItemId() const
40 return m_store_item_id;
43QString MockPayments::formattedPrice() const
45 QLocale locale;
46 return locale.toCurrencyString(m_price, m_currency);
49void MockPayments::setCurrency(const QString &currency)
51 if(m_currency != currency) {
52 m_currency = currency;
53 Q_EMIT currencyChanged(currency);
54 Q_EMIT formattedPriceChanged(formattedPrice());
55 }
58void MockPayments::setPrice(const double price)
60 if(m_price != price) {
61 m_price = price;
62 Q_EMIT priceChanged(price);
63 Q_EMIT formattedPriceChanged(formattedPrice());
64 }
67void MockPayments::setStoreItemId(const QString &store_item_id)
69 if (m_store_item_id != store_item_id) {
70 m_store_item_id = store_item_id;
71 Q_EMIT storeItemIdChanged(m_store_item_id);
72 }
74 if (m_store_item_id.isEmpty()) {
75 return;
76 }
79void MockPayments::start()
81 if (m_store_item_id.isEmpty()) {
82 Q_EMIT purchaseError("No item ID supplied.");
83 }
86void MockPayments::process()
88 if (m_store_item_id == "com.example.cancel") {
89 Q_EMIT purchaseCancelled();
90 } else if (m_store_item_id == "com.example.invalid") {
91 Q_EMIT purchaseError("Purchase failed.");
92 } else {
93 Q_EMIT purchaseCompleted();
94 }