question

tellymasse avatar image
tellymasse asked tellymasse commented

How to print payment receipt?

I want to generate payment receipt available at "https://sandbox.dev.clover.com/p/5RRE8T8WC4CMC" url.

We tried with the code like,

PrintJob printJob = new StaticPaymentPrintJob.Builder().paymentId("5RRE8T8WC4CMC").build();
printJob.print(getBaseContext(),account,printer);

and found the error like below,

onHandleIntent(PrinterIntentService.java:391): print failed, printer: Printer{uuid=K0DVA7JEVKSZ2, type=FIGLEAF_BT, name=Clover Printer 0341, mac=D4:95:24:C8:B4:C6, ip=null, category=RECEIPT}
java.lang.NullPointerException 
at  com.clover.common2.printer.SignatureHelperV3.getPaymentFromOrder(SignatureHelperV3.java:280)
at com.clover.common2.printer.SignatureHelperV3.<init>(SignatureHelperV3.java:67)
at com.clover.engine.services.PrinterIntentService.onHandleIntent(PrinterIntentService.java:302)
at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)

Can anyone please help about this error?

10 |2000

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

Bryanne Vega avatar image
Bryanne Vega answered tellymasse commented

Use this:

new StaticPaymentPrintJob.Builder().payment(payment).paymentId(payment.getId()).build().print(context,account);

Note:

 Payment is a Payment Object from import com.clover.sdk.v3.payments.Payment;

You can get the Payment object from the orders connector OR get the Payment Object from the REST API :

https://api.clover.com:443/v3/merchants/CXGP2EFYNTC36/payments/<payment id>

*Call may differ depending if on production, dev & region

Then, use Payment payment = new Payment(<result from your rest api call here>);

A payment will be a JSONObject, pass the full Object (as string) to the new Payment call. You must create your own httpClient (or use a library) and make a call to the rest full api.

Any further details please visit:

 https://www.clover.com/api_docs#!/payments/GetPayment

The order connector might work well unless you're targeting 2000 clover software.

Hope it helps!

Edit:

  1. Printer is not required unless your merchant has multiple payment receipt printers.
  2. The result from your rest api call will be either null (no content) or a full json object response, verify if it's null before passing it, then calling the new Payment(<result>) requires the full JSON response from the httpClient.
5 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.

tellymasse avatar image tellymasse commented ·

With https://api.clover.com:443/v2/merchants/CXGP2EFYNTC36/payments/<payment id> we can fetched Payment object from it. But when I tried to add this Payment object to printer, it gives error like,

W/ContextImpl: Implicit intents with startService are not safe: Intent { act=com.clover.sdk.printer.intent.action.PRINT_SERVICE (has extras) } android.content.ContextWrapper.startService:494 com.clover.sdk.v1.printer.job.PrintJob.print:99 com.azi.eTMMiCamp.customs.Printerhelper$2.onPostExecute:255

Please note https://api.clover.com:443/v3/... gives Unauthentication error.

0 Likes 0 ·
Bryanne Vega avatar image Bryanne Vega commented ·

Why are you using v2?

Note: I remember having that error but the receipt printed anyways, is this happening to you, or is it not printing at all?

0 Likes 0 ·
tellymasse avatar image tellymasse commented ·

With the https://api.clover.com:443/v3/merchan... and https://apisandbox.dev.clover.com/v3/...

we found error like, Error retrieving merchant info from serverorg.apache.http.HttpException: Received non-OK status from server: HTTP/1.1 404 Not Found

and with https://apisandbox.dev.clover.com/v2/...

we found the payment object, but with that object print receipt won't generated. Any help?

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

"Printer is not required unless your merchant has multiple payment receipt printers"- Printer is never required. If there are multiple configure printers, the merchant will be asked to which to print. The exception is if the connected Clover device is in customer facing mode in which case the first configure printer will be used.

0 Likes 0 ·
tellymasse avatar image tellymasse commented ·

Jeff, we need to print this link "http://sandbox.dev.clover.com/p/ABVQ46CDJ6J46" from our order history screen. And from this screen we need payment object to print the receipt. If you can help, how can I get payment object to print the receipt, that would be great. Thanks.

0 Likes 0 ·
Jeffrey Blattman avatar image
Jeffrey Blattman answered

When printing a payment, you either need to provider the payment OBJECT (not the ID), or an order object AND a payment ID. You are only providing a payment ID. The print is failing because it's trying to look up the payment ID you provided in the order object which you did not provide.

Our print system is based on static objects passed at print time. While it's understandable that you would think that the system will look up the payment object for the provided ID, this leads to problems where the payment changes between calling print() and the data being sent to the printer, resulting in a receipt that does not match the state of the order / payment at the time of printing. So,

PrintJob printJob = new StaticPaymentPrintJob.Builder().order(theOrder).paymentId("5RRE8T8WC4CMC").build();

or,

PrintJob printJob = new StaticPaymentPrintJob.Builder().payment(thePayment).build();
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