ECommerce/Plugin/Details.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran n/a Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 86 CC 1 SCAR 6.9
CC
1
Cov
0%
template_path
2.0
http_post
2.0
http_get
2.0
CRAP 2.0
1 # -------------------------------------------------------------------------------------
2 # MKDoc::ECommerce::Details
3 # -------------------------------------------------------------------------------------
4 # Author : Jean-Michel Hiver <jhiver@mkdoc.com>.
5 # Copyright : (c) MKDoc Holdings Ltd, 2003
6 #
7 # Provides a method for the user to enter details when checking out.
8 # -------------------------------------------------------------------------------------
9 package MKDoc::ECommerce::Details;
10 use MKDoc::ECommerce::Plugin::Order;
11 use MKDoc::ECommerce::Address;
12 use MKDoc::ECommerce::Order;
13 use MKDoc::Core::Session;
14  
15 use warnings;
16 use strict;
17  
18 use base qw /MKDoc::Core::Plugin/;
19  
20  
21 ##
22 # $self->template_path();
23 # -----------------------
24 # Returns the template path in which to find the shopping
25 # basket templates.
26 ##
27 sub template_path
28 {
29 my $self = shift;
30 return 'ecommerce/details';
31 }
32  
33  
34 ##
35 # $self->http_post;
36 # -----------------
37 # Attempts to create a valid address, store it, and create an order
38 # with worldpay's gateway.
39 ##
40 sub http_post
41 {
42 my $self = shift;
43 my $req = $self->request();
44 my $session = $self->session() || return $self->http_get();
45
46 # try to set the address in the session
47 # if the address is invalid, re-display the form
48 my %param = map { $_ => $req->param ($_) } $req->param();
49 $param{country} = $session->{country};
50
51 my $addr = new MKDoc::ECommerce::Address (%param);
52 $addr || return $self->http_get();
53
54 $session->{address} = $addr;
55 $session->save();
56
57
58 # create an order object with the session_id, the address
59 # and the basket object and save it
60 my $order = new MKDoc::ECommerce::Order (
61 session_id => $session->id(),
62 address => $session->{address},
63 basket => $session->{basket}
64 );
65 $order->save();
66
67
68 # now that we have created the order, redirect to the order
69 # page from where the payment can be made.
70 my $uri = $MKDoc::ECommerce::Plugin::Order::CURRENT->uri();
71 $uri =~ s/^(https?:\/\/.*?\/).*?(\..*)$/$1$2/;
72 $uri .= "?id=$order->{id}";
73 print $req->redirect ($uri);
74 return 'TERMINATE';
75 }
76  
77  
78 ##
79 # $self->http_get;
80 # ----------------
81 # Displays the form which lets the editor choose which audiences
82 # the current document relates to.
83 ##
84 sub http_get
85 {
86 my $self = shift;
87
88 $self->_http_get_initialize_req();
89 return $self->SUPER::http_get (@_);
90 }
91  
92  
93 sub _http_get_initialize_req
94 {
95 my $self = shift;
96 my $req = $self->request();
97 $req->param ('submit_ok') && return;
98
99 my $session = $self->session() || return;
100 my $address = $session->{address} || return;
101
102 for (keys %{$address})
103 {
104 $req->param ($_, $address->{$_});
105 }
106 }
107  
108  
109 sub session
110 {
111 my $self = shift;
112 return MKDoc::Session->load();
113 }
114  
115  
116 1;
117  
118  
119 __END__