2 * Copyright (C) 2013 - Canonical Ltd.
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License, as
6 * published by the Free Software Foundation; either version 2.1 or 3.0
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranties of
11 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the applicable version of the GNU Lesser General Public
13 * License for more details.
15 * You should have received a copy of both the GNU Lesser General Public
16 * License along with this program. If not, see <http://www.gnu.org/licenses/>
18 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
25#include <libpay/pay-package.h>
29Payments::Payments(QObject *parent)
34QString Payments::currency() const
39double Payments::price() const
44QString Payments::storeItemId() const
46 return m_store_item_id;
49QString Payments::formattedPrice() const
52 return locale.toCurrencyString(m_price, m_currency);
55void Payments::setCurrency(const QString ¤cy)
57 if(m_currency != currency){
58 m_currency = currency;
59 Q_EMIT currencyChanged(currency);
60 Q_EMIT formattedPriceChanged(formattedPrice());
64void Payments::setPrice(const double price)
68 Q_EMIT priceChanged(price);
69 Q_EMIT formattedPriceChanged(formattedPrice());
73void Payments::setStoreItemId(const QString &store_item_id)
75 if(m_store_item_id != store_item_id){
76 m_store_item_id = store_item_id;
77 Q_EMIT storeItemIdChanged(store_item_id);
81void observer(PayPackage* package, const char* /*itemid*/, PayPackageItemStatus status, void* user_data) {
82 // This function is called in libpay's thread, so be careful with what you call
83 // Emitting signals should be fine as long as they use Queued or Auto connections (the default)
84 // http://qt-project.org/doc/qt-5/threads-qobject.html#signals-and-slots-across-threads
86 qDebug() << "observer called";
87 Payments *self = static_cast<Payments*>(user_data);
88 pay_package_item_observer_uninstall(package, observer, self);
90 case PAY_PACKAGE_ITEM_STATUS_VERIFYING:
92 case PAY_PACKAGE_ITEM_STATUS_PURCHASED:
93 Q_EMIT self->purchaseCompleted();
95 case PAY_PACKAGE_ITEM_STATUS_PURCHASING:
97 case PAY_PACKAGE_ITEM_STATUS_NOT_PURCHASED:
98 Q_EMIT self->purchaseError("not purchased");
100 case PAY_PACKAGE_ITEM_STATUS_UNKNOWN:
108void Payments::start()
110 qDebug("starting the purchase");
112 auto ba = m_store_item_id.toLocal8Bit();
113 qDebug() << "the item id is" << m_store_item_id;
114 auto package = pay_package_new("clickscope");
115 qDebug() << "after new" << ba.data();
116 pay_package_item_observer_install(package, observer, this);
117 qDebug() << "after observer install";
118 // FIXME: Enable once verification is working in pay-service.
119 //pay_package_item_start_verification(package, ba.data());
120 qDebug() << "after start verify";
121 pay_package_item_start_purchase(package, ba.data());
122 qDebug() << "after start purchase";
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list