« Business/CyberSource/Factory/Rule.pm
↑ Summary
Business/CyberSource/Exception/AttributeIsRequiredNotToBeSet.pm »
| 1 | package Business::CyberSource; | ||
| 2 | 1 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | our $VERSION = '0.010007'; # VERSION | |
| 7 | |||
| 8 | 1 | 1; | |
| 9 | |||
| 10 | # ABSTRACT: Perl interface to the CyberSource Simple Order SOAP API | ||
| 11 | |||
| 12 | __END__ | ||
| 13 | |||
| 14 | =pod | ||
| 15 | |||
| 16 | =encoding UTF-8 | ||
| 17 | |||
| 18 | =head1 NAME | ||
| 19 | |||
| 20 | Business::CyberSource - Perl interface to the CyberSource Simple Order SOAP API | ||
| 21 | |||
| 22 | =head1 VERSION | ||
| 23 | |||
| 24 | version 0.010007 | ||
| 25 | |||
| 26 | =head1 DESCRIPTION | ||
| 27 | |||
| 28 | This library is a Perl interface to the CyberSource Simple Order SOAP API built | ||
| 29 | on L<Moose> and L<XML::Compile::SOAP> technologies. This library aims to | ||
| 30 | eventually provide a full interface the SOAPI. | ||
| 31 | |||
| 32 | You may wish to read the Official CyberSource Documentation on L<Credit Card | ||
| 33 | Services for the Simpler Order | ||
| 34 | API|http://apps.cybersource.com/library/documentation/dev_guides/CC_Svcs_SO_API/html/> | ||
| 35 | as it will provide further information on why what some things are and the | ||
| 36 | general workflow. | ||
| 37 | |||
| 38 | To get started you will want to read the documentation in | ||
| 39 | L<Business::CyberSource::Client> and L<Business::CyberSource::Request>. If you | ||
| 40 | find any documentation unclear or outright missing, please file a bug. | ||
| 41 | |||
| 42 | If there are features that are part of CyberSource's API but are not | ||
| 43 | documented, or are missing here, please file a bug. I'll be happy to add them, | ||
| 44 | but due to the size of the upstream API, I have not had time to cover all the features | ||
| 45 | and some are currently undocumented. | ||
| 46 | |||
| 47 | =head1 ENVIRONMENT | ||
| 48 | |||
| 49 | =head2 Debugging | ||
| 50 | |||
| 51 | Supports L<MooseY::RemoteHelper::Role::Client>s C<REMOTE_CLIENT_DEBUG> | ||
| 52 | variable. This can be set to either C<0>, C<1>, C<2>, for varying levels of | ||
| 53 | verbosity. | ||
| 54 | |||
| 55 | =head2 Testing | ||
| 56 | |||
| 57 | all environment variables are prefixed with C<PERL_BUSINESS_CYBERSOURCE_> | ||
| 58 | |||
| 59 | =head3 Credentials | ||
| 60 | |||
| 61 | =head4 USERNAME | ||
| 62 | |||
| 63 | =head4 PASSWORD | ||
| 64 | |||
| 65 | set's the L<username|Busines::CyberSource::Client/"user"> and | ||
| 66 | L<password|Busines::CyberSource::Client/"pass"> in the client for running | ||
| 67 | tests. | ||
| 68 | |||
| 69 | =head3 Direct Currency Conversion | ||
| 70 | |||
| 71 | =head4 DCC_CC_YYYY | ||
| 72 | |||
| 73 | sets the test credit card expiration year for both Visa and MasterCard | ||
| 74 | |||
| 75 | =head4 DCC_CC_MM | ||
| 76 | |||
| 77 | sets the test credit card expiration month for both Visa and MasterCard | ||
| 78 | |||
| 79 | =head4 DCC_MASTERCARD | ||
| 80 | |||
| 81 | A test credit card number provided by your your credit card processor | ||
| 82 | |||
| 83 | =head4 DCC_VISA | ||
| 84 | |||
| 85 | A test credit card number provided by your your credit card processor | ||
| 86 | |||
| 87 | =head1 EXAMPLE | ||
| 88 | |||
| 89 | In the example, C<carp> means you should log something C<Dumper> means you should | ||
| 90 | log it with lots of detail. L<Safe::Isa> is used because you should either use | ||
| 91 | it or check for C<blessed> it is always possible that somewhere in the stack | ||
| 92 | someone is using C<die> on a string. | ||
| 93 | |||
| 94 | use 5.010; | ||
| 95 | use Carp; | ||
| 96 | use Try::Tiny; | ||
| 97 | use Safe::Isa; | ||
| 98 | use Data::Printer alias => 'Dumper'; | ||
| 99 | |||
| 100 | use Business::CyberSource::Client; | ||
| 101 | use Business::CyberSource::Request::Authorization; | ||
| 102 | use Business::CyberSource::Request::Capture; | ||
| 103 | # exception namepsace | ||
| 104 | my $e_ns = 'Business::CyberSource::Exception'; | ||
| 105 | |||
| 106 | my $client = Business::CyberSource::Client->new({ | ||
| 107 | user => 'Merchant ID', | ||
| 108 | pass => 'API Key', | ||
| 109 | test => 1, | ||
| 110 | debug => 1, # do not set in production as it prints sensative | ||
| 111 | # information | ||
| 112 | }); | ||
| 113 | |||
| 114 | my $auth_request; | ||
| 115 | try { | ||
| 116 | $auth_request | ||
| 117 | = Business::CyberSource::Request::Authorization->new({ | ||
| 118 | reference_code => '42', | ||
| 119 | bill_to => { | ||
| 120 | first_name => 'Caleb', | ||
| 121 | last_name => 'Cushing', | ||
| 122 | street1 => '100 somewhere st', | ||
| 123 | city => 'Houston', | ||
| 124 | state => 'TX', | ||
| 125 | postal_code => '77064', | ||
| 126 | country => 'US', | ||
| 127 | email => 'xenoterracide@gmail.com', | ||
| 128 | }, | ||
| 129 | purchase_totals => { | ||
| 130 | currency => 'USD', | ||
| 131 | total => 5.00, | ||
| 132 | }, | ||
| 133 | card => { | ||
| 134 | account_number => '4111111111111111', | ||
| 135 | expiration => { | ||
| 136 | month => 9, | ||
| 137 | year => 2025, | ||
| 138 | }, | ||
| 139 | }, | ||
| 140 | }); | ||
| 141 | } | ||
| 142 | catch { | ||
| 143 | my $e = $_; | ||
| 144 | if ( $e->$_does('Business::CyberSource::Response::Role::Base')) { | ||
| 145 | carp $e->reason_code . $e->reason_text; | ||
| 146 | } | ||
| 147 | elsif ( $e->$_isa( $e_ns . '::SOAPFault' ) ) { | ||
| 148 | carp $e->faultcode . $e->faultstring; | ||
| 149 | } | ||
| 150 | elsif ( $e->$_isa( $e_ns ) || $e->$_isa( 'Moose::Exception' ) ) { | ||
| 151 | Dumper( $e ); | ||
| 152 | ## probably your payload was bad, check type more | ||
| 153 | ## specifically and feed good error messages to your | ||
| 154 | ## customer | ||
| 155 | } | ||
| 156 | else { # probably a coding error | ||
| 157 | Dumper( $e ); | ||
| 158 | } | ||
| 159 | }; | ||
| 160 | return unless $auth_request; | ||
| 161 | |||
| 162 | my $auth_response; | ||
| 163 | try { | ||
| 164 | $auth_response = $client->submit( $auth_request ); | ||
| 165 | } | ||
| 166 | catch { | ||
| 167 | carp $_; | ||
| 168 | }; | ||
| 169 | return unless $auth_response; | ||
| 170 | |||
| 171 | unless( $auth_response->is_accept ) { | ||
| 172 | carp $auth_response->reason_text; | ||
| 173 | } | ||
| 174 | else { | ||
| 175 | my $capture_request | ||
| 176 | = Business::CyberSource::Request::Capture->new({ | ||
| 177 | reference_code => $auth_response->reference_code, | ||
| 178 | service => { | ||
| 179 | request_id => $auth_response->request_id, | ||
| 180 | }, | ||
| 181 | purchase_totals => { | ||
| 182 | total => $auth_response->auth->amount, | ||
| 183 | currency => $auth_response->purchase_totals->currency, | ||
| 184 | }, | ||
| 185 | }); | ||
| 186 | |||
| 187 | my $capture_response; | ||
| 188 | try { | ||
| 189 | $capture_response = $client->submit( $capture_request ); | ||
| 190 | } | ||
| 191 | catch { | ||
| 192 | my $e = $_; | ||
| 193 | if ( $e->$_does('Business::CyberSource::Response::Role::Base') ) | ||
| 194 | carp $e->reason_code . $e->reason_text; | ||
| 195 | } | ||
| 196 | elsif ( $e->$_isa( $e_ns . '::SOAPFault' ) ) { | ||
| 197 | carp $e->faultcode . $e->faultstring; | ||
| 198 | } | ||
| 199 | elsif ( $e->$_isa( $e_ns ) || $e->$_isa( 'Moose::Exception' ) ) { | ||
| 200 | Dumper( $e ); | ||
| 201 | ## probably your payload was bad, check type more | ||
| 202 | ## specifically and feed good error messages to your | ||
| 203 | ## customer | ||
| 204 | } | ||
| 205 | else { # probably a coding error | ||
| 206 | Dumper( $e ); | ||
| 207 | } | ||
| 208 | }; | ||
| 209 | return unless $capture_response; | ||
| 210 | |||
| 211 | if ( $capture_response->is_accept ) { | ||
| 212 | # you probably want to record this | ||
| 213 | say $capture_response->capture->reconciliation_id; | ||
| 214 | } | ||
| 215 | } | ||
| 216 | |||
| 217 | This code is not meant to be DRY, but more of a top to bottom example. Also | ||
| 218 | note that if you really want to do Authorization and Capture at one time use a | ||
| 219 | L<Sale|Business::CyberSource::Request::Sale>. Most common Reasons for | ||
| 220 | Exceptions would be bad input into the request object (which validates things) | ||
| 221 | or CyberSource just randomly throwing an ERROR, in which case you can usually | ||
| 222 | just retry later. You don't have to print the response on error during | ||
| 223 | development, you can easily just use the C<REMOTE_CLIENT_DEBUG> Environment | ||
| 224 | variable. | ||
| 225 | |||
| 226 | =head1 ACKNOWLEDGMENTS | ||
| 227 | |||
| 228 | =over | ||
| 229 | |||
| 230 | =item * Mark Overmeer | ||
| 231 | |||
| 232 | for the help with getting L<XML::Compile::SOAP::WSS> working. | ||
| 233 | |||
| 234 | =item * L<HostGator|http://hostgator.com> | ||
| 235 | |||
| 236 | funding initial development. | ||
| 237 | |||
| 238 | =item * L<GüdTech|http://gudtech.com> | ||
| 239 | |||
| 240 | funding further development. | ||
| 241 | |||
| 242 | =back | ||
| 243 | |||
| 244 | =head1 SEE ALSO | ||
| 245 | |||
| 246 | =over | ||
| 247 | |||
| 248 | =item * L<Checkout::CyberSource::SOAP> | ||
| 249 | |||
| 250 | =item * L<Business::OnlinePayment::CyberSource> | ||
| 251 | |||
| 252 | =back | ||
| 253 | |||
| 254 | =head1 BUGS | ||
| 255 | |||
| 256 | Please report any bugs or feature requests on the bugtracker website | ||
| 257 | https://github.com/xenoterracide/business-cybersource/issues | ||
| 258 | |||
| 259 | When submitting a bug or request, please include a test-file or a | ||
| 260 | patch to an existing test-file that illustrates the bug or desired | ||
| 261 | feature. | ||
| 262 | |||
| 263 | =head1 CONTRIBUTORS | ||
| 264 | |||
| 265 | =for stopwords Carl Carstenson Lantz Jonathan William Taylor Robert Stone | ||
| 266 | |||
| 267 | =over 4 | ||
| 268 | |||
| 269 | =item * | ||
| 270 | |||
| 271 | Carl Carstenson <ccarstenson@hostgator.com> | ||
| 272 | |||
| 273 | =item * | ||
| 274 | |||
| 275 | Carl Lantz <carl.lantz@endurance.com> | ||
| 276 | |||
| 277 | =item * | ||
| 278 | |||
| 279 | Jonathan William Taylor <jonathan.taylor@endurance.com> | ||
| 280 | |||
| 281 | =item * | ||
| 282 | |||
| 283 | Robert Stone <robertstone@hostgator.com> | ||
| 284 | |||
| 285 | =back | ||
| 286 | |||
| 287 | =head1 AUTHOR | ||
| 288 | |||
| 289 | Caleb Cushing <xenoterracide@gmail.com> | ||
| 290 | |||
| 291 | =head1 COPYRIGHT AND LICENSE | ||
| 292 | |||
| 293 | This software is Copyright (c) 2016 by Caleb Cushing <xenoterracide@gmail.com>. | ||
| 294 | |||
| 295 | This is free software, licensed under: | ||
| 296 | |||
| 297 | The Artistic License 2.0 (GPL Compatible) | ||
| 298 | |||
| 299 | =cut | ||