update ResultTransaction integrasi dengan printer
This commit is contained in:
		
							parent
							
								
									b2442ada48
								
							
						
					
					
						commit
						ddf76d2540
					
				@ -25,6 +25,11 @@ import java.text.SimpleDateFormat;
 | 
				
			|||||||
import java.util.Date;
 | 
					import java.util.Date;
 | 
				
			||||||
import java.util.Locale;
 | 
					import java.util.Locale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.sunmi.peripheral.printer.InnerResultCallback;
 | 
				
			||||||
 | 
					import android.os.RemoteException;
 | 
				
			||||||
 | 
					import com.example.bdkipoc.MyApplication;
 | 
				
			||||||
 | 
					import com.sunmi.peripheral.printer.SunmiPrinterService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * ResultTransactionActivity - Enhanced Receipt-style Display using activity_receipt.xml
 | 
					 * ResultTransactionActivity - Enhanced Receipt-style Display using activity_receipt.xml
 | 
				
			||||||
 * Shows EMV/Card transaction results using the same layout as QRIS receipts
 | 
					 * Shows EMV/Card transaction results using the same layout as QRIS receipts
 | 
				
			||||||
@ -78,6 +83,35 @@ public class ResultTransactionActivity extends AppCompatActivity {
 | 
				
			|||||||
    private long serviceFeeAmount = 500; // Default service fee
 | 
					    private long serviceFeeAmount = 500; // Default service fee
 | 
				
			||||||
    private double taxPercentageValue = 0.11; // 11% tax
 | 
					    private double taxPercentageValue = 0.11; // 11% tax
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final InnerResultCallback printCallback = new InnerResultCallback() {
 | 
				
			||||||
 | 
					        @Override
 | 
				
			||||||
 | 
					        public void onRunResult(boolean isSuccess) throws RemoteException {
 | 
				
			||||||
 | 
					            runOnUiThread(() -> {
 | 
				
			||||||
 | 
					                if (isSuccess) {
 | 
				
			||||||
 | 
					                    showToast("Struk berhasil dicetak");
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    showToast("Gagal mencetak struk");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @Override
 | 
				
			||||||
 | 
					        public void onReturnString(String result) throws RemoteException {
 | 
				
			||||||
 | 
					            Log.d(TAG, "Print result: " + result);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @Override
 | 
				
			||||||
 | 
					        public void onRaiseException(int code, String msg) throws RemoteException {
 | 
				
			||||||
 | 
					            runOnUiThread(() -> showToast("Printer error: " + msg));
 | 
				
			||||||
 | 
					            Log.e(TAG, "Printer exception: " + code + " - " + msg);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        @Override
 | 
				
			||||||
 | 
					        public void onPrintResult(int code, String msg) throws RemoteException {
 | 
				
			||||||
 | 
					            Log.d(TAG, "Print result code: " + code + ", msg: " + msg);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    protected void onCreate(Bundle savedInstanceState) {
 | 
					    protected void onCreate(Bundle savedInstanceState) {
 | 
				
			||||||
        super.onCreate(savedInstanceState);
 | 
					        super.onCreate(savedInstanceState);
 | 
				
			||||||
@ -589,8 +623,95 @@ public class ResultTransactionActivity extends AppCompatActivity {
 | 
				
			|||||||
    
 | 
					    
 | 
				
			||||||
    // Action Methods
 | 
					    // Action Methods
 | 
				
			||||||
    private void printReceipt() {
 | 
					    private void printReceipt() {
 | 
				
			||||||
        Log.d(TAG, "Print receipt requested");
 | 
					        try {
 | 
				
			||||||
        showToast("Fitur cetak akan segera tersedia");
 | 
					            // Check if printer service is available
 | 
				
			||||||
 | 
					            if (com.example.bdkipoc.MyApplication.app.sunmiPrinterService == null) {
 | 
				
			||||||
 | 
					                showToast("Printer tidak tersedia");
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            SunmiPrinterService printerService = com.example.bdkipoc.MyApplication.app.sunmiPrinterService;
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            // Get all the data from the views
 | 
				
			||||||
 | 
					            String merchantNameText = merchantName.getText().toString();
 | 
				
			||||||
 | 
					            String merchantLocationText = merchantLocation.getText().toString();
 | 
				
			||||||
 | 
					            String midTextValue = midText.getText().toString();
 | 
				
			||||||
 | 
					            String tidTextValue = tidText.getText().toString();
 | 
				
			||||||
 | 
					            String transactionNumberText = transactionNumber.getText().toString();
 | 
				
			||||||
 | 
					            String transactionDateText = transactionDate.getText().toString();
 | 
				
			||||||
 | 
					            String paymentMethodText = paymentMethod.getText().toString();
 | 
				
			||||||
 | 
					            String cardTypeText = cardType.getText().toString();
 | 
				
			||||||
 | 
					            String transactionTotalText = transactionTotal.getText().toString();
 | 
				
			||||||
 | 
					            String taxPercentageText = taxPercentage.getText().toString();
 | 
				
			||||||
 | 
					            String serviceFeeText = serviceFee.getText().toString();
 | 
				
			||||||
 | 
					            String finalTotalText = finalTotal.getText().toString();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            showToast("Mencetak struk...");
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            try {
 | 
				
			||||||
 | 
					                // Start printing
 | 
				
			||||||
 | 
					                printerService.enterPrinterBuffer(true);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Set alignment to center
 | 
				
			||||||
 | 
					                printerService.setAlignment(1, null);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Print header
 | 
				
			||||||
 | 
					                printerService.printText("# Payvora PRO\n\n", null);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Set alignment to left
 | 
				
			||||||
 | 
					                printerService.setAlignment(0, null);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Print merchant info
 | 
				
			||||||
 | 
					                printerService.printText(merchantNameText + "\n", null);
 | 
				
			||||||
 | 
					                printerService.printText(merchantLocationText + "\n\n", null);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Print MID/TID
 | 
				
			||||||
 | 
					                printerService.printText(midTextValue + " | " + tidTextValue + "\n\n", null);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Print transaction details
 | 
				
			||||||
 | 
					                printerService.printText("Nomor transaksi    " + transactionNumberText + "\n", null);
 | 
				
			||||||
 | 
					                printerService.printText("Tanggal transaksi  " + transactionDateText + "\n", null);
 | 
				
			||||||
 | 
					                printerService.printText("Metode pembayaran    " + paymentMethodText + "\n", null);
 | 
				
			||||||
 | 
					                printerService.printText("Jenis Kartu    " + cardTypeText + "\n\n", null);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Print amounts
 | 
				
			||||||
 | 
					                printerService.printText("Total transaksi    " + transactionTotalText + "\n", null);
 | 
				
			||||||
 | 
					                printerService.printText("Pajak (%)    " + taxPercentageText + "\n", null);
 | 
				
			||||||
 | 
					                printerService.printText("Biaya Layanan    " + serviceFeeText + "\n\n", null);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Print total in bold
 | 
				
			||||||
 | 
					                printerService.printText("**TOTAL** **" + finalTotalText + "**\n", null);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Add EMV specific details if available
 | 
				
			||||||
 | 
					                // if (emvMode && emvCardholderName != null) {
 | 
				
			||||||
 | 
					                //     printerService.printText("\nDETAIL EMV:\n", null);
 | 
				
			||||||
 | 
					                //     printerService.printText("Cardholder: " + emvCardholderName + "\n", null);
 | 
				
			||||||
 | 
					                //     if (cardNo != null) {
 | 
				
			||||||
 | 
					                //         printerService.printText("Card: " + maskCardNumber(cardNo) + "\n", null);
 | 
				
			||||||
 | 
					                //     }
 | 
				
			||||||
 | 
					                //     if (emvAid != null) {
 | 
				
			||||||
 | 
					                //         printerService.printText("AID: " + emvAid + "\n", null);
 | 
				
			||||||
 | 
					                //     }
 | 
				
			||||||
 | 
					                //     if (emvExpiry != null) {
 | 
				
			||||||
 | 
					                //         printerService.printText("Expiry: " + emvExpiry + "\n", null);
 | 
				
			||||||
 | 
					                //     }
 | 
				
			||||||
 | 
					                // }
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Add some line feeds
 | 
				
			||||||
 | 
					                printerService.lineWrap(4, null);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                // Exit buffer mode
 | 
				
			||||||
 | 
					                printerService.exitPrinterBuffer(true);
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					            } catch (RemoteException e) {
 | 
				
			||||||
 | 
					                e.printStackTrace();
 | 
				
			||||||
 | 
					                showToast("Error printer: " + e.getMessage());
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            Log.e(TAG, "Print error", e);
 | 
				
			||||||
 | 
					            showToast("Error saat mencetak: " + e.getMessage());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    private void emailReceipt() {
 | 
					    private void emailReceipt() {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user