| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Dancer::Plugin::Interchange6::Business::OnlinePayment; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 716 | use Business::OnlinePayment 3.02; | 
|  | 1 |  |  |  |  | 3211 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 4 | 1 |  |  | 1 |  | 6 | use Dancer ':syntax'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 11 |  | 
| 5 | 1 |  |  | 1 |  | 480 | use Moo; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 NAME | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | Dancer::Plugin::Interchange6::Business::OnlinePayment - Interchange6 wrapper for Business:OnlinePayment | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 CONFIGURATION | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Configuration for AuthorizeNet provider: | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | plugins: | 
| 16 |  |  |  |  |  |  | Interchange6: | 
| 17 |  |  |  |  |  |  | Payment: | 
| 18 |  |  |  |  |  |  | default_provider: AuthorizeNet | 
| 19 |  |  |  |  |  |  | providers: | 
| 20 |  |  |  |  |  |  | AuthorizeNet: | 
| 21 |  |  |  |  |  |  | login: <API Login ID> | 
| 22 |  |  |  |  |  |  | password: <Transaction Key> | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | If you use a test account, please add the following | 
| 25 |  |  |  |  |  |  | parameters: | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | test_transaction: 1 | 
| 28 |  |  |  |  |  |  | server: test.authorize.net | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =head2 provider | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | Payment provider. | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =cut | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | has provider => ( | 
| 39 |  |  |  |  |  |  | is => 'rwp', | 
| 40 |  |  |  |  |  |  | ); | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head2 provider_args | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | Payment provider settings, like login and password. | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =cut. | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | has provider_args => ( | 
| 49 |  |  |  |  |  |  | is => 'rwp', | 
| 50 |  |  |  |  |  |  | ); | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | =head2 payment_order | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | Payment order object. | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | =cut | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | has payment_order => ( | 
| 59 |  |  |  |  |  |  | is => 'rw', | 
| 60 |  |  |  |  |  |  | ); | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | =head2 is_success | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | True if the payment was successful, false otherwise. | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =cut | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | has is_success => ( | 
| 69 |  |  |  |  |  |  | is => 'rwp', | 
| 70 |  |  |  |  |  |  | ); | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | =head2 authorization | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | Returns authorization code from provider after a successful | 
| 75 |  |  |  |  |  |  | payment. | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =cut | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | has authorization => ( | 
| 80 |  |  |  |  |  |  | is => 'rwp', | 
| 81 |  |  |  |  |  |  | ); | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =head2 order_number | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | Returns unique order number from provider after a successful | 
| 86 |  |  |  |  |  |  | payment. | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | =cut | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | has order_number => ( | 
| 91 |  |  |  |  |  |  | is => 'rwp', | 
| 92 |  |  |  |  |  |  | ); | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =head2 error_code | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | Returns error code in case of payment failure. | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =cut | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | has error_code => ( | 
| 101 |  |  |  |  |  |  | is => 'rwp', | 
| 102 |  |  |  |  |  |  | ); | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | =head2 error_message | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | Returns error message in case of payment failure. | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | =cut | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | has error_message => ( | 
| 111 |  |  |  |  |  |  | is => 'rwp', | 
| 112 |  |  |  |  |  |  | ); | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | sub BUILDARGS { | 
| 115 | 0 |  |  | 0 | 0 |  | my ( $class, @args ) = @_; | 
| 116 | 0 |  |  |  |  |  | my ( %params ); | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | # first argument is the provider | 
| 119 | 0 |  |  |  |  |  | $params{provider} = shift @args; | 
| 120 | 0 |  |  |  |  |  | $params{provider_args} = {@args}; | 
| 121 |  |  |  |  |  |  |  | 
| 122 | 0 |  |  |  |  |  | return \%params; | 
| 123 |  |  |  |  |  |  | } | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =head1 METHODS | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head2 charge | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | Performs charge transaction with payment provider. | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | =cut | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | sub charge { | 
| 134 | 0 |  |  | 0 | 1 |  | my ( $self, %args ) = @_; | 
| 135 | 0 |  |  |  |  |  | my ( $provider_settings, $bop_object ); | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | # reset values | 
| 138 | 0 |  |  |  |  |  | $self->_set_is_success(0); | 
| 139 | 0 |  |  |  |  |  | $self->_set_authorization(''); | 
| 140 | 0 |  |  |  |  |  | $self->_set_order_number(''); | 
| 141 | 0 |  |  |  |  |  | $self->_set_error_code(''); | 
| 142 | 0 |  |  |  |  |  | $self->_set_error_message(''); | 
| 143 |  |  |  |  |  |  |  | 
| 144 | 0 |  |  |  |  |  | $provider_settings = $self->provider_args; | 
| 145 |  |  |  |  |  |  |  | 
| 146 | 0 |  |  |  |  |  | $bop_object = Business::OnlinePayment->new($self->provider, %$provider_settings); | 
| 147 |  |  |  |  |  |  |  | 
| 148 | 0 | 0 |  |  |  |  | if ($provider_settings->{server}) { | 
| 149 | 0 |  |  |  |  |  | $bop_object->server( $provider_settings->{server} ); | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | # Sofortbanking expects amount as xx.xx | 
| 153 | 0 |  |  |  |  |  | $args{amount} = sprintf( '%.2f', $args{amount} ); | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | $bop_object->content( | 
| 156 |  |  |  |  |  |  | %$provider_settings, | 
| 157 |  |  |  |  |  |  | amount      => $args{amount}, | 
| 158 |  |  |  |  |  |  | card_number => $args{card_number}, | 
| 159 |  |  |  |  |  |  | expiration  => $args{expiration}, | 
| 160 |  |  |  |  |  |  | cvc         => $args{cvc}, | 
| 161 |  |  |  |  |  |  | first_name  => $args{first_name}, | 
| 162 |  |  |  |  |  |  | last_name   => $args{last_name}, | 
| 163 |  |  |  |  |  |  | login       => $provider_settings->{login}, | 
| 164 |  |  |  |  |  |  | password    => $provider_settings->{password}, | 
| 165 |  |  |  |  |  |  | type        => $args{type} || $provider_settings->{type} || 'CC', | 
| 166 | 0 |  | 0 |  |  |  | action => $args{action} || $provider_settings->{action} || 'Authorization Only', | 
|  |  |  | 0 |  |  |  |  | 
| 167 |  |  |  |  |  |  | ); | 
| 168 |  |  |  |  |  |  |  | 
| 169 | 0 |  |  |  |  |  | eval { $bop_object->submit(); }; | 
|  | 0 |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  |  | 
| 171 | 0 | 0 |  |  |  |  | if ($@) { | 
| 172 | 0 |  |  |  |  |  | die "Payment with provider ", $self->{provider}, " failed: ", $@; | 
| 173 |  |  |  |  |  |  | } | 
| 174 |  |  |  |  |  |  |  | 
| 175 | 0 | 0 |  |  |  |  | if ( $bop_object->is_success() ) { | 
| 176 | 0 |  |  |  |  |  | $self->_set_is_success(1); | 
| 177 |  |  |  |  |  |  |  | 
| 178 | 0 | 0 |  |  |  |  | if ( $bop_object->can('popup_url') ) { | 
| 179 | 0 |  |  |  |  |  | debug( "Success!  Redirect browser to " . $bop_object->popup_url() ); | 
| 180 |  |  |  |  |  |  | } | 
| 181 |  |  |  |  |  |  | else { | 
| 182 | 0 |  |  |  |  |  | debug("Successful payment, authorization: ", | 
| 183 |  |  |  |  |  |  | $bop_object->authorization); | 
| 184 | 0 |  |  |  |  |  | debug("Order number: ", $bop_object->order_number); | 
| 185 | 0 |  |  |  |  |  | $self->_set_authorization($bop_object->authorization); | 
| 186 | 0 |  |  |  |  |  | $self->_set_order_number($bop_object->order_number); | 
| 187 |  |  |  |  |  |  | } | 
| 188 |  |  |  |  |  |  | } | 
| 189 |  |  |  |  |  |  | else { | 
| 190 | 0 |  |  |  |  |  | debug( 'Card was rejected by ', $self->provider, ': ' , $bop_object->error_message ); | 
| 191 | 0 |  |  |  |  |  | $self->_set_error_code($bop_object->result_code); | 
| 192 | 0 |  |  |  |  |  | $self->_set_error_message($bop_object->error_message); | 
| 193 | 0 |  |  |  |  |  | return; | 
| 194 |  |  |  |  |  |  | } | 
| 195 |  |  |  |  |  |  | } | 
| 196 |  |  |  |  |  |  |  | 
| 197 |  |  |  |  |  |  | =head1 AUTHOR | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | Stefan Hornburg (Racke), <racke@linuxia.de> | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | Copyright 2012-2015 Stefan Hornburg (Racke) <racke@linuxia.de>. | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 206 |  |  |  |  |  |  | under the terms of either: the GNU General Public License as published | 
| 207 |  |  |  |  |  |  | by the Free Software Foundation; or the Artistic License. | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | See http://dev.perl.org/licenses/ for more information. | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | =cut | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | 1; |