Single transaction

Prepare all the data required to perform the transaction as follows.
As you can see, in case of direct debits there are three sets of information: sale, customer and account data.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ddebit_params = array(
    'sale' => array(
        'amount'      => 19.99,
        'currency'    => 'EUR',
        'description' => 'Product #1'
    ),
    'customer' => array(
        'name'    => 'Hans Muller',
        'email'   => 'hans@muller.de',
        'ip'      => '127.0.0.1',
        'address' => array (
            'street_house' => 'Platz der Republik 1',
            'city'         => 'Berlin',
            'state'        => 'Berlin',
            'zip'          => '11011',
            'country_code' => 'DE',
        ),
    ),
    'account' => array(
        'account_holder'  => 'Hans Muller',
        'account_country' => 'DE',
        'iban'            => 'DE12345678901234567890',
        'bic'             => 'BICBICDE',
        'mandate_id'      => '54321',
    ),
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
ddebit_params = {
    'sale'=> {
        'amount'      => 19.99,
        'currency'    => 'EUR',
        'description' => 'Product #1'
    },
    'customer' => {
        'name'    => 'Hans Muller',
        'email'   => 'hans@muller.de',
        'ip'      => '127.0.0.1',
        'address' => {
            'street_house' => 'Platz der Republik 1',
            'city'         => 'Berlin',
            'state'        => 'Berlin',
            'zip'          => '11011',
            'country_code' => 'DE'
        }
    },
    'account' => {
        'account_holder'  => 'Hans Muller',
        'account_country' => 'DE',
        'iban'            => 'DE12345678901234567890',
        'bic'             => 'BICBICDE',
        'mandate_id'      => '54321'
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
ddebits_params = {
  'sale' : {
    'amount'      : 19.99,
    'currency'    : 'EUR',
    'description' : 'Product #1'
  }
  'customer' : {
    'name'  : 'Hans Muller',
    'email' : 'hans@muller.de',
    'ip'    : '127.0.0.1',
    'address' : {
      'street_house' : 'Platz der Republik 1',
      'city'         : 'Berlin',
      'state'        : 'Berlin',
      'zip'          : '500',
      'country_code' : 'DE'
    },
  },
  'account' : {
    'account_holder'  : 'Hans Muller',
    'account_country' : 'DE',
    'iban'            : 'DE12345678901234567890',
    'bic'             : 'BICBICDE',
    'mandate_id'      : '54321'
  }
}
1
2
3
4
Sale sale         = new Sale(19.99, "EUR", "Product #1");
Address address   = new Address("1600 Pennsylvania Avenue Northwest", "Washington", "DC", "500", "US");
Customer customer = new Customer("John Doe", "john@doe.com", "127.0.0.1", address);
Account account   = new Account("Hans Muller","de","DE12345678901234567890","BICBICDE","54321");

Now simply perform the transaction using the directDebitSale method.

You can check whether the transaction was performed successfully by calling the isSuccess method.
Retrieving the transaction ID number (or error details, if anything goes wrong) is also very simple and can be done as shown below.

1
2
3
4
5
6
7
8
9
10
11
12
13
try {
    $status = $client->directDebitSale($ddebit_params);
} catch (Exception $e) {
    // handle exceptions here
}

if ($client->isSuccess()) {
    echo "Success, id_sale: {$status['id_sale']} \n";
} 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.direct_debit_sale(ddebit_params)
rescue PayLane::ClientError => e
    # handle exceptions here
end

if client.success?
    puts "Success, id_sale: #{status["id_sale"]}"
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
try:
    status = client.direct_debit_sale(ddebits_params)
except Exception, e:
    # handle exceptions here

if client.is_success():
    print 'Success, id_sale: %s' % status['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.directDebitSale(sale, customer, account, new Callback<SaleResult>() {

    @Override
    public void onFinish(SaleResult 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.
    }
});

You can find all the structures’ descriptions in the REST Function Reference manual.

Note that a direct debit sale is marked as pending when performed. You can check it’s status (and whether it changed to performed, cleared etc.) using the getSaleInfo method:

1
2
3
4
5
6
try {
    $sale_info = $client->getSaleInfo(array('id_sale' => $id_sale));
}
catch (Exception $e) {
    // handle exceptions here
}
1
2
3
4
5
begin
    sale_info = client.get_sale_info({"id_sale" => id_sale})
rescue PayLane::ClientError => e
    # handle exceptions here
end
1
2
3
4
try:
    sale_info = client.get_sale_info({'id_sale': id_sale})
except Exception, e:
    # handle exceptions here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.
    }
});

Reversals

Just like there are chargebacks in card payments, there are reversals in direct debit transactions.

It is highly recommended to check direct debit transactions statuses after performing them in order to determine whether a reversal occurred or not. You can check this manually in the Merchant Panel, but also via API.

If you want to use our API to check a direct debit status, simply use the getSaleInfo:

1
2
3
4
5
6
try {
    $sale_info = $client->getSaleInfo(array('id_sale' => $id_sale));
}
catch (Exception $e) {
    // handle exceptions here
}
1
2
3
4
5
begin
    status = client.get_sale_info({"id_sale" => id_sale})
rescue PayLane::ClientError => e
    # handle exceptions here
end
1
2
3
4
try:
    sale_info = client.get_sale_info({'id_sale': id_sale})
except Exception, e:
    # handle exceptions here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.
    }
});
Now simply check whether the field is_reversal in sale_infois set to true or false.

You can also use PayLane notifications to check the status automatically. This way you won’t need to send any requests – you’ll receive a notification when a transaction status changes.