Catalyst-Model-PayPal-IPN

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

        Handle PayPal IPN stuff

        =cut

        sub ipn : Path('payment/ipn') {
            my ( $self, $c ) = @_;

            my $ipn = $c->model('Paypal::IPN');

            if ( $ipn->is_completed ) {
                my %ipn_vars = $ipn->buyer_info();
                $c->stash->{ipn_vars} = \%ipn_vars;

                Do stuff here

                # Just so we reply with something, which in turn sends a HTTP Status 200
                # OK, which we need to stop PayPal.
                # We don't get as we don't use a template and RenderView looks for a
                # template, a body or status equal to 3XX
                $c->res->body('ok');
            }
            else {

            # Just so we reply with something, which in turn sends a HTTP Status 200
            # OK, which we need to stop PayPal.
            # We don't get as we don't use a template and RenderView looks for a
            # template, a body or status equal to 3XX
                $c->res->body('not_ok');
                $c->log->debug( $record_payment_result->transmsgtext ) if $c->debug;
                $c->log->debug( $ipn->error ) if $ipn->error && $c->debug;
            }
        }

        =head2 cancelled

        Cancelled Payment

        =cut

        sub cancelled : Path('payment/cancelled') {
            my ( $self, $c ) = @_;

            Do stuff on cancel

            $c->stash->{template} = 'user/subscribe/cancelled.tt';
        }

        =head2 generate_paypal_buttons

        =cut

        sub generate_paypal_buttons : Private {
            my ( $self, $c ) = @_;

            if ( $c->stash->{all_buttons} ) {
                $c->stash->{subtypes} = [
                    $c->model('FTMAdminDB::FTMTariffs')->search(
                        {
                            objectname => 'FTM_SUB_TARIFFS',
                            objectitem => 'TARIFFTYPENO',
                            lovlangid  => $langid,
                        },
                    )
                ];

                for my $tariff ( @{ $c->stash->{subtypes} } ) {
                    next if $tariff->tariffid == 1;
                    my %data = (
                        #cert_id     => $c->config->{paypal}->{cert_id},
                        cmd         => '_xclick',
                        item_name   => $tariff->itemdesc,
                        item_number => $tariff->tariffid,
                        amount      => $tariff->peruser,
                        page_style  => $c->config->{paypal}->{page_style},
                        no_shipping => $c->config->{paypal}->{no_shipping},
                        no_note     => $c->config->{paypal}->{no_note},
                        'lc'        => $c->config->{paypal}->{lc},
                        bn          => $c->config->{paypal}->{bn},
                        custom      => $c->req->param('subid'),
                    );

                    if ( $c->debug ) {
                        for my $param ( keys %data ) {
                            $c->log->debug( $param . '=' . $data{$param} );
                        }
                    }
                    $c->stash->{unencrypted_form_data} =
                      $c->model('Paypal::IPN')->form_info( \%data );

                    my @button_info = (
                        $tariff->itemdesc, $tariff->peruser,
                        $c->stash->{unencrypted_form_data}
                    );
                    push @{ $c->stash->{unencrypted_buttons} }, \@button_info;

                    #$c->stash->{encrypted_form_data} =
                    #  $c->model('Paypal::IPN')->encrypt_form( \%data );

                    #my @button_info = (
                    #    $tariff->itemdesc, $tariff->peruser,
                    #    $c->stash->{encrypted_form_data}
                    #);
                    #push @{ $c->stash->{encrypted_buttons} }, \@button_info;
                }
            }
        }

        buttons.tt

        <table>
            [% FOREACH button IN unencrypted_buttons %]
                <tr>
                    <td><b>[% button.0 %]</b></td>
                    <td><b>Price:</b> £[% button.1 %]</td>
                    <td class="content">
                        <form method="post" action="[% c.model('Paypal::IPN').paypal_gateway %]">
                        <input type="hidden" name="cmd" value="_xclick">
                        <input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0"
                        name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
                        <img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
                [% FOREACH key IN button.2.keys %]



( run in 1.860 second using v1.01-cache-2.11-cpan-97f6503c9c8 )