Merge lp:~diegosarmentero/pay-ui/code-improves into lp:pay-ui
- code-improves
- Merge into first-branch
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 |
Related bugs: |
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
Description of the change
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:10
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'backend/modules/payui/network.cpp' | |||
2 | --- backend/modules/payui/network.cpp 2014-07-02 14:51:06 +0000 | |||
3 | +++ backend/modules/payui/network.cpp 2014-07-16 18:53:33 +0000 | |||
4 | @@ -34,7 +34,6 @@ | |||
5 | 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/" |
6 | 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" |
7 | 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/" |
8 | 37 | //<matiasb> gatox: this is the url, in staging: https://sc.staging.ubuntu.com/click/payment-method/add/ | ||
9 | 38 | 37 | ||
10 | 39 | #define PREFERED_PAYMENT_TYPE "0" | 38 | #define PREFERED_PAYMENT_TYPE "0" |
11 | 40 | #define PAYMENT_TYPES "1" | 39 | #define PAYMENT_TYPES "1" |
12 | @@ -50,23 +49,19 @@ | |||
13 | 50 | Network::Network(QObject *parent) : | 49 | Network::Network(QObject *parent) : |
14 | 51 | QObject(parent), | 50 | QObject(parent), |
15 | 52 | m_nam(this), | 51 | m_nam(this), |
21 | 53 | m_service(this), | 52 | m_service(this) |
17 | 54 | m_selectedPaymentId(""), | ||
18 | 55 | m_selectedBackendId(""), | ||
19 | 56 | m_selectedAppId(""), | ||
20 | 57 | m_selectedItemId("") | ||
22 | 58 | { | 53 | { |
24 | 59 | QObject::connect(&m_nam, SIGNAL(finished(QNetworkReply*)), | 54 | connect(&m_nam, SIGNAL(finished(QNetworkReply*)), |
25 | 60 | this, SLOT(onReply(QNetworkReply*))); | 55 | this, SLOT(onReply(QNetworkReply*))); |
26 | 61 | // SSO SERVICE | 56 | // SSO SERVICE |
28 | 62 | QObject::connect(&m_service, &CredentialsService::credentialsFound, | 57 | connect(&m_service, &CredentialsService::credentialsFound, |
29 | 63 | this, &Network::handleCredentialsFound); | 58 | this, &Network::handleCredentialsFound); |
31 | 64 | QObject::connect(&m_service, &CredentialsService::credentialsNotFound, | 59 | connect(&m_service, &CredentialsService::credentialsNotFound, |
32 | 65 | this, &Network::credentialsNotFound); | 60 | this, &Network::credentialsNotFound); |
34 | 66 | QObject::connect(&m_service, &CredentialsService::credentialsFound, | 61 | connect(&m_service, &CredentialsService::credentialsFound, |
35 | 67 | this, &Network::credentialsFound); | 62 | this, &Network::credentialsFound); |
36 | 68 | 63 | ||
38 | 69 | QObject::connect(this, &Network::credentialsUpdated, | 64 | connect(this, &Network::credentialsUpdated, |
39 | 70 | this, &Network::purchaseProcess); | 65 | this, &Network::purchaseProcess); |
40 | 71 | } | 66 | } |
41 | 72 | 67 | ||
42 | @@ -80,7 +75,7 @@ | |||
43 | 80 | m_service.setCredentials(token); | 75 | m_service.setCredentials(token); |
44 | 81 | } | 76 | } |
45 | 82 | 77 | ||
47 | 83 | void Network::updateCredentials(QString& email, QString& password) | 78 | void Network::updateCredentials(const QString& email, const QString& password) |
48 | 84 | { | 79 | { |
49 | 85 | qDebug() << "Updating Credentials"; | 80 | qDebug() << "Updating Credentials"; |
50 | 86 | QNetworkRequest request; | 81 | QNetworkRequest request; |
51 | @@ -132,14 +127,12 @@ | |||
52 | 132 | qDebug() << "Reply state:" << PAYMENT_TYPES; | 127 | qDebug() << "Reply state:" << PAYMENT_TYPES; |
53 | 133 | QVariantList listPays; | 128 | QVariantList listPays; |
54 | 134 | QJsonArray array = document.array(); | 129 | QJsonArray array = document.array(); |
57 | 135 | int i; | 130 | for (int i = 0; i < array.size(); i++) { |
56 | 136 | for (i = 0; i < array.size(); i++) { | ||
58 | 137 | QJsonObject object = array.at(i).toObject(); | 131 | QJsonObject object = array.at(i).toObject(); |
59 | 138 | QString description = object.value("description").toString(); | 132 | QString description = object.value("description").toString(); |
60 | 139 | QString backend = object.value("id").toString(); | 133 | QString backend = object.value("id").toString(); |
61 | 140 | QJsonArray choices = object.value("choices").toArray(); | 134 | QJsonArray choices = object.value("choices").toArray(); |
64 | 141 | int j; | 135 | for (int j = 0; j < choices.size(); j++) { |
63 | 142 | for (j = 0; j < choices.size(); j++) { | ||
65 | 143 | QJsonObject choice = choices.at(i).toObject(); | 136 | QJsonObject choice = choices.at(i).toObject(); |
66 | 144 | QString name = choice.value("description").toString(); | 137 | QString name = choice.value("description").toString(); |
67 | 145 | QString paymentId = choice.value("id").toString(); | 138 | QString paymentId = choice.value("id").toString(); |
68 | @@ -202,7 +195,7 @@ | |||
69 | 202 | reply->deleteLater(); | 195 | reply->deleteLater(); |
70 | 203 | } | 196 | } |
71 | 204 | 197 | ||
73 | 205 | void Network::getPaymentTypes() | 198 | void Network::requestPaymentTypes() |
74 | 206 | { | 199 | { |
75 | 207 | QNetworkRequest request; | 200 | QNetworkRequest request; |
76 | 208 | request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 201 | request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); |
77 | @@ -216,7 +209,8 @@ | |||
78 | 216 | m_nam.get(request); | 209 | m_nam.get(request); |
79 | 217 | } | 210 | } |
80 | 218 | 211 | ||
82 | 219 | void Network::buyItemWithPreferredPaymentType(QString email, QString password, QString appid, QString itemid) | 212 | void Network::buyItemWithPreferredPaymentType(const QString& email, const QString& password, |
83 | 213 | const QString& appid, const QString& itemid) | ||
84 | 220 | { | 214 | { |
85 | 221 | m_selectedPaymentId = m_preferred->paymentId(); | 215 | m_selectedPaymentId = m_preferred->paymentId(); |
86 | 222 | m_selectedBackendId = m_preferred->backendId(); | 216 | m_selectedBackendId = m_preferred->backendId(); |
87 | @@ -225,7 +219,9 @@ | |||
88 | 225 | updateCredentials(email, password); | 219 | updateCredentials(email, password); |
89 | 226 | } | 220 | } |
90 | 227 | 221 | ||
92 | 228 | void Network::buyItem(QString email, QString password, QString appid, QString itemid, QString paymentId, QString backendId) | 222 | void Network::buyItem(const QString& email, const QString& password, |
93 | 223 | const QString& appid, const QString& itemid, | ||
94 | 224 | const QString& paymentId, const QString& backendId) | ||
95 | 229 | { | 225 | { |
96 | 230 | m_selectedPaymentId = paymentId; | 226 | m_selectedPaymentId = paymentId; |
97 | 231 | m_selectedBackendId = backendId; | 227 | m_selectedBackendId = backendId; |
98 | @@ -310,7 +306,7 @@ | |||
99 | 310 | void Network::handleCredentialsFound(Token token) | 306 | void Network::handleCredentialsFound(Token token) |
100 | 311 | { | 307 | { |
101 | 312 | m_token = token; | 308 | m_token = token; |
103 | 313 | getPaymentTypes(); | 309 | requestPaymentTypes(); |
104 | 314 | } | 310 | } |
105 | 315 | 311 | ||
106 | 316 | } | 312 | } |
107 | 317 | 313 | ||
108 | === modified file 'backend/modules/payui/network.h' | |||
109 | --- backend/modules/payui/network.h 2014-07-02 14:51:06 +0000 | |||
110 | +++ backend/modules/payui/network.h 2014-07-16 18:53:33 +0000 | |||
111 | @@ -53,14 +53,16 @@ | |||
112 | 53 | public: | 53 | public: |
113 | 54 | explicit Network(QObject *parent = 0); | 54 | explicit Network(QObject *parent = 0); |
114 | 55 | 55 | ||
118 | 56 | void getPaymentTypes(); | 56 | void requestPaymentTypes(); |
119 | 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, |
120 | 58 | void buyItemWithPreferredPaymentType(QString email, QString password, QString appid, QString itemid); | 58 | const QString& itemid, const QString& paymentId, const QString& backendId); |
121 | 59 | void buyItemWithPreferredPaymentType(const QString& email, const QString& password, | ||
122 | 60 | const QString& appid, const QString& itemid); | ||
123 | 59 | void getItemInfo(const QString &packagename); | 61 | void getItemInfo(const QString &packagename); |
124 | 60 | 62 | ||
125 | 61 | void getCredentials(); | 63 | void getCredentials(); |
126 | 62 | void setCredentials(Token token); | 64 | void setCredentials(Token token); |
128 | 63 | void updateCredentials(QString& email, QString& password); | 65 | void updateCredentials(const QString& email, const QString& password); |
129 | 64 | QString getAddPaymentUrl(); | 66 | QString getAddPaymentUrl(); |
130 | 65 | 67 | ||
131 | 66 | Q_SIGNALS: | 68 | Q_SIGNALS: |
132 | 67 | 69 | ||
133 | === modified file 'backend/modules/payui/purchase.cpp' | |||
134 | --- backend/modules/payui/purchase.cpp 2014-07-02 20:36:40 +0000 | |||
135 | +++ backend/modules/payui/purchase.cpp 2014-07-16 18:53:33 +0000 | |||
136 | @@ -10,34 +10,31 @@ | |||
137 | 10 | 10 | ||
138 | 11 | Purchase::Purchase(QObject *parent) : | 11 | Purchase::Purchase(QObject *parent) : |
139 | 12 | QObject(parent), | 12 | QObject(parent), |
143 | 13 | m_network(this), | 13 | m_network(this) |
141 | 14 | m_appid(""), | ||
142 | 15 | m_itemid("") | ||
144 | 16 | { | 14 | { |
146 | 17 | QObject::connect(&m_network, &Network::itemDetailsObtained, | 15 | connect(&m_network, &Network::itemDetailsObtained, |
147 | 18 | this, &Purchase::itemDetailsObtained); | 16 | this, &Purchase::itemDetailsObtained); |
149 | 19 | QObject::connect(&m_network, &Network::paymentTypesObtained, | 17 | connect(&m_network, &Network::paymentTypesObtained, |
150 | 20 | this, &Purchase::paymentTypesObtained); | 18 | this, &Purchase::paymentTypesObtained); |
152 | 21 | QObject::connect(&m_network, &Network::buyItemSucceeded, | 19 | connect(&m_network, &Network::buyItemSucceeded, |
153 | 22 | this, &Purchase::buyItemSucceeded); | 20 | this, &Purchase::buyItemSucceeded); |
155 | 23 | QObject::connect(&m_network, &Network::buyItemFailed, | 21 | connect(&m_network, &Network::buyItemFailed, |
156 | 24 | this, &Purchase::buyItemFailed); | 22 | this, &Purchase::buyItemFailed); |
158 | 25 | QObject::connect(&m_network, &Network::buyInteractionRequired, | 23 | connect(&m_network, &Network::buyInteractionRequired, |
159 | 26 | this, &Purchase::buyInterationRequired); | 24 | this, &Purchase::buyInterationRequired); |
161 | 27 | QObject::connect(&m_network, &Network::error, | 25 | connect(&m_network, &Network::error, |
162 | 28 | this, &Purchase::error); | 26 | this, &Purchase::error); |
164 | 29 | QObject::connect(&m_network, &Network::authenticationError, | 27 | connect(&m_network, &Network::authenticationError, |
165 | 30 | this, &Purchase::authenticationError); | 28 | this, &Purchase::authenticationError); |
167 | 31 | QObject::connect(&m_network, &Network::credentialsNotFound, | 29 | connect(&m_network, &Network::credentialsNotFound, |
168 | 32 | this, &Purchase::credentialsNotFound); | 30 | this, &Purchase::credentialsNotFound); |
170 | 33 | QObject::connect(&m_network, &Network::credentialsFound, | 31 | connect(&m_network, &Network::credentialsFound, |
171 | 34 | this, &Purchase::credentialsFound); | 32 | this, &Purchase::credentialsFound); |
172 | 35 | 33 | ||
173 | 36 | QCoreApplication* instance = QCoreApplication::instance(); | 34 | QCoreApplication* instance = QCoreApplication::instance(); |
174 | 37 | Logger::setupLogging(); | 35 | Logger::setupLogging(); |
175 | 38 | int i; | ||
176 | 39 | qCritical() << "Start Pay UI"; | 36 | qCritical() << "Start Pay UI"; |
178 | 40 | for (i = 0; i < instance->arguments().size(); i++) { | 37 | for (int i = 0; i < instance->arguments().size(); i++) { |
179 | 41 | QString argument = instance->arguments().at(i); | 38 | QString argument = instance->arguments().at(i); |
180 | 42 | if (argument.startsWith("purchase://")) { | 39 | if (argument.startsWith("purchase://")) { |
181 | 43 | QUrl data(argument); | 40 | QUrl data(argument); |
182 | @@ -92,7 +89,7 @@ | |||
183 | 92 | 89 | ||
184 | 93 | void Purchase::getPaymentTypes() | 90 | void Purchase::getPaymentTypes() |
185 | 94 | { | 91 | { |
187 | 95 | m_network.getPaymentTypes(); | 92 | m_network.requestPaymentTypes(); |
188 | 96 | } | 93 | } |
189 | 97 | 94 | ||
190 | 98 | void Purchase::buyItemWithPreferredPayment(QString email, QString password) | 95 | void Purchase::buyItemWithPreferredPayment(QString email, QString password) |
191 | 99 | 96 | ||
192 | === modified file 'backend/tests/test_network.cpp' | |||
193 | --- backend/tests/test_network.cpp 2014-07-02 20:48:48 +0000 | |||
194 | +++ backend/tests/test_network.cpp 2014-07-16 18:53:33 +0000 | |||
195 | @@ -94,7 +94,7 @@ | |||
196 | 94 | { | 94 | { |
197 | 95 | setenv("PAY_BASE_URL", "http://localhost:8000/", 1); | 95 | setenv("PAY_BASE_URL", "http://localhost:8000/", 1); |
198 | 96 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); | 96 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); |
200 | 97 | network.getPaymentTypes(); | 97 | network.requestPaymentTypes(); |
201 | 98 | QTRY_COMPARE(spy.count(), 1); | 98 | QTRY_COMPARE(spy.count(), 1); |
202 | 99 | QList<QVariant> arguments = spy.takeFirst(); | 99 | QList<QVariant> arguments = spy.takeFirst(); |
203 | 100 | QVERIFY(arguments.at(0).toList().count() == 3); | 100 | QVERIFY(arguments.at(0).toList().count() == 3); |
204 | @@ -104,7 +104,7 @@ | |||
205 | 104 | { | 104 | { |
206 | 105 | setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1); | 105 | setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1); |
207 | 106 | QSignalSpy spy(&network, SIGNAL(error(QString))); | 106 | QSignalSpy spy(&network, SIGNAL(error(QString))); |
209 | 107 | network.getPaymentTypes(); | 107 | network.requestPaymentTypes(); |
210 | 108 | QTRY_COMPARE(spy.count(), 1); | 108 | QTRY_COMPARE(spy.count(), 1); |
211 | 109 | QList<QVariant> arguments = spy.takeFirst(); | 109 | QList<QVariant> arguments = spy.takeFirst(); |
212 | 110 | QVERIFY(arguments.at(0).toString() == "404"); | 110 | QVERIFY(arguments.at(0).toString() == "404"); |
213 | @@ -144,7 +144,7 @@ | |||
214 | 144 | setenv("PAY_BASE_URL", "http://localhost:8000/", 1); | 144 | setenv("PAY_BASE_URL", "http://localhost:8000/", 1); |
215 | 145 | setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1); | 145 | setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1); |
216 | 146 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); | 146 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); |
218 | 147 | network.getPaymentTypes(); | 147 | network.requestPaymentTypes(); |
219 | 148 | QTRY_COMPARE(spy.count(), 1); | 148 | QTRY_COMPARE(spy.count(), 1); |
220 | 149 | QSignalSpy spy2(&network, SIGNAL(buyItemSucceeded())); | 149 | QSignalSpy spy2(&network, SIGNAL(buyItemSucceeded())); |
221 | 150 | network.buyItemWithPreferredPaymentType("email", "password", "appid", "itemid"); | 150 | network.buyItemWithPreferredPaymentType("email", "password", "appid", "itemid"); |
222 | @@ -156,7 +156,7 @@ | |||
223 | 156 | setenv("PAY_BASE_URL", "http://localhost:8000/", 1); | 156 | setenv("PAY_BASE_URL", "http://localhost:8000/", 1); |
224 | 157 | setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1); | 157 | setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1); |
225 | 158 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); | 158 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); |
227 | 159 | network.getPaymentTypes(); | 159 | network.requestPaymentTypes(); |
228 | 160 | QTRY_COMPARE(spy.count(), 1); | 160 | QTRY_COMPARE(spy.count(), 1); |
229 | 161 | setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1); | 161 | setenv("PAY_BASE_URL", "http://localhost:8000/fail/", 1); |
230 | 162 | QSignalSpy spy2(&network, SIGNAL(buyItemFailed())); | 162 | QSignalSpy spy2(&network, SIGNAL(buyItemFailed())); |
231 | @@ -169,7 +169,7 @@ | |||
232 | 169 | setenv("PAY_BASE_URL", "http://localhost:8000/", 1); | 169 | setenv("PAY_BASE_URL", "http://localhost:8000/", 1); |
233 | 170 | setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1); | 170 | setenv("ACCOUNT_CREDS_URL", "http://localhost:8000/creds/", 1); |
234 | 171 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); | 171 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); |
236 | 172 | network.getPaymentTypes(); | 172 | network.requestPaymentTypes(); |
237 | 173 | QTRY_COMPARE(spy.count(), 1); | 173 | QTRY_COMPARE(spy.count(), 1); |
238 | 174 | setenv("PAY_BASE_URL", "http://localhost:8000/interaction/", 1); | 174 | setenv("PAY_BASE_URL", "http://localhost:8000/interaction/", 1); |
239 | 175 | QSignalSpy spy2(&network, SIGNAL(buyInteractionRequired(QString))); | 175 | QSignalSpy spy2(&network, SIGNAL(buyInteractionRequired(QString))); |
240 | 176 | 176 | ||
241 | === modified file 'manifest.json' | |||
242 | --- manifest.json 2014-07-15 18:50:54 +0000 | |||
243 | +++ manifest.json 2014-07-16 18:53:33 +0000 | |||
244 | @@ -1,7 +1,7 @@ | |||
245 | 1 | { | 1 | { |
246 | 2 | "name": "com.canonical.payui", | 2 | "name": "com.canonical.payui", |
247 | 3 | "description": "UI for Pay Service", | 3 | "description": "UI for Pay Service", |
249 | 4 | "framework": "ubuntu-sdk-14.04-qml-dev2", | 4 | "framework": "ubuntu-sdk-14.10-qml-dev2", |
250 | 5 | "architecture": "armhf", | 5 | "architecture": "armhf", |
251 | 6 | "title": "PayUI", | 6 | "title": "PayUI", |
252 | 7 | "hooks": { | 7 | "hooks": { |
253 | @@ -10,6 +10,6 @@ | |||
254 | 10 | "desktop": "payui.desktop" | 10 | "desktop": "payui.desktop" |
255 | 11 | } | 11 | } |
256 | 12 | }, | 12 | }, |
258 | 13 | "version": "0.2.9", | 13 | "version": "0.3", |
259 | 14 | "maintainer": "Sarmentero Diego <diego.sarmentero@canonical.com>" | 14 | "maintainer": "Sarmentero Diego <diego.sarmentero@canonical.com>" |
260 | 15 | } | 15 | } |
261 | 16 | \ No newline at end of file | 16 | \ No newline at end of file |
262 | 17 | 17 | ||
263 | === modified file 'payui.json' | |||
264 | --- payui.json 2014-06-23 18:20:45 +0000 | |||
265 | +++ payui.json 2014-07-16 18:53:33 +0000 | |||
266 | @@ -1,5 +1,5 @@ | |||
267 | 1 | { | 1 | { |
268 | 2 | "policy_groups": [], | 2 | "policy_groups": [], |
270 | 3 | "policy_version": 1.1, | 3 | "policy_version": 1.2, |
271 | 4 | "template": "unconfined" | 4 | "template": "unconfined" |
272 | 5 | } | 5 | } |
273 | 6 | \ No newline at end of file | 6 | \ No newline at end of file |
Looks good.