Managing Secupay Debits

A direct debit or direct withdrawal is a financial transaction in which one person withdraws funds from another person's bank account . Formally, the person who directly draws the funds ("the payee") instructs his or her bank to collect (i.e., debit) an amount directly from another's ("the payer's") bank account designated by the payer and pay those funds into a bank account designated by the payee. Before the payer's banker will allow the transaction to take place, the payer must have advised the bank that he or she has authorized the payee to directly draw the funds.

See more


To use payment secupay debits transaction your contract needs to be activated for this.

You can only cancel a payment transaction, no delete it's not possible.

Using the secuconnect API one can:

API uses following data structures:

Supported Actions

Create secupay debits transaction

To create new SecupayTransactionProductModel when client uses debits, SecupayTransactionProductDTO need to be passed to PaymentSecupayDebitsApi :: paymentSecupaydebitsPost.

Example

Create secupay prepay - shipping basket item
// Build request object
$shippingItem = new SecupayBasketItem();
$shippingItem->setItemType('shipping')
->setName('standard delivery')
->setTax('19')
->setTotal('1324');

Here we create basket item of shipping type.

Create secupay prepay - article basket items
$articleItem = new SecupayBasketItem();
$articleItem->setItemType('article')
->setArticleNumber('3211')
->setQuantity('2')
->setName('Testname 1')
->setEan('4123412341243')
->setTax('19')
->setTotal('1324')
->setPrice('1000');
$articleItem2 = new SecupayBasketItem();
$articleItem2->setItemType('article')
->setArticleNumber('48875')
->setQuantity('2')
->setName('Testname 2')
->setEan('4123412341236')
->setTax('19')
->setTotal('1324')
->setPrice('1000');

Here we create two basket items of article type.

Create secupay prepay - create basket
//Please note that Basket is just ordinary array
$basket = [];
$basket[] = $shippingItem;
$basket[] = $articleItem;
$basket[] = $articleItem2;

Next we add items to basket. Please note that Basket is just ordinary array.

Create secupay prepay - create ransaction DTO
$transaction = new SecupayTransactionProductDTO();
$transaction->setAmount("100")
->setCurrency("EUR")
->setOrderId("ZZZZZZ")
->setAccrual(True)
->setCustomer('PCU_XYG3DHBX32MJ8DUFASAXVA4X4M3BA2')
->setBasket($basket);

Finally we create SecupayTransactionProductDTO and fill fields we want.


Creating secupay debits transaction
// Make request
try {
$api = new PaymentSecupayDebitsApi();
$response = $api->paymentSecupaydebitsPost($transaction);
// Success. $response contain SecupayTransactionProductModel
} catch (\Secuconnect\Client\ApiException $e) {
//
print_r($e->getResponseBody());
throw $e;
}

It's very straightforward code example. Most important is

  • making a request to our api using PHP SDK on line 42 we create new object of PaymentSecupayDebitsApi and then sending the request using paymentSecupaydebitsPost method to create new debits transaction

Response format

Success

On success API will return SecupayTransactionProductModel filled in with details of transaction.

Error

If cancelation failed, $e→getResponseBody will contain ProductExceptionPayload with following possible errors:

Error

Possible reasons

ProductFormatException

  • no payload provided

  • amount is missing

  • currency is missing

  • customer id is missing

ProductNotAllowedException

  • access to contract denied

  • contract disallows transactions

  • product id is missing

  • api key disallows payment method

ProductDuplicateException

  • duplicate order_id

Cancel secupay debits transaction

To cancel transaction it's ID is required. It will be returned as id property of SecupayTransactionProductModel after successful post call.

Example

Canceling secupay debits transaction
$transactionId = 'q...5';
 
 
// Make request
try {
$api = new PaymentSecupayDebitsApi();
// $transactionId contains id of previously created transaction
$response = $api->paymentSecupaydebitsCancelById($transactionId);
// Success. $response body contain only confirmation.
} catch (\Secuconnect\Client\ApiException $e) {
// Failure. $e->getResponseBody() contains ProductExceptionPayload
print_r($e->getResponseBody());
throw $e;
}

To cancel a debits transaction only thing we have to do is:

  • to fill transactionId that we want to cancel and then call paymentSecupaydebitsCancelById method of PaymentSecupayDebitsApi (line 8)

Response format

Success

On success API will return only confirmation.

Error

If cancelation failed, $e→getResponseBody will contain ProductExceptionPayload with following possible errors:

Error

Possible reasons

ProductNotAllowedException

  • access to contract denied

  • contract id missing

  • contract disallows payment

ProductNotFoundException

  • transaction not found

  • transaction not accepted

ProductUpdateFailedException

  • transaction status disallows canceling

  • transaction status change failed

Get secupay debits transaction

Details of transaction can be retrieved by it's id.

Example

Getting secupay debits transaction
$transactionId = 'q...5';
 
 
// Make request
try {
$api = new PaymentSecupayDebitsApi();
// $transactionId contains id of existing transaction
$response = $api->paymentSecupaydebitsGetById($transactionId);
// Success. $response contain SecupayTransactionDTO
} catch (\Secuconnect\Client\ApiException $e) {
// Failure. $e->getResponseBody() contains ProductExceptionPayload
print_r($e->getResponseBody());
throw $e;
}

To get a debits transaction only thing we have to do is:

  • to fill transactionId that we want to get and then call paymentSecupaydebitsGetById method of PaymentSecupayDebitsApi (line 8)

Response format

Success

On success API will return SecupayTransactionProductModel filled in with details of transaction.

Error

If cancelation failed, $e→getResponseBody will contain ProductExceptionPayload with following possible errors:

Error

Possible reasons

ProductNotFoundException

  • invalid id

  • unknown transaction

ProductNotAllowedException

  • access to contract denied

  • access to transaction denied

ProductFormatException

  • invalid id