| 1 | package Marketplace::Rakuten::Order; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 3 | ▶ | use Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 3 | ▶ | use DateTime; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 3 | ▶ | use DateTime::Format::ISO8601; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 3 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 3 | ▶ | use MooX::Types::MooseLike::Base qw(Str HashRef Int Object); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 3 | ▶ | use Marketplace::Rakuten::Order::Address; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 3 | ▶ | use Marketplace::Rakuten::Order::Item; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 3 | ▶ | use Marketplace::Rakuten::Utils; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 3 | ▶ | use namespace::clean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | =head1 NAME | ||||||||||||||
| 18 | |||||||||||||||
| 19 | =encoding utf8 | ||||||||||||||
| 20 | |||||||||||||||
| 21 | Marketplace::Rakuten::Order | ||||||||||||||
| 22 | |||||||||||||||
| 23 | =head1 DESCRIPTION | ||||||||||||||
| 24 | |||||||||||||||
| 25 | Class to handle the xml structures returned by | ||||||||||||||
| 26 | L<http://webservice.rakuten.de/documentation/method/get_orders> | ||||||||||||||
| 27 | |||||||||||||||
| 28 | The aim is to have a consistent interface with | ||||||||||||||
| 29 | L<Amazon::MWS::XML::Order> so importing the orders can happens almost | ||||||||||||||
| 30 | transparently. | ||||||||||||||
| 31 | |||||||||||||||
| 32 | =cut | ||||||||||||||
| 33 | |||||||||||||||
| 34 | =head1 ACCESSORS/METHODS | ||||||||||||||
| 35 | |||||||||||||||
| 36 | =head2 order | ||||||||||||||
| 37 | |||||||||||||||
| 38 | The raw structure got from the XML parsing | ||||||||||||||
| 39 | |||||||||||||||
| 40 | =head2 shop_type | ||||||||||||||
| 41 | |||||||||||||||
| 42 | Always returns C<rakuten> | ||||||||||||||
| 43 | |||||||||||||||
| 44 | =cut | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 3 | has order => (is => 'ro', isa => HashRef, required => 1); | |||||||||||||
| 47 | |||||||||||||||
| 48 | sub shop_type { | ||||||||||||||
| 49 | 0 | ▶ | return 'rakuten'; | ||||||||||||
|
Subroutine
shop_type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 50 | } | ||||||||||||||
| 51 | |||||||||||||||
| 52 | =head2 order_number | ||||||||||||||
| 53 | |||||||||||||||
| 54 | read-write accessor for the (shop) order number so you can set this | ||||||||||||||
| 55 | while importing it. | ||||||||||||||
| 56 | |||||||||||||||
| 57 | =cut | ||||||||||||||
| 58 | |||||||||||||||
| 59 | 3 | has order_number => (is => 'rw', isa => Str); | |||||||||||||
| 60 | |||||||||||||||
| 61 | =head2 payment_status | ||||||||||||||
| 62 | |||||||||||||||
| 63 | read-write accessor for the payment status, so the shop can set it | ||||||||||||||
| 64 | while importing it. | ||||||||||||||
| 65 | |||||||||||||||
| 66 | =cut | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 3 | has payment_status => (is => 'rw', isa => Str); | |||||||||||||
| 69 | |||||||||||||||
| 70 | =head2 order_status | ||||||||||||||
| 71 | |||||||||||||||
| 72 | Unclear (for now) what to do here. List of statuses: | ||||||||||||||
| 73 | |||||||||||||||
| 74 | =over 4 | ||||||||||||||
| 75 | |||||||||||||||
| 76 | =item pending | ||||||||||||||
| 77 | |||||||||||||||
| 78 | Bestellung ist neu eingegangen | ||||||||||||||
| 79 | |||||||||||||||
| 80 | =item editable | ||||||||||||||
| 81 | |||||||||||||||
| 82 | Bestellung ist zur Bearbeitung freigegeben | ||||||||||||||
| 83 | |||||||||||||||
| 84 | =item shipped | ||||||||||||||
| 85 | |||||||||||||||
| 86 | Bestellung ist versendet | ||||||||||||||
| 87 | |||||||||||||||
| 88 | =item payout | ||||||||||||||
| 89 | |||||||||||||||
| 90 | Bestellung ist ausbezahlt | ||||||||||||||
| 91 | |||||||||||||||
| 92 | =item cancelled | ||||||||||||||
| 93 | |||||||||||||||
| 94 | Bestellung ist storniert | ||||||||||||||
| 95 | |||||||||||||||
| 96 | =back | ||||||||||||||
| 97 | |||||||||||||||
| 98 | =head2 can_be_imported | ||||||||||||||
| 99 | |||||||||||||||
| 100 | It returns true if the status is pending or editable or payout. | ||||||||||||||
| 101 | |||||||||||||||
| 102 | =cut | ||||||||||||||
| 103 | |||||||||||||||
| 104 | sub can_be_imported { | ||||||||||||||
| 105 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
can_be_imported: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 106 | 0 | my %map = ( | |||||||||||||
| 107 | pending => 1, | ||||||||||||||
| 108 | editable => 1, | ||||||||||||||
| 109 | payout => 1, | ||||||||||||||
| 110 | cancelled => 0, | ||||||||||||||
| 111 | ); | ||||||||||||||
| 112 | 0 | ▶ | return $map{$self->order_status} || 0; | ||||||||||||
|
Condition0%0/2
$map{$self->order_status} || 0
MC/DC0%0/1
$map{$self->order_status} || 0
$map{$self->order_status}
Truth table0%0/2
A
A= $map{$self->order_status}
| |||||||||||||||
| 113 | } | ||||||||||||||
| 114 | |||||||||||||||
| 115 | sub order_status { | ||||||||||||||
| 116 | 0 | ▶ | return shift->order->{status}; | ||||||||||||
|
Subroutine
order_status: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 117 | } | ||||||||||||||
| 118 | |||||||||||||||
| 119 | =head2 remote_shop_order_id | ||||||||||||||
| 120 | |||||||||||||||
| 121 | The Rakuten order id. | ||||||||||||||
| 122 | |||||||||||||||
| 123 | =cut | ||||||||||||||
| 124 | |||||||||||||||
| 125 | sub remote_shop_order_id { | ||||||||||||||
| 126 | 0 | ▶ | return shift->order->{order_no}; | ||||||||||||
|
Subroutine
remote_shop_order_id: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 127 | } | ||||||||||||||
| 128 | |||||||||||||||
| 129 | 3 | has shipping_address => (is => 'lazy'); | |||||||||||||
| 130 | |||||||||||||||
| 131 | sub _build_shipping_address { | ||||||||||||||
| 132 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_shipping_address: not called CC=4 SCAR=30.0
| |||||||||||||||
| 133 | 0 | my $address = $self->order->{delivery_address}; | |||||||||||||
| 134 | 0 | my $billing = $self->order->{client}; | |||||||||||||
| 135 | 0 | my %args; | |||||||||||||
| 136 | 0 | ▶ | if ($address) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 137 | 0 | %args = %$address; | |||||||||||||
| 138 | # populate the object with billing data as well | ||||||||||||||
| 139 | 0 | ▶ | if ($billing) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 140 | 0 | foreach my $k (qw/client_id email phone/) { | |||||||||||||
| 141 | 0 | $args{$k} = $billing->{$k}; | |||||||||||||
| 142 | } | ||||||||||||||
| 143 | } | ||||||||||||||
| 144 | 0 | return $self->_address_building_routine(%args); | |||||||||||||
| 145 | } | ||||||||||||||
| 146 | 0 | return; | |||||||||||||
| 147 | } | ||||||||||||||
| 148 | |||||||||||||||
| 149 | 3 | has billing_address => (is => 'lazy'); | |||||||||||||
| 150 | |||||||||||||||
| 151 | sub _build_billing_address { | ||||||||||||||
| 152 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_billing_address: not called CC=2 SCAR=17.9
| |||||||||||||||
| 153 | 0 | my $billing = $self->order->{client}; | |||||||||||||
| 154 | 0 | ▶ | if ($billing) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 155 | 0 | return $self->_address_building_routine(%$billing); | |||||||||||||
| 156 | } | ||||||||||||||
| 157 | 0 | return undef; | |||||||||||||
| 158 | } | ||||||||||||||
| 159 | |||||||||||||||
| 160 | 3 | has items_ref => (is => 'lazy'); | |||||||||||||
| 161 | |||||||||||||||
| 162 | sub _address_building_routine { | ||||||||||||||
| 163 | 0 | ▶ | my ($self, %params) = @_; | ||||||||||||
|
Subroutine
_address_building_routine: not called CC=1 SCAR=6.9
| |||||||||||||||
| 164 | 0 | my %args = %params; | |||||||||||||
| 165 | 0 | Marketplace::Rakuten::Utils::turn_empty_hashrefs_into_empty_strings(\%args); | |||||||||||||
| 166 | 0 | return Marketplace::Rakuten::Order::Address->new(%args); | |||||||||||||
| 167 | } | ||||||||||||||
| 168 | |||||||||||||||
| 169 | |||||||||||||||
| 170 | sub _build_items_ref { | ||||||||||||||
| 171 | 0 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
_build_items_ref: not called CC=6 SCAR=37.4
| |||||||||||||||
| 172 | 0 | my @items; | |||||||||||||
| 173 | 0 | my $order_num = $self->remote_shop_order_id; | |||||||||||||
| 174 | 0 | ▶ | if ($self->order->{items}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 175 | 0 | ▶ | if (my $item = $self->order->{items}->{item}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 176 | 0 | ▶ | if (ref($item) eq 'HASH') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 177 | 0 | Marketplace::Rakuten::Utils::turn_empty_hashrefs_into_empty_strings($item); | |||||||||||||
| 178 | 0 | push @items, | |||||||||||||
| 179 | Marketplace::Rakuten::Order::Item | ||||||||||||||
| 180 | ->new(struct => $item, | ||||||||||||||
| 181 | order_number => $order_num, | ||||||||||||||
| 182 | ); | ||||||||||||||
| 183 | } | ||||||||||||||
| 184 | elsif (ref($item) eq 'ARRAY') { | ||||||||||||||
| 185 | 0 | foreach my $i (@$item) { | |||||||||||||
| 186 | 0 | Marketplace::Rakuten::Utils::turn_empty_hashrefs_into_empty_strings($i); | |||||||||||||
| 187 | 0 | push @items, | |||||||||||||
| 188 | Marketplace::Rakuten::Order::Item | ||||||||||||||
| 189 | ->new(struct => $i, | ||||||||||||||
| 190 | order_number => $order_num, | ||||||||||||||
| 191 | ); | ||||||||||||||
| 192 | } | ||||||||||||||
| 193 | } | ||||||||||||||
| 194 | else { | ||||||||||||||
| 195 | 0 | die "Unexpected orderline" . Dumper($item); | |||||||||||||
| 196 | } | ||||||||||||||
| 197 | } | ||||||||||||||
| 198 | } | ||||||||||||||
| 199 | 0 | return \@items; | |||||||||||||
| 200 | } | ||||||||||||||
| 201 | |||||||||||||||
| 202 | =head2 items | ||||||||||||||
| 203 | |||||||||||||||
| 204 | Returns a list of L<Marketplace::Rakuten::Order::Item> objects. | ||||||||||||||
| 205 | |||||||||||||||
| 206 | =cut | ||||||||||||||
| 207 | |||||||||||||||
| 208 | sub items { | ||||||||||||||
| 209 | 0 | ▶ | return @{ shift->items_ref }; | ||||||||||||
|
Subroutine
items: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 210 | } | ||||||||||||||
| 211 | |||||||||||||||
| 212 | 3 | has number_of_items => (is => 'lazy', isa => Int); | |||||||||||||
| 213 | |||||||||||||||
| 214 | sub _build_number_of_items { | ||||||||||||||
| 215 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_number_of_items: not called CC=2 SCAR=17.9
| |||||||||||||||
| 216 | 0 | my @items = $self->items; | |||||||||||||
| 217 | 0 | my $total = 0; | |||||||||||||
| 218 | 0 | foreach my $i (@items) { | |||||||||||||
| 219 | 0 | $total += $i->quantity; | |||||||||||||
| 220 | } | ||||||||||||||
| 221 | 0 | return $total; | |||||||||||||
| 222 | } | ||||||||||||||
| 223 | |||||||||||||||
| 224 | =head2 email | ||||||||||||||
| 225 | |||||||||||||||
| 226 | The billing address' email | ||||||||||||||
| 227 | |||||||||||||||
| 228 | =cut | ||||||||||||||
| 229 | |||||||||||||||
| 230 | sub email { | ||||||||||||||
| 231 | 0 | ▶ | return shift->billing_address->email; | ||||||||||||
|
Subroutine
email: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 232 | } | ||||||||||||||
| 233 | |||||||||||||||
| 234 | =head2 first_name | ||||||||||||||
| 235 | |||||||||||||||
| 236 | The billing address' first name | ||||||||||||||
| 237 | |||||||||||||||
| 238 | =cut | ||||||||||||||
| 239 | |||||||||||||||
| 240 | sub first_name { | ||||||||||||||
| 241 | 0 | ▶ | return shift->billing_address->first_name; | ||||||||||||
|
Subroutine
first_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 242 | } | ||||||||||||||
| 243 | |||||||||||||||
| 244 | =head2 last_name | ||||||||||||||
| 245 | |||||||||||||||
| 246 | The billing address' last name | ||||||||||||||
| 247 | |||||||||||||||
| 248 | =cut | ||||||||||||||
| 249 | |||||||||||||||
| 250 | sub last_name { | ||||||||||||||
| 251 | 0 | ▶ | return shift->billing_address->last_name; | ||||||||||||
|
Subroutine
last_name: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 252 | } | ||||||||||||||
| 253 | |||||||||||||||
| 254 | =head2 comments | ||||||||||||||
| 255 | |||||||||||||||
| 256 | The buyer's comments. | ||||||||||||||
| 257 | |||||||||||||||
| 258 | =cut | ||||||||||||||
| 259 | |||||||||||||||
| 260 | sub comments { | ||||||||||||||
| 261 | 0 | ▶ | return shift->order->{comment_client}; | ||||||||||||
|
Subroutine
comments: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 262 | } | ||||||||||||||
| 263 | |||||||||||||||
| 264 | =head2 order_date | ||||||||||||||
| 265 | |||||||||||||||
| 266 | Return a DateTime object with the creation time of the order. | ||||||||||||||
| 267 | |||||||||||||||
| 268 | =cut | ||||||||||||||
| 269 | |||||||||||||||
| 270 | sub order_date { | ||||||||||||||
| 271 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
order_date: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||
| 272 | 0 | ▶ | if (my $date = $self->order->{created}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 273 | 0 | $date =~ s/ /T/; # eh | |||||||||||||
| 274 | 0 | return DateTime::Format::ISO8601->parse_datetime($date); | |||||||||||||
| 275 | } | ||||||||||||||
| 276 | 0 | return; | |||||||||||||
| 277 | |||||||||||||||
| 278 | } | ||||||||||||||
| 279 | |||||||||||||||
| 280 | =head2 shipping_method | ||||||||||||||
| 281 | |||||||||||||||
| 282 | It always returns nothing. The data is not provided by the remote | ||||||||||||||
| 283 | service. | ||||||||||||||
| 284 | |||||||||||||||
| 285 | =cut | ||||||||||||||
| 286 | |||||||||||||||
| 287 | sub shipping_method { | ||||||||||||||
| 288 | 0 | ▶ | return; | ||||||||||||
|
Subroutine
shipping_method: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 289 | } | ||||||||||||||
| 290 | |||||||||||||||
| 291 | =head2 shipping_cost | ||||||||||||||
| 292 | |||||||||||||||
| 293 | The shipping costs of the order. | ||||||||||||||
| 294 | |||||||||||||||
| 295 | =cut | ||||||||||||||
| 296 | |||||||||||||||
| 297 | sub shipping_cost { | ||||||||||||||
| 298 | 0 | ▶ | return shift->order->{shipping} || 0; | ||||||||||||
|
Subroutine
shipping_cost: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/2
+(shift())->order->{'shipping'} || 0
MC/DC0%0/1
+(shift())->order->{'shipping'} || 0
+(shift())->order->{'shipping'}
Truth table0%0/2
A
A= +(shift())->order->{'shipping'}
| |||||||||||||||
| 299 | } | ||||||||||||||
| 300 | |||||||||||||||
| 301 | =head2 subtotal | ||||||||||||||
| 302 | |||||||||||||||
| 303 | Subtotal of the order, implemented as total cost minus the shipping | ||||||||||||||
| 304 | cost. | ||||||||||||||
| 305 | |||||||||||||||
| 306 | =cut | ||||||||||||||
| 307 | |||||||||||||||
| 308 | sub subtotal { | ||||||||||||||
| 309 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
subtotal: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 310 | # coupons are not handled yet | ||||||||||||||
| 311 | 0 | my $subtotal = $self->total_cost - $self->shipping_cost; | |||||||||||||
| 312 | 0 | return sprintf('%.2f', $subtotal); | |||||||||||||
| 313 | } | ||||||||||||||
| 314 | |||||||||||||||
| 315 | =head2 total_cost | ||||||||||||||
| 316 | |||||||||||||||
| 317 | The total cost as provided by Rakuten. | ||||||||||||||
| 318 | |||||||||||||||
| 319 | =cut | ||||||||||||||
| 320 | |||||||||||||||
| 321 | sub total_cost { | ||||||||||||||
| 322 | 0 | ▶ | return shift->order->{total} || 0; | ||||||||||||
|
Subroutine
total_cost: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/2
+(shift())->order->{'total'} || 0
MC/DC0%0/1
+(shift())->order->{'total'} || 0
+(shift())->order->{'total'}
Truth table0%0/2
A
A= +(shift())->order->{'total'}
| |||||||||||||||
| 323 | } | ||||||||||||||
| 324 | |||||||||||||||
| 325 | =head2 payment_method | ||||||||||||||
| 326 | |||||||||||||||
| 327 | Mapping: | ||||||||||||||
| 328 | |||||||||||||||
| 329 | |||||||||||||||
| 330 | PP = Vorauskasse | ||||||||||||||
| 331 | CC = Kreditkarte | ||||||||||||||
| 332 | ELV = Lastschrift | ||||||||||||||
| 333 | ELV-AT = Lastschrift Österreich | ||||||||||||||
| 334 | SUE = Sofortüberweisung | ||||||||||||||
| 335 | CB = ClickAndBuy | ||||||||||||||
| 336 | INV = Rechnung | ||||||||||||||
| 337 | INV-AT = Rechnung Österreich | ||||||||||||||
| 338 | PAL = Paypal | ||||||||||||||
| 339 | GP = giropay | ||||||||||||||
| 340 | KLA = Klarna | ||||||||||||||
| 341 | MPA = mpass | ||||||||||||||
| 342 | BAR = Barzahlen | ||||||||||||||
| 343 | YAP = YAPITAL | ||||||||||||||
| 344 | |||||||||||||||
| 345 | =cut | ||||||||||||||
| 346 | |||||||||||||||
| 347 | sub payment_method { | ||||||||||||||
| 348 | 0 | ▶ | return shift->order->{payment}; | ||||||||||||
|
Subroutine
payment_method: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 349 | } | ||||||||||||||
| 350 | |||||||||||||||
| 351 | |||||||||||||||
| 352 | 3 | 1; | |||||||||||||