question

borissedov avatar image
borissedov asked borissedov answered

Duplicate Order Receipt for Credit card only orders on Clover Mini

We found very interesting bug when developed our app.
After the order was created and paid we call Print method in Clover SDK

Here is the code example:

StaticReceiptPrintJob.Builder().order(orderWithCustomer).build().print(this@OrderActivity, account, printer)

So it’s just a simple print receipt method call.And it works correct when we print orders paid by any combinations of Tenders (partial or full payments) except full payment by credit card.
When you fully pay the order by Credit card and call this method it prints TWO order receipts.
We researched this bug many days really thought that it’s our issue or possible result of incorrect multi-threading calls. But now we can tell that the reason is really somewhere in clover SDK. I saw it myself when staid on this line in Debugger: Nothing was printed before this line but right after the line I received duplicate receipt.

We met this bug in both Sandbox and Production environments.

Example Sandbox orders which print OK:
NM7JSY8PWYDPE
WY5GASRMREXF8
3HCMBGKNRJTTC
Example Sandbox orders which print TWICE:
ETBHYX6CXG9DP
1EQ0AFTA716HA
9QMHBWZZBYD3T
I really hope that you’ll help us to resolve that issue because it looks completely strange that really basic API call works not stable.
Clover Android SDKClover Mini
4 comments
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

Please provide an MCVE that causes the problem. Ideally hardcode the problematic order JSON into the MCVE so it isn't reliant on any particular environment.

0 Likes 0 ·
Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ borissedov commented ·

I ran the sample and it printed 1 receipt only. This was on a Clover Mini using its built-in printer. Am I missing something?

EDIT: I see the difference, see answer TBD.

0 Likes 0 ·
borissedov avatar image borissedov Jeffrey Blattman ♦♦ commented ·

Did you see the YouTube video? It shows how it works on our side.

We used Clover Test card and checked Credit Card option.

Duplicate receipt appears only for Credit but not for Debit Cards.

0 Likes 0 ·
Jeffrey Blattman avatar image
Jeffrey Blattman answered Jeffrey Blattman edited
Thanks for the code. I can reproduce it now. The merchant is setup for on-paper signatures.

Looking at our code, what it's trying to do is print the customer and merchant copies of the receipt, but obviously the secure payments app already printed the merchant copy to have the customer sign.

To avoid this, you can set either the flag FLAG_CUSTOMER or FLAG_MERCHANT on the print job. The default behavior if neither of this flags exist is to print both. Seems like you want it to be the customer receipt.

To be honest, seems like questionable behavior on printers that do not have a cutter. If both per printed the merchant would have to tear them apart.

diff --git a/app/src/main/java/testclover/app/example/com/testclover/MainActivity.kt b/app/src/main/java/testclover/app/example/com/testclover/MainActivity.kt
index dbd8b0e..3c97e2e 100644
--- a/app/src/main/java/testclover/app/example/com/testclover/MainActivity.kt
+++ b/app/src/main/java/testclover/app/example/com/testclover/MainActivity.kt
@@ -9,6 +9,7 @@ import android.os.Bundle
 import android.util.Log
 import com.clover.sdk.util.CloverAccount
 import com.clover.sdk.v1.Intents
+import com.clover.sdk.v1.printer.job.PrintJob
 import com.clover.sdk.v1.printer.job.StaticReceiptPrintJob
 import com.clover.sdk.v3.order.LineItem
 import com.clover.sdk.v3.order.Order
@@ -56,7 +57,7 @@ class MainActivity : AppCompatActivity() {
                 val payment = data!!.getParcelableExtra<Payment>(Intents.EXTRA_PAYMENT)
 
                 getOrderClover(payment.order.id) {
-                    StaticReceiptPrintJob.Builder().order(it).build().print(this, account)
+                    StaticReceiptPrintJob.Builder().order(it).flag(PrintJob.FLAG_CUSTOMER).build().print(this, account)
                 }
             }
         }

We will update the docs to make this clear.
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

borissedov avatar image
borissedov answered Jeffrey Blattman commented
Hi Jeffrey
Sure!

private var account: Account? = null

// Method declaration

account = CloverAccount.getAccount(this)        
ReceiptPrintJob.Builder().orderId("F416TQG82BY0A").build().print(this@OrderActivity, account)

Here is the Receipt photo:



And the Order JSON:

{
  "total": 5008,
  "clientCreatedTime": 1534940207000,
  "createdTime": 1534940208000,
  "modifiedTime": 1534940228000,
  "state": "locked",
  "manualTransaction": false,
  "currency": "USD",
  "id": "F416TQG82BY0A",
  "testMode": false,
  "payments": {
    "elements": [
      {
        "result": "SUCCESS",
        "clientCreatedTime": 1534940216000,
        "createdTime": 1534940217000,
        "modifiedTime": 1534940219000,
        "offline": false,
        "cardTransaction": {
          "cardholderName": "",
          "authCode": "OK2796",
          "entryType": "SWIPED",
          "paymentRef": {
            "id": "GNK4GS8Z7NVHE"
          },
          "extra": {
            "card": "{\"DiscNRID\":\"153494021726779\",\"DiscTransQualifier\":\"02\",\"DiscProcCode\":\"000000\",\"DiscPOSEntry\":\"0210\",\"DiscRespCode\":\"00\",\"DiscPOSData\":\"0200010010500\"}",
            "func": "CREDIT",
            "authorizingNetworkName": "DISCOVER",
            "common": "{\"LocalDateTime\":\"20180822121657\",\"POSEntryMode\":\"901\",\"POSID\":\"2170\",\"MerchID\":\"RCTST0000008099\",\"TermEntryCapablt\":\"06\",\"CardCaptCap\":\"1\",\"STAN\":\"000480\",\"POSCondCode\":\"00\",\"TermLocInd\":\"0\",\"TermID\":\"00000001\",\"TrnmsnDateTime\":\"20180822121657\"}",
            "athNtwkId": "04",
            "cvmResult": "SIGNATURE"
          },
          "state": "PENDING",
          "first6": "601136",
          "referenceId": "823400000480",
          "last4": "6668",
          "type": "PREAUTH",
          "cardType": "DISCOVER"
        },
        "id": "GNK4GS8Z7NVHE",
        "amount": 5008,
        "taxAmount": 0,
        "order": {
          "id": "F416TQG82BY0A"
        },
        "device": {
          "id": "96395b2a-ce12-2d3e-8c13-e97b6cfc7daa"
        },
        "tender": {
          "id": "6DZYT05KCD5Y4",
          "enabled": true,
          "visible": true,
          "labelKey": "com.clover.tender.credit_card",
          "label": "Credit Card",
          "opensCashDrawer": false,
          "href": "https://sandbox.dev.clover.com/v3/merchants/MASMXQ36XRFMW/tenders/6DZYT05KCD5Y4",
          "editable": false
        },
        "refunds": {
          "elements": []
        },
        "employee": {
          "id": "CH1DHVST4SWJT"
        },
        "cashbackAmount": 0
      }
    ]
  },
  "device": {
    "id": "96395b2a-ce12-2d3e-8c13-e97b6cfc7daa"
  },
  "groupLineItems": true,
  "employee": {
    "id": "CH1DHVST4SWJT",
    "role": "ADMIN",
    "customId": "",
    "orders": {
      "href": "https://sandbox.dev.clover.com/v3/merchants/MASMXQ36XRFMW/employees/CH1DHVST4SWJT/orders"
    },
    "href": "https://sandbox.dev.clover.com/v3/merchants/MASMXQ36XRFMW/employees/CH1DHVST4SWJT",
    "name": "Alexander Grishin"
  },
  "href": "https://sandbox.dev.clover.com/v3/merchants/MASMXQ36XRFMW/orders/F416TQG82BY0A",
  "lineItems": {
    "elements": [
      {
        "id": "BC63KEHVFGE32",
        "orderClientCreatedTime": 1534940207000,
        "exchanged": false,
        "price": 4600,
        "refunded": false,
        "createdTime": 1534940208000,
        "isRevenue": true,
        "name": "Acne Repair Kit - 3 pcs.",
        "taxRates": {
          "elements": [
            {
              "id": "1GRB71SVAT3YA",
              "lineItemRef": {
                "id": "BC63KEHVFGE32"
              },
              "rate": 887500,
              "isDefault": false,
              "name": "Product"
            }
          ]
        },
        "orderRef": {
          "id": "F416TQG82BY0A"
        },
        "printed": true,
        "alternateName": "",
        "itemCode": "9154850"
      }
    ]
  },
  "note": "\nConsultant: Alex Grishin\nERP Order Number: 3674624\nERP Invoice Number: 10074104\n",
  "isVat": false,
  "taxRemoved": false
}


img-0952.jpg (216.7 KiB)
1 comment
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeffrey Blattman avatar image Jeffrey Blattman ♦♦ commented ·

ReceiptPrintJob is deprecated. Please use StaticReceiptPrintJob. re: MCVE. I'm looking for an app that I can compile install that has a button "print" and when I click it sends 1 print job but prints 2 receipts. You can dump the source on github or wherever you want.

0 Likes 0 ·
borissedov avatar image
borissedov answered
Hi, Jeffrey Blattman
Thank you!

StaticReceiptPrintJob.Builder().order(orderWithCustomer).flag(PrintJob.FLAG_CUSTOMER).build().print(this@OrderActivity, account)

This works perfect for us.
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community