Card Data Storage

You can perform such sales using information provided by customers when they

Card Data Storage based on a previous sale

After performing the first sale, you can easily perform next ones using information from the first transaction. This means you don’t have to collect customer or card data every time, which is very convenient both for you and your customers.

Just get the ID of the previous transaction. If you performed the previous sale just before the resale, you can get the previous sale’s ID from the status information returned by cardSale method.

1
2
$status = $client->cardSale($card_params);
$id_first_sale = $status['id_sale'];
1
2
status = client.card_sale(card_params)
id_first_sale = status['id_sale']
1
2
status = client.card_sale(card_params)
id_first_sale = status['id_sale']
1
2
3
4
5
6
api.cardSale(sale, customer, card, new Callback<CardSaleResult>() {
    @Override
    public void onFinish(CardSaleResult result) {
        long idFirstSale = result.getIdSale();
    }
});

However, in typical cases you should save the ID number to be able to use it in the future to perform resales whenever a customer triggers them. It’s quite similar to a single card sale, just use the resaleBySale method.
We recommend to refer always to the most recent transaction performed by a specific customer – this allows to track the transaction flow easily.

Now prepare the required data and perform a resale. Notice that all you need is the previous sale’s ID number and information describing this particular transaction.

Checking the resale status, getting its ID number or error details looks exactly the same as in the case of a single sale.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$resale_params = array(
    'id_sale'     => $id_first_sale,
    'amount'      => 99.99,
    'currency'    => 'EUR',
    'description' => 'Recurring billing product #1',
);  

// perform the resale:
try {
    $status = $client->resaleBySale($resale_params);
} catch (Exception $e) {
    // handle exceptions here
}

// checking transaction status example (optional):
if ($client->isSuccess()) {
    echo "Success, second 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
15
16
17
18
19
20
21
22
23
resale_params = {
    'id_sale'     => id_first_sale,
    'amount'      => 99.99,
    'currency'    => 'EUR',
    'description' => 'Recurring billing product #1'
}

# perform the resale:
begin
    status = client.resale_by_sale(resale_params)
rescue PayLane::ClientError => e
    # handle exceptions here
end

# checking transaction status example (optional):
if client.success?
    puts "Success, id_second_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
12
13
14
15
16
17
18
19
20
resale_params = {
  'id_sale'     : id_first_sale,
  'amount'      : 99.99,
  'currency'    : 'EUR',
  'description' : 'Recurring billing product #1'
}

# perform the resale:
try:
    status = client.resale_by_sale(resale_params)
except Exception, e:
    # handle exceptions here

# checking transaction status example (optional):
if client.is_success():
    print 'Success, second 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
20
21
22
23
24
25
api.resaleSale(
    idFirstSale,
    99.99,
    "EUR",
    "Recurring billing product #1",
    new Callback<FraudSaleResult>() {

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

Card Data Storage based on authorization

You do not have to require a transaction to allow your customers the payments with Card Data Storage. It is quite enough if they provide you the information required to perform such transactions. They can do this, for example, while setting up an account in your store or signing up for your service.

After receiving the needed information, you just need to authorize the card and save the received authorization ID number – you’ll need it to perform future transactions. (Learn more on how to perform an authorization.)

To perform a sale, get the authorization ID. If you performed the authorization just before the resale, you can get the ID from the status information returned by cardAuthorization method.

1
$id_authorization = $status['id_authorization'];
1
id_authorization = status["id_authorization"]
1
id_authorization = status['id_authorization']
1
2
AuthorizationResult result =...;
long idAuthorization = result.getIdAuthorization();

However, in typical cases you should save the ID number (usually in your database) to be able to use it in the future to perform resales whenever a customer triggers them.

Now prepare the required data and perform a resale. It’s quite similar to a single card sale, just use the resaleByAuthorization method. Notice that all you need is the authorization ID number and information describing this particular transaction.

Checking the resale status, getting its ID number or error details looks exactly the same as in case of a single sale.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$resale_params = array(
    'id_authorization' => $id_authorization,
    'amount'           => 99.99,
    'currency'         => 'EUR',
    'description'      => 'Recurring billing product #1',
);  

// perform the resale:
try {
    $status = $client->resaleByAuthorization($resale_params);
} catch (Exception $e) {
    // handle exceptions here
}

// checking transaction status example (optional):
if ($client->isSuccess()) {
    echo "Success, second 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
15
16
17
18
19
20
21
22
23
resale_params = {
    'id_authorization' => id_authorization,
    'amount'           => 99.99,
    'currency'         => 'EUR',
    'description'      => 'Recurring billing product #1'
}

# perform the resale:
begin
    status = client.resale_by_authorization(resale_params)
rescue PayLane::ClientError => e
    # handle exceptions here
end

# checking transaction status example (optional):
if client.success?
    puts "Success, id_second_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
12
13
14
15
16
17
18
19
20
resale_params = {
  'id_authorization' : id_authorization,
  'amount'           : 99.99,
  'currency'         : 'EUR',
  'description'      : 'Recurring billing product #1'
}

# perform the resale:
try:
    status = client.resale_by_authorization(resale_params)
except Exception, e:
    # handle exceptions here

# checking transaction status example (optional):
if client.is_success():
    print 'Success, second 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.resaleAuthorization(idAuthorization, 99.99, "EUR", "Recurring billing product #1", new Callback<FraudSaleResult>() {

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