killbill / killbill-plugin-framework-ruby

Framework to write Kill Bill plugins in Ruby
http://killbill.io
8 stars 11 forks source link

can not setDefault payment method #13

Closed kares closed 9 years ago

kares commented 9 years ago

have not tried latest 3.2 ... it's something I've run into on 3.1.12 while using the endpoint :

PUT /1.0/kb/accounts/{accountId:\w+-\w+-\w+-\w+-\w+}/paymentMethods/{paymentMethodId:\w+-\w+-\w+-\w+-\w+}/setDefault

request :

52 > PUT http://54.148.66.206:8080/1.0/kb/accounts/3980da6a-2b57-48d3-bf87-d12f1a99ae04/paymentMethods/57c4aac4-d05f-44bf-9324-4c877d83b1a6/setDefault
52 > connection: keep-alive
52 > content-type: application/json
52 > x-killbill-apikey: bob
52 > x-killbill-apisecret: lazar
52 > x-killbill-createdby: demo
52 > content-length: 0
52 > user-agent: Apache-HttpClient/4.2.6 (java 1.5)
52 > authorization: Basic YWRtaW46cGFzc3dvcmQ=

payment method was previously created (using killbill-stripe-plugin 0.2.1) :

2014-12-09 13:14:12,358 [Thread-5] WARN  o.k.b.k.0.1.1 - [stripe-plugin] Failure in set_default_payment_method: undefined local variable or method `gateway' for #<Killbill::Stripe::PaymentPlugin:0x61c78ecd>
/var/tmp/bundles/plugins/ruby/killbill-stripe/0.2.1/gems/gems/killbill-stripe-0.2.1/lib/stripe/api.rb:129:in `set_default_payment_method'
/var/tmp/bundles/plugins/ruby/killbill-stripe/0.2.1/gems/gems/killbill-3.1.12/lib/killbill/gen/plugin-api/payment_plugin_api.rb:547:in `setDefaultPaymentMethod'
Killbill$$Plugin$$Api$$PaymentPluginApi_1991982677.gen:13:in `setDefaultPaymentMethod'
2014-12-09 13:14:12,382 [http-bio-8080-exec-16] WARN  o.k.b.j.mappers.ExceptionMapperBase - Internal error
org.killbill.billing.payment.api.PaymentApiException: Internal payment error : Failed to update payment method for account 8a6440f4-a211-4958-a92e-a0c227d565ac : undefined local variable or method `gateway' for #<Killbill::Stripe::PaymentPlugin:0x61c78ecd>
    at org.killbill.billing.payment.core.PaymentMethodProcessor.setDefaultPaymentMethod(PaymentMethodProcessor.java:404) ~[killbill-payment-0.12.1.jar:na]
    at org.killbill.billing.payment.api.DefaultPaymentApi.setDefaultPaymentMethod(DefaultPaymentApi.java:368) ~[killbill-payment-0.12.1.jar:na]
    at org.killbill.billing.util.glue.KillbillApiAopModule$ProfilingMethodInterceptor$1.execute(KillbillApiAopModule.java:52) ~[killbill-util-0.12.1.jar:na]
    at org.killbill.commons.profiling.Profiling.executeWithProfiling(Profiling.java:33) ~[killbill-concurrent-0.2.28.jar:na]
    at org.killbill.billing.util.glue.KillbillApiAopModule$ProfilingMethodInterceptor.invoke(KillbillApiAopModule.java:49) ~[killbill-util-0.12.1.jar:na]
    at org.killbill.billing.jaxrs.resources.AccountResource.setDefaultPaymentMethod(AccountResource.java:663) ~[killbill-jaxrs-0.12.1.jar:na]
    at com.palominolabs.metrics.guice.TimedInterceptor.invoke(TimedInterceptor.java:47) ~[metrics-guice-3.0.2.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_65]
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_65]
    at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) ~[jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205) ~[jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) ~[jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) ~[jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) ~[jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) ~[jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542) [jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473) [jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419) [jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409) [jersey-server-1.18.1.jar:1.18.1]
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409) [jersey-servlet-1.18.1.jar:1.18.1]
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:540) [jersey-servlet-1.18.1.jar:1.18.1]
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:715) [jersey-servlet-1.18.1.jar:1.18.1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) [servlet-api-3.0.jar:na]
    at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263) [guice-servlet-3.0.jar:na]
    at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178) [guice-servlet-3.0.jar:na]
    at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91) [guice-servlet-3.0.jar:na]
    at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62) [guice-servlet-3.0.jar:na]
    at org.killbill.billing.server.security.TenantFilter.doFilter(TenantFilter.java:112) [TenantFilter.class:na]
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163) [guice-servlet-3.0.jar:na]
    at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58) [guice-servlet-3.0.jar:na]
    at org.killbill.billing.server.filters.ResponseCorsFilter.doFilter(ResponseCorsFilter.java:66) [ResponseCorsFilter.class:na]
    at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163) [guice-servlet-3.0.jar:na]
    at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58) [guice-servlet-3.0.jar:na]
    at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118) [guice-servlet-3.0.jar:na]
    at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113) [guice-servlet-3.0.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:44) [shiro-guice-1.2.3.jar:1.2.3]
    at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108) [shiro-web-1.2.3.jar:1.2.3]
    at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137) [shiro-web-1.2.3.jar:1.2.3]
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) [shiro-web-1.2.3.jar:1.2.3]
    at org.apache.shiro.guice.web.SimpleFilterChain.doFilter(SimpleFilterChain.java:41) [shiro-guice-1.2.3.jar:1.2.3]
    at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) [shiro-web-1.2.3.jar:1.2.3]
    at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) [shiro-web-1.2.3.jar:1.2.3]
    at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) [shiro-core-1.2.3.jar:1.2.3]
    at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) [shiro-core-1.2.3.jar:1.2.3]
    at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383) [shiro-core-1.2.3.jar:1.2.3]
    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) [shiro-web-1.2.3.jar:1.2.3]
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) [shiro-web-1.2.3.jar:1.2.3]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) [tomcat-catalina-7.0.52.jar:7.0.52]
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) [tomcat-coyote-7.0.52.jar:7.0.52]
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) [tomcat-coyote-7.0.52.jar:7.0.52]
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) [tomcat-coyote-7.0.52.jar:7.0.52]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_65]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_65]
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_65]
Caused by: org.killbill.billing.payment.api.PaymentApiException: Failed to update payment method for account 8a6440f4-a211-4958-a92e-a0c227d565ac : undefined local variable or method `gateway' for #<Killbill::Stripe::PaymentPlugin:0x61c78ecd>
    at org.killbill.billing.payment.core.PaymentMethodProcessor$11.doOperation(PaymentMethodProcessor.java:397) ~[killbill-payment-0.12.1.jar:na]
    at org.killbill.billing.payment.core.PaymentMethodProcessor$11.doOperation(PaymentMethodProcessor.java:381) ~[killbill-payment-0.12.1.jar:na]
    at org.killbill.billing.payment.core.ProcessorBase$WithAccountLock.processAccountWithLock(ProcessorBase.java:219) ~[killbill-payment-0.12.1.jar:na]
    at org.killbill.billing.payment.core.PaymentMethodProcessor.setDefaultPaymentMethod(PaymentMethodProcessor.java:381) ~[killbill-payment-0.12.1.jar:na]
    ... 68 common frames omitted

