error handling for accountApi.processPayment

58 views
Skip to first unread message

Roger Parkinson

unread,
Jun 20, 2022, 2:23:25 AM6/20/22
to Kill Bill users mailing-list
Hi there,

I'm developing a payment plugin and I'm implementing this method
public PaymentTransactionInfoPlugin purchasePayment(UUID kbAccountId, UUID kbPaymentId, UUID kbTransactionId,
            UUID kbPaymentMethodId, BigDecimal amount, Currency currency, Iterable<PluginProperty> properties,
            CallContext context) throws PaymentPluginApiException

My plugin gets an error when calling the payment gateway so I send back the PaymentTransactionInfoPlugin object like this:

            return new PaymentTransactionInfoPluginImpl(
                    kbPaymentId, kbTransactionId,
                    TransactionType.PURCHASE, scaledAmount, currency,
                    PaymentPluginStatus.ERROR,
                    e.getErrorMessage(),String.valueOf(e.getStatusCode()),
                    null, null,
                    new DateTime(), null,
                    ImmutableList.copyOf(properties));

however the caller doesn't handle that at all.Here's my caller code:

                final Payment payment = accountApi.processPayment(invoice.getAccountId(),
                        paymentTransaction,
                        paymentMethod.getPaymentMethodId(),
                        NULL_PLUGIN_NAMES,
                        properties,
                        requestOptions);

And here's a snip of the stack trace:
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: (ByteArrayInputStream); line: 1, column: 2]
   at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1804)
   at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:693)
   at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:591)
   at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._handleUnexpectedValue(UTF8StreamJsonParser.java:2630)
   at com.fasterxml.jackson.core.json.UTF8StreamJsonParser._nextTokenNotInObject(UTF8StreamJsonParser.java:832)
   at com.fasterxml.jackson.core.json.UTF8StreamJsonParser.nextToken(UTF8StreamJsonParser.java:729)
   at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:4141)
   at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4000)
   at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3070)
   at org.killbill.billing.client.KillBillHttpClient.unmarshalResponse(KillBillHttpClient.java:480)

You can see the problem happens down in the Killbill client. It is failing to unpack the returned message. Can you suggest how I can do this better?I really want to catch an error when my application calls the KillBill API, but I was hoping an error detected in my plugin would propagate up so I could handle it properly.
Thanks

Reshma Bidikar

unread,
Jun 20, 2022, 8:53:54 AM6/20/22
to Kill Bill users mailing-list
Hello Roger,

At first glance, your code looks correct. Does the issue only occur when you return PaymentPluginStatus.ERROR? Also, could you send us the raw output (from a curl command instead of the client) so we can take a look at the JSON output?

Regards,
Reshma

Roger Parkinson

unread,
Jun 23, 2022, 6:58:01 PM6/23/22
to Kill Bill users mailing-list
I can't reproduce this w curl because the sequence requires a redirect to an HPP and a redirect back. I do have a stack trace though. The error at the gateway end is different to the one above but the result for the caller is the same. This error (which I have solved at the plugin end) causes a stack overflow.This is the top of the stack trace from the log (which is too big to embed, of course)
{"@timestamp":"2022-06-23T22:41:38.278Z","message":"Servlet.service() for servlet [default] in context with path [] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.StackOverflowError] with root cause","logger_name":"org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/].[default]","thread_name":"catalina-exec-1","level":"ERROR","kb.tenantRecordId":"2","kb.userToken":"ddcdc1e0-e749-4932-9f08-1021f9128814","kb.accountRecordId":"2","stack_trace":"java.lang.StackOverflowError: null\n\tat ch.qos.logback.core.UnsynchronizedAppenderBase.doAppend(UnsynchronizedAppenderBase.java:65)\n\tat ch.qos.logback.core.spi.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:51)\n\tat ch.qos.logback.classic.Logger.appendLoopOnAppenders(Logger.java:270)\n\tat ch.qos.logback.classic.Logger.callAppenders(Logger.java:257)\n\tat ch.qos.logback.classic.Logger.buildLoggingEventAndAppend(Logger.java:421)\n\tat ch.qos.logback.classic.Logger.filterAndLog_2(Logger.java:414)\n\tat ch.qos.logback.classic.Logger.warn(Logger.java:700)\n\tat org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperInvocationHandler.errorDuringTransaction(EntitySqlDaoWrapperInvocationHandler.java:171)\n\tat org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperInvocationHandler.errorDuringTransaction(EntitySqlDaoWrapperInvocationHandler.java:182)\n\tat org.killbill.billing.util.entity.dao.EntitySqlDaoWrapperInvocationHandler.invoke(EntitySqlDaoWrapperInvocationHandler.java:148)\n\tat com.sun.proxy.$Proxy264.getByAccountRecordId(Unknown Source)\n\tat org.killbill.billing.payment.dao.DefaultPaymentDao$17.inTransaction(DefaultPaymentDao.java:476)\n\tat org.killbill.billing.payment.dao.DefaultPaymentDao$17.inTransaction(DefaultPaymentDao.java:473)\n\tat org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper$JdbiTransaction.inTransaction(EntitySqlDaoTransactionalJdbiWrapper.java:74)\n\tat org.killbill.billing.util.entity.dao.EntitySqlDaoTransactionalJdbiWrapper$JdbiTransaction.inTransaction(EntitySqlDaoTransactionalJdbiWrapper.java:61)\n\tat org.skife.jdbi.v2.sqlobject.InTransactionHandler$1.inTransaction(InTransactionHandler.java:41)\n\tat org.skife.jdbi.v2.tweak.transactions.LocalTransactionHandler.inTransaction(LocalTransactionHandler.java:188)\n\tat 

R

Roger Parkinson

unread,
Jun 28, 2022, 2:39:42 AM6/28/22
to Kill Bill users mailing-list
I haven't been able to reproduce this one for a few days. Let's put it down to a bug on my side which I fixed by accident. I could wish for more fixes like that.

Reshma Bidikar

unread,
Jun 29, 2022, 3:00:23 AM6/29/22
to Kill Bill users mailing-list
Thanks for letting us know!

Regards,
Reshma

Reply all
Reply to author
Forward
0 new messages