Managing Secupay Debits
Tuesday, October 29, 2019 2:51 PMA 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.
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:
- create a new debit transaction;
- read the debit transaction data;
- cancel the debit transaction.
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
// Build request object
$shippingItem = new SecupayBasketItem();
$shippingItem->setItemType('shipping')
->setName('standard delivery')
->setTax('19')
->setTotal('1324');
Here we create basket item of shipping type.
$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.
//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.
$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.
// 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 |
|
ProductNotAllowedException |
|
ProductDuplicateException |
|
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
$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 |
|
ProductNotFoundException |
|
ProductUpdateFailedException |
|
Get secupay debits transaction
Details of transaction can be retrieved by it's id.
Example
$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 |
|
ProductNotAllowedException |
|
ProductFormatException |
|