blib/lib/Webservice/OVH/Order/Cart.pm untested

filter: Statementstmt 0.0% 0 / 278 Branchbran 0.0% 0 / 196 Conditioncond 0.0% 0 / 6 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 28 Podpod 0.0% 0 / 24 totaltotal 0.0% 0 / 532 SCAR 92.0
CC
99
Cov
0%
add_transfer
420.0
add_transfer_new
420.0
add_domain
272.0
CRAP 9900.0
1 package Webservice::OVH::Order::Cart;
2  
3 =encoding utf-8
4  
5 =head1 NAME
6  
7 Webservice::OVH::Order::Cart
8  
9 =head1 SYNOPSIS
10  
11 use Webservice::OVH;
12
13 my $ovh = Webservice::OVH->new_from_json("credentials.json");
14
15 my $cart = $ovh->order->new_cart(ovh_subsidiary => 'DE');
16
17 $cart->add_domain('www.domain.com');
18
19 $cart->delete;
20  
21 =head1 DESCRIPTION
22  
23 Provides methods to manage shopping carts.
24  
25 =head1 METHODS
26  
27 =cut
28  
29 use strict;
30 use warnings;
31 use Carp qw{ carp croak };
32  
33 our $VERSION = 0.47;
34  
35 use Webservice::OVH::Order::Cart::Item;
36  
37 =head2 _new_existing
38  
39 Internal Method to create the Cart object.
40 This method is not ment to be called directly.
41  
42 =over
43  
44 =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object, $cart_id - api id
45  
46 =item * Return: L<Webservice::OVH::Order::Cart>
47  
48 =item * Synopsis: Webservice::OVH::Order::Cart->_new($ovh_api_wrapper, $cart_id, $module);
49  
50 =back
51  
52 =cut
53  
54 sub _new_existing {
55  
56 my ( $class, %params ) = @_;
57  
58 die "Missing module" unless $params{module};
59 die "Missing wrapper" unless $params{wrapper};
60 die "Missing id" unless $params{id};
61  
62 my $module = $params{module};
63 my $api_wrapper = $params{wrapper};
64 my $cart_id = $params{id};
65  
66 my $response = $api_wrapper->rawCall( method => 'get', path => "/order/cart/$cart_id", noSignature => 0 );
67 carp $response->error if $response->error;
68  
69 if ( !$response->error ) {
70  
71 my $properties = $response->content;
72 my $self = bless { _module => $module, _valid => 1, _api_wrapper => $api_wrapper, _id => $cart_id, _properties => $properties, _items => {} }, $class;
73  
74 return $self;
75  
76 } else {
77  
78 return undef;
79 }
80 }
81  
82 =head2 _new_existing
83  
84 Internal Method to create the Cart object.
85 This method is not ment to be called directly.
86  
87 =over
88  
89 =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object - api id
90  
91 =item * Return: L<Webservice::OVH::Order::Cart>
92  
93 =item * Synopsis: Webservice::OVH::Order::Cart->_new($ovh_api_wrapper, $module, ovhSubsidiary => 'DE', decription => 'Shopping');
94  
95 =back
96  
97 =cut
98  
99 sub _new {
100  
101 my ( $class, %params ) = @_;
102  
103 die "Missing module" unless $params{module};
104 die "Missing wrapper" unless $params{wrapper};
105  
106 my $module = $params{module};
107 my $api_wrapper = $params{wrapper};
108  
109 croak "Missing ovh_subsidiary" unless exists $params{ovh_subsidiary};
110 my $body = {};
111 $body->{description} = $params{description} if exists $params{description};
112 $body->{expire} = $params{expire} if exists $params{expire};
113 $body->{ovhSubsidiary} = $params{ovh_subsidiary};
114 my $response = $api_wrapper->rawCall( method => 'post', path => "/order/cart", body => $body, noSignature => 0 );
115 croak $response->error if $response->error;
116  
117 my $cart_id = $response->content->{cartId};
118 my $properties = $response->content;
119  
120 my $response_assign = $api_wrapper->rawCall( method => 'post', path => "/order/cart/$cart_id/assign", body => {}, noSignature => 0 );
121 croak $response_assign->error if $response_assign->error;
122  
123 my $self = bless { _module => $module, _valid => 1, _api_wrapper => $api_wrapper, _id => $cart_id, _properties => $properties, _items => {} }, $class;
124  
125 return $self;
126 }
127  
128 =head2 properties
129  
130 Retrieves properties.
131 This method updates the intern property variable.
132  
133 =over
134  
135 =item * Return: HASH
136  
137 =item * Synopsis: my $properties = $cart->properties;
138  
139 =back
140  
141 =cut
142  
143 sub properties {
144  
145 my ($self) = @_;
146  
147 my $api = $self->{_api_wrapper};
148 my $cart_id = $self->id;
149 my $response = $api->rawCall( method => 'get', path => "/order/cart/$cart_id", noSignature => 0 );
150 croak $response->error if $response->error;
151  
152 $self->{_properties} = $response->content;
153 return $self->{_properties};
154 }
155  
156 =head2 description
157  
158 Exposed property value.
159  
160 =over
161  
162 =item * Return: VALUE
163  
164 =item * Synopsis: my $description = $cart->description;
165  
166 =back
167  
168 =cut
169  
170 sub description {
171  
172 my ($self) = @_;
173  
174 return $self->{_properties}->{description};
175 }
176  
177 =head2 expire
178  
179 Exposed property value.
180  
181 =over
182  
183 =item * Return: VALUE
184  
185 =item * Synopsis: my $expire = $cart->expire;
186  
187 =back
188  
189 =cut
190  
191 sub expire {
192  
193 my ($self) = @_;
194  
195 return $self->{_properties}->{expire};
196 }
197  
198 =head2 read_only
199  
200 Exposed property value.
201  
202 =over
203  
204 =item * Return: VALUE
205  
206 =item * Synopsis: my $read_only = $cart->read_only;
207  
208 =back
209  
210 =cut
211  
212 sub read_only {
213  
214 my ($self) = @_;
215  
216 return $self->{_properties}->{readOnly} ? 1 : 0;
217 }
218  
219 =head2 change
220  
221 Exposed property value.
222  
223 =over
224  
225 =item * Parameter: %params - key => value description expire
226  
227 =item * Synopsis: my $change = $cart->change(description => 'Shopping!');
228  
229 =back
230  
231 =cut
232  
233 sub change {
234  
235 my ( $self, %params ) = @_;
236  
237 return unless $self->_is_valid;
238  
239 my $api = $self->{_api_wrapper};
240 my $cart_id = $self->id;
241  
242 croak "Missing Parameter description" unless exists $params{description};
243 croak "Missing Parameter description" unless exists $params{expire};
244  
245 my $body = {};
246 $body->{description} = $params{description} if $params{description};
247 $body->{expire} = $params{expire} if $params{expire};
248  
249 my $response = $api->rawCall( method => 'put', path => "/order/cart/$cart_id", body => $body, noSignature => 0 );
250 croak $response->error if $response->error;
251  
252 $self->properties;
253 }
254  
255 =head2 is_valid
256  
257 When this cart is deleted on the api side, this method returns 0.
258  
259 =over
260  
261 =item * Return: VALUE
262  
263 =item * Synopsis: print "Valid" if $cart->is_valid;
264  
265 =back
266  
267 =cut
268  
269 sub is_valid {
270  
271 my ($self) = @_;
272  
273 return $self->{_valid};
274 }
275  
276 =head2 _is_valid
277  
278 Intern method to check validity.
279 Difference is that this method carps an error.
280  
281 =over
282  
283 =item * Return: VALUE
284  
285 =item * Synopsis: $cart->_is_valid;
286  
287 =back
288  
289 =cut
290  
291 sub _is_valid {
292  
293 my ($self) = @_;
294  
295 my $cart_id = $self->id;
296 carp "Cart $cart_id is not valid anymore" unless $self->is_valid;
297 return $self->is_valid;
298 }
299  
300 =head2 delete
301  
302 Deletes the cart api sided and sets this object invalid.
303  
304 =over
305  
306 =item * Synopsis: $cart->delete;
307  
308 =back
309  
310 =cut
311  
312 sub delete {
313  
314 my ($self) = @_;
315  
316 return unless $self->_is_valid;
317  
318 my $api = $self->{_api_wrapper};
319 my $cart_id = $self->id;
320  
321 my $response = $api->rawCall( method => 'delete', path => "/order/cart/$cart_id", noSignature => 0 );
322 croak $response->error if $response->error;
323  
324 $self->{_valid} = 0;
325 }
326  
327 =head2 id
328  
329 Returns the api id.
330  
331 =over
332  
333 =item * Return: VALUE
334  
335 =item * Synopsis: my $id = $cart->id;
336  
337 =back
338  
339 =cut
340  
341 sub id {
342  
343 my ($self) = @_;
344  
345 return $self->{_id},;
346 }
347  
348 =head2 offers_domain
349  
350 Returns an Array of hashs with offers.
351  
352 =over
353  
354 =item * Parameter: $domain - domain name
355  
356 =item * Return: L<ARRAY>
357  
358 =item * Synopsis: my $offers = $cart->offers_domain('mydomain.de');
359  
360 =back
361  
362 =cut
363  
364 sub offers_domain {
365  
366 my ( $self, $domain ) = @_;
367  
368 return unless $self->_is_valid;
369  
370 my $api = $self->{_api_wrapper};
371 my $cart_id = $self->id;
372  
373 my $response = $api->rawCall( method => 'get', path => sprintf( "/order/cart/%s/domain?domain=%s", $cart_id, $domain ), noSignature => 0 );
374 croak $response->error if $response->error;
375  
376 return $response->content;
377 }
378  
379 =head2 add_domain
380  
381 Adds a domain request to a cart.
382  
383 =over
384  
385 =item * Parameter: $domain - domain name, %params - key => value duration offer_id quantity
386  
387 =item * Return: L<Webservice::OVH::Order::Cart::Item>
388  
389 =item * Synopsis: my $item = $cart->add_domain('mydomain.de');
390  
391 =back
392  
393 =cut
394  
395 sub add_domain {
396  
397 my ( $self, $domain, %params ) = @_;
398  
399 return unless $self->_is_valid;
400  
401 my $api = $self->{_api_wrapper};
402 my $cart_id = $self->id;
403  
404 croak "Missing domain parameter" unless $domain;
405  
406 my $body = {};
407 $body->{duration} = $params{duration} if exists $params{duration};
408 $body->{offerId} = $params{offer_id} if exists $params{offer_id};
409 $body->{quantity} = $params{quantity} if exists $params{quantity};
410 $body->{domain} = $domain;
411  
412 my $response = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/domain", body => $body, noSignature => 0 );
413 croak $response->error if $response->error;
414  
415 my $item_id = $response->content->{itemId};
416 my $item = Webservice::OVH::Order::Cart::Item->_new( wrapper => $api, cart => $self, id => $item_id, module => $self->{_module} );
417  
418 my $owner = $params{owner_contact};
419 my $admin = $params{admin_account};
420 my $tech = $params{tech_account};
421  
422 if ($owner) {
423 my $config_preset_owner = { label => "OWNER_CONTACT", value => $owner };
424 my $response_product_set_config_owner = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset_owner, noSignature => 0 );
425 my $config2 = $response_product_set_config_owner->content unless $response_product_set_config_owner->error;
426 croak $response_product_set_config_owner->error if $response_product_set_config_owner->error;
427 }
428  
429 if ($admin) {
430  
431 my $config_preset_admin = { label => "ADMIN_ACCOUNT", value => $admin };
432 my $response_product_set_config_admin = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset_admin, noSignature => 0 );
433 my $config3 = $response_product_set_config_admin->content unless $response_product_set_config_admin->error;
434 croak $response_product_set_config_admin->error if $response_product_set_config_admin->error;
435 }
436  
437 if ($tech) {
438  
439 my $config_preset_tech = { label => "TECH_ACCOUNT", value => $tech };
440 my $response_product_set_config_tech = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset_tech, noSignature => 0 );
441 my $config4 = $response_product_set_config_tech->content unless $response_product_set_config_tech->error;
442 croak $response_product_set_config_tech->error if $response_product_set_config_tech->error;
443 }
444  
445 return $item;
446 }
447  
448 =head2 offer_dns
449  
450 Returns an Hash with information for dns Zone pricing
451 A Domain must be added before requestion info
452  
453 =over
454  
455 =item * Parameter: $dns - domain name
456  
457 =item * Return: L<HASHREF>
458  
459 =item * Synopsis: my $offer = $cart->offers_dns;
460  
461 =back
462  
463 =cut
464  
465 sub offer_dns {
466  
467 my ( $self, $domain ) = @_;
468  
469 return unless $self->_is_valid;
470  
471 my $api = $self->{_api_wrapper};
472 my $cart_id = $self->id;
473  
474 my $response = $api->rawCall( method => 'get', path => sprintf( "/order/cart/%s/dns?domain=%s", $cart_id, $domain ), noSignature => 0 );
475 croak $response->error if $response->error;
476  
477 return $response->content;
478 }
479  
480 =head2 add_dns
481  
482 Adds a dns Zone to a cart.
483  
484 =over
485  
486 =item * Return: L<Webservice::OVH::Order::Cart::Item>
487  
488 =item * Synopsis: my $item = $cart->add_dns;
489  
490 =back
491  
492 =cut
493  
494 sub add_dns {
495  
496 my ( $self, $domain, %params ) = @_;
497  
498 return unless $self->_is_valid;
499  
500 my $api = $self->{_api_wrapper};
501 my $cart_id = $self->id;
502  
503 my $body = {};
504 $body->{duration} = $params{duration} if exists $params{duration};
505 $body->{planCode} = $params{plan_code} if exists $params{plan_code};
506 $body->{pricingMode} = $params{pricing_mode} if exists $params{pricing_mode};
507 $body->{quantity} = $params{quantity} if exists $params{quantity};
508 $body->{domain} = $domain;
509  
510 my $response = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/dns", body => $body, noSignature => 0 );
511 croak $response->error if $response->error;
512  
513 my $item_id = $response->content->{itemId};
514 my $item = Webservice::OVH::Order::Cart::Item->_new( wrapper => $api, cart => $self, id => $item_id, module => $self->{_module} );
515  
516 return $item;
517 }
518  
519  
520 =head2 offers_domain_transfer
521  
522 Returns an Array of hashes with offers.
523  
524 =over
525  
526 =item * Parameter: $domain - domain name
527  
528 =item * Return: L<ARRAY>
529  
530 =item * Synopsis: my $offers = $cart->offers_domain_transfer('mydomain.de');
531  
532 =back
533  
534 =cut
535  
536 sub offers_domain_transfer {
537  
538 my ( $self, $domain ) = @_;
539  
540 return unless $self->_is_valid;
541  
542 my $api = $self->{_api_wrapper};
543 my $cart_id = $self->id;
544  
545 my $response = $api->rawCall( method => 'get', path => sprintf( "/order/cart/%s/domainTransfer?domain=%s", $cart_id, $domain ), noSignature => 0 );
546 croak $response->error if $response->error;
547  
548 return $response->content;
549 }
550  
551 =head2 offers_domain
552  
553 Adds a domain transfer request to a cart.
554  
555 =over
556  
557 =item * Parameter: $domain - domain name, %params - key => value duration offer_id quantity
558  
559 =item * Return: L<Webservice::OVH::Order::Cart::Item>
560  
561 =item * Synopsis: my $item = $cart->add_transfer('mydomain.de');
562  
563 =back
564  
565 =cut
566  
567 sub add_transfer {
568  
569 my ( $self, $domain, %params ) = @_;
570  
571 return unless $self->_is_valid;
572  
573 my $api = $self->{_api_wrapper};
574 my $cart_id = $self->id;
575  
576 croak "Missing domain parameter" unless $domain;
577 croak "Missing auth_info" unless exists $params{auth_info};
578  
579 my $body = {};
580 $body->{duration} = $params{duration} if exists $params{duration};
581 $body->{offerId} = $params{offer_id} if exists $params{offer_id};
582 $body->{quantity} = $params{quantity} if exists $params{quantity};
583 $body->{domain} = $domain;
584  
585 my $response = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/domainTransfer", body => $body, noSignature => 0 );
586 croak $response->error if $response->error;
587  
588 my $item_id = $response->content->{itemId};
589 my $item = Webservice::OVH::Order::Cart::Item->_new( wrapper => $api, cart => $self, id => $item_id, module => $self->{_module} );
590  
591 return unless $item;
592  
593 my $auth_info = $params{auth_info};
594 my $owner = $params{owner_contact};
595 my $admin = $params{admin_account};
596 my $tech = $params{tech_account};
597  
598 my $config_preset = { label => "AUTH_INFO", value => $auth_info };
599 my $response_product_set_config = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset, noSignature => 0 );
600 my $config1 = $response_product_set_config->content unless $response_product_set_config->error;
601 croak $response_product_set_config->error if $response_product_set_config->error;
602  
603 if ($owner) {
604 my $config_preset_owner = { label => "OWNER_CONTACT", value => $owner };
605 my $response_product_set_config_owner = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset_owner, noSignature => 0 );
606 my $config2 = $response_product_set_config_owner->content unless $response_product_set_config_owner->error;
607 croak $response_product_set_config_owner->error if $response_product_set_config_owner->error;
608 }
609  
610 if ($admin) {
611 my $config_preset_admin = { label => "ADMIN_ACCOUNT", value => $admin };
612 my $response_product_set_config_admin = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset_admin, noSignature => 0 );
613 my $config3 = $response_product_set_config_admin->content unless $response_product_set_config_admin->error;
614 croak $response_product_set_config_admin->error if $response_product_set_config_admin->error;
615 }
616  
617 if ($tech) {
618 my $config_preset_tech = { label => "TECH_ACCOUNT", value => $tech };
619 my $response_product_set_config_tech = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset_tech, noSignature => 0 );
620 my $config4 = $response_product_set_config_tech->content unless $response_product_set_config_tech->error;
621 croak $response_product_set_config_tech->error if $response_product_set_config_tech->error;
622 }
623  
624 return $item;
625 }
626  
627 sub add_transfer_new {
628  
629 my ( $self, $domain, %params ) = @_;
630  
631 return unless $self->_is_valid;
632  
633 my $api = $self->{_api_wrapper};
634 my $cart_id = $self->id;
635  
636 croak "Missing domain parameter" unless $domain;
637 croak "Missing auth_info" unless exists $params{auth_info};
638  
639 my $body = {};
640 $body->{duration} = $params{duration} if exists $params{duration};
641 $body->{offerId} = $params{offer_id} if exists $params{offer_id};
642 $body->{quantity} = $params{quantity} if exists $params{quantity};
643 $body->{domain} = $domain;
644  
645 my $response = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/domain", body => $body, noSignature => 0 );
646 croak $response->error if $response->error;
647  
648 my $item_id = $response->content->{itemId};
649 my $item = Webservice::OVH::Order::Cart::Item->_new( wrapper => $api, cart => $self, id => $item_id, module => $self->{_module} );
650  
651 return unless $item;
652  
653 my $auth_info = $params{auth_info};
654 my $owner = $params{owner_contact};
655 my $admin = $params{admin_account};
656 my $tech = $params{tech_account};
657  
658 my $config_preset = { label => "AUTH_INFO", value => $auth_info };
659 my $response_product_set_config = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset, noSignature => 0 );
660 my $config1 = $response_product_set_config->content unless $response_product_set_config->error;
661 croak $response_product_set_config->error if $response_product_set_config->error;
662  
663 if ($owner) {
664 my $config_preset_owner = { label => "OWNER_CONTACT", value => $owner };
665 my $response_product_set_config_owner = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset_owner, noSignature => 0 );
666 my $config2 = $response_product_set_config_owner->content unless $response_product_set_config_owner->error;
667 croak $response_product_set_config_owner->error if $response_product_set_config_owner->error;
668 }
669  
670 if ($admin) {
671 my $config_preset_admin = { label => "ADMIN_ACCOUNT", value => $admin };
672 my $response_product_set_config_admin = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset_admin, noSignature => 0 );
673 my $config3 = $response_product_set_config_admin->content unless $response_product_set_config_admin->error;
674 croak $response_product_set_config_admin->error if $response_product_set_config_admin->error;
675 }
676  
677 if ($tech) {
678 my $config_preset_tech = { label => "TECH_ACCOUNT", value => $tech };
679 my $response_product_set_config_tech = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/item/$item_id/configuration", body => $config_preset_tech, noSignature => 0 );
680 my $config4 = $response_product_set_config_tech->content unless $response_product_set_config_tech->error;
681 croak $response_product_set_config_tech->error if $response_product_set_config_tech->error;
682 }
683  
684 return $item;
685 }
686  
687 =head2 info_checkout
688  
689 Returns checkout without generating an order.
690  
691 =over
692  
693 =item * Return: HASH
694  
695 =item * Synopsis: my $checkout = $cart->info_checkout;
696  
697 =back
698  
699 =cut
700  
701 sub info_checkout {
702  
703 my ($self) = @_;
704  
705 return unless $self->_is_valid;
706  
707 my $api = $self->{_api_wrapper};
708 my $cart_id = $self->id;
709  
710 my $response = $api->rawCall( method => 'get', path => "/order/cart/$cart_id/checkout", noSignature => 0 );
711 croak $response->error if $response->error;
712  
713 return $response->content;
714 }
715  
716 =head2 checkout
717  
718 Generates an order. Makes the cart invalid. Returns the order.
719  
720 =over
721  
722 =item * Return: L<Webservice::OVH::Me::Order>
723  
724 =item * Synopsis: my $order = $cart->checkout;
725  
726 =back
727  
728 =cut
729  
730 sub checkout {
731  
732 my ($self) = @_;
733  
734 return unless $self->_is_valid;
735  
736 my $api = $self->{_api_wrapper};
737 my $cart_id = $self->id;
738  
739 my $response = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/checkout", body => {}, noSignature => 0 );
740 croak $response->error if $response->error;
741  
742 my $order_id = $response->content->{orderId};
743 my $order = Webservice::OVH::Me::Order->_new( wrapper => $api, id => $order_id, module => $self->{_module} );
744  
745 return $order;
746 }
747  
748 =head2 items
749  
750 Produces an Array of Item Objects.
751  
752 =over
753  
754 =item * Return: L<ARRAY>
755  
756 =item * Synopsis: my $items = $cart->items;
757  
758 =back
759  
760 =cut
761  
762 sub items {
763  
764 my ($self) = @_;
765  
766 return unless $self->_is_valid;
767  
768 my $api = $self->{_api_wrapper};
769 my $cart_id = $self->id;
770 my $response = $api->rawCall( method => 'get', path => "/order/cart/$cart_id/item", noSignature => 0 );
771 croak $response->error if $response->error;
772  
773 my $item_ids = $response->content;
774 my $items = [];
775  
776 foreach my $item_id (@$item_ids) {
777  
778 my $item = $self->{_items}{$item_id} = $self->{_items}{$item_id} || Webservice::OVH::Order::Cart::Item->_new( wrapper => $api, cart => $self, id => $item_id, module => $self->{_module} );
779 push @$items, $item;
780 }
781  
782 return $items;
783 }
784  
785 =head2 item
786  
787 Returns a single item by id
788  
789 =over
790  
791 =item * Parameter: $item_id - api id
792  
793 =item * Return: L<Webservice::OVH::Order::Cart::Item>
794  
795 =item * Synopsis: my $item = $ovh->order->cart->item(123456);
796  
797 =back
798  
799 =cut
800  
801 sub item {
802  
803 my ( $self, $item_id ) = @_;
804  
805 return unless $self->_is_valid;
806  
807 my $api = $self->{_api_wrapper};
808 my $item = $self->{_items}{$item_id} = $self->{_items}{$item_id} || Webservice::OVH::Order::Cart::Item->_new( wrapper => $api, cart => $self, id => $item_id, module => $self->{_module} );
809 return $item;
810 }
811  
812 =head2 item
813  
814 Deletes all items from the cart.
815  
816 =over
817  
818 =item * Synopsis: $cart->clear;
819  
820 =back
821  
822 =cut
823  
824 sub clear {
825  
826 my ($self) = @_;
827  
828 return unless $self->_is_valid;
829  
830 my $items = $self->items;
831  
832 foreach my $item (@$items) {
833  
834 $item->delete;
835 }
836 }
837  
838 =head2 assign
839  
840 Assign a shopping cart to an loggedin client
841  
842 =over
843  
844 =item * Synopsis: $cart->assign;
845  
846 =back
847  
848 =cut
849  
850 sub assign {
851  
852 my ($self) = @_;
853  
854 return unless $self->_is_valid;
855  
856 my $api = $self->{_api_wrapper};
857 my $cart_id = $self->id;
858 my $response = $api->rawCall( method => 'post', path => "/order/cart/$cart_id/assign", noSignature => 0 );
859 croak $response->error if $response->error;
860 }
861  
862  
863  
864  
865  
866  
867 1;
868