File Coverage

blib/lib/MooseX/Types/CyberSource.pm
Criterion Covered Total %
statement 33 33 100.0
branch n/a
condition n/a
subroutine 11 11 100.0
pod n/a
total 44 44 100.0


line stmt bran cond sub pod time code
1             package MooseX::Types::CyberSource;
2 16     16   89 use strict;
  16         27  
  16         645  
3 16     16   82 use warnings;
  16         27  
  16         502  
4 16     16   79 use Module::Runtime 'use_module';
  16         22  
  16         120  
5 16     16   729 use namespace::autoclean;
  16         25  
  16         131  
6              
7             our $VERSION = '0.010006'; # VERSION
8              
9 16         216 use MooseX::Types -declare => [ qw(
10             AVSResult
11             ElectronicVerificationResult
12             CardTypeCode
13             CountryCode
14             CvIndicator
15             CvResults
16             DCCIndicator
17              
18             Decision
19             Items
20              
21             Item
22             Card
23             PurchaseTotals
24             Service
25             AuthReversalService
26             CaptureService
27             CreditService
28             TaxService
29             BillTo
30             BusinessRules
31              
32             ResPurchaseTotals
33             AuthReply
34             TaxReply
35             DCCReply
36             Reply
37              
38             TaxReplyItems
39             TaxReplyItem
40              
41             RequestID
42              
43             ExpirationDate
44              
45             DateTimeFromW3C
46              
47             Client
48              
49             _VarcharOne
50             _VarcharSeven
51             _VarcharTen
52             _VarcharTwenty
53             _VarcharFifty
54             _VarcharSixty
55 16     16   8308 ) ];
  16         364340  
56              
57 16     16   277382 use MooseX::Types::Common::Numeric qw( PositiveOrZeroNum );
  16         681904  
  16         160  
58 16     16   45661 use MooseX::Types::Common::String qw( NonEmptySimpleStr SimpleStr );
  16         765143  
  16         165  
59 16     16   43976 use MooseX::Types::Moose qw( Int Num Str HashRef ArrayRef );
  16         50  
  16         106  
60 16     16   89569 use MooseX::Types::Locale::Country qw( Alpha2Country Alpha3Country CountryName );
  16         884742  
  16         139  
61 16     16   43847 use MooseX::Types::DateTime qw( );
  16         2275625  
  16         984  
62 16     16   11058 use MooseX::Types::DateTime::W3C qw( DateTimeW3C );
  16         207521  
  16         96  
