Transaktion anlegen

Nach erfolgreicher Autorisierung und mit gültigem Token ist Ihre Applikation nun in der Lage elektronische Abrufe bzw. die Aktivierung der Produkte durchzuführen.

Der elektronische Abrufe bzw. die Aktivierung der Produkte erfolgt immer in zwei Schritten. Zunächst muss Ihre Applikation eine neue Smart Transaction in unserem System anlegen. Anschließend wird diese gestartet.

Transaktion anlegen

Die anzulegende Transaktion kann folgende Informationen enthalten:

  • die Warenkorbpositionen;

  • den Gesamtwert (sum);

  • eine optionale Händler- und/oder Transaktionsreferenz (merchantRef, transactionRef).

Jede Warenkorbposition wird definiert durch:

  • vorlaufende id je Warenkorb-Item;

  • Artikelbezeichnung desc;

  • Anzahl je Artikel quantity;

  • Einzelpreis des Artikels priceOne;

  • Steuersatz tax;

  • Artikelnummer articleNumber;

  • EAN ean;

  • Seriennummer der gescannten Karte (nur bei POSA Produkten) serialNumber.

Hierbei ist zu beachten, dass im Falle mehrerer gleichartiger Produkte innerhalb eines Warenkorbs mehrere Produkte in den Warenkorb gelegt werden müssen. Für den Abruf bzw. die Aktivierung der Produkte ist es nicht möglich das gleiche Produkt mit quantity 2 anzugeben.

Die Anlage der Transaktion wird wie folgt initiiert:

TransactionService transactions = client.service(Smart.Transactions);
 
// Now you can proceed in two ways:
// - creating an "empty" transaction first and adding products afterwards by updating this transaction step by step
// - adding products to the basket first and creating a new transaction afterwards with the complete basket.
// The second approach may be faster, but you get product errors late and all at once, while the first approach shows
// possible errors immediately after every update.
 
try {
 
// We create an empty product basket and the basket summary, and create a new transaction first.
Transaction stx = new Transaction();
Basket basket = new Basket();
BasketInfo basketInfo = new BasketInfo(0, "EUR");
 
Product prod1 = new Product();
prod1.setId(0);
prod1.setArticleNumber("");
prod1.setEan("4251404503734");
prod1.setDesc("Google Play 15 €");
prod1.setQuantity(new BigDecimal(1));
prod1.setTax(0);
prod1.setPriceOne(1500);
prod1.setSerialNumber("1234");
basket.addProduct(prod1);
 
stx.setBasket(basket);
basketInfo.setSum(1500);
stx.setBasketInfo(basketInfo);
 
stx.setMerchantRef("Kunde234235");
stx.setTransactionRef("Beleg4536676");
 
stx = transactions.create(trans);
} catch (APIError err) {
// The API server responds with an error, maybe your data are wrong or the API was not used correctly.
// Depending on the error text its recoverable by editing the data an trying again.
System.err.println("API Error:");
err.printStackTrace();
} catch (AuthError err) {
// Heavy problem with the token or with token management (refresh), maybe due deactivated account.
// Usually not recoverable. You may close client, clear token and open again (and thus authenticate new).
System.err.println("Auth Error:");
err.printStackTrace();
} catch (NetworkError err) {
// No need to close, try again next time if online ...
System.err.println("You are offline.");
} catch (ClientError err) {
// Something bad happened due a bug or wrong config. Better close client, show error end exit.
System.err.println("Internal error happened.");
err.printStackTrace();
} catch (Exception e) {
// Caused direct by this demo code like NPE
e.printStackTrace();
}
 
System.out.println("STX ID: " + stx.getId());
System.out.println("result: " + stx);
 
// Sample output:
//
// Trans.Id: STX_ZUYTKSY3E2N25VMQYH3G9C8N7DQQAJ
// Trans.result: Transaction{basketInfo=BasketInfo{sum=1500, currency=EUR}, deviceSource=null, targetDevice=null, status='created', created=Mon Jan 21 18:13:25 CET 2019, updated=Mon Jan 21 18:13:25 CET 2019, idents=null, basket=Basket{products=[Product{id='0', parent='null', articleNumber='', ean='4251404503734', desc='Google Play 15 €', quantity=1, priceOne=1500, tax=0, productGroups=[], serialNumber=1234}], texts=[]}, merchantRef='Kunde234235', transactionRef='Beleg4536676', paymentMethod='null', receiptLines=null, receiptNumber='null', error='null'} com.secucard.connect.product.smart.model.Transaction@50378a4

