|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: CNcdRequestPurchase implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ncdrequestpurchase.h" |
|
20 #include "ncdrequestbase.h" |
|
21 #include "ncdrequestconfigurationdata.h" |
|
22 #include "catalogsdebug.h" |
|
23 #include "ncdprotocolutils.h" |
|
24 //#include "ncdprotocoltypes.h" |
|
25 #include "ncdprotocolwords.h" |
|
26 #include "ncdpaymentmethod.h" |
|
27 |
|
28 CNcdRequestPurchase* CNcdRequestPurchase::NewL() |
|
29 { |
|
30 CNcdRequestPurchase* self = CNcdRequestPurchase::NewLC( ); |
|
31 CleanupStack::Pop(); |
|
32 return self; |
|
33 } |
|
34 |
|
35 CNcdRequestPurchase* CNcdRequestPurchase::NewLC() |
|
36 { |
|
37 CNcdRequestPurchase* self = new (ELeave) CNcdRequestPurchase(); |
|
38 CleanupStack::PushL(self); |
|
39 self->ConstructL(); |
|
40 return self; |
|
41 } |
|
42 |
|
43 void CNcdRequestPurchase::ConstructL() |
|
44 { |
|
45 CNcdRequestBase::ConstructL( KTagPreminetRequest ); |
|
46 iName.SetL(KTagPurchase); |
|
47 iNamespaceUri.SetL(KDefaultNamespaceUri); |
|
48 iPrefix = TXmlEngString(); |
|
49 iVersion.SetL(KAttrPreminetVersion); |
|
50 iType = TXmlEngString(); |
|
51 iConfirmationSet = EFalse; |
|
52 iGetDownloadDetailsSet = EFalse; |
|
53 } |
|
54 |
|
55 CNcdRequestPurchase::CNcdRequestPurchase() |
|
56 : CNcdRequestBase() |
|
57 { |
|
58 } |
|
59 |
|
60 CNcdRequestPurchase::~CNcdRequestPurchase() |
|
61 { |
|
62 DLTRACEIN(("")); |
|
63 iName.Free(); |
|
64 iNamespaceUri.Free(); |
|
65 iPrefix.Free(); |
|
66 iType.Free(); |
|
67 iTransactionId.Free(); |
|
68 |
|
69 for (TInt i = 0; i < iEntityDetails.Count(); ++i) |
|
70 { |
|
71 TNcdRequestPurchaseEntity e = iEntityDetails[i]; |
|
72 e.id.Free(); |
|
73 e.timestamp.Free(); |
|
74 e.purchaseOptionId.Free(); |
|
75 e.ticket.Free(); |
|
76 } |
|
77 iEntityDetails.Close(); |
|
78 |
|
79 |
|
80 for (TInt i = 0; i < iConfirmation.entities.Count(); ++i) |
|
81 { |
|
82 TNcdRequestDeliverablePurchaseEntity e = |
|
83 iConfirmation.entities[i]; |
|
84 e.id.Free(); |
|
85 e.timestamp.Free(); |
|
86 e.purchaseOptionId.Free(); |
|
87 e.ticket.Free(); |
|
88 e.deliveryMethod.Free(); |
|
89 } |
|
90 iConfirmation.entities.Close(); |
|
91 iConfirmation.queryResponseId.Free(); |
|
92 iConfirmation.paymentMethod.Free(); |
|
93 |
|
94 |
|
95 |
|
96 iGetDownloadDetails.id.Free(); |
|
97 iGetDownloadDetails.timestamp.Free(); |
|
98 iGetDownloadDetails.purchaseOptionId.Free(); |
|
99 iGetDownloadDetails.ticket.Free(); |
|
100 DLTRACEOUT(("")); |
|
101 } |
|
102 |
|
103 void CNcdRequestPurchase::SetTransactionIdL( const TDesC& aTransactionId ) |
|
104 { |
|
105 iTransactionId.SetL(aTransactionId); |
|
106 } |
|
107 |
|
108 void CNcdRequestPurchase::SetCancelL( TBool aCancel ) |
|
109 { |
|
110 iCancel = aCancel ? EValueTrue : EValueFalse; |
|
111 } |
|
112 |
|
113 void CNcdRequestPurchase::UnsetCancel() |
|
114 { |
|
115 iCancel = EValueNotSet; |
|
116 } |
|
117 |
|
118 void CNcdRequestPurchase::AddEntityDetailsL( |
|
119 const TDesC& aId, const TDesC& aTimestamp, |
|
120 const TDesC& aPurchaseOptionId ) |
|
121 { |
|
122 TNcdRequestPurchaseEntity entity; |
|
123 entity.id.SetL(aId); |
|
124 if ( aTimestamp != KNullDesC ) |
|
125 entity.timestamp.SetL(aTimestamp); |
|
126 entity.ticket = TXmlEngString(); |
|
127 entity.purchaseOptionId.SetL(aPurchaseOptionId); |
|
128 entity.gift = EValueNotSet; |
|
129 iEntityDetails.AppendL(entity); |
|
130 } |
|
131 |
|
132 void CNcdRequestPurchase::AddEntityDetailsL( |
|
133 const TDesC& aId, const TDesC& aTimestamp, |
|
134 const TDesC& aPurchaseOptionId, const TDesC& aTicket ) |
|
135 { |
|
136 TNcdRequestPurchaseEntity entity; |
|
137 entity.id.SetL(aId); |
|
138 if ( aTimestamp != KNullDesC ) |
|
139 entity.timestamp.SetL(aTimestamp); |
|
140 entity.ticket.SetL(aTicket); |
|
141 entity.purchaseOptionId.SetL(aPurchaseOptionId); |
|
142 entity.gift = EValueNotSet; |
|
143 iEntityDetails.AppendL(entity); |
|
144 } |
|
145 |
|
146 void CNcdRequestPurchase::AddEntityDetailsL( |
|
147 const TDesC& aId, const TDesC& aTimestamp, |
|
148 const TDesC& aPurchaseOptionId, const TDesC& aTicket, TBool aGift ) |
|
149 { |
|
150 TNcdRequestPurchaseEntity entity; |
|
151 entity.id.SetL(aId); |
|
152 if ( aTimestamp != KNullDesC ) |
|
153 entity.timestamp.SetL(aTimestamp); |
|
154 entity.ticket.SetL(aTicket); |
|
155 entity.purchaseOptionId.SetL(aPurchaseOptionId); |
|
156 entity.gift = aGift ? EValueTrue : EValueFalse; |
|
157 iEntityDetails.AppendL(entity); |
|
158 } |
|
159 |
|
160 |
|
161 void CNcdRequestPurchase::SetPurchaseConfirmationL( |
|
162 MNcdPaymentMethod::TNcdPaymentMethodType aPaymentMethod ) |
|
163 { |
|
164 SetPurchaseConfirmationL(KNullDesC, aPaymentMethod); |
|
165 } |
|
166 |
|
167 void CNcdRequestPurchase::SetPurchaseConfirmationL( |
|
168 const TDesC& aQueryResponseId, |
|
169 MNcdPaymentMethod::TNcdPaymentMethodType aPaymentMethod ) |
|
170 { |
|
171 iConfirmation.queryResponseId = TXmlEngString(); |
|
172 if ( aQueryResponseId != KNullDesC ) |
|
173 { |
|
174 iConfirmation.queryResponseId.SetL( aQueryResponseId ); |
|
175 } |
|
176 |
|
177 iConfirmation.paymentMethod = TXmlEngString(); |
|
178 if ( aPaymentMethod == MNcdPaymentMethod::EPaymentSms ) |
|
179 { |
|
180 iConfirmation.paymentMethod.SetL( KValueSms ); |
|
181 } |
|
182 else if ( aPaymentMethod == MNcdPaymentMethod::EPaymentCreditCard ) |
|
183 { |
|
184 iConfirmation.paymentMethod.SetL( KValueCreditCard ); |
|
185 } |
|
186 else if ( aPaymentMethod == MNcdPaymentMethod::EPaymentDirect ) |
|
187 { |
|
188 iConfirmation.paymentMethod.SetL( KValueDirect ); |
|
189 } |
|
190 else if ( aPaymentMethod == MNcdPaymentMethod::EPaymentCustom ) |
|
191 { |
|
192 iConfirmation.paymentMethod.SetL( KValueCustom ); |
|
193 } |
|
194 |
|
195 iConfirmationSet = ETrue; |
|
196 // entities must be set separately using AddPurchaseConfirmationEntityL() |
|
197 } |
|
198 |
|
199 void CNcdRequestPurchase::AddPurchaseConfirmationEntityL( |
|
200 const TDesC& aId, |
|
201 const TDesC& aTimestamp, |
|
202 const TDesC& aPurchaseOptionId ) |
|
203 { |
|
204 AddPurchaseConfirmationEntityL(aId, aTimestamp, aPurchaseOptionId, EDeliveryNotSet); |
|
205 } |
|
206 |
|
207 void CNcdRequestPurchase::AddPurchaseConfirmationEntityL( |
|
208 const TDesC& aId, |
|
209 const TDesC& aTimestamp, |
|
210 const TDesC& aPurchaseOptionId, |
|
211 TNcdDeliveryMethod aDeliveryMethod ) |
|
212 { |
|
213 TNcdRequestDeliverablePurchaseEntity entity; |
|
214 entity.id.SetL(aId); |
|
215 entity.purchaseOptionId.SetL(aPurchaseOptionId); |
|
216 entity.ticket = TXmlEngString(); |
|
217 if ( aTimestamp != KNullDesC ) |
|
218 entity.timestamp.SetL(aTimestamp); |
|
219 entity.gift = EValueNotSet; |
|
220 |
|
221 AddPurchaseConfirmationEntityL(entity, aDeliveryMethod); |
|
222 } |
|
223 |
|
224 void CNcdRequestPurchase::AddPurchaseConfirmationEntityL( |
|
225 const TDesC& aId, |
|
226 const TDesC& aTimestamp, |
|
227 const TDesC& aPurchaseOptionId, |
|
228 const TDesC& aTicket ) |
|
229 { |
|
230 TNcdRequestDeliverablePurchaseEntity entity; |
|
231 entity.id.SetL(aId); |
|
232 entity.purchaseOptionId.SetL(aPurchaseOptionId); |
|
233 entity.ticket.SetL(aTicket); |
|
234 if ( aTimestamp != KNullDesC ) |
|
235 entity.timestamp.SetL(aTimestamp); |
|
236 entity.gift = EValueNotSet; |
|
237 |
|
238 AddPurchaseConfirmationEntityL(entity, EDeliveryNotSet); |
|
239 } |
|
240 |
|
241 void CNcdRequestPurchase::AddPurchaseConfirmationEntityL( |
|
242 const TDesC& aId, |
|
243 const TDesC& aTimestamp, |
|
244 const TDesC& aPurchaseOptionId, |
|
245 const TDesC& aTicket, |
|
246 TNcdDeliveryMethod aDeliveryMethod ) |
|
247 { |
|
248 TNcdRequestDeliverablePurchaseEntity entity; |
|
249 entity.id.SetL(aId); |
|
250 entity.purchaseOptionId.SetL(aPurchaseOptionId); |
|
251 entity.ticket.SetL(aTicket); |
|
252 if ( aTimestamp != KNullDesC ) |
|
253 entity.timestamp.SetL(aTimestamp); |
|
254 entity.gift = EValueNotSet; |
|
255 |
|
256 AddPurchaseConfirmationEntityL(entity, aDeliveryMethod); |
|
257 } |
|
258 |
|
259 void CNcdRequestPurchase::AddPurchaseConfirmationEntityL( |
|
260 const TDesC& aId, |
|
261 const TDesC& aTimestamp, |
|
262 const TDesC& aPurchaseOptionId, |
|
263 const TDesC& aTicket, |
|
264 TBool aGift, |
|
265 TNcdDeliveryMethod aDeliveryMethod ) |
|
266 { |
|
267 TNcdRequestDeliverablePurchaseEntity entity; |
|
268 entity.id.SetL(aId); |
|
269 entity.purchaseOptionId.SetL(aPurchaseOptionId); |
|
270 entity.ticket.SetL(aTicket); |
|
271 if ( aTimestamp != KNullDesC ) |
|
272 entity.timestamp.SetL(aTimestamp); |
|
273 entity.gift = aGift ? EValueTrue : EValueFalse; |
|
274 |
|
275 AddPurchaseConfirmationEntityL(entity, aDeliveryMethod); |
|
276 } |
|
277 |
|
278 void CNcdRequestPurchase::AddPurchaseConfirmationEntityL( |
|
279 TNcdRequestDeliverablePurchaseEntity aEntity, |
|
280 TNcdDeliveryMethod aDeliveryMethod ) |
|
281 { |
|
282 TXmlEngString method; |
|
283 switch (aDeliveryMethod) |
|
284 { |
|
285 case EDeliverySms: |
|
286 { |
|
287 method = "sms"; |
|
288 break; |
|
289 } |
|
290 case EDeliveryWapPush: |
|
291 { |
|
292 method = "wap-push"; |
|
293 break; |
|
294 } |
|
295 case EDeliveryDirect: |
|
296 { |
|
297 method = "direct"; |
|
298 break; |
|
299 } |
|
300 case EDeliveryNone: |
|
301 { |
|
302 method = "none"; |
|
303 break; |
|
304 } |
|
305 default: |
|
306 break; |
|
307 } |
|
308 aEntity.deliveryMethod = method; |
|
309 iConfirmation.entities.AppendL(aEntity); |
|
310 } |
|
311 |
|
312 |
|
313 void CNcdRequestPurchase::SetGetDownloadDetailsL( |
|
314 const TDesC& aId, const TDesC& aTimestamp, |
|
315 const TDesC& aPurchaseOptionId ) |
|
316 { |
|
317 SetGetDownloadDetailsL(aId, aTimestamp, aPurchaseOptionId, KNullDesC, EFalse); |
|
318 } |
|
319 |
|
320 void CNcdRequestPurchase::SetGetDownloadDetailsL( |
|
321 const TDesC& aId, const TDesC& aTimestamp, |
|
322 const TDesC& aPurchaseOptionId, const TDesC& aTicket ) |
|
323 { |
|
324 SetGetDownloadDetailsL(aId, aTimestamp, aPurchaseOptionId, aTicket, EFalse); |
|
325 } |
|
326 |
|
327 void CNcdRequestPurchase::SetGetDownloadDetailsL( |
|
328 const TDesC& aId, const TDesC& aTimestamp, |
|
329 const TDesC& aPurchaseOptionId, const TDesC& aTicket, TBool aGift ) |
|
330 { |
|
331 iGetDownloadDetails.id.SetL(aId); |
|
332 iGetDownloadDetails.timestamp.SetL(aTimestamp); |
|
333 iGetDownloadDetails.purchaseOptionId.SetL(aPurchaseOptionId); |
|
334 |
|
335 iGetDownloadDetails.ticket = TXmlEngString(); |
|
336 if ( aTicket != KNullDesC ) |
|
337 iGetDownloadDetails.ticket.SetL(aTicket); |
|
338 |
|
339 iGetDownloadDetails.gift = aGift ? EValueTrue : EValueFalse; |
|
340 iGetDownloadDetailsSet = ETrue; |
|
341 } |
|
342 |
|
343 |
|
344 // generates the dom nodes |
|
345 HBufC8* CNcdRequestPurchase::CreateRequestL() |
|
346 { |
|
347 DLTRACEIN((_L("entry"))); |
|
348 // generate browse part of the request |
|
349 CNcdRequestBase::SetProtocolVersionL(KPreminetReqVersion); |
|
350 iRequestElement = NcdProtocolUtils::NewElementL(iDocument, KTagPurchase); |
|
351 if (iConfiguration) |
|
352 iConfiguration->SetNamespacePrefixL( KAttrCdpNamespacePrefix ); |
|
353 |
|
354 if ( iCancel != EValueNotSet ) |
|
355 NcdProtocolUtils::NewAttributeL( iRequestElement, KAttrCancel, iCancel ); |
|
356 |
|
357 if ( iTransactionId.NotNull() ) |
|
358 NcdProtocolUtils::NewAttributeL( iRequestElement, KAttrTransactionId, iTransactionId ); |
|
359 |
|
360 |
|
361 // only one of the following parts is allowed at a time |
|
362 if (!iConfirmationSet && iEntityDetails.Count() > 0) |
|
363 { |
|
364 for (TInt i = 0; i < iEntityDetails.Count(); ++i) |
|
365 { |
|
366 // create remote entity elements |
|
367 TNcdRequestPurchaseEntity entity = iEntityDetails[i]; |
|
368 TXmlEngElement entityElement = |
|
369 NcdProtocolUtils::NewElementL( |
|
370 iDocument, iRequestElement, KTagEntityDetails ); |
|
371 NcdProtocolUtils::NewAttributeL( entityElement, KAttrId, entity.id); |
|
372 |
|
373 if (entity.timestamp.NotNull()) |
|
374 NcdProtocolUtils::NewAttributeL( |
|
375 entityElement, KAttrTimestamp, entity.timestamp); |
|
376 |
|
377 if (entity.purchaseOptionId.NotNull()) |
|
378 NcdProtocolUtils::NewAttributeL( |
|
379 entityElement, KAttrPurchaseOptionId, entity.purchaseOptionId); |
|
380 |
|
381 if (entity.ticket.NotNull()) |
|
382 NcdProtocolUtils::NewAttributeL( |
|
383 entityElement, KAttrTicket, entity.ticket); |
|
384 |
|
385 if (entity.gift != EValueNotSet) |
|
386 NcdProtocolUtils::NewBoolAttributeL( |
|
387 entityElement, KAttrGift, entity.gift); |
|
388 } |
|
389 } |
|
390 else if (iConfirmationSet && iConfirmation.entities.Count() > 0) |
|
391 { |
|
392 TXmlEngElement confirmation = |
|
393 NcdProtocolUtils::NewElementL( iDocument, iRequestElement, KTagConfirmation ); |
|
394 |
|
395 NcdProtocolUtils::NewAttributeL( confirmation, KAttrQueryResponseId, |
|
396 iConfirmation.queryResponseId ); |
|
397 TXmlEngElement entities = |
|
398 NcdProtocolUtils::NewElementL( iDocument, confirmation, KTagEntities ); |
|
399 for (TInt i = 0; i < iConfirmation.entities.Count(); ++i) |
|
400 { |
|
401 TNcdRequestDeliverablePurchaseEntity entity = |
|
402 iConfirmation.entities[i]; |
|
403 TXmlEngElement entityElement = |
|
404 NcdProtocolUtils::NewElementL( iDocument, entities, KTagEntity ); |
|
405 |
|
406 NcdProtocolUtils::NewAttributeL( |
|
407 entityElement, KAttrId, entity.id); |
|
408 |
|
409 if (entity.timestamp.NotNull()) |
|
410 NcdProtocolUtils::NewAttributeL( |
|
411 entityElement, KAttrTimestamp, entity.timestamp); |
|
412 |
|
413 if (entity.purchaseOptionId.NotNull()) |
|
414 NcdProtocolUtils::NewAttributeL( |
|
415 entityElement, KAttrPurchaseOptionId, |
|
416 entity.purchaseOptionId); |
|
417 |
|
418 if (entity.ticket.NotNull()) |
|
419 NcdProtocolUtils::NewAttributeL( |
|
420 entityElement, KAttrTicket, entity.ticket); |
|
421 |
|
422 if (entity.gift != EValueNotSet) |
|
423 NcdProtocolUtils::NewBoolAttributeL( |
|
424 entityElement, KAttrGift, entity.gift); |
|
425 |
|
426 if (entity.deliveryMethod.NotNull()) |
|
427 { |
|
428 TXmlEngElement deliveryElement = |
|
429 NcdProtocolUtils::NewElementL( |
|
430 iDocument, iRequestElement, KTagDelivery ); |
|
431 NcdProtocolUtils::NewAttributeL( |
|
432 deliveryElement, KAttrMethod, entity.deliveryMethod); |
|
433 } |
|
434 } |
|
435 TXmlEngElement payment = |
|
436 NcdProtocolUtils::NewElementL( iDocument, confirmation, KTagPayment ); |
|
437 NcdProtocolUtils::NewAttributeL( payment, KAttrMethod, iConfirmation.paymentMethod); |
|
438 |
|
439 } |
|
440 else if (iGetDownloadDetailsSet) |
|
441 { |
|
442 TXmlEngElement getDownloadDetails = |
|
443 NcdProtocolUtils::NewElementL( iDocument, iRequestElement, KTagGetDownloadDetails ); |
|
444 NcdProtocolUtils::NewAttributeL( |
|
445 getDownloadDetails, KAttrId, iGetDownloadDetails.id); |
|
446 NcdProtocolUtils::NewAttributeL( |
|
447 getDownloadDetails, KAttrTimestamp, iGetDownloadDetails.timestamp); |
|
448 NcdProtocolUtils::NewAttributeL( |
|
449 getDownloadDetails, KAttrPurchaseOptionId, iGetDownloadDetails.purchaseOptionId); |
|
450 NcdProtocolUtils::NewAttributeL( |
|
451 getDownloadDetails, KAttrTicket, iGetDownloadDetails.ticket); |
|
452 NcdProtocolUtils::NewBoolAttributeL( |
|
453 getDownloadDetails, KAttrGift, iGetDownloadDetails.gift); |
|
454 } |
|
455 |
|
456 DLTRACEOUT((_L("exit"))); |
|
457 |
|
458 // base class generates the complete request |
|
459 return CNcdRequestBase::CreateRequestL(); |
|
460 } |
|
461 |
|
462 |