cXML/Request/PunchOutSetup.pm

filter: Statementstmt 57.1% 24 / 42 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 80.0% 8 / 10 Podpod 100% 2 / 2 totaltotal 35.4% 34 / 96 CC 15 SCAR 42.1
CC
15
Cov
32%
from_node
132.0
to_node
30.0
BEGIN
1.0
CRAP 67.1
« cXML.pm ↑ Summary cXML/Message/PunchOutOrder.pm »
1 =encoding utf-8
2  
3 =head1 NAME
4  
5 Business::cXML::Request::PunchOutSetup - cXML punch-out setup request payload
6  
7 =head1 SYNOPSIS
8  
9 use Business::cXML;
10 my $cxml = new Business::cXML;
11 my $posr = $cxml->new_request('PunchOutSetup');
12 $posr->checkout_url = 'https://www.example.com/welcome_back';
13  
14 =head1 DESCRIPTION
15  
16 Object representation of a cXML punch-out setup request.
17  
18 If no C<Contact> information is supplied directly in the request, this module
19 will try to infer the information (name and e-mail address) from any
20 recognized C<Extrinsic> elements: e-mail is obtained from C<UserEmail> and
21 name from C<UserFullName>, C<UserPrintableName>, C<FirstName>/C<LastName>,
22 C<User>, C<UniqueUsername> or C<UniqueName>.
23  
24 B<Caution:> This implementation is centered around C<create> operations and
25 thus doesn't implement C<SelectedItem> and C<ItemOut>.
26  
27 Also supports the C<ReturnFrame> extrinsic required by Aquiire (Vinimaya).
28 See L</checkout_target()>.
29  
30 =head1 METHODS
31  
32 See L<Business::cXML::Object/COMMON METHODS>.
33  
34 =head1 PROPERTY METHODS
35  
36 See L<Business::cXML::Object/PROPERTY METHODS> for how the following operate.
37  
38 =over
39  
40 =cut
41  
42 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45 package Business::cXML::Request::PunchOutSetup;
46 1 ▶use base qw(Business::cXML::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 1 ▶use constant NODENAME => 'PunchOutSetupRequest';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 1 ▶use constant PROPERTIES => (
Subroutine BEGIN: called CC=1 SCAR=0.0
50 _ext_email => undef,
51 _ext_name => undef,
52 _ext_firstname => undef,
53 _ext_lastname => undef,
54 _ext_user => undef,
55 _ext_userid => undef,
56 _ext_uniqueusername => undef,
57 _ext_uniquename => undef,
58 operation => 'create',
59 buyer_cookie => ' ',
60 checkout_url => undef,
61 checkout_target => undef,
62 contacts => [],
63 shipto => undef,
64 1 );
65 1 ▶use constant OBJ_PROPERTIES => (
Subroutine BEGIN: called CC=1 SCAR=0.0
66 contacts => 'Business::cXML::Contact',
67 shipto => 'Business::cXML::ShipTo',
68 1 );
69  
70 1 ▶use Business::cXML::Contact;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 1 ▶use XML::LibXML::Ferry;
Subroutine BEGIN: called CC=1 SCAR=0.0
72  
73 0 ▶sub from_node {
Subroutine from_node: not called CC=11 SCAR=48.8
Pod documented
74 0 my ($self, $el) = @_;
75  
76 0 $el->ferry($self, {
77 BuyerCookie => 'buyer_cookie',
78 BrowserFormPost => { URL => 'checkout_url' },
79 Contact => [ 'contacts', 'Business::cXML::Contact' ],
80 SupplierSetup => '__OBSOLETE',
81 ShipTo => [ 'shipto', 'Business::cXML::ShipTo' ],
82 SelectedItem => '__UNIMPLEMENTED',
83 ItemOut => '__UNIMPLEMENTED',
84 Extrinsic => {
85 __meta_name => 'name',
86 ReturnFrame => 'checkout_target',
87 UserEmail => '_ext_email',
88 FirstName => '_ext_firstname',
89 LastName => '_ext_lastname',
90 UserFullName => '_ext_name',
91 UserPrintableName => '_ext_name',
92 User => '_ext_user',
93 UserId => '_ext_userid',
94 UniqueUsername => '_ext_uniqueusername',
95 UniqueName => '_ext_uniquename',
96 },
97 }
98 );
99  
100 # Fake a contact from extrinsics if necessary
101 0 ▶ unless (scalar @{ $self->{contacts} } > 0) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @{$self->{"contacts"};} > 0) 0 0 0
102 # 1. Full name
103 # 2. First + last names
104 # 3. User ID is better than nothing
105 $self->{_ext_name} ||= $self->{_ext_firstname} . ' ' . $self->{_ext_lastname}
106 0 ▶ if $self->{_ext_firstname} && $self->{_ext_lastname};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_ext_firstname"} and $self->{"_ext_lastname"} 0 0 0
Condition0%0/5
$self->{"_ext_firstname"} and $self->{"_ext_lastname"}
!ll&&!rl&&r
000
$self->{"_ext_name"} ||= $self->{"_ext_firstname"} . ' ' . $self->{"_ext_lastname"}
l!l
00
MC/DC0%0/2
$self->{"_ext_firstname"} and $self->{"_ext_lastname"}
$self->{"_ext_firstname"} $self->{"_ext_lastname"}
MC/DC0%0/1
$self->{"_ext_name"} ||= $self->{"_ext_firstname"} . ' ' . $self->{"_ext_lastname"}
$self->{"_ext_name"}
Truth table0%0/3
A and B
A= $self->{"_ext_firstname"}B= $self->{"_ext_lastname"}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $self->{"_ext_name"}
Aresult
11
00
107 0 ▶ $self->{_ext_name} ||= $self->{_ext_uniquename} || $self->{_ext_uniqueusername} || $self->{_ext_userid} || $self->{_ext_user};
Condition0%0/12
$self->{"_ext_name"} ||= $self->{"_ext_uniquename"} || $self->{"_ext_uniqueusername"} || $self->{"_ext_userid"} || $self->{"_ext_user"}
l!l&&r!l&&!r
000
$self->{'_ext_uniquename'} || $self->{'_ext_uniqueusername'} || $self->{'_ext_userid'} || $self->{'_ext_user'}
l!l&&r!l&&!r
000
$self->{"_ext_uniquename"} or $self->{"_ext_uniqueusername"} or $self->{"_ext_userid"}
l!l&&r!l&&!r
000
$self->{"_ext_uniquename"} or $self->{"_ext_uniqueusername"}
l!l&&r!l&&!r
000
MC/DC0%0/5
$self->{"_ext_name"} ||= $self->{"_ext_uniquename"} || $self->{"_ext_uniqueusername"} || $self->{"_ext_userid"} || $self->{"_ext_user"}
$self->{"_ext_name"} $self->{"_ext_uniquename"} $self->{"_ext_uniqueusername"} $self->{"_ext_userid"} $self->{'_ext_user'}
Truth table0%0/6
A ||= B or C or D || E
A= $self->{"_ext_name"}B= $self->{"_ext_uniquename"}C= $self->{"_ext_uniqueusername"}D= $self->{"_ext_userid"}E= $self->{'_ext_user'}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
108 0 ▶ if ($self->{_ext_email} && $self->{_ext_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_ext_email"} and $self->{"_ext_name"}) 0 0 0
Condition0%0/3
$self->{"_ext_email"} and $self->{"_ext_name"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"_ext_email"} and $self->{"_ext_name"}
$self->{"_ext_email"} $self->{"_ext_name"}
Truth table0%0/3
A and B
A= $self->{"_ext_email"}B= $self->{"_ext_name"}
ABresult
0X0
100
111
109 $self->contacts(
110 new Business::cXML::Contact 'Contact', {
111 name => $self->{_ext_name},
112 emails => $self->{_ext_email},
113 # CAUTION: the language is left to default, but should ideally be the cXML node's
114 }
115 0 );
116 };
117 };
118 }
119  
120 0 ▶sub to_node {
Subroutine to_node: not called CC=5 SCAR=34.0
Pod documented
121 0 my ($self, $doc) = @_;
122 0 my $node = $doc->create($self->{_nodeName});
123 0 $node->{operation} = $self->{operation};
124  
125 0 $node->add('BuyerCookie', $self->{buyer_cookie});
126 0 ▶ $node->add('Extrinsic', $self->{checkout_target}, name => 'ReturnFrame') if defined $self->{checkout_target};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"checkout_target"} 0 0 0
127 0 ▶ $node->add('BrowserFormPost')->add('URL', $self->{checkout_url}) if defined $self->{checkout_url};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"checkout_url"} 0 0 0
128 0 $node->add($_->to_node($node)) foreach (@{ $self->{contacts} });
129 0 ▶ $node->add($self->{shipto}->to_node($node)) if defined $self->{shipto};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"shipto"} 0 0 0
130  
131 0 return $node;
132 }
133  
134 =item C<B<operation>>
135  
136 Mandatory, one of: C<create> (default), C<inspect>, C<edit>, C<source>
137  
138 =item C<B<buyer_cookie>>
139  
140 Mandatory
141  
142 =item C<B<checkout_url>>
143  
144 Optional, the URL to which a subsequent form post should submit a
145 C<PunchOutOrderMessage>.
146  
147 =item C<B<checkout_target>>
148  
149 Optional, "ReturnFrame" extrinsic which some buyers use to specify the target
150 frame for the checkout POST form.
151  
152 =item C<B<contacts[]>>
153  
154 Optional, L<Business::cXML::Contact> objects
155  
156 =item C<B<shipto>>
157  
158 Optional, L<Business::cXML::ShipTo> object
159  
160 =back
161  
162 =head1 AUTHOR
163  
164 Stéphane Lavergne L<https://github.com/vphantom>
165  
166 =head1 ACKNOWLEDGEMENTS
167  
168 Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
169  
170 =head1 COPYRIGHT & LICENSE
171  
172 Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
173  
174 Permission is hereby granted, free of charge, to any person obtaining a copy
175 of this software and associated documentation files (the "Software"), to deal
176 in the Software without restriction, including without limitation the rights
177 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
178 copies of the Software, and to permit persons to whom the Software is
179 furnished to do so, subject to the following conditions:
180  
181 The above copyright notice and this permission notice shall be included in all
182 copies or substantial portions of the Software.
183  
184 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
185 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
186 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
187 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
188 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
189 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
190 SOFTWARE.
191  
192 =cut
193  
194 1 1;
« cXML.pm ↑ Summary cXML/Message/PunchOutOrder.pm »