| 1 | package Webservice::OVH::Me::Bill; | ||
| 2 | |||
| 3 | =encoding utf-8 | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Webservice::OVH::Me::Bill | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use Webservice::OVH; | ||
| 12 | |||
| 13 | my $ovh = Webservice::OVH->new_from_json("credentials.json"); | ||
| 14 | |||
| 15 | my $bills = $ovh->me->bills; | ||
| 16 | |||
| 17 | foreach my $bill (@$bills) { | ||
| 18 | |||
| 19 | print $contact->url; | ||
| 20 | } | ||
| 21 | |||
| 22 | =head1 DESCRIPTION | ||
| 23 | |||
| 24 | Propvides access to contact properties. | ||
| 25 | No managing methods are available at the moment. | ||
| 26 | |||
| 27 | =head1 METHODS | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | use strict; | ||
| 32 | use warnings; | ||
| 33 | use Carp qw{ carp croak }; | ||
| 34 | |||
| 35 | our $VERSION = 0.47; | ||
| 36 | |||
| 37 | use Webservice::OVH::Me::Order; | ||
| 38 | |||
| 39 | =head2 _new | ||
| 40 | |||
| 41 | Internal Method to create the Bill object. | ||
| 42 | This method is not ment to be called directly. | ||
| 43 | |||
| 44 | =over | ||
| 45 | |||
| 46 | =item * Parameter: $api_wrapper - ovh api wrapper object, $module - root object, $bill_id - api id | ||
| 47 | |||
| 48 | =item * Return: L<Webservice::OVH::Me::Bill> | ||
| 49 | |||
| 50 | =item * Synopsis: Webservice::OVH::Me::Bill->_new($ovh_api_wrapper, $bill_id, $module); | ||
| 51 | |||
| 52 | =back | ||
| 53 | |||
| 54 | =cut | ||
| 55 | |||
| 56 | sub _new { | ||
| 57 | |||
| 58 | my ( $class, %params ) = @_; | ||
| 59 | |||
| 60 | die "Missing module" unless $params{module}; | ||
| 61 | die "Missing wrapper" unless $params{wrapper}; | ||
| 62 | die "Missing id" unless $params{id}; | ||
| 63 | |||
| 64 | my $module = $params{module}; | ||
| 65 | my $api_wrapper = $params{wrapper}; | ||
| 66 | my $bill_id = $params{id}; | ||
| 67 | |||
| 68 | my $response = $api_wrapper->rawCall( method => 'get', path => "/me/bill/$bill_id", noSignature => 0 ); | ||
| 69 | croak $response->error if $response->error; | ||
| 70 | |||
| 71 | my $porperties = $response->content; | ||
| 72 | my $order_id = $porperties->{orderId}; | ||
| 73 | |||
| 74 | my $self = bless { _module => $module, _api_wrapper => $api_wrapper, _id => $bill_id, _properties => $porperties, _order_id => $order_id }, $class; | ||
| 75 | |||
| 76 | return $self; | ||
| 77 | } | ||
| 78 | |||
| 79 | =head2 id | ||
| 80 | |||
| 81 | Returns the api id. | ||
| 82 | |||
| 83 | =over | ||
| 84 | |||
| 85 | =item * Return: VALUE | ||
| 86 | |||
| 87 | =item * Synopsis: my $id = $bill->id; | ||
| 88 | |||
| 89 | =back | ||
| 90 | |||
| 91 | =cut | ||
| 92 | |||
| 93 | sub id { | ||
| 94 | |||
| 95 | my ($self) = @_; | ||
| 96 | |||
| 97 | return $self->{_id}; | ||
| 98 | } | ||
| 99 | |||
| 100 | =head2 order | ||
| 101 | |||
| 102 | Returns associated order. | ||
| 103 | |||
| 104 | =over | ||
| 105 | |||
| 106 | =item * Return: L<Webservice::Me::Order> | ||
| 107 | |||
| 108 | =item * Synopsis: my $order = $bill->order; | ||
| 109 | |||
| 110 | =back | ||
| 111 | |||
| 112 | =cut | ||
| 113 | |||
| 114 | sub order { | ||
| 115 | |||
| 116 | my ( $self, $module ) = @_; | ||
| 117 | |||
| 118 | my $api = $self->{_api_wrapper}; | ||
| 119 | |||
| 120 | my $order_id = $self->{_order_id}; | ||
| 121 | my $order = $module->me->order($order_id); | ||
| 122 | return $order; | ||
| 123 | |||
| 124 | } | ||
| 125 | |||
| 126 | =head2 properties | ||
| 127 | |||
| 128 | Retrieves properties. | ||
| 129 | This method updates the intern property variable. | ||
| 130 | |||
| 131 | =over | ||
| 132 | |||
| 133 | =item * Return: HASH | ||
| 134 | |||
| 135 | =item * Synopsis: my $properties = $bill->properties; | ||
| 136 | |||
| 137 | =back | ||
| 138 | |||
| 139 | =cut | ||
| 140 | |||
| 141 | sub properties { | ||
| 142 | |||
| 143 | my ($self) = @_; | ||
| 144 | |||
| 145 | my $api = $self->{_api_wrapper}; | ||
| 146 | my $bill_id = $self->id; | ||
| 147 | my $response = $api->rawCall( method => 'get', path => "/me/bill/$bill_id", noSignature => 0 ); | ||
| 148 | croak $response->error if $response->error; | ||
| 149 | |||
| 150 | $self->{_properties} = $response->content; | ||
| 151 | return $self->{_properties}; | ||
| 152 | } | ||
| 153 | |||
| 154 | =head2 date | ||
| 155 | |||
| 156 | Exposed property value. | ||
| 157 | |||
| 158 | =over | ||
| 159 | |||
| 160 | =item * Return: DateTime | ||
| 161 | |||
| 162 | =item * Synopsis: my $date = $bill->date; | ||
| 163 | |||
| 164 | =back | ||
| 165 | |||
| 166 | =cut | ||
| 167 | |||
| 168 | sub date { | ||
| 169 | |||
| 170 | my ($self) = @_; | ||
| 171 | |||
| 172 | my $str_datetime = $self->{_properties}->{date}; | ||
| 173 | my $datetime = Webservice::OVH::Helper->parse_datetime($str_datetime); | ||
| 174 | return $datetime; | ||
| 175 | } | ||
| 176 | |||
| 177 | =head2 password | ||
| 178 | |||
| 179 | Exposed property value. | ||
| 180 | |||
| 181 | =over | ||
| 182 | |||
| 183 | =item * Return: VALUE | ||
| 184 | |||
| 185 | =item * Synopsis: my $password = $bill->password; | ||
| 186 | |||
| 187 | =back | ||
| 188 | |||
| 189 | =cut | ||
| 190 | |||
| 191 | sub password { | ||
| 192 | |||
| 193 | my ($self) = @_; | ||
| 194 | |||
| 195 | return $self->{_properties}->{password}; | ||
| 196 | } | ||
| 197 | |||
| 198 | =head2 pdf_url | ||
| 199 | |||
| 200 | Exposed property value. | ||
| 201 | |||
| 202 | =over | ||
| 203 | |||
| 204 | =item * Return: VALUE | ||
| 205 | |||
| 206 | =item * Synopsis: my $pdf_url = $bill->pdf_url; | ||
| 207 | |||
| 208 | =back | ||
| 209 | |||
| 210 | =cut | ||
| 211 | |||
| 212 | sub pdf_url { | ||
| 213 | |||
| 214 | my ($self) = @_; | ||
| 215 | |||
| 216 | return $self->{_properties}->{pdfUrl}; | ||
| 217 | } | ||
| 218 | |||
| 219 | =head2 price_without_tax | ||
| 220 | |||
| 221 | Exposed property value. | ||
| 222 | |||
| 223 | =over | ||
| 224 | |||
| 225 | =item * Return: VALUE | ||
| 226 | |||
| 227 | =item * Synopsis: my $price_without_tax = $bill->price_without_tax; | ||
| 228 | |||
| 229 | =back | ||
| 230 | |||
| 231 | =cut | ||
| 232 | |||
| 233 | sub price_without_tax { | ||
| 234 | |||
| 235 | my ($self) = @_; | ||
| 236 | |||
| 237 | return $self->{_properties}->{priceWithoutTax}; | ||
| 238 | } | ||
| 239 | |||
| 240 | =head2 price_with_tax | ||
| 241 | |||
| 242 | Exposed property value. | ||
| 243 | |||
| 244 | =over | ||
| 245 | |||
| 246 | =item * Return: VALUE | ||
| 247 | |||
| 248 | =item * Synopsis: my $price_with_tax = $bill->price_with_tax; | ||
| 249 | |||
| 250 | =back | ||
| 251 | |||
| 252 | =cut | ||
| 253 | |||
| 254 | sub price_with_tax { | ||
| 255 | |||
| 256 | my ($self) = @_; | ||
| 257 | |||
| 258 | return $self->{_properties}->{priceWithTax}; | ||
| 259 | } | ||
| 260 | |||
| 261 | =head2 tax | ||
| 262 | |||
| 263 | Exposed property value. | ||
| 264 | |||
| 265 | =over | ||
| 266 | |||
| 267 | =item * Return: VALUE | ||
| 268 | |||
| 269 | =item * Synopsis: my $tax = $bill->tax; | ||
| 270 | |||
| 271 | =back | ||
| 272 | |||
| 273 | =cut | ||
| 274 | |||
| 275 | sub tax { | ||
| 276 | |||
| 277 | my ($self) = @_; | ||
| 278 | |||
| 279 | return $self->{_properties}->{tax}; | ||
| 280 | } | ||
| 281 | |||
| 282 | =head2 url | ||
| 283 | |||
| 284 | Exposed property value. | ||
| 285 | |||
| 286 | =over | ||
| 287 | |||
| 288 | =item * Return: VALUE | ||
| 289 | |||
| 290 | =item * Synopsis: my $url = $bill->url; | ||
| 291 | |||
| 292 | =back | ||
| 293 | |||
| 294 | =cut | ||
| 295 | |||
| 296 | sub url { | ||
| 297 | |||
| 298 | my ($self) = @_; | ||
| 299 | |||
| 300 | return $self->{_properties}->{url}; | ||
| 301 | } | ||
| 302 | |||
| 303 | 1; |