63              
64             my $varchar_message = 'string is empty or longer than ';
65              
66             enum Decision, [ qw( ACCEPT REJECT ERROR REVIEW ) ];
67              
68             # can't find a standard on this, so I assume these are a cybersource thing
69             enum CardTypeCode, [ qw(
70             001
71             002
72             003
73             004
74             005
75             006
76             007
77             014
78             021
79             024
80             031
81             033
82             034
83             035
84             036
85             037
86             039
87             040
88             042
89             043
90             ) ];
91              
92             enum CvIndicator, [ qw( 0 1 2 9 ) ];
93              
94             enum CvResults, [ qw( D I M N P S U X 1 2 3 ),'' ];
95              
96             enum AVSResult, [ qw( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 ) ];
97              
98             enum ElectronicVerificationResult, [ qw( N P R S U Y 2) ];
99              
100             my $prefix = 'Business::CyberSource::';
101             my $req = $prefix . 'RequestPart::';
102             my $res = $prefix . 'ResponsePart::';
103              
104             my $itc = $req . 'Item';
105             my $ptc = $req . 'PurchaseTotals';
106             my $svc = $req . 'Service';
107             my $cdc = $req . 'Card';
108             my $btc = $req . 'BillTo';
109             my $brc = $req . 'BusinessRules';
110             my $ars = $req . 'Service::AuthReversal';
111             my $cps = $req . 'Service::Capture';
112             my $cds = $req . 'Service::Credit';
113             my $txs = $req . 'Service::Tax';
114              
115             my $res_pt_c = $res . 'PurchaseTotals';
116             my $res_ar_c = $res . 'AuthReply';
117             my $res_re_c = $res . 'Reply';
118             my $res_dc_c = $res . 'DCCReply';
119             my $res_tr_c = $res . 'TaxReply';
120             my $res_ti_c = $res . 'TaxReply::Item';
121              
122             my $client = 'Business::CyberSource::Client';
123              
124             class_type Item, { class => $itc };
125             class_type PurchaseTotals, { class => $ptc };
126             class_type Service, { class => $svc };
127             class_type Card, { class => $cdc };
128             class_type BillTo, { class => $btc };
129             class_type BusinessRules, { class => $brc };
130             class_type AuthReversalService, { class => $ars };
131             class_type CaptureService, { class => $cps };
132             class_type CreditService, { class => $cds };
133             class_type TaxService, { class => $txs };
134              
135             class_type ResPurchaseTotals, { class => $res_pt_c };
136             class_type AuthReply, { class => $res_ar_c };
137             class_type Reply, { class => $res_re_c };
138             class_type DCCReply, { class => $res_dc_c };
139             class_type TaxReply, { class => $res_tr_c };
140             class_type TaxReplyItem, { class => $res_ti_c };
141              
142             class_type Client, { class => $client };
143              
144             coerce Item, from HashRef, via { use_module( $itc )->new( $_ ) };
145             coerce PurchaseTotals, from HashRef, via { use_module( $ptc )->new( $_ ) };
146             coerce Service, from HashRef, via { use_module( $svc )->new( $_ ) };
147             coerce AuthReversalService, from HashRef, via { use_module( $ars )->new( $_ ) };
148             coerce CaptureService, from HashRef, via { use_module( $cps )->new( $_ ) };
149             coerce CreditService, from HashRef, via { use_module( $cds )->new( $_ ) };
150             coerce TaxService, from HashRef, via { use_module( $txs )->new( $_ ) };
151             coerce Card, from HashRef, via { use_module( $cdc )->new( $_ ) };
152             coerce BillTo, from HashRef, via { use_module( $btc )->new( $_ ) };
153             coerce BusinessRules, from HashRef, via { use_module( $brc )->new( $_ ) };
154             coerce ResPurchaseTotals, from HashRef, via { use_module( $res_pt_c )->new( $_ ) };
155             coerce AuthReply, from HashRef, via { use_module( $res_ar_c )->new( $_ ) };
156             coerce TaxReply, from HashRef, via { use_module( $res_tr_c )->new( $_ ) };
157             coerce DCCReply, from HashRef, via { use_module( $res_dc_c )->new( $_ ) };
158             coerce TaxReplyItem, from HashRef, via { use_module( $res_ti_c )->new( $_ ) };
159             coerce Reply, from HashRef, via { use_module( $res_re_c )->new( $_ ) };
160             coerce Client, from HashRef, via { use_module( $client )->new( $_ ) };
161              
162             subtype CountryCode, as Alpha2Country;
163             subtype ExpirationDate, as MooseX::Types::DateTime::DateTime;
164             subtype DateTimeFromW3C, as MooseX::Types::DateTime::DateTime;
165             subtype TaxReplyItems, as ArrayRef[TaxReplyItem];
166             subtype Items, as ArrayRef[Item];
167              
168              
169             coerce CountryCode,
170             from Alpha3Country,
171             via {
172             use_module('Locale::Code');
173              
174             return uc Locale::Code::country_code2code( $_ ,
175             Locale::Code::LOCALE_CODE_ALPHA_3(),
176             Locale::Code::LOCALE_CODE_ALPHA_2(),
177             );
178             }
179             ;
180              
181             coerce CountryCode,
182             from CountryName,
183             via {
184             use_module('Locale::Code');
185             return uc Locale::Code::country_code2code( $_ ,
186             Locale::Code::LOCALE_CODE_ALPHA_2(),
187             );
188             };
189              
190             enum DCCIndicator, [ qw( 1 2 3 ) ];
191              
192             coerce ExpirationDate,
193             from HashRef,
194             via {
195             return DateTime->last_day_of_month( %{ $_ } );
196             };
197              
198             subtype RequestID,
199             as NonEmptySimpleStr,
200             where { length $_ <= 29 },
201             message { $varchar_message . '29' }
202             ;
203              
204              
205             coerce TaxReplyItems,
206             from ArrayRef[HashRef],
207             via {
208             my $items = $_;
209              
210             my @items = map { use_module( $res_ti_c )->new( $_ ) } @{ $items };
211             return \@items;
212             };
213              
214             coerce Items,
215             from ArrayRef[HashRef],
216             via {
217             my $items = $_;
218              
219             my @items = map { use_module($itc)->new( $_ ) } @{ $items };
220             return \@items;
221             };
222              
223              
224             coerce DateTimeFromW3C,
225             from DateTimeW3C,
226             via {
227             return use_module('DateTime::Format::W3CDTF')
228             ->new->parse_datetime( $_ );
229             };
230              
231             subtype _VarcharOne,
232             as NonEmptySimpleStr,
233             where { length $_ <= 1 },
234             message { $varchar_message . '1' }
235             ;
236              
237             subtype _VarcharSeven,
238             as NonEmptySimpleStr,
239             where { length $_ <= 7 },
240             message { $varchar_message . '7' }
241             ;
242              
243             subtype _VarcharTen,
244             as SimpleStr,
245             where { length $_ <= 10 },
246             message { $varchar_message . '10' }
247             ;
248              
249             subtype _VarcharTwenty,
250             as NonEmptySimpleStr,
251             where { length $_ <= 20 },
252             message { $varchar_message . '20' }
253             ;
254              
255             subtype _VarcharFifty,
256             as NonEmptySimpleStr,
257             where { length $_ <= 50 },
258             message { $varchar_message . '50' }
259             ;
260              
261             subtype _VarcharSixty,
262             as NonEmptySimpleStr,
263             where { length $_ <= 60 },
264             message { $varchar_message . '60' }
265             ;
266             1;
267              
268             # ABSTRACT: Moose Types specific to CyberSource
269              
270             __END__
271              
272             =pod
273              
274             =encoding UTF-8
275              
276             =head1 NAME
277              
278             MooseX::Types::CyberSource - Moose Types specific to CyberSource
279              
280             =head1 VERSION
281              
282             version 0.010006
283              
284             =head1 SYNOPSIS
285              
286             {
287             package My::CyberSource::Response;
288             use Moose;
289             use MooseX::Types::CyberSource qw( Decision );
290              
291             has decision => (
292             is => 'ro',
293             isa => Decision,
294             );
295             __PACKAGE__->meta->make_immutable;
296             }
297              
298             my $response = My::CyberSource::Response->new({
299             decison => 'ACCEPT'
300             });
301              
302             =head1 DESCRIPTION
303              
304             This module provides CyberSource specific Moose Types.
305              
306             =begin Pod::Coverage
307              
308             LOCALE_CODE_ALPHA_2
309              
310             LOCALE_CODE_ALPHA_3
311              
312             =end Pod::Coverage
313              
314             =head1 TYPES
315              
316             =over
317              
318             =item * C<Client>
319              
320             L<Business::CyberSource::Client>
321              
322             =item * C<Decision>
323              
324             Base Type: C<enum>
325              
326             CyberSource Response Decision
327              
328             =item * C<CardTypeCode>
329              
330             Base Type: C<enum>
331              
332             Numeric codes that specify Card types. Codes denoted with an asterisk* are
333             automatically detected when using
334              
335             =item * C<CvResults>
336              
337             Base Type: C<enum>
338              
339             Single character code that defines the result of having sent a CVN. See
340             L<CyberSource's Documentation on Card Verification Results
341             |http://www.cybersource.com/support_center/support_documentation/quick_references/view.php?page_id=421>
342             for more information.
343              
344             =item * C<AVSResults>
345              
346             Base Type: C<enum>
347              
348             Single character code that defines the result of having sent a CVN. See
349             L<CyberSource's Documentation on AVS Results
350             |http://www.cybersource.com/support_center/support_documentation/quick_references/view.php?page_id=423>
351             for more information.
352              
353             =item * C<DCCIndicator>
354              
355             Base Type: C<enum>
356              
357             Single character code that defines the DCC status
358              
359             =over
360              
361             =item * C<1>
362              
363             Converted - DCC is being used.
364              
365             =item * C<2>
366              
367             Non-convertible - DCC cannot be used.
368              
369             =item * C<3>
370              
371             Declined - DCC could be used, but the customer declined it.
372              
373             =back
374              
375             =back
376              
377             =head1 BUGS
378              
379             Please report any bugs or feature requests on the bugtracker website
380             https://github.com/xenoterracide/business-cybersource/issues
381              
382             When submitting a bug or request, please include a test-file or a
383             patch to an existing test-file that illustrates the bug or desired
384             feature.
385              
386             =head1 AUTHOR
387              
388             Caleb Cushing <xenoterracide@gmail.com>
389              
390             =head1 COPYRIGHT AND LICENSE
391              
392             This software is Copyright (c) 2015 by Caleb Cushing <xenoterracide@gmail.com>.
393              
394             This is free software, licensed under:
395              
396             The Artistic License 2.0 (GPL Compatible)
397              
398             =cut