File Coverage

blib/lib/Business/CyberSource/Request.pm
Criterion Covered Total %
statement 21 28 75.0
branch 0 4 0.0
condition 0 3 0.0
subroutine 8 9 88.8
pod 1 1 100.0
total 30 45 66.6


line stmt bran cond sub pod time code
1             package Business::CyberSource::Request;
2 8     8   5066 use 5.010;
  8         20  
3 8     8   33 use strict;
  8         13  
  8         170  
4 8     8   26 use warnings;
  8         11  
  8         209  
5 8     8   30 use namespace::autoclean;
  8         10  
  8         54  
6              
7             our $VERSION = '0.010008'; # VERSION
8              
9 8     8   593 use Moose;
  8         10  
  8         44  
10             extends 'Business::CyberSource::Message';
11             with qw(
12             MooseX::RemoteHelper::CompositeSerialization
13             );
14              
15 8     8   36250 use MooseX::Types::CyberSource qw( PurchaseTotals Service Items InvoiceHeader OtherTax ShipFrom ShipTo );
  8         18  
  8         92  
16              
17 8     8   64632 use Module::Runtime qw( use_module );
  8         16  
  8         81  
18              
19             our @CARP_NOT = ( 'Class::MOP::Method::Wrapped', __PACKAGE__ );
20              
21             before serialize => sub { ## no critic qw( Subroutines::RequireFinalReturn )
22             my $self = shift;
23              
24             if ( !$self->has_total && ( !$self->has_items || $self->items_is_empty ) ) {
25             die ## no critic ( ErrorHandling::RequireCarping )
26             use_module('Business::CyberSource::Exception::ItemsOrTotal')->new;
27             }
28             };
29              
30             sub add_item {
31 0     0 1 0 my ( $self, $args ) = @_;
32              
33 0         0 my $item;
34 0 0 0     0 unless ( blessed $args
35             && $args->isa('Business::CyberSource::RequestPart::Item') )
36             {
37 0         0 $item =
38             use_module('Business::CyberSource::RequestPart::Item')->new($args);
39             }
40             else {
41 0         0 $item = $args;
42             }
43 0 0       0 $self->items( [] ) if !$self->has_items;
44              
45 0         0 return $self->_push_item($item);
46             }
47              
48             sub _build_service {
49 1     1   2869 return use_module('Business::CyberSource::RequestPart::Service')->new;
50             }
51              
52             has comments => (
53             remote_name => 'comments',
54             isa => 'Str',
55             traits => ['SetOnce'],
56             is => 'rw',
57             );
58              
59             has service => (
60             isa => Service,
61             is => 'ro',
62             lazy_build => 1,
63             required => 1,
64             coerce => 1,
65             reader => undef,
66             );
67              
68             has purchase_totals => (
69             isa => PurchaseTotals,
70             remote_name => 'purchaseTotals',
71             is => 'ro',
72             required => 1,
73             coerce => 1,
74             handles => [qw( total has_total discount has_discount duty has_duty )],
75             );
76              
77             has items => (
78             isa => Items,
79             remote_name => 'item',
80             predicate => 'has_items',
81             is => 'rw',
82             traits => ['Array'],
83             coerce => 1,
84             handles => {
85             items_is_empty => 'is_empty',
86             next_item => [ natatime => 1 ],
87             list_items => 'elements',
88             _push_item => 'push',
89             },
90             serializer => sub {
91             my ( $attr, $instance ) = @_;
92              
93             my $items = $attr->get_value($instance);
94              
95             my $i = 0;
96             my @serialized =
97             map { ## no critic ( BuiltinFunctions::ProhibitComplexMappings )
98             my $item = $_->serialize;
99             $item->{id} = $i;
100             $i++;
101             $item
102             } @{$items};
103              
104             return \@serialized;
105             },
106             );
107              
108             has '+http_trace' => (
109             is => 'rw',
110             init_arg => undef
111             );
112              
113             has 'invoice_header' => (
114             isa => InvoiceHeader,
115             remote_name => 'invoiceHeader',
116             is => 'ro',
117             required => 0,
118             coerce => 1
119             );
120              
121             has ship_to => (
122             isa => ShipTo,
123             remote_name => 'shipTo',
124             is => 'ro',
125             coerce => 1,
126             );
127              
128             has 'other_tax' => (
129             isa => OtherTax,
130             remote_name => 'otherTax',
131             is => 'ro',
132             required => 0,
133             coerce => 1,
134             );
135              
136             has 'ship_from' => (
137             isa => ShipFrom,
138             remote_name => 'shipFrom',
139             is => 'ro',
140             required => 0,
141             coerce => 1,
142             );
143              
144             __PACKAGE__->meta->make_immutable;
145             1;
146              
147             # ABSTRACT: Abstract Request Class
148              
149             __END__
150              
151             =pod
152              
153             =encoding UTF-8
154              
155             =head1 NAME
156              
157             Business::CyberSource::Request - Abstract Request Class
158              
159             =head1 VERSION
160              
161             version 0.010008
162              
163             =head1 DESCRIPTION
164              
165             extends L<Business::CyberSource::Message>
166              
167             Here are the provided Request subclasses.
168              
169             =over
170              
171             =item * L<Authorization|Business::CyberSource::Request::Authorization>
172              
173             =item * L<AuthReversal|Business::CyberSource::Request::AuthReversal>
174              
175             =item * L<Capture|Business::CyberSource::Request::Capture>
176              
177             =item * L<Follow-On Credit|Business::CyberSource::Request::FollowOnCredit>
178              
179             =item * L<Stand Alone Credit|Business::CyberSource::Request::StandAloneCredit>
180              
181             =item * L<DCC|Business::CyberSource::Request::DCC>
182              
183             =item * L<Sale|Business::CyberSource::Request::Sale>
184              
185             =back
186              
187             I<note:> You can use the L<Business:CyberSource::Request::Credit> class but,
188             it requires traits to be applied depending on the type of request you need,
189             and thus does not currently work with the factory.
190              
191             =head1 EXTENDS
192              
193             L<Business::CyberSource::Message>
194              
195             =head1 WITH
196              
197             =over
198              
199             =item L<MooseX::RemoteHelper::CompositeSerialization>
200              
201             =back
202              
203             =head1 METHODS
204              
205             =head2 serialize
206              
207             returns a hashref suitable for passing to L<XML::Compile::SOAP>
208              
209             =head2 add_item
210              
211             Add an L<Item|Business::CyberSource::RequestPart::Item> to L<items|/"items">.
212             Accepts an item object or a hashref to construct an item object.
213              
214             an array of L<Items|MooseX::Types::CyberSource/"Items">
215              
216             =head1 ATTRIBUTES
217              
218             =head2 reference_code
219              
220             Merchant-generated order reference or tracking number. CyberSource recommends
221             that you send a unique value for each transaction so that you can perform
222             meaningful searches for the transaction.
223              
224             =head2 service
225              
226             L<Business::CyberSource::RequestPart::Service>
227              
228             =head2 purchase_totals
229              
230             L<Business::CyberSource::RequestPart::PurchaseTotals>
231              
232             =head2 items
233              
234             An array of L<Business::CyberSource::RequestPart::Item>
235              
236             =head2 invoice_header
237              
238             L<Business::CyberSource::RequestPart::InvoiceHeader>
239              
240             =head2 ship_to
241              
242             L<Business::CyberSource::RequestPart::ShipTo>
243              
244             =head2 other_tax
245              
246             L<Business::CyberSource::RequestPart::OtherTax>
247              
248             =head2 ship_from
249              
250             L<Business::CyberSource::RequestPart::ShipFrom>
251              
252             =head2 comments
253              
254             Comment Field
255              
256             =for Pod::Coverage BUILD
257              
258             =head1 BUGS
259              
260             Please report any bugs or feature requests on the bugtracker website
261             https://github.com/hostgator/business-cybersource/issues
262              
263             When submitting a bug or request, please include a test-file or a
264             patch to an existing test-file that illustrates the bug or desired
265             feature.
266              
267             =head1 AUTHOR
268              
269             Caleb Cushing <xenoterracide@gmail.com>
270              
271             =head1 COPYRIGHT AND LICENSE
272              
273             This software is Copyright (c) 2017 by Caleb Cushing <xenoterracide@gmail.com>.
274              
275             This is free software, licensed under:
276              
277             The Artistic License 2.0 (GPL Compatible)
278              
279             =cut