Checking transactions

Manual check

Check the transaction status by calling the getSaleInfo.
You can also check whether the transaction was performed successfully by calling the isSuccess method, retrieve additional information or possible error data.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
try {
    $status = $client->getSaleInfo(array('id_sale' => $id_sale));
}
catch (Exception $e) {
    // handle exceptions here
}

if ($client->isSuccess()) {
    if ('CLEARED' === $status['status']) {
        echo "Success, transaction completed, id_sale: {$id_sale}";
    }
} else {
    die("Error ID: {$status['error']['id_error']}, \n".
        "Error number: {$status['error']['error_number']}, \n".
        "Error description: {$status['error']['error_description']}");
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
begin
    status = client.get_sale_info({"id_sale" => id_sale})
rescue PayLane::ClientError => e
    # handle exceptions here
end

if client.success?
    puts "Success, transaction completed, id_sale: #{id_sale}" if status['status'] == 'CLEARED'
else
    puts "Error ID: #{status["error"]["id_error"]}, \n"\
         "Error number: #{status["error"]["error_number"]}, \n"\
         "Error description: #{status["error"]["error_description"]}"
    exit
end
1
2
3
4
5
6
7
8
9
10
11
12
try:
    status = client.get_sale_info({'id_sale': id_sale})
except Exception, e:
    # handle exceptions here

if client.is_success():
    if status['status'] == 'CLEARED':
        print 'Success, transaction completed, id_sale: %s' % id_sale
else:
    sys.exit('Error ID: ' + str(status["error"]["id_error"]) + '\n' \
             'Error number: ' + str(status["error"]["error_number"]) + '\n' \
             'Error description: ' + str(status["error"]["error_description"]))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
api.saleInfo(idSale, new Callback<SaleInfoResult>() {

    @Override
    public void onFinish(SaleInfoResult result) {
        // success
    }

    @HandleException
    public void onProtocolError(ProtocolException e) {
        // invoke if not success
        // e.getCode() - error code
        // e.getMessage() - error message
    }

    @Override
    public void onError(Exception e) {
        // connection error etc.
    }
});

Automatic check

Instead of checking the transaction status manually, you can simply use the PayLane notifications mechanism. Our systems will send you the desired information using POST – there’s no need for you to send any requests.

Here’s an example of how you can check the communication and receive a notification:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// check communication
if (empty($_POST['communication_id'])) {
    die('Empty communication id');
}

// check if token correct
if ('YOUR_TOKEN' !== $_POST['token']) {
    die('Wrong token');
}

foreach ($_POST['content'] as $notification) {
    if ($notification['type'] === 'S') { // sale created
        // transaction completed, do something useful with id_sale
        $id_sale = $notification['id_sale'];
    }
}

// return communication_id
die($_POST['communication_id']);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# check communication
if params['communication_id'].blank?
    puts "Empty communication id"
    exit
end

# check if token is correct
unless 'YOUR_TOKEN' == params['token']
    puts "Wrong token"
    exit
end

@content = params['content']
# You can do something useful in Rails view later on

@content.each do |notification|
    @id_sale = notification['id_sale'] if notification['type'] == 'S'
end

# render :text => params['communication_id']
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# check communication
communication_id = get_request_param('communication_id')
if not communication_id:
    sys.exit('Empty communication id')

# check if token correct
token = get_request_param('token')
if token != 'YOUR_TOKEN':
    sys.exit('Wrong token')

#content = get_request_param('content')
content = [{'type': 'S', 'id_sale': 123456789}]
for notification in content:
    if notification['type'] == 'S':  # sale created
        # transaction completed, do something useful with id_sale
        id_sale = notification['id_sale']

# print communication_id
1
// Does not apply...
Python note:
The get_request_param function is supposed to collect data from GET params. Depending on your framework or any other toolkit, please use a proper function or write one that suits you best.

For Django, you can use:
1
param_from_get = request.GET.get('param_name')
For Pylons, you can use:
1
2
from pylons import request
param_from_get = request.GET.get('param_name')