Merge lp:~diegosarmentero/pay-ui/code-improves into lp:pay-ui

Proposed by Diego Sarmentero
Status: Merged
Approved by: Diego Sarmentero
Approved revision: 10
Merged at revision: 10
Proposed branch: lp:~diegosarmentero/pay-ui/code-improves
Merge into: lp:pay-ui
Diff against target: 273 lines (+42/-47)
6 files modified
backend/modules/payui/network.cpp (+16/-20)
backend/modules/payui/network.h (+6/-4)
backend/modules/payui/purchase.cpp (+12/-15)
backend/tests/test_network.cpp (+5/-5)
manifest.json (+2/-2)
payui.json (+1/-1)
To merge this branch: bzr merge lp:~diegosarmentero/pay-ui/code-improves
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alejandro J. Cura (community) Approve
Review via email: mp+227088@code.launchpad.net

Commit message

- Some code improves
- Update security and framework on manifest

To post a comment you must log in.
Revision history for this message
Alejandro J. Cura (alecu) wrote :

Looks good.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'backend/modules/payui/network.cpp'
--- backend/modules/payui/network.cpp 2014-07-02 14:51:06 +0000
+++ backend/modules/payui/network.cpp 2014-07-16 18:53:33 +0000
@@ -34,7 +34,6 @@
34#define PAY_BASE_URL "https://sc.ubuntu.com/api/2.0/click/"34#define PAY_BASE_URL "https://sc.ubuntu.com/api/2.0/click/"
35#define ACCOUNT_CREDS_URL "https://login.ubuntu.com/api/v2/tokens/oauth"35#define ACCOUNT_CREDS_URL "https://login.ubuntu.com/api/v2/tokens/oauth"
36#define ADD_PAYMENT_URL "https://sc.ubuntu.com/api/2.0/click/paymentmethods/add/"36#define ADD_PAYMENT_URL "https://sc.ubuntu.com/api/2.0/click/paymentmethods/add/"
37//<matiasb> gatox: this is the url, in staging: https://sc.staging.ubuntu.com/click/payment-method/add/
3837
39#define PREFERED_PAYMENT_TYPE "0"38#define PREFERED_PAYMENT_TYPE "0"
40#define PAYMENT_TYPES "1"39#define PAYMENT_TYPES "1"
@@ -50,23 +49,19 @@
50Network::Network(QObject *parent) :49Network::Network(QObject *parent) :
51 QObject(parent),50 QObject(parent),
52 m_nam(this),51 m_nam(this),
53 m_service(this),52 m_service(this)
54 m_selectedPaymentId(""),
55 m_selectedBackendId(""),
56 m_selectedAppId(""),
57 m_selectedItemId("")
58{53{
59 QObject::connect(&m_nam, SIGNAL(finished(QNetworkReply*)),54 connect(&m_nam, SIGNAL(finished(QNetworkReply*)),
60 this, SLOT(onReply(QNetworkReply*)));55 this, SLOT(onReply(QNetworkReply*)));
61 // SSO SERVICE56 // SSO SERVICE
62 QObject::connect(&m_service, &CredentialsService::credentialsFound,57 connect(&m_service, &CredentialsService::credentialsFound,
63 this, &Network::handleCredentialsFound);58 this, &Network::handleCredentialsFound);
64 QObject::connect(&m_service, &CredentialsService::credentialsNotFound,59 connect(&m_service, &CredentialsService::credentialsNotFound,
65 this, &Network::credentialsNotFound);60 this, &Network::credentialsNotFound);
66 QObject::connect(&m_service, &CredentialsService::credentialsFound,61 connect(&m_service, &CredentialsService::credentialsFound,
67 this, &Network::credentialsFound);62 this, &Network::credentialsFound);
6863
69 QObject::connect(this, &Network::credentialsUpdated,64 connect(this, &Network::credentialsUpdated,
70 this, &Network::purchaseProcess);65 this, &Network::purchaseProcess);
71}66}
7267
@@ -80,7 +75,7 @@
80 m_service.setCredentials(token);75 m_service.setCredentials(token);
81}76}
8277
83void Network::updateCredentials(QString& email, QString& password)78void Network::updateCredentials(const QString& email, const QString& password)
84{79{
85 qDebug() << "Updating Credentials";80 qDebug() << "Updating Credentials";
86 QNetworkRequest request;81 QNetworkRequest request;
@@ -132,14 +127,12 @@
132 qDebug() << "Reply state:" << PAYMENT_TYPES;127 qDebug() << "Reply state:" << PAYMENT_TYPES;
133 QVariantList listPays;128 QVariantList listPays;
134 QJsonArray array = document.array();129 QJsonArray array = document.array();
135 int i;130 for (int i = 0; i < array.size(); i++) {
136 for (i = 0; i < array.size(); i++) {
137 QJsonObject object = array.at(i).toObject();131 QJsonObject object = array.at(i).toObject();
138 QString description = object.value("description").toString();132 QString description = object.value("description").toString();
139 QString backend = object.value("id").toString();133 QString backend = object.value("id").toString();
140 QJsonArray choices = object.value("choices").toArray();134 QJsonArray choices = object.value("choices").toArray();
141 int j;135 for (int j = 0; j < choices.size(); j++) {
142 for (j = 0; j < choices.size(); j++) {
143 QJsonObject choice = choices.at(i).toObject();136 QJsonObject choice = choices.at(i).toObject();
144 QString name = choice.value("description").toString();137 QString name = choice.value("description").toString();
145 QString paymentId = choice.value("id").toString();138 QString paymentId = choice.value("id").toString();
@@ -202,7 +195,7 @@
202 reply->deleteLater();195 reply->deleteLater();
203}196}
204197
205void Network::getPaymentTypes()198void Network::requestPaymentTypes()
206{199{
207 QNetworkRequest request;200 QNetworkRequest request;
208 request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");201 request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
@@ -216,7 +209,8 @@
216 m_nam.get(request);209 m_nam.get(request);
217}210}
218211
219void Network::buyItemWithPreferredPaymentType(QString email, QString password, QString appid, QString itemid)212void Network::buyItemWithPreferredPaymentType(const QString& email, const QString& password,
213 const QString& appid, const QString& itemid)
220{214{
221 m_selectedPaymentId = m_preferred->paymentId();215 m_selectedPaymentId = m_preferred->paymentId();
222 m_selectedBackendId = m_preferred->backendId();216 m_selectedBackendId = m_preferred->backendId();
@@ -225,7 +219,9 @@
225 updateCredentials(email, password);219 updateCredentials(email, password);
226}220}
227221
228void Network::buyItem(QString email, QString password, QString appid, QString itemid, QString paymentId, QString backendId)222void Network::buyItem(const QString& email, const QString& password,
223 const QString& appid, const QString& itemid,
224 const QString& paymentId, const QString& backendId)
229{225{
230 m_selectedPaymentId = paymentId;226 m_selectedPaymentId = paymentId;
231 m_selectedBackendId = backendId;227 m_selectedBackendId = backendId;
@@ -310,7 +306,7 @@
310void Network::handleCredentialsFound(Token token)306void Network::handleCredentialsFound(Token token)
311{307{
312 m_token = token;308 m_token = token;
313 getPaymentTypes();309 requestPaymentTypes();
314}310}
315311
316}312}
317313
=== modified file 'backend/modules/payui/network.h'
--- backend/modules/payui/network.h 2014-07-02 14:51:06 +0000
+++ backend/modules/payui/network.h 2014-07-16 18:53:33 +0000
@@ -53,14 +53,16 @@
53public:53public:
54 explicit Network(QObject *parent = 0);54 explicit Network(QObject *parent = 0);
5555
56 void getPaymentTypes();56 void requestPaymentTypes();
57 void buyItem(QString email, QString password, QString appid, QString itemid, QString paymentId, QString backendId);57 void buyItem(const QString& email, const QString& password, const QString& appid,
58 void buyItemWithPreferredPaymentType(QString email, QString password, QString appid, QString itemid);58 const QString& itemid, const QString& paymentId, const QString& backendId);
59 void buyItemWithPreferredPaymentType(const QString& email, const QString& password,
60 const QString& appid, const QString& itemid);
59 void getItemInfo(const QString &packagename);61 void getItemInfo(const QString &packagename);
6062
61 void getCredentials();63 void getCredentials();
62 void setCredentials(Token token);64 void setCredentials(Token token);
63 void updateCredentials(QString& email, QString& password);65 void updateCredentials(const QString& email, const QString& password);
64 QString getAddPaymentUrl();66 QString getAddPaymentUrl();
6567
66Q_SIGNALS:68Q_SIGNALS:
6769
=== modified file 'backend/modules/payui/purchase.cpp'
--- backend/modules/payui/purchase.cpp 2014-07-02 20:36:40 +0000
+++ backend/modules/payui/purchase.cpp 2014-07-16 18:53:33 +0000
@@ -10,34 +10,31 @@
1010
11Purchase::Purchase(QObject *parent) :11Purchase::Purchase(QObject *parent) :
12 QObject(parent),12 QObject(parent),
13 m_network(this),13 m_network(this)
14 m_appid(""),
15 m_itemid("")
16{14{
17 QObject::connect(&m_network, &Network::itemDetailsObtained,15 connect(&m_network, &Network::itemDetailsObtained,
18 this, &Purchase::itemDetailsObtained);16 this, &Purchase::itemDetailsObtained);
19 QObject::connect(&m_network, &Network::paymentTypesObtained,17 connect(&m_network, &Network::paymentTypesObtained,
20 this, &Purchase::paymentTypesObtained);18 this, &Purchase::paymentTypesObtained);
21 QObject::connect(&m_network, &Network::buyItemSucceeded,19 connect(&m_network, &Network::buyItemSucceeded,
22 this, &Purchase::buyItemSucceeded);20 this, &Purchase::buyItemSucceeded);
23 QObject::connect(&m_network, &Network::buyItemFailed,21 connect(&m_network, &Network::buyItemFailed,
24 this, &Purchase::buyItemFailed);22 this, &Purchase::buyItemFailed);
25 QObject::connect(&m_network, &Network::buyInteractionRequired,23 connect(&m_network, &Network::buyInteractionRequired,
26 this, &Purchase::buyInterationRequired);24 this, &Purchase::buyInterationRequired);
27 QObject::connect(&m_network, &Network::error,25 connect(&m_network, &Network::error,
28 this, &Purchase::error);26 this, &Purchase::error);
29 QObject::connect(&m_network, &Network::authenticationError,27 connect(&m_network, &Network::authenticationError,
30 this, &Purchase::authenticationError);28 this, &Purchase::authenticationError);
31 QObject::connect(&m_network, &Network::credentialsNotFound,29 connect(&m_network, &Network::credentialsNotFound,
32 this, &Purchase::credentialsNotFound);30 this, &Purchase::credentialsNotFound);
33 QObject::connect(&m_network, &Network::credentialsFound,31 connect(&m_network, &Network::credentialsFound,
34 this, &Purchase::credentialsFound);32 this, &Purchase::credentialsFound);
3533
36 QCoreApplication* instance = QCoreApplication::instance();34 QCoreApplication* instance = QCoreApplication::instance();
37 Logger::setupLogging();35 Logger::setupLogging();
38 int i;
39 qCritical() << "Start Pay UI";36 qCritical() << "Start Pay UI";
40 for (i = 0; i < instance->arguments().size(); i++) {37 for (int i = 0; i < instance->arguments().size(); i++) {
41 QString argument = instance->arguments().at(i);38 QString argument = instance->arguments().at(i);
42 if (argument.startsWith("purchase://")) {39 if (argument.startsWith("purchase://")) {
43 QUrl data(argument);40 QUrl data(argument);
@@ -92,7 +89,7 @@
9289
93void Purchase::getPaymentTypes()90void Purchase::getPaymentTypes()
94{91{
95 m_network.getPaymentTypes();92 m_network.requestPaymentTypes();
96}93}
9794
98void Purchase::buyItemWithPreferredPayment(QString email, QString password)95void Purchase::buyItemWithPreferredPayment(QString email, QString password)
9996
=== modified file 'backend/tests/test_network.cpp'
--- backend/tests/test_network.cpp 2014-07-02 20:48:48 +0000
+++ backend/tests/test_network.cpp 2014-07-16 18:53:33 +0000
@@ -94,7 +94,7 @@
94{94{
95 setenv("PAY_BASE_URL", "http://localhost:8000/", 1); 95 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);
96 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));96 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));
97 network.getPaymentTypes();97 network.requestPaymentTypes();
98 QTRY_COMPARE(spy.count(), 1);98 QTRY_COMPARE(spy.count(), 1);
99 QList<QVariant> arguments = spy.takeFirst();99 QList<QVariant> arguments = spy.takeFirst();
100 QVERIFY(arguments.at(0).toList().count() == 3);100 QVERIFY(arguments.at(0).toList().count() == 3);
@@ -104,7 +104,7 @@
104{104{
105 setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1);105 setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1);
106 QSignalSpy spy(&network, SIGNAL(error(QString)));106 QSignalSpy spy(&network, SIGNAL(error(QString)));
107 network.getPaymentTypes();107 network.requestPaymentTypes();
108 QTRY_COMPARE(spy.count(), 1);108 QTRY_COMPARE(spy.count(), 1);
109 QList<QVariant> arguments = spy.takeFirst();109 QList<QVariant> arguments = spy.takeFirst();
110 QVERIFY(arguments.at(0).toString() == "404");110 QVERIFY(arguments.at(0).toString() == "404");
@@ -144,7 +144,7 @@
144 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);144 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);
145 setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1);145 setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1);
146 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));146 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));
147 network.getPaymentTypes();147 network.requestPaymentTypes();
148 QTRY_COMPARE(spy.count(), 1);148 QTRY_COMPARE(spy.count(), 1);
149 QSignalSpy spy2(&network, SIGNAL(buyItemSucceeded()));149 QSignalSpy spy2(&network, SIGNAL(buyItemSucceeded()));
150 network.buyItemWithPreferredPaymentType("email", "password", "appid", "itemid");150 network.buyItemWithPreferredPaymentType("email", "password", "appid", "itemid");
@@ -156,7 +156,7 @@
156 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);156 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);
157 setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1);157 setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1);
158 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));158 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));
159 network.getPaymentTypes();159 network.requestPaymentTypes();
160 QTRY_COMPARE(spy.count(), 1);160 QTRY_COMPARE(spy.count(), 1);
161 setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1);161 setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1);
162 QSignalSpy spy2(&network, SIGNAL(buyItemFailed()));162 QSignalSpy spy2(&network, SIGNAL(buyItemFailed()));
@@ -169,7 +169,7 @@
169 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);169 setenv("PAY_BASE_URL", "http://localhost:8000/", 1);
170 setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1);170 setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1);
171 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));171 QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList)));
172 network.getPaymentTypes();172 network.requestPaymentTypes();
173 QTRY_COMPARE(spy.count(), 1);173 QTRY_COMPARE(spy.count(), 1);
174 setenv("PAY_BASE_URL", "http://localhost:8000/interaction/", 1);174 setenv("PAY_BASE_URL", "http://localhost:8000/interaction/", 1);
175 QSignalSpy spy2(&network, SIGNAL(buyInteractionRequired(QString)));175 QSignalSpy spy2(&network, SIGNAL(buyInteractionRequired(QString)));
176176
=== modified file 'manifest.json'
--- manifest.json 2014-07-15 18:50:54 +0000
+++ manifest.json 2014-07-16 18:53:33 +0000
@@ -1,7 +1,7 @@
1{1{
2 "name": "com.canonical.payui",2 "name": "com.canonical.payui",
3 "description": "UI for Pay Service",3 "description": "UI for Pay Service",
4 "framework": "ubuntu-sdk-14.04-qml-dev2",4 "framework": "ubuntu-sdk-14.10-qml-dev2",
5 "architecture": "armhf",5 "architecture": "armhf",
6 "title": "PayUI",6 "title": "PayUI",
7 "hooks": {7 "hooks": {
@@ -10,6 +10,6 @@
10 "desktop": "payui.desktop"10 "desktop": "payui.desktop"
11 }11 }
12 },12 },
13 "version": "0.2.9",13 "version": "0.3",
14 "maintainer": "Sarmentero Diego <diego.sarmentero@canonical.com>"14 "maintainer": "Sarmentero Diego <diego.sarmentero@canonical.com>"
15}15}
16\ No newline at end of file16\ No newline at end of file
1717
=== modified file 'payui.json'
--- payui.json 2014-06-23 18:20:45 +0000
+++ payui.json 2014-07-16 18:53:33 +0000
@@ -1,5 +1,5 @@
1{1{
2 "policy_groups": [],2 "policy_groups": [],
3 "policy_version": 1.1,3 "policy_version": 1.2,
4 "template": "unconfined"4 "template": "unconfined"
5}5}
6\ No newline at end of file6\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: