Dancer-Plugin-Nitesi

 view release on metacpan or  search on metacpan

lib/Dancer/Plugin/Nitesi/Business/OnlinePayment.pm  view on Meta::CPAN


    # first argument is the provider
    $params{provider} = shift @args;
    $params{provider_args} = {@args};

    return \%params;
}

=head1 METHODS

=head2 charge

Performs charge transaction with payment provider.

=cut

sub charge {
    my ( $self, %args ) = @_;
    my ( $provider_settings, $bop_object );

    # reset values
    $self->_set_is_success(0);
    $self->_set_authorization('');
    $self->_set_order_number('');
    $self->_set_error_message('');

    $provider_settings = $self->provider_args;

    $bop_object = Business::OnlinePayment->new($self->provider, %$provider_settings);

	if ($provider_settings->{server}) {
		$bop_object->server( $provider_settings->{server} );
	}

	# Sofortbanking expects amount as xx.xx
	$args{amount} = sprintf( '%.2f', $args{amount} );

	$bop_object->content(
        %$provider_settings,
		amount      => $args{amount},
		card_number => $args{card_number},
		expiration  => $args{expiration},
		cvc         => $args{cvc},
        first_name  => $args{first_name},
        last_name   => $args{last_name},
		login       => $provider_settings->{login},
		password    => $provider_settings->{password},
		type        => $args{type} || $provider_settings->{type} || 'CC',
		action => $args{action} || $provider_settings->{action} || 'Authorization Only',
	);

	eval { $bop_object->submit(); };

	if ($@) {
		die "Payment with provider ", $self->{provider}, " failed: ", $@;
	}

	if ( $bop_object->is_success() ) {
        $self->_set_is_success(1);

		if ( $bop_object->can('popup_url') ) {
			debug( "Success!  Redirect browser to " . $bop_object->popup_url() );
		}
        else {
            debug("Successful payment, authorization: ",
                  $bop_object->authorization);
            debug("Order number: ", $bop_object->order_number);
            $self->_set_authorization($bop_object->authorization);
            $self->_set_order_number($bop_object->order_number);
        }
	}
	else {
		debug( 'Card was rejected by ', $self->provider, ': ' , $bop_object->error_message );
        $self->_set_error_message($bop_object->error_message);
        return;
	}
}

=head1 AUTHOR

Stefan Hornburg (Racke), <racke@linuxia.de>

=head1 LICENSE AND COPYRIGHT

Copyright 2012-2013 Stefan Hornburg (Racke) <racke@linuxia.de>.

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

=cut

1;



( run in 1.475 second using v1.01-cache-2.11-cpan-364913b4093 )