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