Merge lp:~alecu/pay-ui/euro-and-more into lp:pay-ui
- euro-and-more
- Merge into first-branch
Proposed by
Alejandro J. Cura
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | dobey | ||||
Approved revision: | 72 | ||||
Merged at revision: | 63 | ||||
Proposed branch: | lp:~alecu/pay-ui/euro-and-more | ||||
Merge into: | lp:pay-ui | ||||
Diff against target: |
763 lines (+229/-92) 8 files modified
app/payui.qml (+21/-19) backend/modules/payui/network.cpp (+76/-14) backend/modules/payui/network.h (+10/-5) backend/modules/payui/purchase.cpp (+23/-24) backend/modules/payui/purchase.h (+7/-6) backend/tests/mock_click_server.py (+14/-5) backend/tests/test_network.cpp (+76/-17) manifest.json (+2/-2) |
||||
To merge this branch: | bzr merge lp:~alecu/pay-ui/euro-and-more | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
dobey (community) | Approve | ||
Diego Sarmentero (community) | Approve | ||
Review via email: mp+236792@code.launchpad.net |
Commit message
Support for currencies other than USD
Description of the change
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Approve
(continuous-integration)
Revision history for this message
dobey (dobey) : | # |
review:
Needs Fixing
lp:~alecu/pay-ui/euro-and-more
updated
- 71. By Alejandro J. Cura
-
Make the pay-ui handle suggested currencies just like the click scope
- 72. By Alejandro J. Cura
-
Update maintainer
Revision history for this message
dobey (dobey) : | # |
review:
Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:72
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 'app/payui.qml' | |||
2 | --- app/payui.qml 2014-09-29 22:27:29 +0000 | |||
3 | +++ app/payui.qml 2014-10-02 18:57:25 +0000 | |||
4 | @@ -56,6 +56,7 @@ | |||
5 | 56 | property bool purchasing: false | 56 | property bool purchasing: false |
6 | 57 | property bool recentLogin: false | 57 | property bool recentLogin: false |
7 | 58 | property bool cancellable: true | 58 | property bool cancellable: true |
8 | 59 | property string suggestedCurrency: "USD" | ||
9 | 59 | 60 | ||
10 | 60 | backgroundColor: "transparent" | 61 | backgroundColor: "transparent" |
11 | 61 | 62 | ||
12 | @@ -88,20 +89,17 @@ | |||
13 | 88 | id: purchase | 89 | id: purchase |
14 | 89 | 90 | ||
15 | 90 | onItemDetailsObtained: { | 91 | onItemDetailsObtained: { |
21 | 91 | var loc_c = Qt.locale("C"); | 92 | suggestedCurrency = currency; |
17 | 92 | // This string comes from a json double, and must be parsed with C locale | ||
18 | 93 | var pnum = Number.fromLocaleString(loc_c, price); | ||
19 | 94 | |||
20 | 95 | var loc = Qt.locale(); | ||
22 | 96 | checkout.itemTitle = title; | 93 | checkout.itemTitle = title; |
23 | 97 | checkout.itemSubtitle = publisher; | 94 | checkout.itemSubtitle = publisher; |
25 | 98 | checkout.price = pnum.toLocaleCurrencyString(loc, "US$"); | 95 | checkout.price = formatted_price; |
26 | 99 | payment.itemTitle = title; | 96 | payment.itemTitle = title; |
27 | 100 | payment.itemSubtitle = publisher; | 97 | payment.itemSubtitle = publisher; |
29 | 101 | payment.price = pnum.toLocaleCurrencyString(loc, "US$"); | 98 | payment.price = formatted_price; |
30 | 102 | direct.itemTitle = title; | 99 | direct.itemTitle = title; |
31 | 103 | direct.itemSubtitle = publisher; | 100 | direct.itemSubtitle = publisher; |
33 | 104 | direct.price = pnum.toLocaleCurrencyString(loc, "US$"); | 101 | direct.price = formatted_price; |
34 | 102 | checkCredentials(); | ||
35 | 105 | } | 103 | } |
36 | 106 | 104 | ||
37 | 107 | onPaymentTypesObtained: { | 105 | onPaymentTypesObtained: { |
38 | @@ -190,10 +188,14 @@ | |||
39 | 190 | if (mainView.state == "online-accounts") { | 188 | if (mainView.state == "online-accounts") { |
40 | 191 | purchase.checkItemPurchased(); | 189 | purchase.checkItemPurchased(); |
41 | 192 | } else if (mainView.state != "checkout" && !mainView.purchasing && mainView.state != "buy-interaction") { | 190 | } else if (mainView.state != "checkout" && !mainView.purchasing && mainView.state != "buy-interaction") { |
43 | 193 | purchase.getPaymentTypes(); | 191 | purchase.getPaymentTypes(suggestedCurrency); |
44 | 194 | } | 192 | } |
45 | 195 | } | 193 | } |
46 | 196 | 194 | ||
47 | 195 | onItemNotPurchased: { | ||
48 | 196 | purchase.getPaymentTypes(suggestedCurrency); | ||
49 | 197 | } | ||
50 | 198 | |||
51 | 197 | onCredentialsNotFound: { | 199 | onCredentialsNotFound: { |
52 | 198 | mainView.recentLogin = false; | 200 | mainView.recentLogin = false; |
53 | 199 | if (mainView.state == "online-accounts") { | 201 | if (mainView.state == "online-accounts") { |
54 | @@ -286,7 +288,7 @@ | |||
55 | 286 | 288 | ||
56 | 287 | onRetry: { | 289 | onRetry: { |
57 | 288 | mainView.showLoading(); | 290 | mainView.showLoading(); |
59 | 289 | purchase.checkCredentials(); | 291 | purchase.getItemDetails(); |
60 | 290 | } | 292 | } |
61 | 291 | 293 | ||
62 | 292 | onClose: { | 294 | onClose: { |
63 | @@ -301,7 +303,7 @@ | |||
64 | 301 | 303 | ||
65 | 302 | onRetry: { | 304 | onRetry: { |
66 | 303 | mainView.showLoading(); | 305 | mainView.showLoading(); |
68 | 304 | purchase.checkCredentials(); | 306 | purchase.getItemDetails(); |
69 | 305 | } | 307 | } |
70 | 306 | 308 | ||
71 | 307 | onClose: { | 309 | onClose: { |
72 | @@ -316,7 +318,7 @@ | |||
73 | 316 | 318 | ||
74 | 317 | onRetry: { | 319 | onRetry: { |
75 | 318 | mainView.showLoading(); | 320 | mainView.showLoading(); |
77 | 319 | purchase.checkCredentials(); | 321 | purchase.getItemDetails(); |
78 | 320 | } | 322 | } |
79 | 321 | 323 | ||
80 | 322 | onClose: { | 324 | onClose: { |
81 | @@ -360,7 +362,7 @@ | |||
82 | 360 | Component.onCompleted: { | 362 | Component.onCompleted: { |
83 | 361 | showLoading(); | 363 | showLoading(); |
84 | 362 | mainView.createDB(); | 364 | mainView.createDB(); |
86 | 363 | purchase.checkCredentials(); | 365 | purchase.getItemDetails(); |
87 | 364 | } | 366 | } |
88 | 365 | 367 | ||
89 | 366 | onCurrentPageChanged: { | 368 | onCurrentPageChanged: { |
90 | @@ -400,17 +402,17 @@ | |||
91 | 400 | mainView.purchasing = true; | 402 | mainView.purchasing = true; |
92 | 401 | mainView.cancellable = false; | 403 | mainView.cancellable = false; |
93 | 402 | showLoading(); | 404 | showLoading(); |
95 | 403 | purchase.buyItem(email, password, otp, direct.paymentId, direct.backendId, mainView.recentLogin); | 405 | purchase.buyItem(email, password, otp, suggestedCurrency, direct.paymentId, direct.backendId, mainView.recentLogin); |
96 | 404 | } else if (direct.hasPayments && direct.hasPreferredPayment) { | 406 | } else if (direct.hasPayments && direct.hasPreferredPayment) { |
97 | 405 | mainView.purchasing = true; | 407 | mainView.purchasing = true; |
98 | 406 | mainView.cancellable = false; | 408 | mainView.cancellable = false; |
99 | 407 | showLoading(); | 409 | showLoading(); |
101 | 408 | purchase.buyItemWithPreferredPayment(email, password, otp, mainView.recentLogin); | 410 | purchase.buyItemWithPreferredPayment(email, password, otp, suggestedCurrency, mainView.recentLogin); |
102 | 409 | } else if (direct.hasStoredPayment) { | 411 | } else if (direct.hasStoredPayment) { |
103 | 410 | var values = mainView.getLastPayment(); | 412 | var values = mainView.getLastPayment(); |
104 | 411 | var backendid = values[0]; | 413 | var backendid = values[0]; |
105 | 412 | var paymentid = values[1]; | 414 | var paymentid = values[1]; |
107 | 413 | purchase.buyItem(email, password, otp, paymentid, backendid, mainView.recentLogin); | 415 | purchase.buyItem(email, password, otp, suggestedCurrency, paymentid, backendid, mainView.recentLogin); |
108 | 414 | } else { | 416 | } else { |
109 | 415 | mainView.state = "checkout"; | 417 | mainView.state = "checkout"; |
110 | 416 | pageStack.push(checkout); | 418 | pageStack.push(checkout); |
111 | @@ -439,7 +441,7 @@ | |||
112 | 439 | } | 441 | } |
113 | 440 | 442 | ||
114 | 441 | if (mainView.recentLogin) { | 443 | if (mainView.recentLogin) { |
116 | 442 | purchase.buyItem(email, "", "", paymentId, backendId, mainView.recentLogin); | 444 | purchase.buyItem(email, "", "", suggestedCurrency, paymentId, backendId, mainView.recentLogin); |
117 | 443 | } else { | 445 | } else { |
118 | 444 | mainView.cancellable = true; | 446 | mainView.cancellable = true; |
119 | 445 | mainView.purchasing = false; | 447 | mainView.purchasing = false; |
120 | @@ -458,7 +460,7 @@ | |||
121 | 458 | 460 | ||
122 | 459 | onAddCreditCard: { | 461 | onAddCreditCard: { |
123 | 460 | webkit.title = i18n.tr("Add Payment"); | 462 | webkit.title = i18n.tr("Add Payment"); |
125 | 461 | webkit.url = purchase.getAddPaymentUrl(); | 463 | webkit.url = purchase.getAddPaymentUrl(suggestedCurrency); |
126 | 462 | mainView.state = "add-payment"; | 464 | mainView.state = "add-payment"; |
127 | 463 | pageStack.push(webkit); | 465 | pageStack.push(webkit); |
128 | 464 | } | 466 | } |
129 | @@ -494,7 +496,7 @@ | |||
130 | 494 | onPurchaseSucceeded: { | 496 | onPurchaseSucceeded: { |
131 | 495 | if (mainView.state == "add-payment") { | 497 | if (mainView.state == "add-payment") { |
132 | 496 | showLoading(); | 498 | showLoading(); |
134 | 497 | purchase.getPaymentTypes(); | 499 | purchase.getPaymentTypes(suggestedCurrency); |
135 | 498 | } else { | 500 | } else { |
136 | 499 | purchase.quitSuccess(); | 501 | purchase.quitSuccess(); |
137 | 500 | } | 502 | } |
138 | 501 | 503 | ||
139 | === modified file 'backend/modules/payui/network.cpp' | |||
140 | --- backend/modules/payui/network.cpp 2014-09-25 20:46:48 +0000 | |||
141 | +++ backend/modules/payui/network.cpp 2014-10-02 18:57:25 +0000 | |||
142 | @@ -36,6 +36,7 @@ | |||
143 | 36 | #define PAY_PURCHASES_PATH "/purchases" | 36 | #define PAY_PURCHASES_PATH "/purchases" |
144 | 37 | #define PAY_PAYMENTMETHODS_PATH "/paymentmethods" | 37 | #define PAY_PAYMENTMETHODS_PATH "/paymentmethods" |
145 | 38 | #define PAY_PAYMENTMETHODS_ADD_PATH PAY_PAYMENTMETHODS_PATH + "/add" | 38 | #define PAY_PAYMENTMETHODS_ADD_PATH PAY_PAYMENTMETHODS_PATH + "/add" |
146 | 39 | #define SUGGESTED_CURRENCY_HEADER_NAME "X-Suggested-Currency" | ||
147 | 39 | 40 | ||
148 | 40 | #define PREFERED_PAYMENT_TYPE "0" | 41 | #define PREFERED_PAYMENT_TYPE "0" |
149 | 41 | #define PAYMENT_TYPES "1" | 42 | #define PAYMENT_TYPES "1" |
150 | @@ -90,6 +91,42 @@ | |||
151 | 90 | m_service.setCredentials(token); | 91 | m_service.setCredentials(token); |
152 | 91 | } | 92 | } |
153 | 92 | 93 | ||
154 | 94 | QMap<QString, QString> buildCurrencyMap() | ||
155 | 95 | { | ||
156 | 96 | /* NOTE: The list of currencies we need to handle mapping symbols of. | ||
157 | 97 | * Please keep this list in A-Z order. | ||
158 | 98 | */ | ||
159 | 99 | QMap<QString, QString> currencies_map { | ||
160 | 100 | { "CNY", "RMB"}, | ||
161 | 101 | { "EUR", "€"}, | ||
162 | 102 | { "GBP", "₤"}, | ||
163 | 103 | { "HKD", "HK$"}, | ||
164 | 104 | { "TWD", "TW$"}, | ||
165 | 105 | { "USD", "US$"}, | ||
166 | 106 | }; | ||
167 | 107 | return currencies_map; | ||
168 | 108 | } | ||
169 | 109 | |||
170 | 110 | const QString DEFAULT_CURRENCY {"USD"}; | ||
171 | 111 | |||
172 | 112 | QString Network::getSymbolForCurrency(const QString ¤cy_code) | ||
173 | 113 | { | ||
174 | 114 | static QMap<QString, QString> currency_map = buildCurrencyMap(); | ||
175 | 115 | |||
176 | 116 | if (currency_map.contains(currency_code)) { | ||
177 | 117 | return currency_map[currency_code]; | ||
178 | 118 | } else{ | ||
179 | 119 | return currency_code; | ||
180 | 120 | } | ||
181 | 121 | } | ||
182 | 122 | |||
183 | 123 | bool Network::isSupportedCurrency(const QString& currency_code) | ||
184 | 124 | { | ||
185 | 125 | static QMap<QString, QString> currency_map = buildCurrencyMap(); | ||
186 | 126 | |||
187 | 127 | return currency_map.contains(currency_code); | ||
188 | 128 | } | ||
189 | 129 | |||
190 | 93 | void Network::onReply(QNetworkReply *reply) | 130 | void Network::onReply(QNetworkReply *reply) |
191 | 94 | { | 131 | { |
192 | 95 | QVariant statusAttr = reply->attribute( | 132 | QVariant statusAttr = reply->attribute( |
193 | @@ -167,10 +204,26 @@ | |||
194 | 167 | QJsonObject object = document.object(); | 204 | QJsonObject object = document.object(); |
195 | 168 | QString title = object.value("title").toString(); | 205 | QString title = object.value("title").toString(); |
196 | 169 | QString publisher = object.value("publisher").toString(); | 206 | QString publisher = object.value("publisher").toString(); |
197 | 170 | QString price = QString::number(object.value("price").toDouble()); | ||
198 | 171 | QString icon = object.value("icon_url").toString(); | 207 | QString icon = object.value("icon_url").toString(); |
199 | 172 | 208 | ||
201 | 173 | Q_EMIT itemDetailsObtained(title, publisher, price, icon); | 209 | QJsonObject prices = object.value("prices").toObject(); |
202 | 210 | QString suggested_currency = DEFAULT_CURRENCY; | ||
203 | 211 | QString currency = DEFAULT_CURRENCY; | ||
204 | 212 | if (reply->hasRawHeader(SUGGESTED_CURRENCY_HEADER_NAME)) { | ||
205 | 213 | suggested_currency = reply->rawHeader(SUGGESTED_CURRENCY_HEADER_NAME); | ||
206 | 214 | } | ||
207 | 215 | const char* env_value = std::getenv(CURRENCY_ENVVAR); | ||
208 | 216 | if (env_value != NULL) { | ||
209 | 217 | suggested_currency = env_value; | ||
210 | 218 | } | ||
211 | 219 | |||
212 | 220 | if (isSupportedCurrency(suggested_currency) && prices.contains(suggested_currency)) { | ||
213 | 221 | currency = suggested_currency; | ||
214 | 222 | } | ||
215 | 223 | double price = prices[currency].toDouble(); | ||
216 | 224 | QLocale locale; | ||
217 | 225 | QString formatted_price = locale.toCurrencyString(price, getSymbolForCurrency(currency)); | ||
218 | 226 | Q_EMIT itemDetailsObtained(title, publisher, currency, formatted_price, icon); | ||
219 | 174 | } else if (state->operation.contains(CHECK_PURCHASED)) { | 227 | } else if (state->operation.contains(CHECK_PURCHASED)) { |
220 | 175 | Q_EMIT buyItemSucceeded(); | 228 | Q_EMIT buyItemSucceeded(); |
221 | 176 | } else { | 229 | } else { |
222 | @@ -182,22 +235,25 @@ | |||
223 | 182 | } else if (httpStatus == 401 || httpStatus == 403) { | 235 | } else if (httpStatus == 401 || httpStatus == 403) { |
224 | 183 | Q_EMIT authenticationError(); | 236 | Q_EMIT authenticationError(); |
225 | 184 | } else if (httpStatus == 404 && state->operation.contains(CHECK_PURCHASED)) { | 237 | } else if (httpStatus == 404 && state->operation.contains(CHECK_PURCHASED)) { |
227 | 185 | requestPaymentTypes(); | 238 | Q_EMIT itemNotPurchased(); |
228 | 186 | } else { | 239 | } else { |
229 | 187 | Q_EMIT error(QString::number(httpStatus)); | 240 | Q_EMIT error(QString::number(httpStatus)); |
230 | 188 | } | 241 | } |
231 | 189 | reply->deleteLater(); | 242 | reply->deleteLater(); |
232 | 190 | } | 243 | } |
233 | 191 | 244 | ||
235 | 192 | void Network::requestPaymentTypes() | 245 | void Network::requestPaymentTypes(const QString& currency) |
236 | 193 | { | 246 | { |
237 | 194 | QNetworkRequest request; | 247 | QNetworkRequest request; |
238 | 195 | request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); | 248 | request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); |
242 | 196 | QString url = getAPIUrl(PAY_BASE_URL_ENVVAR, QString(PAY_BASE_URL)) + PAY_API_ROOT + PAY_PAYMENTMETHODS_PATH + "/"; | 249 | QUrl url(getAPIUrl(PAY_BASE_URL_ENVVAR, QString(PAY_BASE_URL)) + PAY_API_ROOT + PAY_PAYMENTMETHODS_PATH + "/"); |
243 | 197 | qDebug() << "Request Payment Types:" << url; | 250 | QUrlQuery query; |
244 | 198 | signRequestUrl(request, url); | 251 | query.addQueryItem("currency", currency); |
245 | 252 | url.setQuery(query); | ||
246 | 253 | qDebug() << "Request Payment Types:" << url.toString(); | ||
247 | 254 | signRequestUrl(request, url.toString()); | ||
248 | 199 | request.setRawHeader("Accept", "application/json"); | 255 | request.setRawHeader("Accept", "application/json"); |
250 | 200 | request.setUrl(QUrl(url)); | 256 | request.setUrl(url); |
251 | 201 | RequestObject* reqObject = new RequestObject(QString(PAYMENT_TYPES)); | 257 | RequestObject* reqObject = new RequestObject(QString(PAYMENT_TYPES)); |
252 | 202 | request.setOriginatingObject(reqObject); | 258 | request.setOriginatingObject(reqObject); |
253 | 203 | m_nam.get(request); | 259 | m_nam.get(request); |
254 | @@ -210,12 +266,14 @@ | |||
255 | 210 | } | 266 | } |
256 | 211 | 267 | ||
257 | 212 | void Network::buyItemWithPreferredPaymentType(const QString& email, const QString& password, const QString& otp, | 268 | void Network::buyItemWithPreferredPaymentType(const QString& email, const QString& password, const QString& otp, |
259 | 213 | const QString& appid, const QString& itemid, bool recentLogin) | 269 | const QString& appid, const QString& itemid, const QString& currency, |
260 | 270 | bool recentLogin) | ||
261 | 214 | { | 271 | { |
262 | 215 | m_selectedPaymentId = m_preferred->paymentId(); | 272 | m_selectedPaymentId = m_preferred->paymentId(); |
263 | 216 | m_selectedBackendId = m_preferred->backendId(); | 273 | m_selectedBackendId = m_preferred->backendId(); |
264 | 217 | m_selectedAppId = appid; | 274 | m_selectedAppId = appid; |
265 | 218 | m_selectedItemId = itemid; | 275 | m_selectedItemId = itemid; |
266 | 276 | m_currency = currency; | ||
267 | 219 | if (recentLogin) { | 277 | if (recentLogin) { |
268 | 220 | purchaseProcess(); | 278 | purchaseProcess(); |
269 | 221 | } else { | 279 | } else { |
270 | @@ -226,13 +284,14 @@ | |||
271 | 226 | 284 | ||
272 | 227 | void Network::buyItem(const QString& email, const QString& password, | 285 | void Network::buyItem(const QString& email, const QString& password, |
273 | 228 | const QString& otp, | 286 | const QString& otp, |
275 | 229 | const QString& appid, const QString& itemid, | 287 | const QString& appid, const QString& itemid, const QString& currency, |
276 | 230 | const QString& paymentId, const QString& backendId, bool recentLogin) | 288 | const QString& paymentId, const QString& backendId, bool recentLogin) |
277 | 231 | { | 289 | { |
278 | 232 | m_selectedPaymentId = paymentId; | 290 | m_selectedPaymentId = paymentId; |
279 | 233 | m_selectedBackendId = backendId; | 291 | m_selectedBackendId = backendId; |
280 | 234 | m_selectedAppId = appid; | 292 | m_selectedAppId = appid; |
281 | 235 | m_selectedItemId = itemid; | 293 | m_selectedItemId = itemid; |
282 | 294 | m_currency = currency; | ||
283 | 236 | if (recentLogin) { | 295 | if (recentLogin) { |
284 | 237 | purchaseProcess(); | 296 | purchaseProcess(); |
285 | 238 | } else { | 297 | } else { |
286 | @@ -252,6 +311,7 @@ | |||
287 | 252 | serializer.insert("name", m_selectedAppId); | 311 | serializer.insert("name", m_selectedAppId); |
288 | 253 | serializer.insert("backend_id", m_selectedBackendId); | 312 | serializer.insert("backend_id", m_selectedBackendId); |
289 | 254 | serializer.insert("method_id", m_selectedPaymentId); | 313 | serializer.insert("method_id", m_selectedPaymentId); |
290 | 314 | serializer.insert("currency", m_currency); | ||
291 | 255 | QJsonDocument doc(serializer); | 315 | QJsonDocument doc(serializer); |
292 | 256 | 316 | ||
293 | 257 | QByteArray content = doc.toJson(); | 317 | QByteArray content = doc.toJson(); |
294 | @@ -304,14 +364,16 @@ | |||
295 | 304 | request.setRawHeader("Authorization", sign.toUtf8()); | 364 | request.setRawHeader("Authorization", sign.toUtf8()); |
296 | 305 | } | 365 | } |
297 | 306 | 366 | ||
299 | 307 | QString Network::getAddPaymentUrl() | 367 | QString Network::getAddPaymentUrl(const QString& currency) |
300 | 308 | { | 368 | { |
302 | 309 | QString baseUrl = getAPIUrl(PAY_BASE_URL_ENVVAR, QString(PAY_BASE_URL)) + PAY_API_ROOT + PAY_PAYMENTMETHODS_ADD_PATH + "/"; | 369 | QUrl baseUrl(getAPIUrl(PAY_BASE_URL_ENVVAR, QString(PAY_BASE_URL)) + PAY_API_ROOT + PAY_PAYMENTMETHODS_ADD_PATH + "/"); |
303 | 370 | QUrlQuery query; | ||
304 | 371 | query.addQueryItem("currency", currency); | ||
305 | 372 | baseUrl.setQuery(query); | ||
306 | 310 | qDebug() << "Get Add Payment URL:" << baseUrl; | 373 | qDebug() << "Get Add Payment URL:" << baseUrl; |
308 | 311 | QString sign = m_token.signUrl(baseUrl, QStringLiteral("GET"), true); | 374 | QString sign = m_token.signUrl(baseUrl.toString(), QStringLiteral("GET"), true); |
309 | 312 | QUrl signedUrl(baseUrl); | 375 | QUrl signedUrl(baseUrl); |
310 | 313 | signedUrl.setQuery(sign); | 376 | signedUrl.setQuery(sign); |
311 | 314 | |||
312 | 315 | return signedUrl.toString(); | 377 | return signedUrl.toString(); |
313 | 316 | } | 378 | } |
314 | 317 | 379 | ||
315 | 318 | 380 | ||
316 | === modified file 'backend/modules/payui/network.h' | |||
317 | --- backend/modules/payui/network.h 2014-09-11 03:10:25 +0000 | |||
318 | +++ backend/modules/payui/network.h 2014-10-02 18:57:25 +0000 | |||
319 | @@ -38,6 +38,7 @@ | |||
320 | 38 | constexpr static const char* PAY_BASE_URL_ENVVAR{"PAY_BASE_URL"}; | 38 | constexpr static const char* PAY_BASE_URL_ENVVAR{"PAY_BASE_URL"}; |
321 | 39 | constexpr static const char* PAY_BASE_URL{"https://software-center.ubuntu.com"}; | 39 | constexpr static const char* PAY_BASE_URL{"https://software-center.ubuntu.com"}; |
322 | 40 | constexpr static const char* PAY_API_ROOT{"/api/2.0/click"}; | 40 | constexpr static const char* PAY_API_ROOT{"/api/2.0/click"}; |
323 | 41 | constexpr static const char* CURRENCY_ENVVAR {"U1_SEARCH_CURRENCY"}; | ||
324 | 41 | 42 | ||
325 | 42 | class RequestObject : public QObject | 43 | class RequestObject : public QObject |
326 | 43 | { | 44 | { |
327 | @@ -58,26 +59,28 @@ | |||
328 | 58 | public: | 59 | public: |
329 | 59 | explicit Network(QObject *parent = 0); | 60 | explicit Network(QObject *parent = 0); |
330 | 60 | 61 | ||
332 | 61 | void requestPaymentTypes(); | 62 | void requestPaymentTypes(const QString& currency); |
333 | 62 | void buyItem(const QString& email, const QString& password, | 63 | void buyItem(const QString& email, const QString& password, |
334 | 63 | const QString& otp, const QString& appid, | 64 | const QString& otp, const QString& appid, |
336 | 64 | const QString& itemid, const QString& paymentId, | 65 | const QString& itemid, const QString& currency, const QString& paymentId, |
337 | 65 | const QString& backendId, bool recentLogin); | 66 | const QString& backendId, bool recentLogin); |
338 | 66 | void buyItemWithPreferredPaymentType(const QString& email, const QString& password, | 67 | void buyItemWithPreferredPaymentType(const QString& email, const QString& password, |
339 | 67 | const QString& otp, | 68 | const QString& otp, |
341 | 68 | const QString& appid, const QString& itemid, | 69 | const QString& appid, const QString& itemid, const QString& currency, |
342 | 69 | bool recentLogin); | 70 | bool recentLogin); |
343 | 70 | void getItemInfo(const QString &packagename); | 71 | void getItemInfo(const QString &packagename); |
344 | 71 | void checkPassword(const QString& email, const QString& password, | 72 | void checkPassword(const QString& email, const QString& password, |
345 | 72 | const QString& otp); | 73 | const QString& otp); |
346 | 73 | void getCredentials(); | 74 | void getCredentials(); |
347 | 74 | void setCredentials(Token token); | 75 | void setCredentials(Token token); |
349 | 75 | QString getAddPaymentUrl(); | 76 | QString getAddPaymentUrl(const QString& currency); |
350 | 76 | QDateTime getTokenUpdated(); | 77 | QDateTime getTokenUpdated(); |
351 | 77 | void checkItemPurchased(const QString& appid); | 78 | void checkItemPurchased(const QString& appid); |
352 | 79 | static QString getSymbolForCurrency(const QString& currency_code); | ||
353 | 80 | static bool isSupportedCurrency(const QString& currency_code); | ||
354 | 78 | 81 | ||
355 | 79 | Q_SIGNALS: | 82 | Q_SIGNALS: |
357 | 80 | void itemDetailsObtained(QString title, QString publisher, QString price, QString icon); | 83 | void itemDetailsObtained(QString title, QString publisher, QString currency, QString formatted_price, QString icon); |
358 | 81 | void paymentTypesObtained(QVariantList payments); | 84 | void paymentTypesObtained(QVariantList payments); |
359 | 82 | void buyItemSucceeded(); | 85 | void buyItemSucceeded(); |
360 | 83 | void buyItemFailed(); | 86 | void buyItemFailed(); |
361 | @@ -90,6 +93,7 @@ | |||
362 | 90 | void noPreferredPaymentMethod(); | 93 | void noPreferredPaymentMethod(); |
363 | 91 | void loginError(const QString& message); | 94 | void loginError(const QString& message); |
364 | 92 | void twoFactorAuthRequired(); | 95 | void twoFactorAuthRequired(); |
365 | 96 | void itemNotPurchased(); | ||
366 | 93 | 97 | ||
367 | 94 | private Q_SLOTS: | 98 | private Q_SLOTS: |
368 | 95 | void onReply(QNetworkReply*); | 99 | void onReply(QNetworkReply*); |
369 | @@ -107,6 +111,7 @@ | |||
370 | 107 | QString m_selectedBackendId; | 111 | QString m_selectedBackendId; |
371 | 108 | QString m_selectedAppId; | 112 | QString m_selectedAppId; |
372 | 109 | QString m_selectedItemId; | 113 | QString m_selectedItemId; |
373 | 114 | QString m_currency; | ||
374 | 110 | bool m_startPurchase = false; | 115 | bool m_startPurchase = false; |
375 | 111 | 116 | ||
376 | 112 | QString getAPIUrl(QString urlKey, QString defaultValue); | 117 | QString getAPIUrl(QString urlKey, QString defaultValue); |
377 | 113 | 118 | ||
378 | === modified file 'backend/modules/payui/purchase.cpp' | |||
379 | --- backend/modules/payui/purchase.cpp 2014-09-11 03:10:25 +0000 | |||
380 | +++ backend/modules/payui/purchase.cpp 2014-10-02 18:57:25 +0000 | |||
381 | @@ -38,6 +38,8 @@ | |||
382 | 38 | this, &Purchase::loginError); | 38 | this, &Purchase::loginError); |
383 | 39 | connect(&m_network, &Network::twoFactorAuthRequired, | 39 | connect(&m_network, &Network::twoFactorAuthRequired, |
384 | 40 | this, &Purchase::twoFactorAuthRequired); | 40 | this, &Purchase::twoFactorAuthRequired); |
385 | 41 | connect(&m_network, &Network::itemNotPurchased, | ||
386 | 42 | this, &Purchase::itemNotPurchased); | ||
387 | 41 | 43 | ||
388 | 42 | QCoreApplication* instance = QCoreApplication::instance(); | 44 | QCoreApplication* instance = QCoreApplication::instance(); |
389 | 43 | Logger::setupLogging(); | 45 | Logger::setupLogging(); |
390 | @@ -74,30 +76,27 @@ | |||
391 | 74 | 76 | ||
392 | 75 | void Purchase::checkCredentials() | 77 | void Purchase::checkCredentials() |
393 | 76 | { | 78 | { |
394 | 79 | m_network.getCredentials(); | ||
395 | 80 | } | ||
396 | 81 | |||
397 | 82 | QString Purchase::getAddPaymentUrl(QString currency) | ||
398 | 83 | { | ||
399 | 84 | return m_network.getAddPaymentUrl(currency); | ||
400 | 85 | } | ||
401 | 86 | |||
402 | 87 | void Purchase::getItemDetails() | ||
403 | 88 | { | ||
404 | 77 | if (m_appid.isEmpty() && m_itemid.isEmpty()) { | 89 | if (m_appid.isEmpty() && m_itemid.isEmpty()) { |
405 | 78 | qDebug() << "AppId or ItemId not provided"; | 90 | qDebug() << "AppId or ItemId not provided"; |
406 | 79 | quitCancel(); | 91 | quitCancel(); |
407 | 80 | } else { | ||
408 | 81 | qDebug() << "Getting Item Details"; | ||
409 | 82 | getItemDetails(m_appid, m_itemid); | ||
410 | 83 | } | 92 | } |
428 | 84 | m_network.getCredentials(); | 93 | qDebug() << "Getting Item Details"; |
429 | 85 | } | 94 | m_network.getItemInfo(m_appid); |
430 | 86 | 95 | } | |
431 | 87 | QString Purchase::getAddPaymentUrl() | 96 | |
432 | 88 | { | 97 | void Purchase::getPaymentTypes(const QString& currency) |
433 | 89 | return m_network.getAddPaymentUrl(); | 98 | { |
434 | 90 | } | 99 | m_network.requestPaymentTypes(currency); |
418 | 91 | |||
419 | 92 | void Purchase::getItemDetails(QString packagename, QString itemid) | ||
420 | 93 | { | ||
421 | 94 | Q_UNUSED(itemid); | ||
422 | 95 | m_network.getItemInfo(packagename); | ||
423 | 96 | } | ||
424 | 97 | |||
425 | 98 | void Purchase::getPaymentTypes() | ||
426 | 99 | { | ||
427 | 100 | m_network.requestPaymentTypes(); | ||
435 | 101 | } | 100 | } |
436 | 102 | 101 | ||
437 | 103 | void Purchase::checkWallet(QString email, QString password, QString otp) | 102 | void Purchase::checkWallet(QString email, QString password, QString otp) |
438 | @@ -105,14 +104,14 @@ | |||
439 | 105 | m_network.checkPassword(email, password, otp); | 104 | m_network.checkPassword(email, password, otp); |
440 | 106 | } | 105 | } |
441 | 107 | 106 | ||
443 | 108 | void Purchase::buyItemWithPreferredPayment(QString email, QString password, QString otp, bool recentLogin) | 107 | void Purchase::buyItemWithPreferredPayment(QString email, QString password, QString otp, QString currency, bool recentLogin) |
444 | 109 | { | 108 | { |
446 | 110 | m_network.buyItemWithPreferredPaymentType(email, password, otp, m_appid, m_itemid, recentLogin); | 109 | m_network.buyItemWithPreferredPaymentType(email, password, otp, m_appid, m_itemid, currency, recentLogin); |
447 | 111 | } | 110 | } |
448 | 112 | 111 | ||
450 | 113 | void Purchase::buyItem(QString email, QString password, QString otp, QString paymentId, QString backendId, bool recentLogin) | 112 | void Purchase::buyItem(QString email, QString password, QString otp, QString currency, QString paymentId, QString backendId, bool recentLogin) |
451 | 114 | { | 113 | { |
453 | 115 | m_network.buyItem(email, password, otp, m_appid, m_itemid, paymentId, backendId, recentLogin); | 114 | m_network.buyItem(email, password, otp, m_appid, m_itemid, currency, paymentId, backendId, recentLogin); |
454 | 116 | } | 115 | } |
455 | 117 | 116 | ||
456 | 118 | QDateTime Purchase::getTokenUpdated() | 117 | QDateTime Purchase::getTokenUpdated() |
457 | 119 | 118 | ||
458 | === modified file 'backend/modules/payui/purchase.h' | |||
459 | --- backend/modules/payui/purchase.h 2014-09-11 03:10:25 +0000 | |||
460 | +++ backend/modules/payui/purchase.h 2014-10-02 18:57:25 +0000 | |||
461 | @@ -17,12 +17,12 @@ | |||
462 | 17 | explicit Purchase(QObject *parent = 0); | 17 | explicit Purchase(QObject *parent = 0); |
463 | 18 | ~Purchase(); | 18 | ~Purchase(); |
464 | 19 | 19 | ||
469 | 20 | Q_INVOKABLE void getItemDetails(QString packagename, QString itemid); | 20 | Q_INVOKABLE void getItemDetails(); |
470 | 21 | Q_INVOKABLE void getPaymentTypes(); | 21 | Q_INVOKABLE void getPaymentTypes(const QString ¤cy); |
471 | 22 | Q_INVOKABLE void buyItemWithPreferredPayment(QString email, QString password, QString otp, bool recentLogin); | 22 | Q_INVOKABLE void buyItemWithPreferredPayment(QString email, QString password, QString otp, QString currency, bool recentLogin); |
472 | 23 | Q_INVOKABLE void buyItem(QString email, QString password, QString otp, QString paymentId, QString backendId, bool recentLogin); | 23 | Q_INVOKABLE void buyItem(QString email, QString password, QString otp, QString currency, QString paymentId, QString backendId, bool recentLogin); |
473 | 24 | Q_INVOKABLE void checkCredentials(); | 24 | Q_INVOKABLE void checkCredentials(); |
475 | 25 | Q_INVOKABLE QString getAddPaymentUrl(); | 25 | Q_INVOKABLE QString getAddPaymentUrl(QString currency); |
476 | 26 | Q_INVOKABLE void checkWallet(QString email, QString password, QString otp); | 26 | Q_INVOKABLE void checkWallet(QString email, QString password, QString otp); |
477 | 27 | 27 | ||
478 | 28 | Q_INVOKABLE void quitSuccess(); | 28 | Q_INVOKABLE void quitSuccess(); |
479 | @@ -31,7 +31,7 @@ | |||
480 | 31 | Q_INVOKABLE void checkItemPurchased(); | 31 | Q_INVOKABLE void checkItemPurchased(); |
481 | 32 | 32 | ||
482 | 33 | Q_SIGNALS: | 33 | Q_SIGNALS: |
484 | 34 | void itemDetailsObtained(QString title, QString publisher, QString price, QString icon); | 34 | void itemDetailsObtained(QString title, QString publisher, QString currency, QString formatted_price, QString icon); |
485 | 35 | void paymentTypesObtained(QVariantList payments); | 35 | void paymentTypesObtained(QVariantList payments); |
486 | 36 | void buyItemSucceeded(); | 36 | void buyItemSucceeded(); |
487 | 37 | void buyItemFailed(); | 37 | void buyItemFailed(); |
488 | @@ -44,6 +44,7 @@ | |||
489 | 44 | void noPreferredPaymentMethod(); | 44 | void noPreferredPaymentMethod(); |
490 | 45 | void loginError(const QString& message); | 45 | void loginError(const QString& message); |
491 | 46 | void twoFactorAuthRequired(); | 46 | void twoFactorAuthRequired(); |
492 | 47 | void itemNotPurchased(); | ||
493 | 47 | 48 | ||
494 | 48 | private: | 49 | private: |
495 | 49 | Network m_network; | 50 | Network m_network; |
496 | 50 | 51 | ||
497 | === modified file 'backend/tests/mock_click_server.py' | |||
498 | --- backend/tests/mock_click_server.py 2014-09-12 19:21:55 +0000 | |||
499 | +++ backend/tests/mock_click_server.py 2014-10-02 18:57:25 +0000 | |||
500 | @@ -1,8 +1,5 @@ | |||
501 | 1 | import sys | ||
502 | 2 | import os | ||
503 | 3 | import json | 1 | import json |
504 | 4 | import threading | 2 | import threading |
505 | 5 | import subprocess | ||
506 | 6 | from http.server import BaseHTTPRequestHandler, HTTPServer | 3 | from http.server import BaseHTTPRequestHandler, HTTPServer |
507 | 7 | 4 | ||
508 | 8 | 5 | ||
509 | @@ -89,11 +86,17 @@ | |||
510 | 89 | self.end_headers() | 86 | self.end_headers() |
511 | 90 | self.wfile.write(bytes(json.dumps(response), 'UTF-8')) | 87 | self.wfile.write(bytes(json.dumps(response), 'UTF-8')) |
512 | 91 | 88 | ||
514 | 92 | def response_item_info(self, fail=False): | 89 | def response_item_info(self, fail, eurozone, dotar): |
515 | 93 | response = { | 90 | response = { |
516 | 94 | "title": "title", | 91 | "title": "title", |
517 | 95 | "publisher": "publisher", | 92 | "publisher": "publisher", |
518 | 96 | "price": 9.99, | 93 | "price": 9.99, |
519 | 94 | "prices": { | ||
520 | 95 | "USD": 1.99, | ||
521 | 96 | "EUR": 1.69, | ||
522 | 97 | "GBP": 1.29, | ||
523 | 98 | "ARS": 18.05, | ||
524 | 99 | }, | ||
525 | 97 | "icon_url": "icon_url", | 100 | "icon_url": "icon_url", |
526 | 98 | } | 101 | } |
527 | 99 | if fail: | 102 | if fail: |
528 | @@ -101,6 +104,10 @@ | |||
529 | 101 | else: | 104 | else: |
530 | 102 | self.send_response(200) | 105 | self.send_response(200) |
531 | 103 | self.send_header("Content-type", "application/json") | 106 | self.send_header("Content-type", "application/json") |
532 | 107 | if eurozone: | ||
533 | 108 | self.send_header("X-Suggested-Currency", "EUR") | ||
534 | 109 | if dotar: | ||
535 | 110 | self.send_header("X-Suggested-Currency", "ARS") | ||
536 | 104 | self.end_headers() | 111 | self.end_headers() |
537 | 105 | self.wfile.write(bytes(json.dumps(response), 'UTF-8')) | 112 | self.wfile.write(bytes(json.dumps(response), 'UTF-8')) |
538 | 106 | 113 | ||
539 | @@ -132,7 +139,9 @@ | |||
540 | 132 | self.response_buy_item(fail=fail, interaction=interaction) | 139 | self.response_buy_item(fail=fail, interaction=interaction) |
541 | 133 | elif self.path.find("iteminfo/") != -1: | 140 | elif self.path.find("iteminfo/") != -1: |
542 | 134 | fail = self.path.find("/fail/") != -1 | 141 | fail = self.path.find("/fail/") != -1 |
544 | 135 | self.response_item_info(fail) | 142 | eurozone = self.path.find("/eurozone/") != -1 |
545 | 143 | dotar = self.path.find("/dotar/") != -1 | ||
546 | 144 | self.response_item_info(fail, eurozone, dotar) | ||
547 | 136 | 145 | ||
548 | 137 | 146 | ||
549 | 138 | def run_click_server(): | 147 | def run_click_server(): |
550 | 139 | 148 | ||
551 | === modified file 'backend/tests/test_network.cpp' | |||
552 | --- backend/tests/test_network.cpp 2014-09-12 19:21:55 +0000 | |||
553 | +++ backend/tests/test_network.cpp 2014-10-02 18:57:25 +0000 | |||
554 | @@ -53,6 +53,10 @@ | |||
555 | 53 | void testNetworkButItemWithPaymentTypeFail(); | 53 | void testNetworkButItemWithPaymentTypeFail(); |
556 | 54 | void testNetworkButItemWithPaymentTypeInProgress(); | 54 | void testNetworkButItemWithPaymentTypeInProgress(); |
557 | 55 | void testNetworkGetItemInfo(); | 55 | void testNetworkGetItemInfo(); |
558 | 56 | void testNetworkGetItemInfoEurozone(); | ||
559 | 57 | void testNetworkGetItemInfoOtherCoins(); | ||
560 | 58 | void testNetworkGetItemInfoOverride(); | ||
561 | 59 | void testNetworkGetItemInfoOverrideOther(); | ||
562 | 56 | void testNetworkGetItemInfoFail(); | 60 | void testNetworkGetItemInfoFail(); |
563 | 57 | void testUseExistingCredentials(); | 61 | void testUseExistingCredentials(); |
564 | 58 | void testCheckAlreadyPurchased(); | 62 | void testCheckAlreadyPurchased(); |
565 | @@ -89,7 +93,7 @@ | |||
566 | 89 | { | 93 | { |
567 | 90 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/authError/", 1); | 94 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/authError/", 1); |
568 | 91 | QSignalSpy spy(&network, SIGNAL(authenticationError())); | 95 | QSignalSpy spy(&network, SIGNAL(authenticationError())); |
570 | 92 | network.buyItem("email", "password", "otp", "appid", "itemid", "paymentid", "backendid", false); | 96 | network.buyItem("email", "password", "otp", "USD", "appid", "itemid", "paymentid", "backendid", false); |
571 | 93 | QTRY_COMPARE(spy.count(), 1); | 97 | QTRY_COMPARE(spy.count(), 1); |
572 | 94 | } | 98 | } |
573 | 95 | 99 | ||
574 | @@ -97,7 +101,7 @@ | |||
575 | 97 | { | 101 | { |
576 | 98 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); | 102 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); |
577 | 99 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); | 103 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); |
579 | 100 | network.requestPaymentTypes(); | 104 | network.requestPaymentTypes("USD"); |
580 | 101 | QTRY_COMPARE(spy.count(), 1); | 105 | QTRY_COMPARE(spy.count(), 1); |
581 | 102 | QList<QVariant> arguments = spy.takeFirst(); | 106 | QList<QVariant> arguments = spy.takeFirst(); |
582 | 103 | QVERIFY(arguments.at(0).toList().count() == 3); | 107 | QVERIFY(arguments.at(0).toList().count() == 3); |
583 | @@ -117,7 +121,7 @@ | |||
584 | 117 | { | 121 | { |
585 | 118 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/fail/", 1); | 122 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/fail/", 1); |
586 | 119 | QSignalSpy spy(&network, SIGNAL(error(QString))); | 123 | QSignalSpy spy(&network, SIGNAL(error(QString))); |
588 | 120 | network.requestPaymentTypes(); | 124 | network.requestPaymentTypes("USD"); |
589 | 121 | QTRY_COMPARE(spy.count(), 1); | 125 | QTRY_COMPARE(spy.count(), 1); |
590 | 122 | QList<QVariant> arguments = spy.takeFirst(); | 126 | QList<QVariant> arguments = spy.takeFirst(); |
591 | 123 | QVERIFY(arguments.at(0).toString() == "404"); | 127 | QVERIFY(arguments.at(0).toString() == "404"); |
592 | @@ -127,7 +131,7 @@ | |||
593 | 127 | { | 131 | { |
594 | 128 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); | 132 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); |
595 | 129 | QSignalSpy spy(&network, SIGNAL(buyItemSucceeded())); | 133 | QSignalSpy spy(&network, SIGNAL(buyItemSucceeded())); |
597 | 130 | network.buyItem("email", "password", "otp", "appid", "itemid", "paymentid", "backendid", false); | 134 | network.buyItem("email", "password", "otp", "USD", "appid", "itemid", "paymentid", "backendid", false); |
598 | 131 | QTRY_COMPARE(spy.count(), 1); | 135 | QTRY_COMPARE(spy.count(), 1); |
599 | 132 | } | 136 | } |
600 | 133 | 137 | ||
601 | @@ -135,7 +139,7 @@ | |||
602 | 135 | { | 139 | { |
603 | 136 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/interaction/", 1); | 140 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/interaction/", 1); |
604 | 137 | QSignalSpy spy(&network, SIGNAL(buyInteractionRequired(QString))); | 141 | QSignalSpy spy(&network, SIGNAL(buyInteractionRequired(QString))); |
606 | 138 | network.buyItem("email", "password", "otp", "appid", "itemid", "paymentid", "backendid", false); | 142 | network.buyItem("email", "password", "otp", "USD", "appid", "itemid", "paymentid", "backendid", false); |
607 | 139 | QTRY_COMPARE(spy.count(), 1); | 143 | QTRY_COMPARE(spy.count(), 1); |
608 | 140 | QList<QVariant> arguments = spy.takeFirst(); | 144 | QList<QVariant> arguments = spy.takeFirst(); |
609 | 141 | QString url(arguments.at(0).toString()); | 145 | QString url(arguments.at(0).toString()); |
610 | @@ -147,7 +151,7 @@ | |||
611 | 147 | { | 151 | { |
612 | 148 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/fail/", 1); | 152 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/fail/", 1); |
613 | 149 | QSignalSpy spy(&network, SIGNAL(buyItemFailed())); | 153 | QSignalSpy spy(&network, SIGNAL(buyItemFailed())); |
615 | 150 | network.buyItem("email", "password", "otp", "appid", "itemid", "paymentid", "backendid", false); | 154 | network.buyItem("email", "password", "otp", "USD", "appid", "itemid", "paymentid", "backendid", false); |
616 | 151 | QTRY_COMPARE(spy.count(), 1); | 155 | QTRY_COMPARE(spy.count(), 1); |
617 | 152 | } | 156 | } |
618 | 153 | 157 | ||
619 | @@ -155,10 +159,10 @@ | |||
620 | 155 | { | 159 | { |
621 | 156 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); | 160 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); |
622 | 157 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); | 161 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); |
624 | 158 | network.requestPaymentTypes(); | 162 | network.requestPaymentTypes("USD"); |
625 | 159 | QTRY_COMPARE(spy.count(), 1); | 163 | QTRY_COMPARE(spy.count(), 1); |
626 | 160 | QSignalSpy spy2(&network, SIGNAL(buyItemSucceeded())); | 164 | QSignalSpy spy2(&network, SIGNAL(buyItemSucceeded())); |
628 | 161 | network.buyItemWithPreferredPaymentType("email", "password", "otp", "appid", "itemid", false); | 165 | network.buyItemWithPreferredPaymentType("email", "password", "otp", "USD", "appid", "itemid", false); |
629 | 162 | QTRY_COMPARE(spy2.count(), 1); | 166 | QTRY_COMPARE(spy2.count(), 1); |
630 | 163 | } | 167 | } |
631 | 164 | 168 | ||
632 | @@ -166,11 +170,11 @@ | |||
633 | 166 | { | 170 | { |
634 | 167 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); | 171 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); |
635 | 168 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); | 172 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); |
637 | 169 | network.requestPaymentTypes(); | 173 | network.requestPaymentTypes("USD"); |
638 | 170 | QTRY_COMPARE(spy.count(), 1); | 174 | QTRY_COMPARE(spy.count(), 1); |
639 | 171 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/fail/", 1); | 175 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/fail/", 1); |
640 | 172 | QSignalSpy spy2(&network, SIGNAL(buyItemFailed())); | 176 | QSignalSpy spy2(&network, SIGNAL(buyItemFailed())); |
642 | 173 | network.buyItemWithPreferredPaymentType("email", "password", "otp", "appid", "itemid", false); | 177 | network.buyItemWithPreferredPaymentType("email", "password", "otp", "USD", "appid", "itemid", false); |
643 | 174 | QTRY_COMPARE(spy2.count(), 1); | 178 | QTRY_COMPARE(spy2.count(), 1); |
644 | 175 | } | 179 | } |
645 | 176 | 180 | ||
646 | @@ -178,25 +182,80 @@ | |||
647 | 178 | { | 182 | { |
648 | 179 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); | 183 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); |
649 | 180 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); | 184 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); |
651 | 181 | network.requestPaymentTypes(); | 185 | network.requestPaymentTypes("USD""USD"); |
652 | 182 | QTRY_COMPARE(spy.count(), 1); | 186 | QTRY_COMPARE(spy.count(), 1); |
653 | 183 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/interaction/", 1); | 187 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/interaction/", 1); |
654 | 184 | QSignalSpy spy2(&network, SIGNAL(buyInteractionRequired(QString))); | 188 | QSignalSpy spy2(&network, SIGNAL(buyInteractionRequired(QString))); |
656 | 185 | network.buyItemWithPreferredPaymentType("email", "password", "otp", "appid", "itemid", false); | 189 | network.buyItemWithPreferredPaymentType("email", "password", "otp", "USD", "appid", "itemid", false); |
657 | 186 | QTRY_COMPARE(spy2.count(), 1); | 190 | QTRY_COMPARE(spy2.count(), 1); |
658 | 187 | } | 191 | } |
659 | 188 | 192 | ||
660 | 189 | void TestNetwork::testNetworkGetItemInfo() | 193 | void TestNetwork::testNetworkGetItemInfo() |
661 | 190 | { | 194 | { |
662 | 191 | setenv("URL_PACKAGE_INFO", "http://localhost:8000/iteminfo/", 1); | 195 | setenv("URL_PACKAGE_INFO", "http://localhost:8000/iteminfo/", 1); |
666 | 192 | QSignalSpy spy(&network, SIGNAL(itemDetailsObtained(QString,QString,QString,QString))); | 196 | unsetenv(CURRENCY_ENVVAR); |
667 | 193 | network.getItemInfo("packagename"); | 197 | QSignalSpy spy(&network, SIGNAL(itemDetailsObtained(QString,QString,QString,QString,QString))); |
668 | 194 | QTRY_COMPARE(spy.count(), 1); | 198 | network.getItemInfo("packagename"); |
669 | 199 | QTRY_COMPARE(spy.count(), 1); | ||
670 | 200 | QList<QVariant> arguments = spy.takeFirst(); | ||
671 | 201 | QCOMPARE(arguments.at(2).toString(), QStringLiteral("USD")); | ||
672 | 202 | QCOMPARE(arguments.at(3).toString(), QStringLiteral("US$1.99")); | ||
673 | 203 | } | ||
674 | 204 | |||
675 | 205 | void TestNetwork::testNetworkGetItemInfoEurozone() | ||
676 | 206 | { | ||
677 | 207 | setenv("URL_PACKAGE_INFO", "http://localhost:8000/iteminfo/eurozone/", 1); | ||
678 | 208 | unsetenv(CURRENCY_ENVVAR); | ||
679 | 209 | QSignalSpy spy(&network, SIGNAL(itemDetailsObtained(QString,QString,QString,QString,QString))); | ||
680 | 210 | network.getItemInfo("packagename"); | ||
681 | 211 | QTRY_COMPARE(spy.count(), 1); | ||
682 | 212 | QList<QVariant> arguments = spy.takeFirst(); | ||
683 | 213 | QCOMPARE(arguments.at(2).toString(), QStringLiteral("EUR")); | ||
684 | 214 | QCOMPARE(arguments.at(3).toString(), QStringLiteral("€1.69")); | ||
685 | 215 | } | ||
686 | 216 | |||
687 | 217 | void TestNetwork::testNetworkGetItemInfoOtherCoins() | ||
688 | 218 | { | ||
689 | 219 | setenv("URL_PACKAGE_INFO", "http://localhost:8000/iteminfo/dotar/", 1); | ||
690 | 220 | unsetenv(CURRENCY_ENVVAR); | ||
691 | 221 | QSignalSpy spy(&network, SIGNAL(itemDetailsObtained(QString,QString,QString,QString,QString))); | ||
692 | 222 | network.getItemInfo("packagename"); | ||
693 | 223 | QTRY_COMPARE(spy.count(), 1); | ||
694 | 224 | QList<QVariant> arguments = spy.takeFirst(); | ||
695 | 225 | QCOMPARE(arguments.at(2).toString(), QStringLiteral("USD")); | ||
696 | 226 | QCOMPARE(arguments.at(3).toString(), QStringLiteral("US$1.99")); | ||
697 | 227 | } | ||
698 | 228 | |||
699 | 229 | void TestNetwork::testNetworkGetItemInfoOverride() | ||
700 | 230 | { | ||
701 | 231 | setenv("URL_PACKAGE_INFO", "http://localhost:8000/iteminfo/", 1); | ||
702 | 232 | setenv(CURRENCY_ENVVAR, "EUR", true); | ||
703 | 233 | QSignalSpy spy(&network, SIGNAL(itemDetailsObtained(QString,QString,QString,QString,QString))); | ||
704 | 234 | network.getItemInfo("packagename"); | ||
705 | 235 | QTRY_COMPARE(spy.count(), 1); | ||
706 | 236 | QList<QVariant> arguments = spy.takeFirst(); | ||
707 | 237 | QCOMPARE(arguments.at(2).toString(), QStringLiteral("EUR")); | ||
708 | 238 | QCOMPARE(arguments.at(3).toString(), QStringLiteral("€1.69")); | ||
709 | 239 | unsetenv(CURRENCY_ENVVAR); | ||
710 | 240 | } | ||
711 | 241 | |||
712 | 242 | void TestNetwork::testNetworkGetItemInfoOverrideOther() | ||
713 | 243 | { | ||
714 | 244 | setenv("URL_PACKAGE_INFO", "http://localhost:8000/iteminfo/dotar/", 1); | ||
715 | 245 | setenv(CURRENCY_ENVVAR, "EUR", true); | ||
716 | 246 | QSignalSpy spy(&network, SIGNAL(itemDetailsObtained(QString,QString,QString,QString,QString))); | ||
717 | 247 | network.getItemInfo("packagename"); | ||
718 | 248 | QTRY_COMPARE(spy.count(), 1); | ||
719 | 249 | QList<QVariant> arguments = spy.takeFirst(); | ||
720 | 250 | QCOMPARE(arguments.at(2).toString(), QStringLiteral("EUR")); | ||
721 | 251 | QCOMPARE(arguments.at(3).toString(), QStringLiteral("€1.69")); | ||
722 | 252 | unsetenv(CURRENCY_ENVVAR); | ||
723 | 195 | } | 253 | } |
724 | 196 | 254 | ||
725 | 197 | void TestNetwork::testNetworkGetItemInfoFail() | 255 | void TestNetwork::testNetworkGetItemInfoFail() |
726 | 198 | { | 256 | { |
727 | 199 | setenv("URL_PACKAGE_INFO", "http://localhost:8000/fail/iteminfo/", 1); | 257 | setenv("URL_PACKAGE_INFO", "http://localhost:8000/fail/iteminfo/", 1); |
728 | 258 | unsetenv(CURRENCY_ENVVAR); | ||
729 | 200 | QSignalSpy spy(&network, SIGNAL(error(QString))); | 259 | QSignalSpy spy(&network, SIGNAL(error(QString))); |
730 | 201 | network.getItemInfo("packagename"); | 260 | network.getItemInfo("packagename"); |
731 | 202 | QTRY_COMPARE(spy.count(), 1); | 261 | QTRY_COMPARE(spy.count(), 1); |
732 | @@ -206,7 +265,7 @@ | |||
733 | 206 | { | 265 | { |
734 | 207 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); | 266 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/", 1); |
735 | 208 | QSignalSpy spy(&network, SIGNAL(buyItemSucceeded())); | 267 | QSignalSpy spy(&network, SIGNAL(buyItemSucceeded())); |
737 | 209 | network.buyItem("email", "password", "otp", "appid", "itemid", "paymentid", "backendid", true); | 268 | network.buyItem("email", "password", "otp", "USD", "appid", "itemid", "paymentid", "backendid", true); |
738 | 210 | QTRY_COMPARE(spy.count(), 1); | 269 | QTRY_COMPARE(spy.count(), 1); |
739 | 211 | } | 270 | } |
740 | 212 | 271 | ||
741 | @@ -221,7 +280,7 @@ | |||
742 | 221 | void TestNetwork::testCheckAlreadyPurchasedFail() | 280 | void TestNetwork::testCheckAlreadyPurchasedFail() |
743 | 222 | { | 281 | { |
744 | 223 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/notpurchased/", 1); | 282 | setenv(PAY_BASE_URL_ENVVAR, "http://localhost:8000/notpurchased/", 1); |
746 | 224 | QSignalSpy spy(&network, SIGNAL(paymentTypesObtained(QVariantList))); | 283 | QSignalSpy spy(&network, SIGNAL(itemNotPurchased())); |
747 | 225 | network.checkItemPurchased("com.example.fakeapp"); | 284 | network.checkItemPurchased("com.example.fakeapp"); |
748 | 226 | QTRY_COMPARE(spy.count(), 1); | 285 | QTRY_COMPARE(spy.count(), 1); |
749 | 227 | } | 286 | } |
750 | 228 | 287 | ||
751 | === modified file 'manifest.json' | |||
752 | --- manifest.json 2014-09-30 16:45:24 +0000 | |||
753 | +++ manifest.json 2014-10-02 18:57:25 +0000 | |||
754 | @@ -11,6 +11,6 @@ | |||
755 | 11 | "pay-ui": "payui_payui.desktop" | 11 | "pay-ui": "payui_payui.desktop" |
756 | 12 | } | 12 | } |
757 | 13 | }, | 13 | }, |
760 | 14 | "version": "0.3.26", | 14 | "version": "0.4.0", |
761 | 15 | "maintainer": "Diego Sarmentero <diego.sarmentero@canonical.com>" | 15 | "maintainer": "Ubuntu Appstore Developers <ubuntu-appstore-developers@lists.launchpad.net>" |
762 | 16 | } | 16 | } |
763 | 17 | \ No newline at end of file | 17 | \ No newline at end of file |
PASSED: Continuous integration, rev:70 jenkins. qa.ubuntu. com/job/ pay-ui- ci/94/ jenkins. qa.ubuntu. com/job/ generic- click-builder- utopic- armhf/742 jenkins. qa.ubuntu. com/job/ pay-ui- utopic- amd64-ci/ 91 jenkins. qa.ubuntu. com/job/ pay-ui- utopic- armhf-ci/ 91 jenkins. qa.ubuntu. com/job/ pay-ui- utopic- armhf-ci/ 91/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ pay-ui- utopic- i386-ci/ 91
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/pay- ui-ci/94/ rebuild
http://