not sure if this should have been reported against the stripe repo - feels like an API issue from a quick look

pierre commented 9 years ago

It looks like a bug in the Stripe plugin actually.

https://github.com/killbill/killbill-stripe-plugin/blob/master/lib/stripe/api.rb#L129: gateway should now be lookup_gateway(options[:payment_processor_account_id]). I must have overlooked it when I upgraded it to the latest version. Could you try and verify it does the trick?

kares commented 9 years ago

have some issues locally with the plugin ... seems to start yet it's not registered, anyhow tried on EC2 and :

Caused by: org.killbill.billing.payment.api.PaymentApiException: Failed to update payment method for account d0a80a57-d629-4f6c-b368-9386fce5ab90 : wrong number of arguments calling `options` (0 for 1)
    at org.killbill.billing.payment.core.PaymentMethodProcessor$11.doOperation(PaymentMethodProcessor.java:397) ~[killbill-payment-0.12.1.jar:na]
    at org.killbill.billing.payment.core.PaymentMethodProcessor$11.doOperation(PaymentMethodProcessor.java:381) ~[killbill-payment-0.12.1.jar:na]
    at org.killbill.billing.payment.core.ProcessorBase$WithAccountLock.processAccountWithLock(ProcessorBase.java:219) ~[killbill-payment-0.12.1.jar:na]
    at org.killbill.billing.payment.core.PaymentMethodProcessor.setDefaultPaymentMethod(PaymentMethodProcessor.java:381) ~[killbill-payment-0.12.1.jar:na]
    ... 68 common frames omitted

... also I do not need this working ASAP - I'll just use isDefault=true

pierre commented 9 years ago

The complete patch would look like:

options = properties_to_hash(properties)
payment_processor_account_id = options[:payment_processor_account_id] || :default
gateway = lookup_gateway(payment_processor_account_id)
kares commented 9 years ago

well almost - seems I run into method (API) changes ... this really needs a spec :)

{"className":"org.killbill.billing.payment.api.PaymentApiException","code":7019,"message":"Internal payment error : Failed to update payment method for account eaa8d5aa-02a1-4a39-89a9-dc136f982b58 : wrong number of arguments calling save_response_and_transaction (4 for 5)","causeClassName":"org.killbill.billing.payment.api.PaymentApiException","causeMessage":"Failed to update payment method for account eaa8d5aa-02a1-4a39-89a9-dc136f982b58 : wrong number of arguments calling save_response_and_transaction (4 for 5)","stackTrace":[]}

https://gist.github.com/kares/957ffe253e01af672247

sorry for the late response, but I still needed to try remotely ... localhost still has issues with the plugin being not registered (although after git pull it seemed promising) - have not looked into it since I do not need it that much yet.

pierre commented 9 years ago

this really needs a spec :)

Indeed...

Let me know if I can help with the registration issue.