on xenial help sign in
Use libpayto start the purchase
ffedb92Alejandro J. Cura
plugins/Ubuntu/Payments/CMakeLists.txt+5
@@ -14,3 +14,8 @@ add_library(Payments MODULE ${PAYMENTS_SOURCES})
14qt5_use_modules(Payments Qml Quick DBus Core)
14qt5_use_modules(Payments Qml Quick DBus Core)
15
15
16add_unity8_plugin(Ubuntu.Payments 0.1 Ubuntu/Payments TARGETS Payments)
16add_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 @@
18 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
18 * Authored by: Diego Sarmentero <diego.sarmentero@canonical.com>
19 */
19 */
20
20
21+#include <QDebug>
21#include <QLocale>
22#include <QLocale>
22#include <QTimer>
23#include <QTimer>
23
24
25+#include <libpay/pay-package.h>
26+
24#include "Payments.h"
27#include "Payments.h"
25
28
26Payments::Payments(QObject *parent)
29Payments::Payments(QObject *parent)
@@ -75,10 +78,41 @@ void Payments::setStoreItemId(const QString &store_item_id)
75 }
78 }
76}
79}
77
80
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+
78void Payments::start()
104void Payments::start()
79{
105{
80 qDebug("starting the purchase");
106 qDebug("starting the purchase");
81− // start the purchase here, raise finished(), error or canceled when done
107+
82− QTimer::singleShot(3000, this, SIGNAL(finished()));
108+ auto ba = m_store_item_id.toLocal8Bit();
83− // FIXME ^^^^
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";
84}
118}
qml/Dash/Previews/PreviewPayments.qml+3
@@ -41,11 +41,14 @@ PreviewWidget {
41 iconSource: data && data.icon || ""
41 iconSource: data && data.icon || ""
42 iconPosition: "left"
42 iconPosition: "left"
43 onClicked: paymentClient.start()
43 onClicked: paymentClient.start()
44+ anchors.right: parent.right
45+ width: (root.width - units.gu(1)) / 2
44
46
45 Payments {
47 Payments {
46 id: paymentClient
48 id: paymentClient
47 price: paymentButton.source["price"]
49 price: paymentButton.source["price"]
48 currency: paymentButton.source["currency"]
50 currency: paymentButton.source["currency"]
51+ storeItemId: paymentButton.source["store_item_id"]
49 onFinished: root.triggered(widgetId, "finished", data)
52 onFinished: root.triggered(widgetId, "finished", data)
50 onCanceled: root.triggered(widgetId, "canceled", data)
53 onCanceled: root.triggered(widgetId, "canceled", data)
51 onError: root.triggered(widgetId, "error", data)
54 onError: root.triggered(widgetId, "error", data)