Nach erfolgreicher Transaktionsanlage im secucard Backend wird eine Transaktions_id "id" (STX_3MUK5YG2M2MYAFQHASAXV8CU05E0A2) vom Backend an die Applikation zurückgegeben. Diese hat vorerst den Status Smart.Transactions.Transaction.STATUS_CREATED.

Transaktion ausführen

Nach erfolgreicher Anlage der Smart Transaction kann der Checkout unter Angabe der Transaction ID mit der Startmethode "cash" auf folgende Weise initiiert werden:

TransactionService transactions = client.service(Smart.Transactions);
 
try {
stx = transactions.start(stx.getId(), TransactionService.TYPE_CASH, null);
} catch (APIError err) {
System.err.println("API Error:");
err.printStackTrace();
} catch (AuthError err) {
System.err.println("Auth Error:");
err.printStackTrace();
} catch (NetworkError err) {
System.err.println("You are offline.");
} catch (ClientError err) {
System.err.println("Internal error happened.");
err.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
 
if (stx.getStatus().equals(Transaction.STATUS_OK)) {
System.out.println("Transaction started!");
 
// "Print" receipt
List<ReceiptLine> receiptLines = stx.getReceiptLines();
for (ReceiptLine line : receiptLines) {
System.out.println("Receipt Line: " + line.getLineType() + ", " + line.getValue());
}
} else {
System.out.println("Transaction not started, status " + stx.getStatus());
}

Bei fehlgeschlagenem Processing der Transaktion erfolgt eine negative Antwort vom secucard backend. Indikatoren hierfür sind die Status "failed" und "timeout"

Nach erfolgreichem Processing der Transaktion erfolgt eine Antwort aus dem secucard Backend, welche neben dem Ergebnis im Status "ok" auch Belege für das Kassensystem zurück liefert.

{
"object": "smart.transactions",
"id": "STX_3WBNDJ6H62N25NV0YH3G93RCW2JJAH",
"merchant": {
"object": "general.merchants",
"id": "MRC_EU8ZV3CYW4GX5K2ZQXJEM5X9WF5POJ",
"companyname": "COFFEE HOUSE GmbH"
},
"device_source": {
"object": "smart.devices",
"id": "SDV_WE7BCZZPT2N25NRJ5H3G93YNWTZCA2"
},
"transactions": [],
"created": "2019-01-21T13:49:05+01:00",
"updated": "2019-01-21T13:49:05+01:00",
"status": "ok",
"transactionRef": "Beleg4536676",
"merchantRef": "Kunde234235",
"basket": {
"products": [
{
"id": 0,
"parent": null,
"articleNumber": "",
"ean": "4251404503734",
"desc": "Google Play 15 €",
"quantity": 1,
"priceOne": 1500,
"tax": 0,
"group": null,
"serialNumber": "1234",
"item_type": null,
"reference_id": null
}
],
"texts": [],
"type": "default"
},
"receipt": [
{
"type": "textline",
"value": {
"text": "Google Play 15 € EUR",
"decoration": []
}
},
{
"type": "space"
},
{
"type": "textline",
"value": {
"text": "Datum: 21.01.2019 12:50",
"decoration": []
}
},
{
"type": "space"
},
{
"type": "textline",
"value": {
"text": "*****",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "Google Play",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "15,00 EUR",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "Kartennummer:",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "1234",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "*****",
"decoration": []
}
},
{
"type": "space"
},
{
"type": "textline",
"value": {
"text": "Sie koennen Ihren digitalen Google Play",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "Gutscheincode im Web oder auf einem",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "beliebigen Android-Geraet einloesen.",
"decoration": []
}
},
{
"type": "space"
},
{
"type": "textline",
"value": {
"text": "Ueber die Google Play Store App:",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "1) Oeffnen Sie die Google Play Store App.",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "2) Tippen Sie auf das Menuesymbol >",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "Einloesen.",
"decoration": [
"align-center"
]
}
},
{
"type": "textline",
"value": {
"text": "3) Geben Sie den Code ein.",
"decoration": []
}
},
{
"type": "space"
},
{
"type": "textline",
"value": {
"text": "Auf Computern:",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "1) Rufen Sie",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "play.google.com/einloesen auf",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "2) Geben Sie den Code ein.",
"decoration": []
}
},
{
"type": "space"
},
{
"type": "textline",
"value": {
"text": "Falls Sie Hilfe benoetigen, rufen Sie",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "support.google.com/googleplay/go/cardhelp",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "auf. Dort koennen Sie auch das",
"decoration": []
}
},
{
"type": "textline",
"value": {
"text": "Guthaben der Geschenkkarte abrufen.",
"decoration": []
}
}
],
"basket_info": {
"sum": 1500,
"gratuity": null,
"currency": "EUR"
},
"payment_method": "Barzahlung"
}