question

tenforegolf avatar image
tenforegolf asked bryanvargas commented

onDeviceConnected is the only event triggering in IPaymentConnectorListener

I'm running my Android POS app on a Clover Flex WiFi gen 2. When I hit "run card" button in my app, I run this code:

initializePaymentConnector()

val saleRequest = SaleRequest()
saleRequest.externalId = ExternalIdUtils.generateNewID()
saleRequest.amount = amount
paymentConnector!!.sale(saleRequest)
private fun initializePaymentConnector() {
                 
    val cloverAccount: android.accounts.Account? = getAccount(requireContext())
    val remoteApplicationId = "..."

    if (paymentConnector == null) {
                 2
        paymentConnector = PaymentConnector(requireContext(), cloverAccount, paymentConnectorListener, remoteApplicationId)
        paymentConnector!!.initializeConnection()
    }
}
val paymentConnectorListener: IPaymentConnectorListener =
    object : IPaymentConnectorListener {
        override fun onDeviceDisconnected() {
            Toast.makeText(requireContext(), "onDeviceDisconnected", Toast.LENGTH_LONG).show()
        }

        override fun onDeviceConnected() {
            activityProShopPayment8!!.runOnUiThread(Runnable {
                Timber.d(tag, "onDeviceConnected")
                Toast.makeText(requireContext(), "onDeviceConnected", Toast.LENGTH_LONG).show()
            })
        }

        override fun onPreAuthResponse(response: PreAuthResponse?) {
            Toast.makeText(requireContext(), "onPreAuthResponse", Toast.LENGTH_LONG).show()
        }

        override fun onAuthResponse(response: AuthResponse?) {
            activityProShopPayment8!!.runOnUiThread(Runnable {
                Timber.d(tag, "onAuthResponse")
                Toast.makeText(requireContext(), "onAuthResponse", Toast.LENGTH_LONG).show()
            })
        }

        override fun onTipAdjustAuthResponse(response: TipAdjustAuthResponse?) {
            Toast.makeText(requireContext(), "onTipAdjustAuthResponse", Toast.LENGTH_LONG).show()
        }

        override fun onCapturePreAuthResponse(response: CapturePreAuthResponse?) {
            Toast.makeText(requireContext(), "onCapturePreAuthResponse", Toast.LENGTH_LONG).show()
        }

        override fun onVerifySignatureRequest(request: VerifySignatureRequest?) {
            Toast.makeText(requireContext(), "onVerifySignatureRequest", Toast.LENGTH_LONG).show()
        }

        override fun onConfirmPaymentRequest(request: ConfirmPaymentRequest?) {
            if (request!!.payment == null || request.challenges == null) {
                showError("Error: The ConfirmPaymentRequest was missing the payment and/or challenges.")
            } else {
                currentPayment = request.payment
            }
        }

        override fun onSaleResponse(saleResponse: SaleResponse) {
            activityProShopPayment8!!.runOnUiThread(Runnable {
                Timber.d(tag, "onSaleResponse")
                processSaleResponse(saleResponse)
            })
        }

        override fun onManualRefundResponse(response: ManualRefundResponse?) {
            Toast.makeText(requireContext(), "onManualRefundResponse", Toast.LENGTH_LONG).show()
        }

        override fun onRefundPaymentResponse(response: RefundPaymentResponse?) {
            Toast.makeText(requireContext(), "onRefundPaymentResponse", Toast.LENGTH_LONG).show()
        }

        override fun onTipAdded(tipAdded: TipAdded?) {
            Toast.makeText(requireContext(), "onTipAdded", Toast.LENGTH_LONG).show()
        }

        override fun onVoidPaymentResponse(response: VoidPaymentResponse?) {
            Toast.makeText(requireContext(), "onVoidPaymentResponse", Toast.LENGTH_LONG).show()
        }

        override fun onVaultCardResponse(response: VaultCardResponse?) {
            Toast.makeText(requireContext(), "onVaultCardResponse", Toast.LENGTH_LONG).show()
        }

        override fun onRetrievePendingPaymentsResponse(retrievePendingPaymentResponse: RetrievePendingPaymentsResponse?) {
            Toast.makeText(requireContext(), "onRetrievePendingPaymentsResponse", Toast.LENGTH_LONG).show()
        }

        override fun onReadCardDataResponse(response: ReadCardDataResponse?) {
            Toast.makeText(requireContext(), "onReadCardDataResponse", Toast.LENGTH_LONG).show()
        }

        override fun onCloseoutResponse(response: CloseoutResponse?) {
            Toast.makeText(requireContext(), "onCloseoutResponse", Toast.LENGTH_LONG).show()
        }

        override fun onRetrievePaymentResponse(response: RetrievePaymentResponse?) {
            Toast.makeText(requireContext(), "onRetrievePaymentResponse", Toast.LENGTH_LONG).show()
        }

        override fun onVoidPaymentRefundResponse(response: VoidPaymentRefundResponse?) {
            Toast.makeText(requireContext(), "onVoidPaymentRefundResponse", Toast.LENGTH_LONG).show()
        }
    }


I set breakpoints on all of the override functions and the only one that fires is onDeviceConnected. The Clover sales flow does work, and the card is charged, but after clicking no receipt, the app just closes. onSaleResponse never fires.

I'm new to this, so forgive me if I'm missing something obvious...

PaymentConnector
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.

bryanvargas avatar image bryanvargas ♦♦ commented ·

I am not seeing you pass a Toast.make on the sales response.

Alternatively, you can add a simple logic to see if you get any response back:

fun onSaleResponse(response: SaleResponse) {
       val result: String = response.getSuccess() ? "Sale was successful" : "Sale was unsuccessful" + response.getReason() + ":" + response.getMessage()
       Toast.makeText(this, result, Toast.LENGTH_LONG).show()
   }



We also have an example of the PaymentConnector here: https://docs.clover.com/docs/take-a-payment-with-payment-connector#creating-the-listener

0 Likes 0 ·

0 Answers

·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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