Can't pass the plugin properties to killbill

189 views
Skip to first unread message

Cheong Shin Liew

unread,
May 28, 2021, 2:35:03 AM5/28/21
to Kill Bill users mailing-list
Hi,
I'm trying to create a payment method from Stripe using Killbill PHP

//Add Payment Method
$pmMethod = new \Killbill\Client\Swagger\Model\PaymentMethod();  
$pmMethod->setPluginName('killbill-stripe');

$xKillbillCreatedBy = "Killbill_php_test"; 
$xKillbillReason = "xKillbillReason_example";
$xKillbillComment = "xKillbillComment_example";
$isDefault = true;  
$payAllUnpaidInvoices = true;  
$controlPluginName = array("killbill-stripe");
$pluginProperty =array("token"=>"tok_1Ivy0FAU3x82b2RspqFeOoqT");

try{
$result2 = $accountApi->createPaymentMethod($pmMethod, $xKillbillCreatedBy, $accountId, $xKillbillReason, $xKillbillComment, $isDefault, $payAllUnpaidInvoices, $controlPluginName, $pluginProperty);
}catch(Exception $e){
echo 'Exception when calling AccountApi->createPaymentMethod: ', $e->getMessage(), PHP_EOL;
}

But it show error as shown below:Exception when calling AccountApi->createPaymentMethod: [400] Client error: `POST http://127.0.0.1:8080/1.0/kb/accounts/c2cbf9bc-72ee-48c8-9ef5-44f8b122bfe3/paymentMethods?isDefault=true&payAllUnpaidInvoices=false&controlPluginName=killbill-stripe&pluginProperty=tok_1Ivy0FAU3x82b2RspqFeOoqT` resulted in a `400 Bad Request` response:

{"className":"org.killbill.billing.payment.api.PaymentApiException","code":7005,"message":"Failed to add payment method  (truncated...)

I'm not sure is it the correct way to pass the plugin properties because it seem like the error come from here.

Thank you,

Cheong Shin


Pierre-Alexandre Meyer

unread,
May 28, 2021, 4:53:17 AM5/28/21
to Cheong Shin Liew, Kill Bill users mailing-list
Hello,

I'm not sure what's going on with the PHP code, but it looks like you are sending in the url:

  ...&pluginProperty=tok_XXX

This should be instead:

  ...&pluginProperty=token=tok_XXX

Take a look at our example here: https://github.com/killbill/killbill-stripe-plugin#using-tokens

Hope this helps, 

--
You received this message because you are subscribed to the Google Groups "Kill Bill users mailing-list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to killbilling-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/killbilling-users/40be8779-a7c0-447b-a604-1e5f315643ddn%40googlegroups.com.


--
Pierre
Message has been deleted

Cheong Shin Liew

unread,
May 31, 2021, 12:28:12 AM5/31/21
to Kill Bill users mailing-list
Hi,

When I try to add equal sign '=" according to your solution, the url encoding will convert the equal sign '=' to '%3D'.

should be like this ......&pluginProperty=token=tok_XXX

but it become like this ......&pluginProperty=token%3Dtok_XXX

Is there any way to avoid the url encoding function?

Regards, 
Shin

a...@caravelo.com

unread,
Aug 3, 2021, 5:31:13 AM8/3/21
to Kill Bill users mailing-list
Hello,

we are actually hitting this very same problem with the Adyen plugin (yes, still with Kill Bill 0.20...).

After "fixing" our backend so to properly use pluginProperties to pass the customerId, everything stopped working because the id contains a @, which is saved as %40 in the database.

Until now it was working because we were (incorrectly) using the pluginInfo properties, which goes in the paymentMethodBody. I guess the workaround is to "abuse" the API (by leveraging a possible bug in the Kill Bill API... :-D ).

Hope this helps (us too :-D )!

Regards
--
Alessio Gaeta

a...@caravelo.com

unread,
Aug 3, 2021, 6:00:14 AM8/3/21
to Kill Bill users mailing-list
Here again. Just to tell that I may have found the culprit. The implementation of org.killbill.billing.jaxrs.resources.JaxRsResourceBase#extractPluginProperties() is:

protected Iterable<PluginProperty> extractPluginProperties(@Nullable final Iterable<String> pluginProperties, final PluginProperty... additionalProperties) {
        final Collection<PluginProperty> properties = new LinkedList<PluginProperty>();
        if (pluginProperties == null) {
            return properties;
        }

        for (final String pluginProperty : pluginProperties) {
            final List<String> property = ImmutableList.<String>copyOf(pluginProperty.split("="));
            // Skip entries for which there is no value
            if (property.size() == 1) {
                continue;
            }

            final String key = property.get(0);
            // Should we URL decode the value?
            String value = Joiner.on("=").join(property.subList(1, property.size()));
            if (pluginProperty.endsWith("=")) {
                value += "=";
            }
            properties.add(new PluginProperty(key, value, false));
        }
        for (final PluginProperty cur : additionalProperties) {
            properties.add(cur);
        }
        return properties;
    }


Pierre had the doubt when he implemented it, though... :-D
// Should we URL decode the value?

Maybe this could/should be considered to be fixed in any upcoming versions of Kill Bill? BTW, in my opinion the API could be more "RESTful", and drop the pluginProperties query param altogether, also considering that the query string has a length limit.

Have a nice day! :-)
--
Alessio Gaeta
Reply all
Reply to author
Forward
0 new messages