on xenial help sign in
Use libpayto start the purchase
commitffedb92f8b969e6b0f6d99467726daa7e85778c6 authorAlejandro J. Cura <alecu@canonical.com> dateWed 28 May 2014, 11:48 (12 years ago) parent156aa46
3 files changed+45−3
plugins/Ubuntu/Payments/CMakeLists.txt+5 plugins/Ubuntu/Payments/Payments.cpp+37−3 qml/Dash/Previews/PreviewPayments.qml+3
plugins/Ubuntu/Payments/CMakeLists.txt+5
@@ -14,3 +14,8 @@ add_library(Payments MODULE ${PAYMENTS_SOURCES})
1414qt5_use_modules(Payments Qml Quick DBus Core)
1515
1616add_unity8_plugin(Ubuntu.Payments 0.1 Ubuntu/Payments TARGETS Payments)
17+
18+pkg_check_modules(LIBPAY REQUIRED pay-1)
19+add_definitions(${LIBPAY_CFLAGS} ${LIBPAY_CFLAGS_OTHER})
20+
21+target_link_libraries(Payments ${LIBPAY_LDFLAGS})
plugins/Ubuntu/Payments/Payments.cpp+37−3
@@ -18,9 +18,12 @@
1818 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
1919 */
2020
21+#include <QDebug>
2122#include <QLocale>
2223#include <QTimer>
2324
25+#include <libpay/pay-package.h>
26+
2427#include "Payments.h"
2528
2629Payments::Payments(QObject *parent)
@@ -75,10 +78,41 @@ void Payments::setStoreItemId(const QString &store_item_id)
7578 }
7679}
7780
81+void observer(PayPackage* package, const char* /*itemid*/, PayPackageItemStatus status, void* user_data) {
82+ qDebug() << "observer called";
83+ Payments *self = static_cast<Payments*>(user_data);
84+ pay_package_item_observer_uninstall(package, observer, self);
85+ switch (status) {
86+ case PAY_PACKAGE_ITEM_STATUS_VERIFYING:
87+ break;
88+ case PAY_PACKAGE_ITEM_STATUS_PURCHASED:
89+ self->finished();
90+ break;
91+ case PAY_PACKAGE_ITEM_STATUS_PURCHASING:
92+ break;
93+ case PAY_PACKAGE_ITEM_STATUS_NOT_PURCHASED:
94+ self->error("not purchased");
95+ break;
96+ case PAY_PACKAGE_ITEM_STATUS_UNKNOWN:
97+ break;
98+ default:
99+ break;
100+ }
101+
102+}
103+
78104void Payments::start()
79105{
80106 qDebug("starting the purchase");
81− // start the purchase here, raise finished(), error or canceled when done
82− QTimer::singleShot(3000, this, SIGNAL(finished()));
83− // FIXME ^^^^
107+
108+ auto ba = m_store_item_id.toLocal8Bit();
109+ qDebug() << "the item id is" << m_store_item_id;
110+ auto package = pay_package_new("clickscope");
111+ qDebug() << "after new" << ba.data();
112+ pay_package_item_observer_install(package, observer, this);
113+ qDebug() << "after observer install";
114+ //pay_package_item_start_verification(package, ba.data());
115+ qDebug() << "after start verify";
116+ pay_package_item_start_purchase(package, ba.data());
117+ qDebug() << "after start purchase";
84118}
qml/Dash/Previews/PreviewPayments.qml+3
@@ -41,11 +41,14 @@ PreviewWidget {
4141 iconSource: data && data.icon || ""
4242 iconPosition: "left"
4343 onClicked: paymentClient.start()
44+ anchors.right: parent.right
45+ width: (root.width - units.gu(1)) / 2
4446
4547 Payments {
4648 id: paymentClient
4749 price: paymentButton.source["price"]
4850 currency: paymentButton.source["currency"]
51+ storeItemId: paymentButton.source["store_item_id"]
4952 onFinished: root.triggered(widgetId, "finished", data)
5053 onCanceled: root.triggered(widgetId, "canceled", data)
5154 onError: root.triggered(widgetId, "error", data)