Finance-Bank-SuomenVerkkomaksut
view release on metacpan or search on metacpan
lib/Finance/Bank/Paytrail.pm view on Meta::CPAN
# failure).
$self->result_code($server_response_status_code);
if ( $self->is_success() ) {
my $json_content = JSON::XS::decode_json( $self->server_response_json() );
# TODO: What if json is invalid
$self->server_response( JSON::XS::decode_json($page) );
$self->url( $json_content->{url} );
$self->token( $json_content->{token} );
$self->order_number( $json_content->{orderNumber} );
}
return 1;
}
=head2 is_success
Populated when you call submit. Status of the submission.
=cut
has 'is_success' => ( is => 'rw' );
=head2 url
Populated when you call submit. This is the URL the user should go to to make the payment.
=cut
has 'url' => ( is => 'rw' );
=head2 token
(Nice-to-have) Populated when you call submit and the submission is succesful.
=cut
has 'token' => ( is => 'rw' );
=head2 order_number
(Nice-to-have) Populated when you call submit and the submission is succesful.
=cut
has 'order_number' => ( is => 'rw' ); # the reply order number
=head2 server_response_json
(Nice-to-have) Populated when you call submit and the submission is succesful.
=cut
has 'server_response_json' => ( is => 'rw' ); # the json string as it came from the server, unprocessed
=head2 server_response
(Nice-to-have) Populated when you call submit. The entire unprocessed response content.
=cut
has 'server_response' => ( is => 'rw' ); # the response as a perl data structure, decoded from json
=head2 result_code
(Nice-to-have) Populated when you call submit. The HTTP status code of the reply.
=cut
has 'result_code' => ( is => 'rw' );
=head2 error_message
Populated when you call submit and the submission is not succesful. Contains the error message from Paytrail.
=cut
has 'error_message' => ( is => 'rw' );
=head2 verify_return
When the end-user has completed the payment he will return to your specified RETURN_ADDRESS,
CANCEL_ADDRESS or PENDING_ADDRESS. Before you process the returning any further you must
check that the parameters given to this address have the correct checksum.
This method verifies the checksum and returns true or false stating if the checksum matched or did not.
After you know that the checksum matched you can mark the payment as paid (if returned to RETURN_ADDRESS),
as pending (if returned to PENDING_ADDRESS) or canceled (if returned to CANCEL_ADDRESS).
Also your NOTIFY_ADDRESS should call verify_return first to verify the checksum and only if the verification
is passed proceed with the information received.
=cut
sub verify_return {
my $self = shift;
my $args = shift;
my $type = $args->{type} || 'success';
my $order_number = $args->{ORDER_NUMBER};
my $timestamp = $args->{TIMESTAMP};
my $paid = $args->{PAID};
my $method = $args->{METHOD};
my $their_return_authcode = $args->{RETURN_AUTHCODE};
# use test_merchant_secret if in test mode, otherwise use the real merchant_secret.
my $secret = $self->test_transaction() ? $self->test_merchant_secret() : $self->merchant_secret();
warn 'Paytrail verify_return got ' . Dumper($args) if ( $self->debug() );
my $our_return_authcode;
if ( $type eq 'failure' ) {
warn 'Paytrail: type eq failure.' if ( $self->debug() );
$our_return_authcode = uc( md5_hex( join( '|', $order_number, $timestamp, $secret ) ) );
}
else {
warn 'Paytrail: type defaulting to success.' if ( $self->debug() );
# default: type eq 'success'
$our_return_authcode = uc( md5_hex( join( '|', $order_number, $timestamp, $paid, $method, $secret ) ) );
}
warn 'Paytrail: our return authcode: ' . $our_return_authcode if ( $self->debug() );
warn 'Paytrail: their return authcode: ' . $their_return_authcode if ( $self->debug() );
( run in 0.645 second using v1.01-cache-2.11-cpan-364913b4093 )