File Coverage

blib/lib/Business/cXML/Request/PunchOutSetup.pm
Criterion Covered Total %
statement 41 41 100.0
branch 14 14 100.0
condition 9 9 100.0
subroutine 10 10 100.0
pod 2 2 100.0
total 76 76 100.0


line stmt bran cond sub pod time code
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 5     5   1318 use 5.014;
  5         18  
43 5     5   24 use strict;
  5         10  
  5         230  
44              
45             use base qw(Business::cXML::Object);
46 5     5   26  
  5         8  
  5         407  
47             use constant NODENAME => 'PunchOutSetupRequest';
48 5     5   30 use constant PROPERTIES => (
  5         12  
  5         457  
49 5         318 _ext_email => undef,
50             _ext_name => undef,
51             _ext_firstname => undef,
52             _ext_lastname => undef,
53             _ext_uid => undef,
54             operation => 'create',
55             buyer_cookie => ' ',
56             checkout_url => undef,
57             checkout_target => undef,
58             contacts => [],
59             shipto => undef,
60             );
61 5     5   31 use constant OBJ_PROPERTIES => (
  5         14  
62 5         223 contacts => 'Business::cXML::Contact',
63             shipto => 'Business::cXML::ShipTo',
64             );
65 5     5   31  
  5         10  
66             use Business::cXML::Contact;
67 5     5   32 use XML::LibXML::Ferry;
  5         10  
  5         112  
68 5     5   25  
  5         8  
  5         1623  
69             my ($self, $el) = @_;
70              
71 15     15 1 42 $el->ferry($self, {
72             BuyerCookie => 'buyer_cookie',
73 15         295 BrowserFormPost => { URL => 'checkout_url' },
74             Contact => [ 'contacts', 'Business::cXML::Contact' ],
75             SupplierSetup => '__OBSOLETE',
76             ShipTo => [ 'shipto', 'Business::cXML::ShipTo' ],
77             SelectedItem => '__UNIMPLEMENTED',
78             ItemOut => '__UNIMPLEMENTED',
79             Extrinsic => {
80             __meta_name => 'name',
81             ReturnFrame => 'checkout_target',
82             UserEmail => '_ext_email',
83             FirstName => '_ext_firstname',
84             LastName => '_ext_lastname',
85             UserFullName => '_ext_name',
86             UserPrintableName => '_ext_name',
87             User => '_ext_uid',
88             UserId => '_ext_uid',
89             UniqueUsername => '_ext_uid',
90             UniqueName => '_ext_uid',
91             },
92             }
93             );
94              
95             # Fake a contact from extrinsics if necessary
96             unless (scalar @{ $self->{contacts} } > 0) {
97             # 1. Full name
98 15 100       942 # 2. First + last names
  15         89  
99             # 3. User ID is better than nothing
100             $self->{_ext_name} = $self->{_ext_firstname} . ' ' . $self->{_ext_lastname}
101             if !$self->{_ext_name} && $self->{_ext_firstname} && $self->{_ext_lastname};
102             $self->{_ext_name} = $self->{_ext_uid}
103 6 100 100     61 unless $self->{_ext_name};
      100        
104             if ($self->{_ext_email} && $self->{_ext_name}) {
105 6 100       31 $self->contacts(
106 6 100 100     48 new Business::cXML::Contact 'Contact', {
107             name => $self->{_ext_name},
108             emails => $self->{_ext_email},
109             # CAUTION: the language is left to default, but should ideally be the cXML node's
110             }
111             );
112             };
113 3         31 };
114             }
115              
116             my ($self, $doc) = @_;
117             my $node = $doc->create($self->{_nodeName});
118             $node->{operation} = $self->{operation};
119 5     5 1 14  
120 5         17 $node->add('BuyerCookie', $self->{buyer_cookie});
121 5         81 $node->add('Extrinsic', $self->{checkout_target}, name => 'ReturnFrame') if defined $self->{checkout_target};
122             $node->add('BrowserFormPost')->add('URL', $self->{checkout_url}) if defined $self->{checkout_url};
123 5         381 $node->add($_->to_node($node)) foreach (@{ $self->{contacts} });
124 5 100       207 $node->add($self->{shipto}->to_node($node)) if defined $self->{shipto};
125 5 100       224  
126 5         228 return $node;
  5         72  
127 5 100       142 }
128              
129 5         75 =item C<B<operation>>
130              
131             Mandatory, one of: C<create> (default), C<inspect>, C<edit>, C<source>
132              
133             =item C<B<buyer_cookie>>
134              
135             Mandatory
136              
137             =item C<B<checkout_url>>
138              
139             Optional, the URL to which a subsequent form post should submit a
140             C<PunchOutOrderMessage>.
141              
142             =item C<B<checkout_target>>
143              
144             Optional, "ReturnFrame" extrinsic which some buyers use to specify the target
145             frame for the checkout POST form.
146              
147             =item C<B<contacts[]>>
148              
149             Optional, L<Business::cXML::Contact> objects
150              
151             =item C<B<shipto>>
152              
153             Optional, L<Business::cXML::ShipTo> object
154              
155             =back
156              
157             =head1 AUTHOR
158              
159             Stéphane Lavergne L<https://github.com/vphantom>
160              
161             =head1 ACKNOWLEDGEMENTS
162              
163             Graph X Design Inc. L<https://www.gxd.ca/> sponsored this project.
164              
165             =head1 COPYRIGHT & LICENSE
166              
167             Copyright (c) 2017-2018 Stéphane Lavergne L<https://github.com/vphantom>
168              
169             Permission is hereby granted, free of charge, to any person obtaining a copy
170             of this software and associated documentation files (the "Software"), to deal
171             in the Software without restriction, including without limitation the rights
172             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
173             copies of the Software, and to permit persons to whom the Software is
174             furnished to do so, subject to the following conditions:
175              
176             The above copyright notice and this permission notice shall be included in all
177             copies or substantial portions of the Software.
178              
179             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
180             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
181             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
182             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
183             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
184             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
185             SOFTWARE.
186              
187             =cut
188              
189             1;