diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/PaymentMethodJson.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/PaymentMethodJson.java
index 77a5acd..7e0c04b 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/PaymentMethodJson.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/json/PaymentMethodJson.java
@@ -33,6 +33,7 @@ import org.killbill.billing.payment.api.PluginProperty;
import org.killbill.billing.util.audit.AccountAuditLogs;
import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
@@ -66,6 +67,7 @@ public class PaymentMethodJson extends JsonBase {
this.pluginInfo = pluginInfo;
}
+
public static PaymentMethodJson toPaymentMethodJson(final Account account, final PaymentMethod in, @Nullable final AccountAuditLogs accountAuditLogs) {
final boolean isDefault = account.getPaymentMethodId() != null && account.getPaymentMethodId().equals(in.getId());
final PaymentMethodPlugin pluginDetail = in.getPluginDetail();
@@ -185,6 +187,16 @@ public class PaymentMethodJson extends JsonBase {
return externalKey;
}
+ @JsonIgnore
+ public boolean isEmpty() {
+ return (externalKey == null &&
+ paymentMethodId == null &&
+ accountId == null &&
+ isDefault == null &&
+ pluginName == null &&
+ pluginInfo == null);
+ }
+
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("PaymentMethodJson{");
diff --git a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/ComboPaymentResource.java b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/ComboPaymentResource.java
index b2299ad..2bb01e2 100644
--- a/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/ComboPaymentResource.java
+++ b/jaxrs/src/main/java/org/killbill/billing/jaxrs/resources/ComboPaymentResource.java
@@ -79,7 +79,13 @@ public abstract class ComboPaymentResource extends JaxRsResourceBase {
return accountUserApi.createAccount(accountJson.toAccount(null), callContext);
}
- protected UUID getOrCreatePaymentMethod(final Account account, final PaymentMethodJson paymentMethodJson, final Iterable<PluginProperty> pluginProperties, final CallContext callContext) throws PaymentApiException {
+ protected UUID getOrCreatePaymentMethod(final Account account, @Nullable final PaymentMethodJson paymentMethodJson, final Iterable<PluginProperty> pluginProperties, final CallContext callContext) throws PaymentApiException {
+
+ // No info about payment method was passed, we default to null payment Method ID (which is allowed to be overiden in payment control plugins)
+ if (paymentMethodJson == null || paymentMethodJson.isEmpty()) {
+ return null;
+ }
+
// Get all payment methods for account
final List<PaymentMethod> accountPaymentMethods = paymentApi.getAccountPaymentMethods(account.getId(), false, ImmutableList.<PluginProperty>of(), callContext);