On-line payment plug-in

Discussion in 'Installation and "How-To" Questions' started by ViktorB, Nov 11, 2013.

  1. ViktorB

    ViktorB Kilo Poster

    Messages:
    15
    Hi,
    We're trying to create on-line redirect payment plug-in.
    PBAs version is 4.3.3-47.
    External gateway notifies PBAS about finishing the payment. PBAS updates the status of the payment. It works out here.
    But when the external gateway redirects the user to the PBAS result URL. PBAS displays an error - "Template broken"
    Please can you say what we're doing wrong.

    Logic Module
    use strict;
    use HSPC::pluginToolkit::HTMLTemplate qw(parse_template);
    use HSPC::pluginToolkit::General qw(string argparam uriparam log log_warn log_debug);
    use HSPC::pluginToolkit::pP qw(callback_url);
    use Digest::MD5 qw(md5 md5_hex md5_base64);

    sub get_title {
    my $class = shift;
    return string('title_moneyua_plugin');
    }

    sub process_preauthorize {
    my $class = shift;
    return $class->_process_redirect(@_);
    }

    sub process_sale{
    my $class = shift;
    return $class->_process_redirect(@_);
    }

    sub _process_redirect {
    my $class = shift;
    my %h = (
    document_info => undef,
    ref_no => undef,
    config => undef,
    @_
    );

    ## URL where redirect customers from Gate to.
    my $result_url = callback_url(action => 'return');

    ## URL where sent notifications from Gate to.
    my $notify_url = callback_url(action => 'notify');

    my $uan_rate = 815;

    my $config = $h{config};
    my $url = $config->{gateway_url};
    my $document_info = $h{document_info};
    my $ref_no = $h{ref_no};
    my $payment_amount = $uan_rate * $document_info->{total};
    my $payment_addvalue = "$ref_no";
    my $payment_info = "Neohost service";
    my $merchant_info = "281";
    my $payment_deliver = "";
    my $payment_order = "";
    my $payment_visa = "";
    my $payment_type = "16";
    my $payment_rule = "1";
    my $payment_returnres = $notify_url;
    my $payment_return = $result_url;
    my $payment_returnmet = "2";
    my $payment_testmode = "";

    my $redirect_hash = {
    url => $url,
    method => "POST",
    attrs => {
    #ref_no => $ref_no,
    PAYMENT_AMOUNT => $payment_amount,
    PAYMENT_INFO => $payment_info,
    PAYMENT_DELIVER => $payment_deliver,
    PAYMENT_ADDVALUE => $payment_addvalue,
    MERCHANT_INFO => $merchant_info, #
    PAYMENT_ORDER => $payment_order,
    PAYMENT_TYPE => $payment_type, # VISA/MASTER Card
    PAYMENT_RULE => $payment_rule, #
    PAYMENT_VISA => $payment_visa,
    PAYMENT_RETURN => $payment_return,
    PAYMENT_RETURNRES => $payment_returnres,
    PAYMENT_RETURNMET => $payment_returnmet, #
    PAYMENT_TESTMODE => $payment_testmode,
    PAYMENT_HASH => $payment_hash,
    }
    };

    return {
    STATUS => 'REDIRECT',
    REDIRECT_HASH => $redirect_hash,
    };
    }

    sub collect_transaction_refno{
    my $class = shift;
    my $ref_no = argparam('RETURN_ADDVALUE');
    return $ref_no;
    }

    sub process_callback{
    my $uan_rate = 815;

    my $class = shift;
    my $url = $ENV{q}->url(-path_info => 1);
    my $action = uriparam('action');

    my $ret;
    my $status;
    my $return_merchant = argparam('RETURN_MERCHANT');
    my $return_addvalue = argparam('RETURN_ADDVALUE');
    my $return_clientorder = argparam('RETURN_CLIENTORDER');
    my $return_amount = argparam('RETURN_AMOUNT');
    my $return_comission = argparam('RETURN_COMISSION');
    my $return_uniq_id = argparam('RETURN_UNIQ_ID');
    my $test_mode = argparam('TEST_MODE');
    my $payment_date = argparam('PAYMENT_DATE');
    my $return_result = argparam('RETURN_RESULT');
    my $amount = $return_amount / $uan_rate;


    if ($return_result eq "20") {
    $status = "Success";
    }else {
    $status = "Failure";
    }

    log_debug("log_debug status = $status");

    if ($action eq "return") {
    my $code;
    my $desc;

    if ('Success' eq $status) {
    $code = "APPROVED";
    $desc = "Success";
    } elsif ('Failure' eq $status) {
    $code = "DECLINED";
    $desc = "Failure";
    } elsif ('Pending' eq $status) {
    $code = "PENDING";
    $desc = "Pending";
    } elsif ('Cancel' eq $status) {
    $code = "DECLINED";
    $desc = "Cancel";
    }

    $ret = {
    STATUS => $code,
    TEXT => {customer_message => $desc,},
    amount => $amount,
    ref_no => $return_addvalue,
    ACTION => "restore_session",
    };
    } elsif ($action eq "notify") {
    $ret = $class->_process_notification();
    }

    return $ret;
    }


    sub _process_notification {
    my $class = shift;

    my $ret;
    my $ref_no = argparam('RETURN_ADDVALUE');
    my $amount = argparam('RETURN_AMOUNT');
    my $status;
    my $desc;
    my $details;
    my $gate_answer = argparam('RETURN_RESULT');

    if ($gate_answer eq "20") {
    $ret = "Success";
    }else {
    $ret = "Failure";
    }


    if ('Success' eq $ret) {
    $status = "APPROVED";
    $desc = "Success";
    } elsif ('Failure' eq $ret) {
    $status = "DECLINED";
    $desc = "Failure";
    } elsif ('Pending' eq $ret) {
    $status = "PENDING";
    $desc = "Pending";
    } elsif ('Cancel' eq $ret) {
    $status = "DECLINED";
    $desc = "Cancel";
    }

    $details->{desc} = $desc;

    return {
    TEXT => {vendor_message => $desc},
    STATUS => $status,
    TRANSACTION_DETAILS => $details,
    ACTION => 'update',
    CUSTOM_RESPONSE => 'OK',
    };
    }

    Error log from /var/log/hspcd/error_log

    Constant subroutine HSPC::VZAgent::VZA46::BackupGate::OP_BACKM redefined at /usr/lib/perl5/5.
    [Mon Nov 11 10:20:33 2013] [notice] Apache configured -- resuming normal operations
    [Mon Nov 11 10:20:33 2013] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
    [Mon Nov 11 10:20:33 2013] [notice] Accept mutex: sysvsem (Default: sysvsem)
    Use of uninitialized value in numeric gt (>) at /usr/lib/perl5/site_perl/5.8.8/HSPC/API/PP.pm
    Use of uninitialized value in numeric gt (>) at /usr/lib/perl5/site_perl/5.8.8/HSPC/API/PP.pm
    URI handler (HSPC::MT::pP::pluginEngine::OP->callback_handler) error: Can't call method "id"
    Use of uninitialized value in numeric gt (>) at /usr/lib/perl5/site_perl/5.8.8/HSPC/API/PP.pm
     
  2. FedorK

    FedorK Mega Poster

    Messages:
    224
    Make sure that collect_transaction_refno return correct ref_no.
    PBAS can't find transaction with reference number which return your collect_transaction_refno.
     
  3. ViktorB

    ViktorB Kilo Poster

    Messages:
    15
    Thanks for you answer, but collect_transaction_refno is correct.
    You can see it in debug log below.

    [2013/11/11 17:44:38] [DEBUG] [24791] [HSPC::MT::plugin::pP::OP_Moneyua::_process_redirect] log_debug _process_redirect_refno = 2013-11-11-68-063898d072d4458

    [2013/11/11 17:45:14] [DEBUG] [24790] [HSPC::MT::pP::pluginEngine::OP::callback_handler] Parameters: $VAR1 = {
    'RETURN_TYPE' => '16',
    'RETURN_COMISSION' => '212',
    'RETURN_AMOUNT' => '1630',
    'RETURN_UNIQ_ID' => '2994199',
    'RETURN_RESULT' => '20',
    'RETURN_MERCHANT' => '281',
    'RETURN_PMEMAIL' => '',
    'RETURN_COMMISSTYPE' => '1',
    'TEST_MODE' => '',
    'RETURN_ADDVALUE' => '2013-11-11-68-063898d072d4458',
    'PAYMENT_DATE' => '1383744500',
    'RETURN_TPHONE' => '',
    'RETURN_CLIENTORDER' => ''
    };

    [2013/11/11 17:45:14] [DEBUG] [24790] [HSPC::MT::plugin::pP::OP_Moneyua::collect_transaction_refno] log_debug collect_transaction_refno = 2013-11-11-68-063898d072d4458
     
  4. FedorK

    FedorK Mega Poster

    Messages:
    224
    collect_transaction_refno calls twice:
    ## URL where redirect customers from Gate to.
    my $result_url = callback_url(action => 'return');

    ## URL where sent notifications from Gate to.
    my $notify_url = callback_url(action => 'notify');

    Make sure that collect_transaction_refno return correct ref_no twice.
     
  5. ViktorB

    ViktorB Kilo Poster

    Messages:
    15
    yes, collect_transaction_refno has called twice:

    [2013/11/12 15:52:04] [DEBUG] [12786] [HSPC::MT::plugin::pP::OP_Moneyua::_process_redirect] log_debug _process_redirect_refno = 2013-11-12-68-3a0c8f4f2d6e4f0
    [2013/11/12 15:53:45] [DEBUG] [12787] [HSPC::MT::pP::pluginEngine::OP::callback_handler] Parameters: $VAR1 = {
    'RETURN_TYPE' => '16',
    'RETURN_COMISSION' => '32',
    'RETURN_AMOUNT' => '1630',
    'RETURN_UNIQ_ID' => '2994199',
    'RETURN_RESULT' => '20',
    'RETURN_MERCHANT' => '281',
    'RETURN_PMEMAIL' => '',
    'RETURN_COMMISSTYPE' => '1',
    'TEST_MODE' => '',
    'RETURN_ADDVALUE' => '2013-11-12-68-3a0c8f4f2d6e4f0',
    'PAYMENT_DATE' => '1383744500',
    'RETURN_TPHONE' => '',
    'RETURN_CLIENTORDER' => ''
    };

    [2013/11/12 15:53:45] [DEBUG] [12787] [HSPC::MT::plugin::pP::OP_Moneyua::collect_transaction_refno] log_debug collect_transaction_refno = 2013-11-12-68-3a0c8f4f2d6e4f0
    [2013/11/12 15:53:51] [DEBUG] [12355] [HSPC::MT::plugin::pP::OP_Moneyua::collect_transaction_refno] log_debug collect_transaction_refno = 2013-11-12-68-3a0c8f4f2d6e4f0
     
  6. FedorK

    FedorK Mega Poster

    Messages:
    224
    Compose by hand correct URL which you expect to recieve from PaymentGate and try to redirect to it using your brawser.
     
  7. ViktorB

    ViktorB Kilo Poster

    Messages:
    15
  8. FedorK

    FedorK Mega Poster

    Messages:
    224
    Last edited: Nov 12, 2013
  9. ViktorB

    ViktorB Kilo Poster

    Messages:
    15
    Thank you!
    It really work!
     
  10. SmithS123

    SmithS123 Bit Poster

    Messages:
    9
    yes..it really works..:)
     

Share This Page