From 0203bc26f9578855c7741e27926222957001086d Mon Sep 17 00:00:00 2001 From: "sergey.kukurudzyak" Date: Fri, 6 Sep 2019 17:33:56 +0300 Subject: [PATCH 01/58] fixed problem with error handling --- pom.xml | 16 +++++++++++++++- .../com/chargify/exceptions/ChargifyError.java | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9845b2f..961cc2b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.2.7 + 0.2.8 jar Chargify SDK for Java @@ -39,6 +39,9 @@ UTF-8 1.8 1.8 + backendless_private + http://maven.backendless.com/repository/backendless_private/ + @@ -88,6 +91,17 @@ + + + ${repo.bkndls_private} + ${repo.bkndls_private.url}snapshots/ + + + ${repo.bkndls_private} + ${repo.bkndls_private.url} + + + diff --git a/src/main/java/com/chargify/exceptions/ChargifyError.java b/src/main/java/com/chargify/exceptions/ChargifyError.java index fb75b7a..f9a8b90 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyError.java +++ b/src/main/java/com/chargify/exceptions/ChargifyError.java @@ -14,7 +14,7 @@ public final class ChargifyError private final Object errors; @JsonCreator - public ChargifyError( @JsonProperty( "errors" ) Object errors ) + public ChargifyError( @JsonProperty( "error" ) Object errors ) { this.errors = errors; } From 9a0deba858052302e262f64138d79b7001c92383 Mon Sep 17 00:00:00 2001 From: kao78 Date: Mon, 18 May 2020 15:40:55 +0300 Subject: [PATCH 02/58] [BKNDLSS-21361] Change the duration of the Cloud99 trial to be 30 days. / [BKNDLSS-21551] Billing service does not return info about product recurring type or not --- pom.xml | 10 +- src/main/java/com/chargify/Chargify.java | 3 +- .../java/com/chargify/ChargifyService.java | 7 +- .../java/com/chargify/model/Component.java | 163 +----- .../chargify/model/CreateSubscription.java | 69 +++ .../java/com/chargify/model/Subscription.java | 515 +----------------- .../wrappers/CreateSubscriptionWrapper.java | 22 + .../SubscriptionDelayedChangeTest.java | 3 +- .../java/com/chargify/SubscriptionsTest.java | 3 +- 9 files changed, 116 insertions(+), 679 deletions(-) create mode 100644 src/main/java/com/chargify/model/CreateSubscription.java create mode 100644 src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java diff --git a/pom.xml b/pom.xml index 961cc2b..914f1de 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.2.8 + 0.3.0 jar Chargify SDK for Java @@ -75,6 +75,14 @@ 1.2.3 + + + org.projectlombok + lombok + 1.18.12 + provided + + junit junit diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 8f62159..3e5bfbb 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -3,6 +3,7 @@ import com.chargify.model.Allocation; import com.chargify.model.Component; import com.chargify.model.ComponentPricePointUpdate; +import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; import com.chargify.model.Metadata; import com.chargify.model.Product; @@ -38,7 +39,7 @@ public interface Chargify Product archiveProductById( String id ); - Subscription createSubscription( Subscription subscription ); + Subscription createSubscription( CreateSubscription subscription ); Subscription findSubscriptionById( String id ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index db65199..7c42121 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -5,6 +5,7 @@ import com.chargify.model.Allocation; import com.chargify.model.Component; import com.chargify.model.ComponentPricePointUpdate; +import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; import com.chargify.model.Metadata; import com.chargify.model.Migration; @@ -20,6 +21,7 @@ import com.chargify.model.wrappers.AnyComponentWrapper; import com.chargify.model.wrappers.ComponentPricePointUpdatesWrapper; import com.chargify.model.wrappers.ComponentWrapper; +import com.chargify.model.wrappers.CreateSubscriptionWrapper; import com.chargify.model.wrappers.CustomerWrapper; import com.chargify.model.wrappers.MetadataWrapper; import com.chargify.model.wrappers.MeteredComponentWrapper; @@ -200,10 +202,9 @@ public Product archiveProductById( String id ) } @Override - public Subscription createSubscription( Subscription subscription ) + public Subscription createSubscription( CreateSubscription subscription ) { - return httpClient.postForObject( "/subscriptions.json", - new SubscriptionWrapper( subscription ), SubscriptionWrapper.class ) + return httpClient.postForObject( "/subscriptions.json", new CreateSubscriptionWrapper( subscription ), SubscriptionWrapper.class ) .getSubscription(); } diff --git a/src/main/java/com/chargify/model/Component.java b/src/main/java/com/chargify/model/Component.java index cdc0486..c1b613a 100644 --- a/src/main/java/com/chargify/model/Component.java +++ b/src/main/java/com/chargify/model/Component.java @@ -20,10 +20,11 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; import java.io.Serializable; -import java.util.Arrays; +@Data @JsonInclude( JsonInclude.Include.NON_NULL ) public class Component implements Serializable { @@ -60,163 +61,7 @@ public class Component implements Serializable private Boolean taxable; - private String description; + private Boolean recurring; - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - public String getPricingScheme() - { - return pricingScheme; - } - - public void setPricingScheme( String pricingScheme ) - { - this.pricingScheme = pricingScheme; - } - - public String getUnitName() - { - return unitName; - } - - public void setUnitName( String unitName ) - { - this.unitName = unitName; - } - - public Double getUnitPrice() - { - return unitPrice; - } - - public void setUnitPrice( Double unitPrice ) - { - this.unitPrice = unitPrice; - } - - public String getProductFamilyId() - { - return productFamilyId; - } - - public void setProductFamilyId( String productFamilyId ) - { - this.productFamilyId = productFamilyId; - } - - public ComponentKind getKind() - { - return kind; - } - - public void setKind( ComponentKind kind ) - { - this.kind = kind; - } - - public Boolean getArchived() - { - return archived; - } - - public void setArchived( Boolean archived ) - { - this.archived = archived; - } - - public Boolean getTaxable() - { - return taxable; - } - - public void setTaxable( Boolean taxable ) - { - this.taxable = taxable; - } - - public String getDescription() - { - return description; - } - - public void setDescription( String description ) - { - this.description = description; - } - - public Price[] getPrices() - { - return prices; - } - - public void setPrices( Price[] prices ) - { - this.prices = prices; - } - - public PricePoint[] getPricePoints() - { - return pricePoints; - } - - public void setPricePoints( PricePoint[] pricePoints ) - { - this.pricePoints = pricePoints; - } - - public String toString() - { - return "Component{" + - "id='" + id + '\'' + - ", name='" + name + '\'' + - ", pricingScheme='" + pricingScheme + '\'' + - ", unitName='" + unitName + '\'' + - ", unitPrice=" + unitPrice + - ", productFamilyId='" + productFamilyId + '\'' + - ", prices=" + Arrays.toString( prices ) + - ", pricePoints=" + Arrays.toString( pricePoints ) + - ", kind=" + kind + - ", archived=" + archived + - ", taxable=" + taxable + - ", description='" + description + '\'' + - '}'; - } - - public String getDefaultPricePointName() - { - return defaultPricePointName; - } - - public void setDefaultPricePointName( String defaultPricePointName ) - { - this.defaultPricePointName = defaultPricePointName; - } - - public String getDefaultPricePointHandle() - { - return defaultPricePointHandle; - } - - public void setDefaultPricePointHandle( String defaultPricePointHandle ) - { - this.defaultPricePointHandle = defaultPricePointHandle; - } + private String description; } diff --git a/src/main/java/com/chargify/model/CreateSubscription.java b/src/main/java/com/chargify/model/CreateSubscription.java new file mode 100644 index 0000000..fc6f744 --- /dev/null +++ b/src/main/java/com/chargify/model/CreateSubscription.java @@ -0,0 +1,69 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.io.Serializable; +import java.time.ZonedDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +@Data +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class CreateSubscription implements Serializable +{ + + @JsonProperty( "product_handle" ) + private String productHandle; + + @JsonProperty( "product_id" ) + private String productId; + + @JsonProperty( "product_price_point_handle" ) + private String productPricePointHandle; + + @JsonProperty( "product_price_point_id" ) + private String productPricePointId; + + @JsonProperty( "coupon_code" ) + private String couponCode; + + @JsonProperty( "payment_collection_method" ) + private String paymentCollectionMethod; + + @JsonProperty( "receives_invoice_emails" ) + private Boolean receivesInvoiceEmails; + + @JsonProperty( "net_terms" ) + private String netTerms; + + @JsonProperty( "customer_id" ) + private String customerId; + + @JsonProperty( "customer_reference" ) + private String customerReference; + + @JsonProperty( "next_billing_at" ) + private ZonedDateTime nextBillingAt; + + @JsonProperty( "stored_credential_transaction_id" ) + private Integer storedCredentialTransactionId; + + @JsonProperty( "sales_rep_id" ) + private Integer salesRepId; + + @JsonProperty( "payment_profile_id" ) + private String paymentProfileId; + + private String reference; + + @JsonProperty( "customer_attributes" ) + private Customer customerAttributes; + + private List components; + + private Map metafields = new HashMap<>(); +} diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java index 3d63a39..8e5db04 100644 --- a/src/main/java/com/chargify/model/Subscription.java +++ b/src/main/java/com/chargify/model/Subscription.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; import java.io.Serializable; import java.time.ZonedDateTime; @@ -28,6 +29,7 @@ import java.util.List; import java.util.Map; +@Data @JsonInclude( JsonInclude.Include.NON_NULL ) public class Subscription implements Serializable { @@ -162,517 +164,4 @@ public class Subscription implements Serializable private List components; private Map metafields = new HashMap<>(); - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getState() - { - return state; - } - - public void setState( String state ) - { - this.state = state; - } - - public Integer getBalanceInCents() - { - return balanceInCents; - } - - public void setBalanceInCents( Integer balanceInCents ) - { - this.balanceInCents = balanceInCents; - } - - public Integer getTotalRevenueInCents() - { - return totalRevenueInCents; - } - - public void setTotalRevenueInCents( Integer totalRevenueInCents ) - { - this.totalRevenueInCents = totalRevenueInCents; - } - - public Integer getProductPriceInCents() - { - return productPriceInCents; - } - - public void setProductPriceInCents( Integer productPriceInCents ) - { - this.productPriceInCents = productPriceInCents; - } - - public Integer getProductVersionNumber() - { - return productVersionNumber; - } - - public void setProductVersionNumber( Integer productVersionNumber ) - { - this.productVersionNumber = productVersionNumber; - } - - public Date getCurrentPeriodEndsAt() - { - return currentPeriodEndsAt; - } - - public void setCurrentPeriodEndsAt( Date currentPeriodEndsAt ) - { - this.currentPeriodEndsAt = currentPeriodEndsAt; - } - - public Date getTrialStartedAt() - { - return trialStartedAt; - } - - public void setTrialStartedAt( Date trialStartedAt ) - { - this.trialStartedAt = trialStartedAt; - } - - public Date getTrialEndedAt() - { - return trialEndedAt; - } - - public void setTrialEndedAt( Date trialEndedAt ) - { - this.trialEndedAt = trialEndedAt; - } - - public Date getActivatedAt() - { - return activatedAt; - } - - public void setActivatedAt( Date activatedAt ) - { - this.activatedAt = activatedAt; - } - - public Date getExpiresAt() - { - return expiresAt; - } - - public void setExpiresAt( Date expiresAt ) - { - this.expiresAt = expiresAt; - } - - public Date getCreatedAt() - { - return createdAt; - } - - public void setCreatedAt( Date createdAt ) - { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() - { - return updatedAt; - } - - public void setUpdatedAt( Date updatedAt ) - { - this.updatedAt = updatedAt; - } - - public String getCancellationMessage() - { - return cancellationMessage; - } - - public void setCancellationMessage( String cancellationMessage ) - { - this.cancellationMessage = cancellationMessage; - } - - public String getCancellationMethod() - { - return cancellationMethod; - } - - public void setCancellationMethod( String cancellationMethod ) - { - this.cancellationMethod = cancellationMethod; - } - - public Boolean getCancelAtEndOfPeriod() - { - return cancelAtEndOfPeriod; - } - - public void setCancelAtEndOfPeriod( Boolean cancelAtEndOfPeriod ) - { - this.cancelAtEndOfPeriod = cancelAtEndOfPeriod; - } - - public Date getCanceledAt() - { - return canceledAt; - } - - public void setCanceledAt( Date canceledAt ) - { - this.canceledAt = canceledAt; - } - - public Date getCurrentPeriodStartedAt() - { - return currentPeriodStartedAt; - } - - public void setCurrentPeriodStartedAt( Date currentPeriodStartedAt ) - { - this.currentPeriodStartedAt = currentPeriodStartedAt; - } - - public String getPreviousState() - { - return previousState; - } - - public void setPreviousState( String previousState ) - { - this.previousState = previousState; - } - - public Integer getSignupPaymentId() - { - return signupPaymentId; - } - - public void setSignupPaymentId( Integer signupPaymentId ) - { - this.signupPaymentId = signupPaymentId; - } - - public String getSignupRevenue() - { - return signupRevenue; - } - - public void setSignupRevenue( String signupRevenue ) - { - this.signupRevenue = signupRevenue; - } - - public Date getDelayedCancelAt() - { - return delayedCancelAt; - } - - public void setDelayedCancelAt( Date delayedCancelAt ) - { - this.delayedCancelAt = delayedCancelAt; - } - - public String getCouponCode() - { - return couponCode; - } - - public void setCouponCode( String couponCode ) - { - this.couponCode = couponCode; - } - - public String getPaymentCollectionMethod() - { - return paymentCollectionMethod; - } - - public void setPaymentCollectionMethod( String paymentCollectionMethod ) - { - this.paymentCollectionMethod = paymentCollectionMethod; - } - - public String getSnapDay() - { - return snapDay; - } - - public void setSnapDay( String snapDay ) - { - this.snapDay = snapDay; - } - - public String getReasonCode() - { - return reasonCode; - } - - public void setReasonCode( String reasonCode ) - { - this.reasonCode = reasonCode; - } - - public Customer getCustomer() - { - return customer; - } - - public void setCustomer( Customer customer ) - { - this.customer = customer; - } - - public Product getProduct() - { - return product; - } - - public void setProduct( Product product ) - { - this.product = product; - } - - public CreditCard getCreditCard() - { - return creditCard; - } - - public void setCreditCard( CreditCard creditCard ) - { - this.creditCard = creditCard; - } - - public String getPaymentType() - { - return paymentType; - } - - public void setPaymentType( String paymentType ) - { - this.paymentType = paymentType; - } - - public String getReferralCode() - { - return referralCode; - } - - public void setReferralCode( String referralCode ) - { - this.referralCode = referralCode; - } - - public String getNextProductId() - { - return nextProductId; - } - - public void setNextProductId( String nextProductId ) - { - this.nextProductId = nextProductId; - } - - public Integer getCouponUseCount() - { - return couponUseCount; - } - - public void setCouponUseCount( Integer couponUseCount ) - { - this.couponUseCount = couponUseCount; - } - - public Integer getCouponUsesAllowed() - { - return couponUsesAllowed; - } - - public void setCouponUsesAllowed( Integer couponUsesAllowed ) - { - this.couponUsesAllowed = couponUsesAllowed; - } - - public String getProductId() - { - return productId; - } - - public void setProductId( String productId ) - { - this.productId = productId; - } - - public String getCustomerId() - { - return customerId; - } - - public void setCustomerId( String customerId ) - { - this.customerId = customerId; - } - - public String getCustomerReference() - { - return customerReference; - } - - public void setCustomerReference( String customerReference ) - { - this.customerReference = customerReference; - } - - public String getProductHandle() - { - return productHandle; - } - - public void setProductHandle( String productHandle ) - { - this.productHandle = productHandle; - } - - public Customer getCustomerAttributes() - { - return customerAttributes; - } - - public void setCustomerAttributes( Customer customerAttributes ) - { - this.customerAttributes = customerAttributes; - } - - public boolean isProductChangeDelayed() - { - return productChangeDelayed; - } - - public void setProductChangeDelayed( boolean productChangeDelayed ) - { - this.productChangeDelayed = productChangeDelayed; - } - - public Map getMetafields() - { - return metafields; - } - - public void setMetafields( Map metafields ) - { - this.metafields = metafields; - } - - public List getComponents() - { - return components; - } - - public void setComponents( List components ) - { - this.components = components; - } - - public String getPaymentProfileId() - { - return paymentProfileId; - } - - public void setPaymentProfileId( String paymentProfileId ) - { - this.paymentProfileId = paymentProfileId; - } - - public ZonedDateTime getNextBillingAt() - { - return nextBillingAt; - } - - public void setNextBillingAt( ZonedDateTime nextBillingAt ) - { - this.nextBillingAt = nextBillingAt; - } - - public ZonedDateTime getNextAssessmentAt() - { - return nextAssessmentAt; - } - - public void setNextAssessmentAt( ZonedDateTime nextAssessmentAt ) - { - this.nextAssessmentAt = nextAssessmentAt; - } - - public String getReference() - { - return reference; - } - - public void setReference( String reference ) - { - this.reference = reference; - } - - @Override - public String toString() - { - return "Subscription{" + - "id='" + id + '\'' + - ", state='" + state + '\'' + - ", balanceInCents=" + balanceInCents + - ", totalRevenueInCents=" + totalRevenueInCents + - ", productPriceInCents=" + productPriceInCents + - ", productVersionNumber=" + productVersionNumber + - ", currentPeriodEndsAt=" + currentPeriodEndsAt + - ", nextAssessmentAt=" + nextAssessmentAt + - ", nextBillingAt=" + nextBillingAt + - ", trialStartedAt=" + trialStartedAt + - ", trialEndedAt=" + trialEndedAt + - ", activatedAt=" + activatedAt + - ", expiresAt=" + expiresAt + - ", createdAt=" + createdAt + - ", updatedAt=" + updatedAt + - ", cancellationMessage='" + cancellationMessage + '\'' + - ", cancellationMethod='" + cancellationMethod + '\'' + - ", cancelAtEndOfPeriod=" + cancelAtEndOfPeriod + - ", canceledAt=" + canceledAt + - ", currentPeriodStartedAt=" + currentPeriodStartedAt + - ", customerAttributes=" + customerAttributes + - ", customerId='" + customerId + '\'' + - ", customerReference='" + customerReference + '\'' + - ", productChangeDelayed=" + productChangeDelayed + - ", previousState='" + previousState + '\'' + - ", productHandle='" + productHandle + '\'' + - ", productId='" + productId + '\'' + - ", signupPaymentId=" + signupPaymentId + - ", signupRevenue='" + signupRevenue + '\'' + - ", delayedCancelAt=" + delayedCancelAt + - ", couponCode='" + couponCode + '\'' + - ", paymentCollectionMethod='" + paymentCollectionMethod + '\'' + - ", paymentProfileId='" + paymentProfileId + '\'' + - ", snapDay='" + snapDay + '\'' + - ", reasonCode='" + reasonCode + '\'' + - ", customer=" + customer + - ", product=" + product + - ", creditCard=" + creditCard + - ", paymentType='" + paymentType + '\'' + - ", referralCode='" + referralCode + '\'' + - ", reference='" + reference + '\'' + - ", nextProductId='" + nextProductId + '\'' + - ", couponUseCount=" + couponUseCount + - ", couponUsesAllowed=" + couponUsesAllowed + - ", components=" + components + - ", metafields=" + metafields + - '}'; - } } diff --git a/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java b/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java new file mode 100644 index 0000000..8a939f4 --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java @@ -0,0 +1,22 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.CreateSubscription; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + + +public final class CreateSubscriptionWrapper +{ + private final CreateSubscription subscription; + + @JsonCreator + public CreateSubscriptionWrapper( @JsonProperty( "subscription" ) CreateSubscription wrappedSubscription ) + { + this.subscription = wrappedSubscription; + } + + public CreateSubscription getSubscription() + { + return subscription; + } +} diff --git a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java index ac3fb8f..872c119 100644 --- a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java +++ b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java @@ -1,5 +1,6 @@ package com.chargify; +import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; import com.chargify.model.Product; import com.chargify.model.ProductFamily; @@ -37,7 +38,7 @@ public static void setup() customer = chargify.createCustomer( new Customer( randomName(), randomName(), randomEmail() ) ); - final Subscription subscription = new Subscription(); + final CreateSubscription subscription = new CreateSubscription(); subscription.setProductId( SubscriptionDelayedChangeTest.initialProduct.getId() ); subscription.setCustomerId( customer.getId() ); SubscriptionDelayedChangeTest.subscription = chargify.createSubscription( subscription ); diff --git a/src/test/java/com/chargify/SubscriptionsTest.java b/src/test/java/com/chargify/SubscriptionsTest.java index 727a4c1..78e927f 100644 --- a/src/test/java/com/chargify/SubscriptionsTest.java +++ b/src/test/java/com/chargify/SubscriptionsTest.java @@ -1,5 +1,6 @@ package com.chargify; +import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; import com.chargify.model.Product; import com.chargify.model.ProductFamily; @@ -47,7 +48,7 @@ public static void setup() customerUnderTest = chargify.createCustomer( new Customer( "Andy", "Panda", "andypanda@example.com" ) ); - final Subscription subscription = new Subscription(); + final CreateSubscription subscription = new CreateSubscription(); subscription.setProductId( productUnderTest.getId() ); subscription.setCustomerId( customerUnderTest.getId() ); subscriptionUnderTest = chargify.createSubscription( subscription ); From 5ebd2057e00098f9a624f0fd79dcc327729ee58a Mon Sep 17 00:00:00 2001 From: "sergey.kukurudzyak" Date: Thu, 21 May 2020 14:54:50 +0300 Subject: [PATCH 03/58] added adjust method as part of task BKNDLSS-21574 Add route for BBs conversion --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 17 ++----- .../java/com/chargify/ChargifyService.java | 44 +++++-------------- .../model/wrappers/AdjustmentWrapper.java | 21 +++++++++ 4 files changed, 36 insertions(+), 48 deletions(-) create mode 100644 src/main/java/com/chargify/model/wrappers/AdjustmentWrapper.java diff --git a/pom.xml b/pom.xml index 914f1de..0a371d1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.3.0 + 0.3.1 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 3e5bfbb..738f14d 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -1,19 +1,6 @@ package com.chargify; -import com.chargify.model.Allocation; -import com.chargify.model.Component; -import com.chargify.model.ComponentPricePointUpdate; -import com.chargify.model.CreateSubscription; -import com.chargify.model.Customer; -import com.chargify.model.Metadata; -import com.chargify.model.Product; -import com.chargify.model.ProductFamily; -import com.chargify.model.ReferralCode; -import com.chargify.model.RenewalPreview; -import com.chargify.model.Subscription; -import com.chargify.model.SubscriptionComponent; -import com.chargify.model.SubscriptionMetadata; -import com.chargify.model.Usage; +import com.chargify.model.*; import java.util.List; @@ -97,4 +84,6 @@ ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subsc void deleteCustomerById( String id ); ReferralCode validateReferralCode( String code ); + + Adjustment adjust( String subscriptionId, Adjustment adjustment ); } diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 7c42121..d7344c3 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -2,39 +2,8 @@ import com.chargify.exceptions.ChargifyResponseErrorHandler; import com.chargify.exceptions.ResourceNotFoundException; -import com.chargify.model.Allocation; -import com.chargify.model.Component; -import com.chargify.model.ComponentPricePointUpdate; -import com.chargify.model.CreateSubscription; -import com.chargify.model.Customer; -import com.chargify.model.Metadata; -import com.chargify.model.Migration; -import com.chargify.model.Product; -import com.chargify.model.ProductFamily; -import com.chargify.model.ReferralCode; -import com.chargify.model.RenewalPreview; -import com.chargify.model.Subscription; -import com.chargify.model.SubscriptionComponent; -import com.chargify.model.SubscriptionMetadata; -import com.chargify.model.Usage; -import com.chargify.model.wrappers.AllocationWrapper; -import com.chargify.model.wrappers.AnyComponentWrapper; -import com.chargify.model.wrappers.ComponentPricePointUpdatesWrapper; -import com.chargify.model.wrappers.ComponentWrapper; -import com.chargify.model.wrappers.CreateSubscriptionWrapper; -import com.chargify.model.wrappers.CustomerWrapper; -import com.chargify.model.wrappers.MetadataWrapper; -import com.chargify.model.wrappers.MeteredComponentWrapper; -import com.chargify.model.wrappers.MigrationWrapper; -import com.chargify.model.wrappers.OnOffComponentWrapper; -import com.chargify.model.wrappers.ProductFamilyWrapper; -import com.chargify.model.wrappers.ProductWrapper; -import com.chargify.model.wrappers.QuantityBasedComponentWrapper; -import com.chargify.model.wrappers.ReferralCodeWrapper; -import com.chargify.model.wrappers.RenewalPreviewWrapper; -import com.chargify.model.wrappers.SubscriptionComponentWrapper; -import com.chargify.model.wrappers.SubscriptionWrapper; -import com.chargify.model.wrappers.UsageWrapper; +import com.chargify.model.*; +import com.chargify.model.wrappers.*; import com.fasterxml.jackson.databind.SerializationFeature; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RootUriTemplateHandler; @@ -537,4 +506,13 @@ public ReferralCode validateReferralCode( String code ) return null; } } + + @Override + public Adjustment adjust( String subscriptionId, Adjustment adjustment ) + { + return httpClient.exchange( "/subscriptions/" + subscriptionId + "/adjustments.json", HttpMethod.POST, + new HttpEntity<>( new AdjustmentWrapper( adjustment ) ), AdjustmentWrapper.class ) + .getBody() + .getAdjustment(); + } } diff --git a/src/main/java/com/chargify/model/wrappers/AdjustmentWrapper.java b/src/main/java/com/chargify/model/wrappers/AdjustmentWrapper.java new file mode 100644 index 0000000..1abf496 --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/AdjustmentWrapper.java @@ -0,0 +1,21 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.Adjustment; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +public final class AdjustmentWrapper +{ + private final Adjustment adjustment; + + @JsonCreator + public AdjustmentWrapper( @JsonProperty( "adjustment" ) Adjustment wrappedAdjustment ) + { + this.adjustment = wrappedAdjustment; + } + + public Adjustment getAdjustment() + { + return adjustment; + } +} From 7d050855dea16cee65241367296713d9516d29ae Mon Sep 17 00:00:00 2001 From: kao78 Date: Mon, 15 Jun 2020 11:49:58 +0300 Subject: [PATCH 04/58] [BKNDLSS-21873] Credit balance should not reset before payment --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 2 + .../java/com/chargify/ChargifyService.java | 37 +++++++++++++++++++ .../model/SubscriptionReactivationData.java | 17 +++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/chargify/model/SubscriptionReactivationData.java diff --git a/pom.xml b/pom.xml index 0a371d1..8986e2d 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.3.1 + 0.4.0 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 738f14d..0d1406e 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -44,6 +44,8 @@ public interface Chargify Subscription reactivateSubscription( String subscriptionId ); + Subscription reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ); + ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subscriptionId, int componentId, String pricePointHandle ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index d7344c3..97105bb 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -11,7 +11,9 @@ import org.springframework.http.HttpMethod; import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriUtils; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @@ -266,6 +268,19 @@ public Subscription reactivateSubscription( String subscriptionId ) .getSubscription(); } + @Override + public Subscription reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ) + { + return httpClient.exchange( + prepareSubscriptionReactivationURI( subscriptionId, reactivationData ), + HttpMethod.PUT, + HttpEntity.EMPTY, + SubscriptionWrapper.class + ) + .getBody() + .getSubscription(); + } + @Override public ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subscriptionId, int componentId, String pricePointHandle ) @@ -515,4 +530,26 @@ public Adjustment adjust( String subscriptionId, Adjustment adjustment ) .getBody() .getAdjustment(); } + + private String prepareSubscriptionReactivationURI( String subscriptionId, SubscriptionReactivationData reactivationData ) + { + StringBuilder urlBuilder = new StringBuilder( "/subscriptions/" ).append( subscriptionId ).append( "/reactivate.json" ); + + urlBuilder.append( "?include_trial=" ).append( reactivationData.isIncludeTrial() ? "1" : "0" ); + urlBuilder.append( "&preserve_balance=" ).append( reactivationData.isPreserveBalance() ? "1" : "0" ); + if( reactivationData.getCouponCode() != null ) + { + urlBuilder.append( "&coupon_code=" ).append( UriUtils.encode( reactivationData.getCouponCode(), StandardCharsets.UTF_8 ) ); + } + if( reactivationData.getResume() != null ) + { + urlBuilder.append( "&resume=" ).append( reactivationData.getResume() ? "true" : "false" ); + } + if( reactivationData.isForgiveBalance() ) + { + urlBuilder.append( "&resume%5Bforgive_balance%5D=" ).append( reactivationData.isForgiveBalance() ? "true" : "false" ); + } + + return urlBuilder.toString(); + } } diff --git a/src/main/java/com/chargify/model/SubscriptionReactivationData.java b/src/main/java/com/chargify/model/SubscriptionReactivationData.java new file mode 100644 index 0000000..7c119fa --- /dev/null +++ b/src/main/java/com/chargify/model/SubscriptionReactivationData.java @@ -0,0 +1,17 @@ +package com.chargify.model; + +import lombok.Data; +import lombok.NoArgsConstructor; + + +@NoArgsConstructor +@Data +public class SubscriptionReactivationData +{ + private String subscriptionId; + private boolean includeTrial = false; + private boolean preserveBalance = false; + private String couponCode; + private Boolean resume; + private boolean forgiveBalance = false; +} From cb1c07b2377b19c18e40b0064ca7ba8e8c9a22e2 Mon Sep 17 00:00:00 2001 From: kao78 Date: Fri, 31 Jul 2020 09:48:27 +0300 Subject: [PATCH 05/58] Constants for events and subscription states. --- pom.xml | 2 +- src/main/java/com/chargify/model/Events.java | 33 +++++++++++++++++++ .../chargify/model/SubscriptionStates.java | 19 +++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/chargify/model/Events.java create mode 100644 src/main/java/com/chargify/model/SubscriptionStates.java diff --git a/pom.xml b/pom.xml index 8986e2d..50e8fef 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.4.0 + 0.4.1 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/Events.java b/src/main/java/com/chargify/model/Events.java new file mode 100644 index 0000000..aa26f20 --- /dev/null +++ b/src/main/java/com/chargify/model/Events.java @@ -0,0 +1,33 @@ +package com.chargify.model; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + + +@NoArgsConstructor( access = AccessLevel.PRIVATE ) +public final class Events +{ + public static final String BILLING_DATE_CHANGE = "billing_date_change"; + public static final String COMPONENT_ALLOCATION_CHANGE = "component_allocation_change"; + public static final String CUSTOMER_CREATE = "customer_create"; + public static final String CUSTOMER_UPDATE = "customer_update"; + public static final String DUNNING_STEP_REACHED = "dunning_step_reached"; + public static final String EXPIRATION_DATE_CHANGE = "expiration_date_change"; + public static final String EXPIRING_CARD = "expiring_card"; + public static final String INVOICE_ISSUED = "invoice_issued"; + public static final String METERED_USAGE = "metered_usage"; + public static final String PAYMENT_FAILURE = "payment_failure"; + public static final String PAYMENT_SUCCESS = "payment_success"; + public static final String PREPAID_USAGE = "prepaid_usage"; + public static final String RENEWAL_FAILURE = "renewal_failure"; + public static final String RENEWAL_SUCCESS = "renewal_success"; + public static final String SIGNUP_SUCCESS = "signup_success"; + public static final String SIGNUP_FAILURE = "signup_failure"; + public static final String SUBSCRIPTION_CARD_UPDATE = "subscription_card_update"; + public static final String SUBSCRIPTION_PRODUCT_CHANGE = "subscription_product_change"; + public static final String SUBSCRIPTION_STATE_CHANGE = "subscription_state_change"; + public static final String UPCOMING_RENEWAL_NOTICE = "upcoming_renewal_notice"; + public static final String UPGRADE_DOWNGRADE_FAILURE = "upgrade_downgrade_failure"; + public static final String UPGRADE_DOWNGRADE_SUCCESS = "upgrade_downgrade_success"; + public static final String PENDING_CANCELLATION_CHANGE = "pending_cancellation_change"; +} diff --git a/src/main/java/com/chargify/model/SubscriptionStates.java b/src/main/java/com/chargify/model/SubscriptionStates.java new file mode 100644 index 0000000..7b0abe3 --- /dev/null +++ b/src/main/java/com/chargify/model/SubscriptionStates.java @@ -0,0 +1,19 @@ +package com.chargify.model; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + + +@NoArgsConstructor( access = AccessLevel.PRIVATE ) +public final class SubscriptionStates +{ + public static final String ACTIVE = "active"; + public static final String CANCELED = "canceled"; + public static final String EXPIRED = "expired"; + public static final String ON_HOLD = "on_hold"; + public static final String PAST_DUE = "past_due"; + public static final String SOFT_FAILURE = "soft_failure"; + public static final String TRAILING = "trialing"; + public static final String TRIAL_ENDED = "trial_ended"; + public static final String UNPAID = "unpaid"; +} From 532155ebe919518ee488757e3434ebeb07ac57ec Mon Sep 17 00:00:00 2001 From: kao78 Date: Wed, 5 Aug 2020 12:46:08 +0300 Subject: [PATCH 06/58] Fixed creation of ChargifyError instances --- pom.xml | 2 +- src/main/java/com/chargify/exceptions/ChargifyError.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 50e8fef..992b5d3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.4.1 + 0.4.2 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/exceptions/ChargifyError.java b/src/main/java/com/chargify/exceptions/ChargifyError.java index f9a8b90..fb75b7a 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyError.java +++ b/src/main/java/com/chargify/exceptions/ChargifyError.java @@ -14,7 +14,7 @@ public final class ChargifyError private final Object errors; @JsonCreator - public ChargifyError( @JsonProperty( "error" ) Object errors ) + public ChargifyError( @JsonProperty( "errors" ) Object errors ) { this.errors = errors; } From 660119500dfed916b0d93c30b34b3769614f8fde Mon Sep 17 00:00:00 2001 From: kao78 Date: Wed, 19 Aug 2020 15:44:37 +0300 Subject: [PATCH 07/58] [BKNDLSS-22518] Applications with referral code created without Chargify subscription --- pom.xml | 2 +- src/main/java/com/chargify/model/CreateSubscription.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 992b5d3..02f2645 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.4.2 + 0.4.3 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/CreateSubscription.java b/src/main/java/com/chargify/model/CreateSubscription.java index fc6f744..9a0e51a 100644 --- a/src/main/java/com/chargify/model/CreateSubscription.java +++ b/src/main/java/com/chargify/model/CreateSubscription.java @@ -58,6 +58,7 @@ public class CreateSubscription implements Serializable @JsonProperty( "payment_profile_id" ) private String paymentProfileId; + @JsonProperty( "ref" ) private String reference; @JsonProperty( "customer_attributes" ) From 72260a92f270dec5ca9169eabcaeddd2ba7e37b6 Mon Sep 17 00:00:00 2001 From: kao78 Date: Mon, 31 Aug 2020 12:04:13 +0300 Subject: [PATCH 08/58] [BKNDLSS-22600] Card added to app, but it is not displayed --- pom.xml | 2 +- .../java/com/chargify/model/event/Site.java | 16 ++++ .../model/event/SubscriptionCardUpdate.java | 91 +++++++++++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/chargify/model/event/Site.java create mode 100644 src/main/java/com/chargify/model/event/SubscriptionCardUpdate.java diff --git a/pom.xml b/pom.xml index 02f2645..973312c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.4.3 + 0.5.0 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/event/Site.java b/src/main/java/com/chargify/model/event/Site.java new file mode 100644 index 0000000..094ae03 --- /dev/null +++ b/src/main/java/com/chargify/model/event/Site.java @@ -0,0 +1,16 @@ +package com.chargify.model.event; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties( ignoreUnknown = true ) +public class Site +{ + private Long id; + private String subdomain; +} diff --git a/src/main/java/com/chargify/model/event/SubscriptionCardUpdate.java b/src/main/java/com/chargify/model/event/SubscriptionCardUpdate.java new file mode 100644 index 0000000..cbb67b0 --- /dev/null +++ b/src/main/java/com/chargify/model/event/SubscriptionCardUpdate.java @@ -0,0 +1,91 @@ +package com.chargify.model.event; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@JsonIgnoreProperties( ignoreUnknown = true ) +public class SubscriptionCardUpdate +{ + @JsonProperty( "event_id" ) + private String eventId; + private Site site; + private Subscription subscription; + private Customer customer; + @JsonProperty( "previous_payment_profile" ) + private PaymentProfile previousPaymentProfile; + @JsonProperty( "updated_payment_profile" ) + private PaymentProfile updatedPaymentProfile; + + @Data + @NoArgsConstructor + @AllArgsConstructor + @JsonIgnoreProperties( ignoreUnknown = true ) + public static class Subscription + { + private Long id; + private String state; + @JsonProperty( "balance_in_cents" ) + private Long balanceInCents; + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + @JsonIgnoreProperties( ignoreUnknown = true ) + public static class Customer + { + private Long id; + @JsonProperty( "first_name" ) + private String firstName; + @JsonProperty( "last_name" ) + private String lastName; + private String reference; + private String organization; + private String email; + } + + @Data + @NoArgsConstructor + @AllArgsConstructor + @JsonIgnoreProperties( ignoreUnknown = true ) + public static class PaymentProfile + { + private Long id; + @JsonProperty( "first_name" ) + private String firstName; + @JsonProperty( "last_name" ) + private String lastName; + @JsonProperty( "masked_card_number" ) + private String maskedCardNumber; + @JsonProperty( "card_type" ) + private String cardType; + @JsonProperty( "expiration_month" ) + private Integer expirationMonth; + @JsonProperty( "expiration_year" ) + private Integer expirationYear; + @JsonProperty( "current_vault" ) + private String currentVault; + @JsonProperty( "vault_token" ) + private String vaultToken; + @JsonProperty( "customer_vault_token" ) + private String customerVaultToken; + @JsonProperty( "billing_address" ) + private String billingAddress; + @JsonProperty( "billing_address_2" ) + private String billingAddress2; + @JsonProperty( "billing_city" ) + private String billingCity; + @JsonProperty( "billing_state" ) + private String billingState; + @JsonProperty( "billing_zip" ) + private String billingZip; + @JsonProperty( "billing_country" ) + private String billingCountry; + } +} From 308296d1c8193f5dc6474a839ff6bfef5f9dfde6 Mon Sep 17 00:00:00 2001 From: kao78 Date: Mon, 14 Sep 2020 14:50:13 +0300 Subject: [PATCH 09/58] [BKNDLSS-22702] Special handling of "Springboard Shortcut" / [BKNDLSS-22701] Support for changing the billing plan before the end of the trial period --- pom.xml | 10 +++- src/main/java/com/chargify/Chargify.java | 5 ++ .../java/com/chargify/ChargifyService.java | 29 +++++++++++ .../chargify/model/SubscriptionCharge.java | 26 ++++++++++ .../model/SubscriptionChargeResult.java | 48 +++++++++++++++++++ .../wrappers/SubscriptionChargeWrapper.java | 21 ++++++++ 6 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/chargify/model/SubscriptionCharge.java create mode 100644 src/main/java/com/chargify/model/SubscriptionChargeResult.java create mode 100644 src/main/java/com/chargify/model/wrappers/SubscriptionChargeWrapper.java diff --git a/pom.xml b/pom.xml index 973312c..a807f06 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.5.0 + 0.6.0 jar Chargify SDK for Java @@ -136,6 +136,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 11 + 11 + + diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 0d1406e..a762df2 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -2,6 +2,7 @@ import com.chargify.model.*; +import java.time.LocalDateTime; import java.util.List; public interface Chargify @@ -28,6 +29,10 @@ public interface Chargify Subscription createSubscription( CreateSubscription subscription ); + void updateSubscriptionNextBillingDate( String subscriptionId, LocalDateTime nextBillingDate ); + + SubscriptionChargeResult createSubscriptionCharge( String subscriptionId, SubscriptionCharge subscriptionCharge ); + Subscription findSubscriptionById( String id ); List findSubscriptionsByCustomerId( String customerId ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 97105bb..8797b34 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -14,8 +14,12 @@ import org.springframework.web.util.UriUtils; import java.nio.charset.StandardCharsets; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; public final class ChargifyService implements Chargify @@ -179,6 +183,31 @@ public Subscription createSubscription( CreateSubscription subscription ) .getSubscription(); } + @Override + public void updateSubscriptionNextBillingDate( String subscriptionId, LocalDateTime nextBillingDate ) + { + httpClient.put( + "/subscriptions/" + subscriptionId + ".json", + Map.of( + "subscription", + Map.of( + "next_billing_at", + nextBillingDate.atZone( ZoneId.systemDefault() ) + .withZoneSameInstant( ZoneId.of( "UTC" ) ) + .toLocalDateTime() + .format( DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'") ) ) + ) + ); + } + + @Override + public SubscriptionChargeResult createSubscriptionCharge( String subscriptionId, SubscriptionCharge subscriptionCharge ) + { + return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/charges.json", + Map.of( "charge", subscriptionCharge ), SubscriptionChargeWrapper.class ) + .getSubscriptionChargeResult(); + } + @Override public Subscription findSubscriptionById( String id ) { diff --git a/src/main/java/com/chargify/model/SubscriptionCharge.java b/src/main/java/com/chargify/model/SubscriptionCharge.java new file mode 100644 index 0000000..a759a4f --- /dev/null +++ b/src/main/java/com/chargify/model/SubscriptionCharge.java @@ -0,0 +1,26 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + + +@NoArgsConstructor +@AllArgsConstructor +@Data +@JsonIgnoreProperties( ignoreUnknown = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class SubscriptionCharge implements Serializable +{ + private String amount; + private String memo; + @JsonProperty( "period_range_start" ) + private String periodRangeStart; + @JsonProperty( "period_range_end" ) + private String periodRangeEnd; +} diff --git a/src/main/java/com/chargify/model/SubscriptionChargeResult.java b/src/main/java/com/chargify/model/SubscriptionChargeResult.java new file mode 100644 index 0000000..8088d66 --- /dev/null +++ b/src/main/java/com/chargify/model/SubscriptionChargeResult.java @@ -0,0 +1,48 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + + +@NoArgsConstructor +@AllArgsConstructor +@Data +@JsonIgnoreProperties( ignoreUnknown = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class SubscriptionChargeResult implements Serializable +{ + private Integer id; + @JsonProperty( "subscription_id" ) + private Integer subscriptionId; + private String type; + private String kind; + @JsonProperty( "transaction_type" ) + private String transactionType; + private Boolean success; + @JsonProperty( "amount_in_cents" ) + private Integer amountInCents; + private String memo; + @JsonProperty( "created_at" ) + private String createdAt; + @JsonProperty( "starting_balance_in_cents" ) + private Integer startingBalanceInCents; + @JsonProperty( "ending_balance_in_cents" ) + private Integer endingBalanceInCents; + @JsonProperty( "product_id" ) + private Integer productId; + @JsonProperty( "statement_id" ) + private Integer statementId; + @JsonProperty( "customer_id" ) + private Integer customerId; + @JsonProperty( "period_range_start" ) + private String periodRangeStart; + @JsonProperty( "period_range_end" ) + private String periodRangeEnd; + +} diff --git a/src/main/java/com/chargify/model/wrappers/SubscriptionChargeWrapper.java b/src/main/java/com/chargify/model/wrappers/SubscriptionChargeWrapper.java new file mode 100644 index 0000000..b54a188 --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/SubscriptionChargeWrapper.java @@ -0,0 +1,21 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.SubscriptionChargeResult; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.ToString; + + +@ToString +public final class SubscriptionChargeWrapper +{ + @Getter + private final SubscriptionChargeResult subscriptionChargeResult; + + @JsonCreator + public SubscriptionChargeWrapper( @JsonProperty( "charge" ) SubscriptionChargeResult subscriptionChargeResult ) + { + this.subscriptionChargeResult = subscriptionChargeResult; + } +} From 73f6a989b0b3f54068151e85212281725cae4c42 Mon Sep 17 00:00:00 2001 From: "sergey.kukurudzyak" Date: Tue, 15 Sep 2020 17:10:28 +0300 Subject: [PATCH 10/58] BKNDLSS-22478 Marketplace from EU cloud. Added currency property. --- pom.xml | 2 +- src/main/java/com/chargify/model/CreateSubscription.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a807f06..fd037f7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.6.0 + 0.7.0 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/CreateSubscription.java b/src/main/java/com/chargify/model/CreateSubscription.java index 9a0e51a..6a8ff9f 100644 --- a/src/main/java/com/chargify/model/CreateSubscription.java +++ b/src/main/java/com/chargify/model/CreateSubscription.java @@ -67,4 +67,6 @@ public class CreateSubscription implements Serializable private List components; private Map metafields = new HashMap<>(); + + private String currency; } From 5f9bd5f503b5a8345e3a4acfa97cbc051f3c7436 Mon Sep 17 00:00:00 2001 From: kao78 Date: Mon, 11 Jan 2021 09:17:45 +0200 Subject: [PATCH 11/58] [BKNDLSS-23440] Add support for annual pricing plans --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 22 +- .../java/com/chargify/ChargifyService.java | 89 +++- .../java/com/chargify/model/Component.java | 2 +- .../model/ComponentPricePointUpdate.java | 36 +- .../java/com/chargify/model/Migration.java | 23 +- src/main/java/com/chargify/model/Price.java | 2 + .../java/com/chargify/model/PricePoint.java | 68 +-- .../model/PricePointIntervalUnit.java | 6 + src/main/java/com/chargify/model/Product.java | 390 ------------------ .../java/com/chargify/model/Subscription.java | 1 + .../chargify/model/SubscriptionComponent.java | 96 +---- .../model/SubscriptionProductUpdate.java | 22 + .../com/chargify/model/product/Product.java | 111 +++++ .../{ => product}/ProductComponentItem.java | 2 +- .../model/{ => product}/ProductFamily.java | 2 +- .../model/product/ProductPricePoint.java | 53 +++ .../ComponentPricePointUpdatesWrapper.java | 24 +- .../wrappers/ComponentPricePointsWrapper.java | 22 + .../model/wrappers/ProductFamilyWrapper.java | 2 +- .../wrappers/ProductPricePointsWrapper.java | 22 + .../model/wrappers/ProductWrapper.java | 2 +- .../SubscriptionProductUpdateWrapper.java | 19 + .../java/com/chargify/ComponentsTest.java | 2 +- .../com/chargify/ProductFamiliesTest.java | 2 +- src/test/java/com/chargify/ProductsTest.java | 9 +- .../SubscriptionDelayedChangeTest.java | 9 +- .../java/com/chargify/SubscriptionsTest.java | 7 +- 28 files changed, 434 insertions(+), 613 deletions(-) create mode 100644 src/main/java/com/chargify/model/PricePointIntervalUnit.java delete mode 100644 src/main/java/com/chargify/model/Product.java create mode 100644 src/main/java/com/chargify/model/SubscriptionProductUpdate.java create mode 100644 src/main/java/com/chargify/model/product/Product.java rename src/main/java/com/chargify/model/{ => product}/ProductComponentItem.java (98%) rename src/main/java/com/chargify/model/{ => product}/ProductFamily.java (97%) create mode 100644 src/main/java/com/chargify/model/product/ProductPricePoint.java create mode 100644 src/main/java/com/chargify/model/wrappers/ComponentPricePointsWrapper.java create mode 100644 src/main/java/com/chargify/model/wrappers/ProductPricePointsWrapper.java create mode 100644 src/main/java/com/chargify/model/wrappers/SubscriptionProductUpdateWrapper.java diff --git a/pom.xml b/pom.xml index fd037f7..c6c73e7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.7.0 + 0.8.0 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index a762df2..c6bd66c 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -1,9 +1,13 @@ package com.chargify; import com.chargify.model.*; +import com.chargify.model.product.Product; +import com.chargify.model.product.ProductFamily; +import com.chargify.model.product.ProductPricePoint; import java.time.LocalDateTime; import java.util.List; +import java.util.Set; public interface Chargify { @@ -21,6 +25,10 @@ public interface Chargify Product findProductByApiHandle( String apiHandle ); + Set findProductPricePointsByProductId( String productId ); + + Set findComponentPricePoints( int componentId ); + List findAllProducts(); List findProductsByProductFamilyId( String productFamilyId ); @@ -47,6 +55,8 @@ public interface Chargify Subscription migrateSubscription( String subscriptionId, String productHandle ); + Subscription migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ); + Subscription reactivateSubscription( String subscriptionId ); Subscription reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ); @@ -54,8 +64,12 @@ public interface Chargify ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subscriptionId, int componentId, String pricePointHandle ); + List bulkUpdateSubscriptionComponentPricePoint( String subscriptionId, List items ); + Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, boolean delayed ); + Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, String pricePointHandle, boolean delayed ); + RenewalPreview previewSubscriptionRenewal( String subscriptionId ); List createSubscriptionMetadata( String subscriptionId, Metadata... metadata ); @@ -66,17 +80,17 @@ ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subsc Component createComponent( String productFamilyId, Component component ); - Allocation createComponentAllocation( String subscriptionId, String componentId, Allocation allocation ); + Allocation createComponentAllocation( String subscriptionId, int componentId, Allocation allocation ); List findComponentsByProductFamily( String productFamilyId ); - Component findComponentByIdAndProductFamily( String componentId, String productFamilyId ); + Component findComponentByIdAndProductFamily( int componentId, String productFamilyId ); List findSubscriptionComponents( String subscriptionId ); - SubscriptionComponent findSubscriptionComponentById( String subscriptionId, String componentId ); + SubscriptionComponent findSubscriptionComponentById( String subscriptionId, int componentId ); - Usage reportSubscriptionComponentUsage( String subscriptionId, String componentId, Usage usage ); + Usage reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ); Customer createCustomer( Customer customer ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 8797b34..83fffe5 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -3,6 +3,9 @@ import com.chargify.exceptions.ChargifyResponseErrorHandler; import com.chargify.exceptions.ResourceNotFoundException; import com.chargify.model.*; +import com.chargify.model.product.Product; +import com.chargify.model.product.ProductFamily; +import com.chargify.model.product.ProductPricePoint; import com.chargify.model.wrappers.*; import com.fasterxml.jackson.databind.SerializationFeature; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -20,6 +23,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; public final class ChargifyService implements Chargify @@ -143,6 +147,36 @@ public Product findProductByApiHandle( String apiHandle ) } } + @Override + public Set findProductPricePointsByProductId( String productId ) + { + try + { + return httpClient.getForObject( + "/products/" + productId + "/price_points.json", ProductPricePointsWrapper.class ) + .getPricePoints(); + } + catch( ResourceNotFoundException e ) + { + return null; + } + } + + @Override + public Set findComponentPricePoints( int componentId ) + { + try + { + return httpClient.getForObject( + "/components/" + componentId + "/price_points.json", ComponentPricePointsWrapper.class ) + .getPricePoints(); + } + catch( ResourceNotFoundException e ) + { + return null; + } + } + @Override public List findAllProducts() { @@ -288,6 +322,18 @@ public Subscription migrateSubscription( String subscriptionId, String productHa .getSubscription(); } + @Override + public Subscription migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ) + { + final Migration migration = new Migration(); + migration.setProductHandle( productHandle ); + migration.setPricePointHandle( pricePointHandle ); + + return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/migrations.json", + new MigrationWrapper( migration ), SubscriptionWrapper.class ) + .getSubscription(); + } + @Override public Subscription reactivateSubscription( String subscriptionId ) { @@ -316,20 +362,43 @@ public ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( Strin { return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/price_points.json", new ComponentPricePointUpdatesWrapper( - new ComponentPricePointUpdate( componentId, pricePointHandle ) ), + List.of( new ComponentPricePointUpdate( componentId, pricePointHandle ) ) ), + ComponentPricePointUpdatesWrapper.class ) + .getPricePointUpdates().get( 0 ); + } + + @Override + public List bulkUpdateSubscriptionComponentPricePoint( String subscriptionId, List items ) + { + return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/price_points.json", + new ComponentPricePointUpdatesWrapper( items ), ComponentPricePointUpdatesWrapper.class ) - .getPricePointUpdates()[ 0 ]; + .getPricePointUpdates(); } @Override public Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, boolean delayed ) { - final Subscription subscription = new Subscription(); - subscription.setProductHandle( productHandle ); - subscription.setProductChangeDelayed( delayed ); + final SubscriptionProductUpdate productUpdate = new SubscriptionProductUpdate(); + productUpdate.setProductHandle( productHandle ); + productUpdate.setChangeDelayed( delayed ); return httpClient.exchange( "/subscriptions/" + subscriptionId + ".json", HttpMethod.PUT, - new HttpEntity<>( new SubscriptionWrapper( subscription ) ), SubscriptionWrapper.class ) + new HttpEntity<>( new SubscriptionProductUpdateWrapper( productUpdate ) ), SubscriptionWrapper.class ) + .getBody() + .getSubscription(); + } + + @Override + public Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, String pricePointHandle, boolean delayed ) + { + final SubscriptionProductUpdate productUpdate = new SubscriptionProductUpdate(); + productUpdate.setProductHandle( productHandle ); + productUpdate.setChangeDelayed( delayed ); + productUpdate.setPricePointHandle( pricePointHandle ); + + return httpClient.exchange( "/subscriptions/" + subscriptionId + ".json", HttpMethod.PUT, + new HttpEntity<>( new SubscriptionProductUpdateWrapper( productUpdate ) ), SubscriptionWrapper.class ) .getBody() .getSubscription(); } @@ -404,7 +473,7 @@ public Component createComponent( String productFamilyId, Component component ) } @Override - public Allocation createComponentAllocation( String subscriptionId, String componentId, Allocation allocation ) + public Allocation createComponentAllocation( String subscriptionId, int componentId, Allocation allocation ) { return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/components/" + componentId + "/allocations.json", @@ -422,7 +491,7 @@ public List findComponentsByProductFamily( String productFamilyId ) } @Override - public Component findComponentByIdAndProductFamily( String componentId, String productFamilyId ) + public Component findComponentByIdAndProductFamily( int componentId, String productFamilyId ) { try { @@ -447,7 +516,7 @@ public List findSubscriptionComponents( String subscripti } @Override - public SubscriptionComponent findSubscriptionComponentById( String subscriptionId, String componentId ) + public SubscriptionComponent findSubscriptionComponentById( String subscriptionId, int componentId ) { try { @@ -463,7 +532,7 @@ public SubscriptionComponent findSubscriptionComponentById( String subscriptionI } @Override - public Usage reportSubscriptionComponentUsage( String subscriptionId, String componentId, Usage usage ) + public Usage reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ) { return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/components/" + componentId + "/usages.json", diff --git a/src/main/java/com/chargify/model/Component.java b/src/main/java/com/chargify/model/Component.java index c1b613a..531cb05 100644 --- a/src/main/java/com/chargify/model/Component.java +++ b/src/main/java/com/chargify/model/Component.java @@ -28,7 +28,7 @@ @JsonInclude( JsonInclude.Include.NON_NULL ) public class Component implements Serializable { - private String id; + private Integer id; private String name; diff --git a/src/main/java/com/chargify/model/ComponentPricePointUpdate.java b/src/main/java/com/chargify/model/ComponentPricePointUpdate.java index 1c84694..3c6ea83 100644 --- a/src/main/java/com/chargify/model/ComponentPricePointUpdate.java +++ b/src/main/java/com/chargify/model/ComponentPricePointUpdate.java @@ -2,38 +2,32 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +@Data public final class ComponentPricePointUpdate { - private final int componentId; - private final String pricePointHandle; + @JsonProperty( "component_id" ) + private int componentId; + @JsonProperty( "price_point" ) + private String pricePointHandle; + @JsonProperty( value = "message" ) + private String message; @JsonCreator - public ComponentPricePointUpdate( @JsonProperty( "component_id" ) int componentId, - @JsonProperty( "price_point" ) String pricePointHandle ) + public ComponentPricePointUpdate() { - this.componentId = componentId; - this.pricePointHandle = pricePointHandle; } - @JsonProperty( "component_id" ) - public int getComponentId() + public ComponentPricePointUpdate( int componentId, String pricePointHandle ) { - return componentId; + this( componentId, pricePointHandle, null ); } - @JsonProperty( "price_point" ) - public String getPricePointHandle() + public ComponentPricePointUpdate( int componentId, String pricePointHandle, String message ) { - return pricePointHandle; - } - - @Override - public String toString() - { - return "ComponentPricePointUpdate{" + - "componentId='" + componentId + '\'' + - ", pricePointHandle='" + pricePointHandle + '\'' + - '}'; + this.componentId = componentId; + this.pricePointHandle = pricePointHandle; + this.message = message; } } diff --git a/src/main/java/com/chargify/model/Migration.java b/src/main/java/com/chargify/model/Migration.java index d1e22da..18195d5 100644 --- a/src/main/java/com/chargify/model/Migration.java +++ b/src/main/java/com/chargify/model/Migration.java @@ -2,7 +2,9 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +@Data @JsonInclude( JsonInclude.Include.NON_NULL ) public class Migration { @@ -12,23 +14,6 @@ public class Migration @JsonProperty( "include_trial") private Integer includeTrial; - public String getProductHandle() - { - return productHandle; - } - - public void setProductHandle( String productHandle ) - { - this.productHandle = productHandle; - } - - public Integer getIncludeTrial() - { - return includeTrial; - } - - public void setIncludeTrial( Integer includeTrial ) - { - this.includeTrial = includeTrial; - } + @JsonProperty( "product_price_point_handle") + private String pricePointHandle; } diff --git a/src/main/java/com/chargify/model/Price.java b/src/main/java/com/chargify/model/Price.java index 25ff9d3..70ccd03 100644 --- a/src/main/java/com/chargify/model/Price.java +++ b/src/main/java/com/chargify/model/Price.java @@ -3,9 +3,11 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; import java.io.Serializable; +@AllArgsConstructor @JsonInclude( JsonInclude.Include.NON_NULL ) public final class Price implements Serializable { diff --git a/src/main/java/com/chargify/model/PricePoint.java b/src/main/java/com/chargify/model/PricePoint.java index 58dd693..fc697a5 100644 --- a/src/main/java/com/chargify/model/PricePoint.java +++ b/src/main/java/com/chargify/model/PricePoint.java @@ -1,63 +1,35 @@ package com.chargify.model; -import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@AllArgsConstructor +@Data public final class PricePoint implements Serializable { + private Integer id; + @JsonProperty( "default" ) + private boolean defaultPricePoint = false; private String name; private String handle; + @JsonProperty( "pricing_scheme" ) private String pricingScheme; + @JsonProperty( "component_id" ) + private String componentId; + @JsonProperty( "archived_at" ) + private String archivedAt; + @JsonProperty( "created_at" ) + private String createdAt; + @JsonProperty( "updated_at" ) + private String updatedAt; + @JsonProperty( "use_site_exchange_rate" ) + private Boolean useSiteExchangeRate; private Price[] prices; - - @JsonCreator - public PricePoint() - { - } - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - public String getHandle() - { - return handle; - } - - public void setHandle( String handle ) - { - this.handle = handle; - } - - @JsonProperty( "pricing_scheme" ) - public String getPricingScheme() - { - return pricingScheme; - } - - public void setPricingScheme( String pricingScheme ) - { - this.pricingScheme = pricingScheme; - } - - @JsonProperty( "prices" ) - public Price[] getPrices() - { - return prices; - } - - public void setPrices( Price[] prices ) - { - this.prices = prices; - } } diff --git a/src/main/java/com/chargify/model/PricePointIntervalUnit.java b/src/main/java/com/chargify/model/PricePointIntervalUnit.java new file mode 100644 index 0000000..32a7ffd --- /dev/null +++ b/src/main/java/com/chargify/model/PricePointIntervalUnit.java @@ -0,0 +1,6 @@ +package com.chargify.model; + +public enum PricePointIntervalUnit +{ + day, month +} diff --git a/src/main/java/com/chargify/model/Product.java b/src/main/java/com/chargify/model/Product.java deleted file mode 100644 index 64e63a7..0000000 --- a/src/main/java/com/chargify/model/Product.java +++ /dev/null @@ -1,390 +0,0 @@ -package com.chargify.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -import java.io.Serializable; -import java.util.Date; -import java.util.List; - -@JsonInclude( JsonInclude.Include.NON_NULL ) -public class Product implements Serializable -{ - private String id; - - private String name; - - private String handle; - - private String description; - - @JsonProperty( "accounting_code" ) - private String accountingCode; - - @JsonProperty( "request_credit_card" ) - private Boolean requestCreditCard; - - @JsonProperty( "expiration_interval" ) - private String expirationInterval; - - @JsonProperty( "expiration_interval_unit" ) - private String expirationIntervalUnit; - - @JsonProperty( "created_at" ) - private Date createdAt; - - @JsonProperty( "updated_at" ) - private Date updatedAt; - - @JsonProperty( "price_in_cents" ) - private int priceInCents; - - @JsonProperty( "interval" ) - private int recurringInterval; - - @JsonProperty( "interval_unit" ) - private IntervalUnit intervalUnit; - - @JsonProperty( "initial_charge_in_cents" ) - private String initialChargeInCents; - - @JsonProperty( "trial_price_in_cents" ) - private Integer trialPriceInCents; - - @JsonProperty( "trial_interval" ) - private Integer trialInterval; - - @JsonProperty( "trial_interval_unit" ) - private String trialIntervalUnit; - - @JsonProperty( "archived_at" ) - private Date archivedAt; - - @JsonProperty( "require_credit_card" ) - private Boolean requireCreditCard; - - @JsonProperty( "return_params" ) - private String returnParams; - - private Boolean taxable; - - @JsonProperty( "update_return_url" ) - private String updateReturnUrl; - - @JsonProperty( "initial_charge_after_trial" ) - private Boolean initialChargeAfterTrial; - - @JsonProperty( "version_number" ) - private Integer versionNumber; - - @JsonProperty( "update_return_params" ) - private String updateReturnParams; - - @JsonProperty( "product_family" ) - private ProductFamily productFamily; - - @JsonProperty( "public_signup_pages" ) - private List publicSignupPages; - - @JsonCreator - public Product( @JsonProperty( "name" ) final String name, - @JsonProperty( "price" ) final int priceInCents, - @JsonProperty( "interval" ) final int recurringInterval, - @JsonProperty( "interval_unit" ) final IntervalUnit intervalUnit ) - { - this.name = name; - this.priceInCents = priceInCents; - this.recurringInterval = recurringInterval; - this.intervalUnit = intervalUnit; - } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getName() - { - return name; - } - - public String getHandle() - { - return handle; - } - - public void setHandle( String handle ) - { - this.handle = handle; - } - - public String getDescription() - { - return description; - } - - public void setDescription( String description ) - { - this.description = description; - } - - public String getAccountingCode() - { - return accountingCode; - } - - public void setAccountingCode( String accountingCode ) - { - this.accountingCode = accountingCode; - } - - public Boolean getRequestCreditCard() - { - return requestCreditCard; - } - - public void setRequestCreditCard( Boolean requestCreditCard ) - { - this.requestCreditCard = requestCreditCard; - } - - public String getExpirationInterval() - { - return expirationInterval; - } - - public void setExpirationInterval( String expirationInterval ) - { - this.expirationInterval = expirationInterval; - } - - public String getExpirationIntervalUnit() - { - return expirationIntervalUnit; - } - - public void setExpirationIntervalUnit( String expirationIntervalUnit ) - { - this.expirationIntervalUnit = expirationIntervalUnit; - } - - public Date getCreatedAt() - { - return createdAt; - } - - public void setCreatedAt( Date createdAt ) - { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() - { - return updatedAt; - } - - public void setUpdatedAt( Date updatedAt ) - { - this.updatedAt = updatedAt; - } - - public Integer getPriceInCents() - { - return priceInCents; - } - - public int getRecurringInterval() - { - return recurringInterval; - } - - public IntervalUnit getIntervalUnit() - { - return intervalUnit; - } - - public String getInitialChargeInCents() - { - return initialChargeInCents; - } - - public void setInitialChargeInCents( String initialChargeInCents ) - { - this.initialChargeInCents = initialChargeInCents; - } - - public Integer getTrialInterval() - { - return trialInterval; - } - - public void setTrialInterval( Integer trialInterval ) - { - this.trialInterval = trialInterval; - } - - public String getTrialIntervalUnit() - { - return trialIntervalUnit; - } - - public void setTrialIntervalUnit( String trialIntervalUnit ) - { - this.trialIntervalUnit = trialIntervalUnit; - } - - public Date getArchivedAt() - { - return archivedAt; - } - - public void setArchivedAt( Date archivedAt ) - { - this.archivedAt = archivedAt; - } - - public Boolean getRequireCreditCard() - { - return requireCreditCard; - } - - public void setRequireCreditCard( Boolean requireCreditCard ) - { - this.requireCreditCard = requireCreditCard; - } - - public String getReturnParams() - { - return returnParams; - } - - public void setReturnParams( String returnParams ) - { - this.returnParams = returnParams; - } - - public Boolean getTaxable() - { - return taxable; - } - - public void setTaxable( Boolean taxable ) - { - this.taxable = taxable; - } - - public String getUpdateReturnUrl() - { - return updateReturnUrl; - } - - public void setUpdateReturnUrl( String updateReturnUrl ) - { - this.updateReturnUrl = updateReturnUrl; - } - - public Boolean getInitialChargeAfterTrial() - { - return initialChargeAfterTrial; - } - - public void setInitialChargeAfterTrial( Boolean initialChargeAfterTrial ) - { - this.initialChargeAfterTrial = initialChargeAfterTrial; - } - - public Integer getVersionNumber() - { - return versionNumber; - } - - public void setVersionNumber( Integer versionNumber ) - { - this.versionNumber = versionNumber; - } - - public String getUpdateReturnParams() - { - return updateReturnParams; - } - - public void setUpdateReturnParams( String updateReturnParams ) - { - this.updateReturnParams = updateReturnParams; - } - - public ProductFamily getProductFamily() - { - return productFamily; - } - - public void setProductFamily( ProductFamily productFamily ) - { - this.productFamily = productFamily; - } - - public List getPublicSignupPages() - { - return publicSignupPages; - } - - public void setPublicSignupPages( List publicSignupPages ) - { - this.publicSignupPages = publicSignupPages; - } - - public Integer getTrialPriceInCents() - { - return trialPriceInCents; - } - - public void setTrialPriceInCents( Integer trialPriceInCents ) - { - this.trialPriceInCents = trialPriceInCents; - } - - @Override - public String toString() - { - return "Product{" + - "id='" + id + '\'' + - ", name='" + name + '\'' + - ", handle='" + handle + '\'' + - ", description='" + description + '\'' + - ", accountingCode='" + accountingCode + '\'' + - ", requestCreditCard=" + requestCreditCard + - ", expirationInterval='" + expirationInterval + '\'' + - ", expirationIntervalUnit='" + expirationIntervalUnit + '\'' + - ", createdAt=" + createdAt + - ", updatedAt=" + updatedAt + - ", priceInCents=" + priceInCents + - ", recurringInterval=" + recurringInterval + - ", intervalUnit=" + intervalUnit + - ", initialChargeInCents='" + initialChargeInCents + '\'' + - ", trialPriceInCents=" + trialPriceInCents + - ", trialInterval=" + trialInterval + - ", trialIntervalUnit='" + trialIntervalUnit + '\'' + - ", archivedAt=" + archivedAt + - ", requireCreditCard=" + requireCreditCard + - ", returnParams='" + returnParams + '\'' + - ", taxable=" + taxable + - ", updateReturnUrl='" + updateReturnUrl + '\'' + - ", initialChargeAfterTrial=" + initialChargeAfterTrial + - ", versionNumber=" + versionNumber + - ", updateReturnParams='" + updateReturnParams + '\'' + - ", productFamily=" + productFamily + - ", publicSignupPages=" + publicSignupPages + - '}'; - } - - public enum IntervalUnit - { - month, day - } -} diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java index 8e5db04..5a2df95 100644 --- a/src/main/java/com/chargify/model/Subscription.java +++ b/src/main/java/com/chargify/model/Subscription.java @@ -18,6 +18,7 @@ package com.chargify.model; +import com.chargify.model.product.Product; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; diff --git a/src/main/java/com/chargify/model/SubscriptionComponent.java b/src/main/java/com/chargify/model/SubscriptionComponent.java index 7839b88..f9c4e97 100644 --- a/src/main/java/com/chargify/model/SubscriptionComponent.java +++ b/src/main/java/com/chargify/model/SubscriptionComponent.java @@ -20,14 +20,16 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; import java.io.Serializable; +@Data @JsonInclude( JsonInclude.Include.NON_NULL ) public class SubscriptionComponent implements Serializable { @JsonProperty( "component_id" ) - private String componentId; + private Integer componentId; @JsonProperty( "subscription_id" ) private String subscriptionId; @@ -51,93 +53,9 @@ public class SubscriptionComponent implements Serializable @JsonProperty( "allocated_quantity" ) private Integer allocatedQuantity; - public String getComponentId() - { - return componentId; - } + @JsonProperty( "price_point_id" ) + private Integer pricePointId; - public void setComponentId( String componentId ) - { - this.componentId = componentId; - } - - public String getSubscriptionId() - { - return subscriptionId; - } - - public void setSubscriptionId( String subscriptionId ) - { - this.subscriptionId = subscriptionId; - } - - public Integer getUnitBalance() - { - return unitBalance; - } - - public void setUnitBalance( Integer unitBalance ) - { - this.unitBalance = unitBalance; - } - - public String getPricingScheme() - { - return pricingScheme; - } - - public void setPricingScheme( String pricingScheme ) - { - this.pricingScheme = pricingScheme; - } - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - public ComponentKind getKind() - { - return kind; - } - - public void setKind( ComponentKind kind ) - { - this.kind = kind; - } - - public String getUnitName() - { - return unitName; - } - - public void setUnitName( String unitName ) - { - this.unitName = unitName; - } - - public Boolean getEnabled() - { - return enabled; - } - - public void setEnabled( Boolean enabled ) - { - this.enabled = enabled; - } - - public Integer getAllocatedQuantity() - { - return allocatedQuantity; - } - - public void setAllocatedQuantity( Integer allocatedQuantity ) - { - this.allocatedQuantity = allocatedQuantity; - } + @JsonProperty( "price_point_handle" ) + private String pricePointHandle; } diff --git a/src/main/java/com/chargify/model/SubscriptionProductUpdate.java b/src/main/java/com/chargify/model/SubscriptionProductUpdate.java new file mode 100644 index 0000000..e9c2853 --- /dev/null +++ b/src/main/java/com/chargify/model/SubscriptionProductUpdate.java @@ -0,0 +1,22 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.io.Serializable; + +@Data +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class SubscriptionProductUpdate implements Serializable +{ + + @JsonProperty( "product_handle" ) + private String productHandle; + + @JsonProperty( "product_change_delayed" ) + private boolean changeDelayed; + + @JsonProperty( "product_price_point_handle" ) + private String pricePointHandle; +} diff --git a/src/main/java/com/chargify/model/product/Product.java b/src/main/java/com/chargify/model/product/Product.java new file mode 100644 index 0000000..59170fc --- /dev/null +++ b/src/main/java/com/chargify/model/product/Product.java @@ -0,0 +1,111 @@ +package com.chargify.model.product; + +import com.chargify.model.PricePointIntervalUnit; +import com.chargify.model.PublicSignupPage; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +@Data +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class Product implements Serializable +{ + private String id; + + private String name; + + private String handle; + + private String description; + + @JsonProperty( "accounting_code" ) + private String accountingCode; + + @JsonProperty( "request_credit_card" ) + private Boolean requestCreditCard; + + @JsonProperty( "expiration_interval" ) + private String expirationInterval; + + @JsonProperty( "expiration_interval_unit" ) + private String expirationIntervalUnit; + + @JsonProperty( "created_at" ) + private Date createdAt; + + @JsonProperty( "updated_at" ) + private Date updatedAt; + + @JsonProperty( "price_in_cents" ) + private int priceInCents; + + @JsonProperty( "interval" ) + private int recurringInterval; + + @JsonProperty( "interval_unit" ) + private PricePointIntervalUnit intervalUnit; + + @JsonProperty( "initial_charge_in_cents" ) + private String initialChargeInCents; + + @JsonProperty( "trial_price_in_cents" ) + private Integer trialPriceInCents; + + @JsonProperty( "trial_interval" ) + private Integer trialInterval; + + @JsonProperty( "trial_interval_unit" ) + private PricePointIntervalUnit trialIntervalUnit; + + @JsonProperty( "archived_at" ) + private Date archivedAt; + + @JsonProperty( "require_credit_card" ) + private Boolean requireCreditCard; + + @JsonProperty( "return_params" ) + private String returnParams; + + @JsonProperty( "product_price_point_name" ) + private String productPricePointName; + + @JsonProperty( "product_price_point_handle" ) + private String productPricePointHandle; + + private Boolean taxable; + + @JsonProperty( "update_return_url" ) + private String updateReturnUrl; + + @JsonProperty( "initial_charge_after_trial" ) + private Boolean initialChargeAfterTrial; + + @JsonProperty( "version_number" ) + private Integer versionNumber; + + @JsonProperty( "update_return_params" ) + private String updateReturnParams; + + @JsonProperty( "product_family" ) + private ProductFamily productFamily; + + @JsonProperty( "public_signup_pages" ) + private List publicSignupPages; + + @JsonCreator + public Product( @JsonProperty( "name" ) final String name, + @JsonProperty( "price" ) final int priceInCents, + @JsonProperty( "interval" ) final int recurringInterval, + @JsonProperty( "interval_unit" ) final PricePointIntervalUnit intervalUnit ) + { + this.name = name; + this.priceInCents = priceInCents; + this.recurringInterval = recurringInterval; + this.intervalUnit = intervalUnit; + } +} diff --git a/src/main/java/com/chargify/model/ProductComponentItem.java b/src/main/java/com/chargify/model/product/ProductComponentItem.java similarity index 98% rename from src/main/java/com/chargify/model/ProductComponentItem.java rename to src/main/java/com/chargify/model/product/ProductComponentItem.java index 859a126..ee155a8 100644 --- a/src/main/java/com/chargify/model/ProductComponentItem.java +++ b/src/main/java/com/chargify/model/product/ProductComponentItem.java @@ -16,7 +16,7 @@ * ******************************************************************************************************************** */ -package com.chargify.model; +package com.chargify.model.product; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/src/main/java/com/chargify/model/ProductFamily.java b/src/main/java/com/chargify/model/product/ProductFamily.java similarity index 97% rename from src/main/java/com/chargify/model/ProductFamily.java rename to src/main/java/com/chargify/model/product/ProductFamily.java index 3174306..9986c2f 100644 --- a/src/main/java/com/chargify/model/ProductFamily.java +++ b/src/main/java/com/chargify/model/product/ProductFamily.java @@ -1,4 +1,4 @@ -package com.chargify.model; +package com.chargify.model.product; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/src/main/java/com/chargify/model/product/ProductPricePoint.java b/src/main/java/com/chargify/model/product/ProductPricePoint.java new file mode 100644 index 0000000..48464bc --- /dev/null +++ b/src/main/java/com/chargify/model/product/ProductPricePoint.java @@ -0,0 +1,53 @@ +package com.chargify.model.product; + +import com.chargify.model.PricePointIntervalUnit; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@AllArgsConstructor +@Data +public class ProductPricePoint implements Serializable +{ + private Integer id; + private String name; + private String handle; + @JsonProperty( "price_in_cents" ) + private Integer priceInCents; + private Integer interval; + @JsonProperty( "interval_unit" ) + private PricePointIntervalUnit intervalUnit; + @JsonProperty( "trial_price_in_cents" ) + private Integer trialPriceInCents; + @JsonProperty( "trial_interval" ) + private Integer trialInterval; + @JsonProperty( "trial_interval_unit" ) + private PricePointIntervalUnit trialIntervalUnit; + @JsonProperty( "trial_type" ) + private String trialType; + @JsonProperty( "initial_charge_in_cents" ) + private Integer initialChargeInCents; + @JsonProperty( "initial_charge_after_trial" ) + private boolean initialChargeAfterTrial = false; + @JsonProperty( "expiration_interval" ) + private Integer expirationInterval; + @JsonProperty( "expiration_interval_unit" ) + private String expirationIntervalUnit; + @JsonProperty( "product_id" ) + private String productId; + @JsonProperty( "archived_at" ) + private String archivedAt; + @JsonProperty( "created_at" ) + private String createdAt; + @JsonProperty( "updated_at" ) + private String updatedAt; + @JsonProperty( "use_site_exchange_rate" ) + private Boolean useSiteExchangeRate; + +} diff --git a/src/main/java/com/chargify/model/wrappers/ComponentPricePointUpdatesWrapper.java b/src/main/java/com/chargify/model/wrappers/ComponentPricePointUpdatesWrapper.java index 1a7ade9..21c0e90 100644 --- a/src/main/java/com/chargify/model/wrappers/ComponentPricePointUpdatesWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/ComponentPricePointUpdatesWrapper.java @@ -3,31 +3,29 @@ import com.chargify.model.ComponentPricePointUpdate; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.Data; +import lombok.Setter; import java.util.Arrays; +import java.util.List; +@Data +@Setter( AccessLevel.NONE ) public final class ComponentPricePointUpdatesWrapper { - private final ComponentPricePointUpdate[] pricePointUpdates; + @JsonProperty( "components" ) + private final List pricePointUpdates; @JsonCreator public ComponentPricePointUpdatesWrapper( @JsonProperty( "components" ) ComponentPricePointUpdate... pricePointUpdates ) { - this.pricePointUpdates = pricePointUpdates; + this.pricePointUpdates = Arrays.asList( pricePointUpdates ); } - @JsonProperty( "components" ) - public ComponentPricePointUpdate[] getPricePointUpdates() + public ComponentPricePointUpdatesWrapper( List pricePointUpdates ) { - return pricePointUpdates; - } - - @Override - public String toString() - { - return "ComponentPricePointUpdatesWrapper{" + - "pricePointUpdates=" + Arrays.toString( pricePointUpdates ) + - '}'; + this.pricePointUpdates = pricePointUpdates; } } diff --git a/src/main/java/com/chargify/model/wrappers/ComponentPricePointsWrapper.java b/src/main/java/com/chargify/model/wrappers/ComponentPricePointsWrapper.java new file mode 100644 index 0000000..d88db76 --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/ComponentPricePointsWrapper.java @@ -0,0 +1,22 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.PricePoint; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.ToString; + +import java.util.Set; + +@ToString +public final class ComponentPricePointsWrapper +{ + @Getter + private final Set pricePoints; + + @JsonCreator + public ComponentPricePointsWrapper( @JsonProperty( "price_points" ) Set pricePoints ) + { + this.pricePoints = pricePoints; + } +} diff --git a/src/main/java/com/chargify/model/wrappers/ProductFamilyWrapper.java b/src/main/java/com/chargify/model/wrappers/ProductFamilyWrapper.java index 76a281f..d3af269 100644 --- a/src/main/java/com/chargify/model/wrappers/ProductFamilyWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/ProductFamilyWrapper.java @@ -1,6 +1,6 @@ package com.chargify.model.wrappers; -import com.chargify.model.ProductFamily; +import com.chargify.model.product.ProductFamily; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/com/chargify/model/wrappers/ProductPricePointsWrapper.java b/src/main/java/com/chargify/model/wrappers/ProductPricePointsWrapper.java new file mode 100644 index 0000000..f365730 --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/ProductPricePointsWrapper.java @@ -0,0 +1,22 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.product.ProductPricePoint; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.ToString; + +import java.util.Set; + +@ToString +public final class ProductPricePointsWrapper +{ + @Getter + private final Set pricePoints; + + @JsonCreator + public ProductPricePointsWrapper( @JsonProperty( "price_points" ) Set pricePoints ) + { + this.pricePoints = pricePoints; + } +} diff --git a/src/main/java/com/chargify/model/wrappers/ProductWrapper.java b/src/main/java/com/chargify/model/wrappers/ProductWrapper.java index 31651c5..09e1482 100644 --- a/src/main/java/com/chargify/model/wrappers/ProductWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/ProductWrapper.java @@ -1,6 +1,6 @@ package com.chargify.model.wrappers; -import com.chargify.model.Product; +import com.chargify.model.product.Product; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/com/chargify/model/wrappers/SubscriptionProductUpdateWrapper.java b/src/main/java/com/chargify/model/wrappers/SubscriptionProductUpdateWrapper.java new file mode 100644 index 0000000..4a66e2c --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/SubscriptionProductUpdateWrapper.java @@ -0,0 +1,19 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.SubscriptionProductUpdate; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +public final class SubscriptionProductUpdateWrapper +{ + @Getter + private final SubscriptionProductUpdate subscription; + + @JsonCreator + public SubscriptionProductUpdateWrapper( @JsonProperty( "subscription" ) + SubscriptionProductUpdate wrappedSubscription ) + { + this.subscription = wrappedSubscription; + } +} diff --git a/src/test/java/com/chargify/ComponentsTest.java b/src/test/java/com/chargify/ComponentsTest.java index 9529b25..61e71dd 100644 --- a/src/test/java/com/chargify/ComponentsTest.java +++ b/src/test/java/com/chargify/ComponentsTest.java @@ -2,7 +2,7 @@ import com.chargify.model.Component; import com.chargify.model.ComponentKind; -import com.chargify.model.ProductFamily; +import com.chargify.model.product.ProductFamily; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; diff --git a/src/test/java/com/chargify/ProductFamiliesTest.java b/src/test/java/com/chargify/ProductFamiliesTest.java index 3e3083c..1dcffe5 100644 --- a/src/test/java/com/chargify/ProductFamiliesTest.java +++ b/src/test/java/com/chargify/ProductFamiliesTest.java @@ -1,7 +1,7 @@ package com.chargify; import com.chargify.exceptions.ApiHandleNotUniqueException; -import com.chargify.model.ProductFamily; +import com.chargify.model.product.ProductFamily; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; diff --git a/src/test/java/com/chargify/ProductsTest.java b/src/test/java/com/chargify/ProductsTest.java index a211308..1d9cb17 100644 --- a/src/test/java/com/chargify/ProductsTest.java +++ b/src/test/java/com/chargify/ProductsTest.java @@ -1,8 +1,9 @@ package com.chargify; import com.chargify.exceptions.ChargifyException; -import com.chargify.model.Product; -import com.chargify.model.ProductFamily; +import com.chargify.model.PricePointIntervalUnit; +import com.chargify.model.product.Product; +import com.chargify.model.product.ProductFamily; import org.junit.AfterClass; import org.junit.Assert; import org.junit.BeforeClass; @@ -23,9 +24,9 @@ public static void setup() productUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), new Product( randomName(), 0, 1, - Product.IntervalUnit.month ) ); + PricePointIntervalUnit.month ) ); - final Product productWithHandle = new Product( randomName(), 0, 1, Product.IntervalUnit.month ); + final Product productWithHandle = new Product( randomName(), 0, 1, PricePointIntervalUnit.month ); productWithHandle.setHandle( randomName() ); productWithHandleUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), productWithHandle ); } diff --git a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java index 872c119..092079f 100644 --- a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java +++ b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java @@ -2,8 +2,9 @@ import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; -import com.chargify.model.Product; -import com.chargify.model.ProductFamily; +import com.chargify.model.PricePointIntervalUnit; +import com.chargify.model.product.Product; +import com.chargify.model.product.ProductFamily; import com.chargify.model.Subscription; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -25,12 +26,12 @@ public static void setup() { productFamily = chargify.createProductFamily( new ProductFamily( randomName() ) ); - final Product initialProduct = new Product( randomName(), 0, 1, Product.IntervalUnit.month ); + final Product initialProduct = new Product( randomName(), 0, 1, PricePointIntervalUnit.month ); initialProduct.setRequestCreditCard( false ); initialProduct.setRequireCreditCard( false ); SubscriptionDelayedChangeTest.initialProduct = chargify.createProduct( productFamily.getId(), initialProduct ); - final Product targetProduct = new Product( randomName(), 0, 1, Product.IntervalUnit.month ); + final Product targetProduct = new Product( randomName(), 0, 1, PricePointIntervalUnit.month ); targetProduct.setRequestCreditCard( false ); targetProduct.setRequireCreditCard( false ); targetProduct.setHandle( randomName() ); diff --git a/src/test/java/com/chargify/SubscriptionsTest.java b/src/test/java/com/chargify/SubscriptionsTest.java index 78e927f..6fc2a68 100644 --- a/src/test/java/com/chargify/SubscriptionsTest.java +++ b/src/test/java/com/chargify/SubscriptionsTest.java @@ -2,8 +2,9 @@ import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; -import com.chargify.model.Product; -import com.chargify.model.ProductFamily; +import com.chargify.model.PricePointIntervalUnit; +import com.chargify.model.product.Product; +import com.chargify.model.product.ProductFamily; import com.chargify.model.Subscription; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -31,7 +32,7 @@ public static void setup() { productFamilyUnderTest = chargify.createProductFamily( new ProductFamily( randomName() ) ); - final Product product = new Product( randomName(), 0, 1, Product.IntervalUnit.month ); + final Product product = new Product( randomName(), 0, 1, PricePointIntervalUnit.month ); product.setRequestCreditCard( false ); product.setRequireCreditCard( false ); productUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), product ); From e90811b242aa0f1f7e421d8e19d4e5b838143c14 Mon Sep 17 00:00:00 2001 From: kao78 Date: Mon, 11 Jan 2021 17:12:22 +0200 Subject: [PATCH 12/58] Added method for retrieval of component with its price points --- src/main/java/com/chargify/Chargify.java | 2 ++ .../java/com/chargify/ChargifyService.java | 7 +++++++ .../model/ComponentWithPricePoints.java | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/main/java/com/chargify/model/ComponentWithPricePoints.java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index c6bd66c..2530be2 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -86,6 +86,8 @@ ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subsc Component findComponentByIdAndProductFamily( int componentId, String productFamilyId ); + ComponentWithPricePoints findComponentWithPricePointsByIdAndProductFamily( int componentId, String productFamilyId ); + List findSubscriptionComponents( String subscriptionId ); SubscriptionComponent findSubscriptionComponentById( String subscriptionId, int componentId ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 83fffe5..75ae7f1 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -506,6 +506,13 @@ public Component findComponentByIdAndProductFamily( int componentId, String prod } } + @Override + public ComponentWithPricePoints findComponentWithPricePointsByIdAndProductFamily( int componentId, String productFamilyId ) + { + return new ComponentWithPricePoints( findComponentByIdAndProductFamily( componentId, productFamilyId ), + findComponentPricePoints( componentId ) ); + } + @Override public List findSubscriptionComponents( String subscriptionId ) { diff --git a/src/main/java/com/chargify/model/ComponentWithPricePoints.java b/src/main/java/com/chargify/model/ComponentWithPricePoints.java new file mode 100644 index 0000000..9a7d5b0 --- /dev/null +++ b/src/main/java/com/chargify/model/ComponentWithPricePoints.java @@ -0,0 +1,19 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.util.Set; + +@NoArgsConstructor +@AllArgsConstructor +@Data +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class ComponentWithPricePoints implements Serializable +{ + private Component component; + private Set pricePoints; +} From a00f700bdd1a566ca85031fce602ec1eba2a5d7f Mon Sep 17 00:00:00 2001 From: kao78 Date: Thu, 14 Jan 2021 12:21:10 +0200 Subject: [PATCH 13/58] Added method for component allocation preview --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 2 + .../java/com/chargify/ChargifyService.java | 9 ++ .../com/chargify/model/AllocationPreview.java | 113 ++++++++++++++++++ .../wrappers/AllocationPreviewWrapper.java | 18 +++ 5 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/chargify/model/AllocationPreview.java create mode 100644 src/main/java/com/chargify/model/wrappers/AllocationPreviewWrapper.java diff --git a/pom.xml b/pom.xml index c6c73e7..73873e4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.8.0 + 0.9.0 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 2530be2..78376a9 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -82,6 +82,8 @@ ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subsc Allocation createComponentAllocation( String subscriptionId, int componentId, Allocation allocation ); + AllocationPreview previewComponentAllocation( String subscriptionId, int componentId, int quantity ); + List findComponentsByProductFamily( String productFamilyId ); Component findComponentByIdAndProductFamily( int componentId, String productFamilyId ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 75ae7f1..ec4ebb5 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -481,6 +481,15 @@ public Allocation createComponentAllocation( String subscriptionId, int componen .getAllocation(); } + @Override + public AllocationPreview previewComponentAllocation( String subscriptionId, int componentId, int quantity ) + { + return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/allocations/preview.json", + Map.of( "allocations", List.of( new AllocationPreview.ComponentAllocationDTO( componentId, quantity ) ) ), + AllocationPreviewWrapper.class ) + .getAllocationPreview(); + } + @Override public List findComponentsByProductFamily( String productFamilyId ) { diff --git a/src/main/java/com/chargify/model/AllocationPreview.java b/src/main/java/com/chargify/model/AllocationPreview.java new file mode 100644 index 0000000..c4ced35 --- /dev/null +++ b/src/main/java/com/chargify/model/AllocationPreview.java @@ -0,0 +1,113 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; +import java.util.List; + +@NoArgsConstructor +@Data +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class AllocationPreview +{ + @JsonProperty( "start_date" ) + private LocalDateTime startDate; + @JsonProperty( "end_date" ) + private LocalDateTime endDate; + @JsonProperty( "period_type" ) + private String periodType; + @JsonProperty( "total_in_cents" ) + private Integer totalInCents; + @JsonProperty( "total_discount_in_cents" ) + private Integer totalDiscountInCents; + @JsonProperty( "total_tax_in_cents" ) + private Integer totalTaxInCents; + @JsonProperty( "subtotal_in_cents" ) + private Integer subtotalInCents; + @JsonProperty( "existing_balance_in_cents" ) + private Integer existingBalanceInCents; + @JsonProperty( "direction" ) + private String direction; + @JsonProperty( "proration_scheme" ) + private String prorationScheme; + @JsonProperty( "line_items" ) + private List lineItems; + @JsonProperty( "allocations" ) + private List allocations; + + + @NoArgsConstructor + @Data + @JsonInclude( JsonInclude.Include.NON_NULL ) + public static class LineItem + { + @JsonProperty( "transaction_type" ) + private String transactionType; + private ComponentKind kind; + @JsonProperty( "amount_in_cents" ) + private Integer amountInCents; + private String memo; + @JsonProperty( "discount_amount_in_cents" ) + private Integer discountAmountInCents; + @JsonProperty( "taxable_amount_in_cents" ) + private Integer taxable_amount_in_cents; + @JsonProperty( "component_id" ) + private Integer componentId; + @JsonProperty( "component_handle" ) + private String componentHandle; + @JsonProperty( "accrue_charge" ) + private Boolean accrueCharge; + @JsonProperty( "upgrade_charge" ) + private String upgradeCharge; + } + + @NoArgsConstructor + @Data + @JsonInclude( JsonInclude.Include.NON_NULL ) + public static class Allocation + { + @JsonProperty( "allocation_id" ) + private String allocationId; + @JsonProperty( "component_id" ) + private Integer componentId; + @JsonProperty( "subscription_id" ) + private Integer subscriptionId; + private Integer quantity; + @JsonProperty( "previous_quantity" ) + private Integer previousQuantity; + private String memo; + private LocalDateTime timestamp; + @JsonProperty( "proration_upgrade_scheme" ) + private String prorationUpgradeScheme; + @JsonProperty( "proration_downgrade_scheme" ) + private String prorationDowngradeScheme; + @JsonProperty( "price_point_id" ) + private Integer pricePointId; + @JsonProperty( "previous_price_point_id" ) + private Integer previousPricePointId; + @JsonProperty( "component_handle" ) + private String componentHandle; + @JsonProperty( "accrue_charge" ) + private Boolean accrueCharge; + @JsonProperty( "upgrade_charge" ) + private String upgradeCharge; + @JsonProperty( "downgrade_credit" ) + private String downgradeCredit; + @JsonProperty( "created_at" ) + private LocalDateTime createdAt; + } + + @AllArgsConstructor + @Getter + public static class ComponentAllocationDTO + { + @JsonProperty( "component_id" ) + private final int componentId; + private final int quantity; + } +} diff --git a/src/main/java/com/chargify/model/wrappers/AllocationPreviewWrapper.java b/src/main/java/com/chargify/model/wrappers/AllocationPreviewWrapper.java new file mode 100644 index 0000000..61528ee --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/AllocationPreviewWrapper.java @@ -0,0 +1,18 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.AllocationPreview; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +public final class AllocationPreviewWrapper +{ + @Getter + private final AllocationPreview allocationPreview; + + @JsonCreator + public AllocationPreviewWrapper( @JsonProperty( "allocation_preview" ) AllocationPreview allocationPreview ) + { + this.allocationPreview = allocationPreview; + } +} From 3719c36107a8453cb26eb3c4798bc1c4f19f086e Mon Sep 17 00:00:00 2001 From: kao78 Date: Tue, 23 Feb 2021 16:36:08 +0200 Subject: [PATCH 14/58] [BKNDLSS-24139] Add information about the next billing plan --- .../java/com/chargify/model/BaseProduct.java | 97 +++++ .../java/com/chargify/model/IntervalUnit.java | 6 + src/main/java/com/chargify/model/Product.java | 382 +----------------- .../java/com/chargify/model/Subscription.java | 8 +- .../chargify/model/SubscriptionProduct.java | 34 ++ src/test/java/com/chargify/ProductsTest.java | 5 +- .../SubscriptionDelayedChangeTest.java | 5 +- .../java/com/chargify/SubscriptionsTest.java | 3 +- 8 files changed, 167 insertions(+), 373 deletions(-) create mode 100644 src/main/java/com/chargify/model/BaseProduct.java create mode 100644 src/main/java/com/chargify/model/IntervalUnit.java create mode 100644 src/main/java/com/chargify/model/SubscriptionProduct.java diff --git a/src/main/java/com/chargify/model/BaseProduct.java b/src/main/java/com/chargify/model/BaseProduct.java new file mode 100644 index 0000000..4b3772f --- /dev/null +++ b/src/main/java/com/chargify/model/BaseProduct.java @@ -0,0 +1,97 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +@NoArgsConstructor +@Data +@ToString +@JsonInclude( JsonInclude.Include.NON_NULL ) +public abstract class BaseProduct implements Serializable +{ + protected String id; + + protected String name; + + protected String handle; + + protected String description; + + @JsonProperty( "accounting_code" ) + protected String accountingCode; + + @JsonProperty( "request_credit_card" ) + protected Boolean requestCreditCard; + + @JsonProperty( "expiration_interval" ) + protected String expirationInterval; + + @JsonProperty( "expiration_interval_unit" ) + protected String expirationIntervalUnit; + + @JsonProperty( "created_at" ) + protected Date createdAt; + + @JsonProperty( "updated_at" ) + protected Date updatedAt; + + @JsonProperty( "price_in_cents" ) + protected int priceInCents; + + @JsonProperty( "interval" ) + protected int recurringInterval; + + @JsonProperty( "interval_unit" ) + protected IntervalUnit intervalUnit; + + @JsonProperty( "initial_charge_in_cents" ) + protected String initialChargeInCents; + + @JsonProperty( "trial_price_in_cents" ) + protected Integer trialPriceInCents; + + @JsonProperty( "trial_interval" ) + protected Integer trialInterval; + + @JsonProperty( "trial_interval_unit" ) + protected String trialIntervalUnit; + + @JsonProperty( "require_credit_card" ) + protected Boolean requireCreditCard; + + @JsonProperty( "return_params" ) + protected String returnParams; + + protected Boolean taxable; + + @JsonProperty( "update_return_url" ) + protected String updateReturnUrl; + + @JsonProperty( "tax_code" ) + protected String taxCode; + + @JsonProperty( "initial_charge_after_trial" ) + protected Boolean initialChargeAfterTrial; + + @JsonProperty( "version_number" ) + protected Integer versionNumber; + + @JsonProperty( "update_return_params" ) + protected String updateReturnParams; + + @JsonProperty( "product_family" ) + protected ProductFamily productFamily; + + @JsonProperty( "public_signup_pages" ) + protected List publicSignupPages; + + @JsonProperty( "product_price_point_name" ) + protected String productPricePointName; +} diff --git a/src/main/java/com/chargify/model/IntervalUnit.java b/src/main/java/com/chargify/model/IntervalUnit.java new file mode 100644 index 0000000..2df9682 --- /dev/null +++ b/src/main/java/com/chargify/model/IntervalUnit.java @@ -0,0 +1,6 @@ +package com.chargify.model; + +public enum IntervalUnit +{ + month, day +} diff --git a/src/main/java/com/chargify/model/Product.java b/src/main/java/com/chargify/model/Product.java index 64e63a7..548734f 100644 --- a/src/main/java/com/chargify/model/Product.java +++ b/src/main/java/com/chargify/model/Product.java @@ -3,89 +3,26 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import java.io.Serializable; -import java.util.Date; -import java.util.List; +@Data +@ToString +@EqualsAndHashCode( callSuper = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) -public class Product implements Serializable +public class Product extends BaseProduct implements Serializable { - private String id; - - private String name; - - private String handle; - - private String description; - - @JsonProperty( "accounting_code" ) - private String accountingCode; - - @JsonProperty( "request_credit_card" ) - private Boolean requestCreditCard; - - @JsonProperty( "expiration_interval" ) - private String expirationInterval; - - @JsonProperty( "expiration_interval_unit" ) - private String expirationIntervalUnit; - - @JsonProperty( "created_at" ) - private Date createdAt; - - @JsonProperty( "updated_at" ) - private Date updatedAt; - - @JsonProperty( "price_in_cents" ) - private int priceInCents; - - @JsonProperty( "interval" ) - private int recurringInterval; - - @JsonProperty( "interval_unit" ) - private IntervalUnit intervalUnit; - - @JsonProperty( "initial_charge_in_cents" ) - private String initialChargeInCents; - - @JsonProperty( "trial_price_in_cents" ) - private Integer trialPriceInCents; - - @JsonProperty( "trial_interval" ) - private Integer trialInterval; - - @JsonProperty( "trial_interval_unit" ) - private String trialIntervalUnit; - - @JsonProperty( "archived_at" ) - private Date archivedAt; - - @JsonProperty( "require_credit_card" ) - private Boolean requireCreditCard; - - @JsonProperty( "return_params" ) - private String returnParams; - - private Boolean taxable; - - @JsonProperty( "update_return_url" ) - private String updateReturnUrl; - - @JsonProperty( "initial_charge_after_trial" ) - private Boolean initialChargeAfterTrial; - - @JsonProperty( "version_number" ) - private Integer versionNumber; - - @JsonProperty( "update_return_params" ) - private String updateReturnParams; - - @JsonProperty( "product_family" ) - private ProductFamily productFamily; - - @JsonProperty( "public_signup_pages" ) - private List publicSignupPages; + @JsonProperty( "request_billing_address" ) + private Boolean requestBillingAddress; + @JsonProperty( "require_billing_address" ) + private Boolean requireBillingAddress; + @JsonProperty( "require_shipping_address" ) + private Boolean requireShippingAddress; + @JsonProperty( "default_product_price_point_id" ) + private Integer defaultProductPricePointId; @JsonCreator public Product( @JsonProperty( "name" ) final String name, @@ -98,293 +35,4 @@ public Product( @JsonProperty( "name" ) final String name, this.recurringInterval = recurringInterval; this.intervalUnit = intervalUnit; } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getName() - { - return name; - } - - public String getHandle() - { - return handle; - } - - public void setHandle( String handle ) - { - this.handle = handle; - } - - public String getDescription() - { - return description; - } - - public void setDescription( String description ) - { - this.description = description; - } - - public String getAccountingCode() - { - return accountingCode; - } - - public void setAccountingCode( String accountingCode ) - { - this.accountingCode = accountingCode; - } - - public Boolean getRequestCreditCard() - { - return requestCreditCard; - } - - public void setRequestCreditCard( Boolean requestCreditCard ) - { - this.requestCreditCard = requestCreditCard; - } - - public String getExpirationInterval() - { - return expirationInterval; - } - - public void setExpirationInterval( String expirationInterval ) - { - this.expirationInterval = expirationInterval; - } - - public String getExpirationIntervalUnit() - { - return expirationIntervalUnit; - } - - public void setExpirationIntervalUnit( String expirationIntervalUnit ) - { - this.expirationIntervalUnit = expirationIntervalUnit; - } - - public Date getCreatedAt() - { - return createdAt; - } - - public void setCreatedAt( Date createdAt ) - { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() - { - return updatedAt; - } - - public void setUpdatedAt( Date updatedAt ) - { - this.updatedAt = updatedAt; - } - - public Integer getPriceInCents() - { - return priceInCents; - } - - public int getRecurringInterval() - { - return recurringInterval; - } - - public IntervalUnit getIntervalUnit() - { - return intervalUnit; - } - - public String getInitialChargeInCents() - { - return initialChargeInCents; - } - - public void setInitialChargeInCents( String initialChargeInCents ) - { - this.initialChargeInCents = initialChargeInCents; - } - - public Integer getTrialInterval() - { - return trialInterval; - } - - public void setTrialInterval( Integer trialInterval ) - { - this.trialInterval = trialInterval; - } - - public String getTrialIntervalUnit() - { - return trialIntervalUnit; - } - - public void setTrialIntervalUnit( String trialIntervalUnit ) - { - this.trialIntervalUnit = trialIntervalUnit; - } - - public Date getArchivedAt() - { - return archivedAt; - } - - public void setArchivedAt( Date archivedAt ) - { - this.archivedAt = archivedAt; - } - - public Boolean getRequireCreditCard() - { - return requireCreditCard; - } - - public void setRequireCreditCard( Boolean requireCreditCard ) - { - this.requireCreditCard = requireCreditCard; - } - - public String getReturnParams() - { - return returnParams; - } - - public void setReturnParams( String returnParams ) - { - this.returnParams = returnParams; - } - - public Boolean getTaxable() - { - return taxable; - } - - public void setTaxable( Boolean taxable ) - { - this.taxable = taxable; - } - - public String getUpdateReturnUrl() - { - return updateReturnUrl; - } - - public void setUpdateReturnUrl( String updateReturnUrl ) - { - this.updateReturnUrl = updateReturnUrl; - } - - public Boolean getInitialChargeAfterTrial() - { - return initialChargeAfterTrial; - } - - public void setInitialChargeAfterTrial( Boolean initialChargeAfterTrial ) - { - this.initialChargeAfterTrial = initialChargeAfterTrial; - } - - public Integer getVersionNumber() - { - return versionNumber; - } - - public void setVersionNumber( Integer versionNumber ) - { - this.versionNumber = versionNumber; - } - - public String getUpdateReturnParams() - { - return updateReturnParams; - } - - public void setUpdateReturnParams( String updateReturnParams ) - { - this.updateReturnParams = updateReturnParams; - } - - public ProductFamily getProductFamily() - { - return productFamily; - } - - public void setProductFamily( ProductFamily productFamily ) - { - this.productFamily = productFamily; - } - - public List getPublicSignupPages() - { - return publicSignupPages; - } - - public void setPublicSignupPages( List publicSignupPages ) - { - this.publicSignupPages = publicSignupPages; - } - - public Integer getTrialPriceInCents() - { - return trialPriceInCents; - } - - public void setTrialPriceInCents( Integer trialPriceInCents ) - { - this.trialPriceInCents = trialPriceInCents; - } - - @Override - public String toString() - { - return "Product{" + - "id='" + id + '\'' + - ", name='" + name + '\'' + - ", handle='" + handle + '\'' + - ", description='" + description + '\'' + - ", accountingCode='" + accountingCode + '\'' + - ", requestCreditCard=" + requestCreditCard + - ", expirationInterval='" + expirationInterval + '\'' + - ", expirationIntervalUnit='" + expirationIntervalUnit + '\'' + - ", createdAt=" + createdAt + - ", updatedAt=" + updatedAt + - ", priceInCents=" + priceInCents + - ", recurringInterval=" + recurringInterval + - ", intervalUnit=" + intervalUnit + - ", initialChargeInCents='" + initialChargeInCents + '\'' + - ", trialPriceInCents=" + trialPriceInCents + - ", trialInterval=" + trialInterval + - ", trialIntervalUnit='" + trialIntervalUnit + '\'' + - ", archivedAt=" + archivedAt + - ", requireCreditCard=" + requireCreditCard + - ", returnParams='" + returnParams + '\'' + - ", taxable=" + taxable + - ", updateReturnUrl='" + updateReturnUrl + '\'' + - ", initialChargeAfterTrial=" + initialChargeAfterTrial + - ", versionNumber=" + versionNumber + - ", updateReturnParams='" + updateReturnParams + '\'' + - ", productFamily=" + productFamily + - ", publicSignupPages=" + publicSignupPages + - '}'; - } - - public enum IntervalUnit - { - month, day - } } diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java index 8e5db04..ac0c3f2 100644 --- a/src/main/java/com/chargify/model/Subscription.java +++ b/src/main/java/com/chargify/model/Subscription.java @@ -138,7 +138,7 @@ public class Subscription implements Serializable private Customer customer; - private Product product; + private SubscriptionProduct product; @JsonProperty( "credit_card" ) private CreditCard creditCard; @@ -155,6 +155,12 @@ public class Subscription implements Serializable @JsonProperty( "next_product_id" ) private String nextProductId; + @JsonProperty( "next_product_handle" ) + private String nextProductHandle; + + @JsonProperty( "next_product_price_point_id" ) + private String nextProductPricePointId; + @JsonProperty( "coupon_use_count" ) private Integer couponUseCount; diff --git a/src/main/java/com/chargify/model/SubscriptionProduct.java b/src/main/java/com/chargify/model/SubscriptionProduct.java new file mode 100644 index 0000000..9ea53e8 --- /dev/null +++ b/src/main/java/com/chargify/model/SubscriptionProduct.java @@ -0,0 +1,34 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +@Data +@ToString +@EqualsAndHashCode( callSuper = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class SubscriptionProduct extends BaseProduct implements Serializable +{ + @JsonProperty( "archived_at" ) + private Date archivedAt; + + @JsonCreator + public SubscriptionProduct( @JsonProperty( "name" ) final String name, + @JsonProperty( "price" ) final int priceInCents, + @JsonProperty( "interval" ) final int recurringInterval, + @JsonProperty( "interval_unit" ) final IntervalUnit intervalUnit ) + { + this.name = name; + this.priceInCents = priceInCents; + this.recurringInterval = recurringInterval; + this.intervalUnit = intervalUnit; + } +} diff --git a/src/test/java/com/chargify/ProductsTest.java b/src/test/java/com/chargify/ProductsTest.java index a211308..4b57d52 100644 --- a/src/test/java/com/chargify/ProductsTest.java +++ b/src/test/java/com/chargify/ProductsTest.java @@ -1,6 +1,7 @@ package com.chargify; import com.chargify.exceptions.ChargifyException; +import com.chargify.model.IntervalUnit; import com.chargify.model.Product; import com.chargify.model.ProductFamily; import org.junit.AfterClass; @@ -23,9 +24,9 @@ public static void setup() productUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), new Product( randomName(), 0, 1, - Product.IntervalUnit.month ) ); + IntervalUnit.month ) ); - final Product productWithHandle = new Product( randomName(), 0, 1, Product.IntervalUnit.month ); + final Product productWithHandle = new Product( randomName(), 0, 1, IntervalUnit.month ); productWithHandle.setHandle( randomName() ); productWithHandleUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), productWithHandle ); } diff --git a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java index 872c119..c0918fc 100644 --- a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java +++ b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java @@ -2,6 +2,7 @@ import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; +import com.chargify.model.IntervalUnit; import com.chargify.model.Product; import com.chargify.model.ProductFamily; import com.chargify.model.Subscription; @@ -25,12 +26,12 @@ public static void setup() { productFamily = chargify.createProductFamily( new ProductFamily( randomName() ) ); - final Product initialProduct = new Product( randomName(), 0, 1, Product.IntervalUnit.month ); + final Product initialProduct = new Product( randomName(), 0, 1, IntervalUnit.month ); initialProduct.setRequestCreditCard( false ); initialProduct.setRequireCreditCard( false ); SubscriptionDelayedChangeTest.initialProduct = chargify.createProduct( productFamily.getId(), initialProduct ); - final Product targetProduct = new Product( randomName(), 0, 1, Product.IntervalUnit.month ); + final Product targetProduct = new Product( randomName(), 0, 1, IntervalUnit.month ); targetProduct.setRequestCreditCard( false ); targetProduct.setRequireCreditCard( false ); targetProduct.setHandle( randomName() ); diff --git a/src/test/java/com/chargify/SubscriptionsTest.java b/src/test/java/com/chargify/SubscriptionsTest.java index 78e927f..5cd7bf2 100644 --- a/src/test/java/com/chargify/SubscriptionsTest.java +++ b/src/test/java/com/chargify/SubscriptionsTest.java @@ -2,6 +2,7 @@ import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; +import com.chargify.model.IntervalUnit; import com.chargify.model.Product; import com.chargify.model.ProductFamily; import com.chargify.model.Subscription; @@ -31,7 +32,7 @@ public static void setup() { productFamilyUnderTest = chargify.createProductFamily( new ProductFamily( randomName() ) ); - final Product product = new Product( randomName(), 0, 1, Product.IntervalUnit.month ); + final Product product = new Product( randomName(), 0, 1, IntervalUnit.month ); product.setRequestCreditCard( false ); product.setRequireCreditCard( false ); productUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), product ); From 7bba6018244a10c3372003ab97b0eb6b19af528e Mon Sep 17 00:00:00 2001 From: kao78 Date: Tue, 23 Feb 2021 16:46:53 +0200 Subject: [PATCH 15/58] Fixed build after sync with master --- .../java/com/chargify/model/IntervalUnit.java | 6 -- src/main/java/com/chargify/model/Product.java | 38 ------- .../chargify/model/SubscriptionProduct.java | 4 +- .../model/{ => product}/BaseProduct.java | 6 +- .../com/chargify/model/product/Product.java | 98 +++---------------- src/test/java/com/chargify/ProductsTest.java | 1 - .../SubscriptionDelayedChangeTest.java | 1 - .../java/com/chargify/SubscriptionsTest.java | 1 - 8 files changed, 19 insertions(+), 136 deletions(-) delete mode 100644 src/main/java/com/chargify/model/IntervalUnit.java delete mode 100644 src/main/java/com/chargify/model/Product.java rename src/main/java/com/chargify/model/{ => product}/BaseProduct.java (92%) diff --git a/src/main/java/com/chargify/model/IntervalUnit.java b/src/main/java/com/chargify/model/IntervalUnit.java deleted file mode 100644 index 2df9682..0000000 --- a/src/main/java/com/chargify/model/IntervalUnit.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.chargify.model; - -public enum IntervalUnit -{ - month, day -} diff --git a/src/main/java/com/chargify/model/Product.java b/src/main/java/com/chargify/model/Product.java deleted file mode 100644 index 548734f..0000000 --- a/src/main/java/com/chargify/model/Product.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.chargify.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -import java.io.Serializable; - -@Data -@ToString -@EqualsAndHashCode( callSuper = true ) -@JsonInclude( JsonInclude.Include.NON_NULL ) -public class Product extends BaseProduct implements Serializable -{ - @JsonProperty( "request_billing_address" ) - private Boolean requestBillingAddress; - @JsonProperty( "require_billing_address" ) - private Boolean requireBillingAddress; - @JsonProperty( "require_shipping_address" ) - private Boolean requireShippingAddress; - @JsonProperty( "default_product_price_point_id" ) - private Integer defaultProductPricePointId; - - @JsonCreator - public Product( @JsonProperty( "name" ) final String name, - @JsonProperty( "price" ) final int priceInCents, - @JsonProperty( "interval" ) final int recurringInterval, - @JsonProperty( "interval_unit" ) final IntervalUnit intervalUnit ) - { - this.name = name; - this.priceInCents = priceInCents; - this.recurringInterval = recurringInterval; - this.intervalUnit = intervalUnit; - } -} diff --git a/src/main/java/com/chargify/model/SubscriptionProduct.java b/src/main/java/com/chargify/model/SubscriptionProduct.java index 9ea53e8..735d75f 100644 --- a/src/main/java/com/chargify/model/SubscriptionProduct.java +++ b/src/main/java/com/chargify/model/SubscriptionProduct.java @@ -1,5 +1,6 @@ package com.chargify.model; +import com.chargify.model.product.BaseProduct; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; @@ -9,7 +10,6 @@ import java.io.Serializable; import java.util.Date; -import java.util.List; @Data @ToString @@ -24,7 +24,7 @@ public class SubscriptionProduct extends BaseProduct implements Serializable public SubscriptionProduct( @JsonProperty( "name" ) final String name, @JsonProperty( "price" ) final int priceInCents, @JsonProperty( "interval" ) final int recurringInterval, - @JsonProperty( "interval_unit" ) final IntervalUnit intervalUnit ) + @JsonProperty( "interval_unit" ) final PricePointIntervalUnit intervalUnit ) { this.name = name; this.priceInCents = priceInCents; diff --git a/src/main/java/com/chargify/model/BaseProduct.java b/src/main/java/com/chargify/model/product/BaseProduct.java similarity index 92% rename from src/main/java/com/chargify/model/BaseProduct.java rename to src/main/java/com/chargify/model/product/BaseProduct.java index 4b3772f..492c73f 100644 --- a/src/main/java/com/chargify/model/BaseProduct.java +++ b/src/main/java/com/chargify/model/product/BaseProduct.java @@ -1,5 +1,7 @@ -package com.chargify.model; +package com.chargify.model.product; +import com.chargify.model.PricePointIntervalUnit; +import com.chargify.model.PublicSignupPage; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -49,7 +51,7 @@ public abstract class BaseProduct implements Serializable protected int recurringInterval; @JsonProperty( "interval_unit" ) - protected IntervalUnit intervalUnit; + protected PricePointIntervalUnit intervalUnit; @JsonProperty( "initial_charge_in_cents" ) protected String initialChargeInCents; diff --git a/src/main/java/com/chargify/model/product/Product.java b/src/main/java/com/chargify/model/product/Product.java index 59170fc..271b26a 100644 --- a/src/main/java/com/chargify/model/product/Product.java +++ b/src/main/java/com/chargify/model/product/Product.java @@ -1,101 +1,29 @@ package com.chargify.model.product; import com.chargify.model.PricePointIntervalUnit; -import com.chargify.model.PublicSignupPage; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; import java.io.Serializable; -import java.util.Date; -import java.util.List; @Data +@ToString +@EqualsAndHashCode( callSuper = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) -public class Product implements Serializable +public class Product extends BaseProduct implements Serializable { - private String id; - - private String name; - - private String handle; - - private String description; - - @JsonProperty( "accounting_code" ) - private String accountingCode; - - @JsonProperty( "request_credit_card" ) - private Boolean requestCreditCard; - - @JsonProperty( "expiration_interval" ) - private String expirationInterval; - - @JsonProperty( "expiration_interval_unit" ) - private String expirationIntervalUnit; - - @JsonProperty( "created_at" ) - private Date createdAt; - - @JsonProperty( "updated_at" ) - private Date updatedAt; - - @JsonProperty( "price_in_cents" ) - private int priceInCents; - - @JsonProperty( "interval" ) - private int recurringInterval; - - @JsonProperty( "interval_unit" ) - private PricePointIntervalUnit intervalUnit; - - @JsonProperty( "initial_charge_in_cents" ) - private String initialChargeInCents; - - @JsonProperty( "trial_price_in_cents" ) - private Integer trialPriceInCents; - - @JsonProperty( "trial_interval" ) - private Integer trialInterval; - - @JsonProperty( "trial_interval_unit" ) - private PricePointIntervalUnit trialIntervalUnit; - - @JsonProperty( "archived_at" ) - private Date archivedAt; - - @JsonProperty( "require_credit_card" ) - private Boolean requireCreditCard; - - @JsonProperty( "return_params" ) - private String returnParams; - - @JsonProperty( "product_price_point_name" ) - private String productPricePointName; - - @JsonProperty( "product_price_point_handle" ) - private String productPricePointHandle; - - private Boolean taxable; - - @JsonProperty( "update_return_url" ) - private String updateReturnUrl; - - @JsonProperty( "initial_charge_after_trial" ) - private Boolean initialChargeAfterTrial; - - @JsonProperty( "version_number" ) - private Integer versionNumber; - - @JsonProperty( "update_return_params" ) - private String updateReturnParams; - - @JsonProperty( "product_family" ) - private ProductFamily productFamily; - - @JsonProperty( "public_signup_pages" ) - private List publicSignupPages; + @JsonProperty( "request_billing_address" ) + private Boolean requestBillingAddress; + @JsonProperty( "require_billing_address" ) + private Boolean requireBillingAddress; + @JsonProperty( "require_shipping_address" ) + private Boolean requireShippingAddress; + @JsonProperty( "default_product_price_point_id" ) + private Integer defaultProductPricePointId; @JsonCreator public Product( @JsonProperty( "name" ) final String name, diff --git a/src/test/java/com/chargify/ProductsTest.java b/src/test/java/com/chargify/ProductsTest.java index ee27478..1d9cb17 100644 --- a/src/test/java/com/chargify/ProductsTest.java +++ b/src/test/java/com/chargify/ProductsTest.java @@ -1,7 +1,6 @@ package com.chargify; import com.chargify.exceptions.ChargifyException; -import com.chargify.model.IntervalUnit; import com.chargify.model.PricePointIntervalUnit; import com.chargify.model.product.Product; import com.chargify.model.product.ProductFamily; diff --git a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java index 85461f8..092079f 100644 --- a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java +++ b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java @@ -2,7 +2,6 @@ import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; -import com.chargify.model.IntervalUnit; import com.chargify.model.PricePointIntervalUnit; import com.chargify.model.product.Product; import com.chargify.model.product.ProductFamily; diff --git a/src/test/java/com/chargify/SubscriptionsTest.java b/src/test/java/com/chargify/SubscriptionsTest.java index 2cfba78..6fc2a68 100644 --- a/src/test/java/com/chargify/SubscriptionsTest.java +++ b/src/test/java/com/chargify/SubscriptionsTest.java @@ -2,7 +2,6 @@ import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; -import com.chargify.model.IntervalUnit; import com.chargify.model.PricePointIntervalUnit; import com.chargify.model.product.Product; import com.chargify.model.product.ProductFamily; From a38b180b5c231ab210f258aefcdc79c316ce7909 Mon Sep 17 00:00:00 2001 From: kao78 Date: Wed, 24 Feb 2021 10:51:34 +0200 Subject: [PATCH 16/58] Updated SDK version, minor changes to Subscription and SubscriptionProduct --- pom.xml | 2 +- src/main/java/com/chargify/model/Subscription.java | 3 +-- src/main/java/com/chargify/model/SubscriptionProduct.java | 2 ++ 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 73873e4..dc1464e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.9.0 + 0.10 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java index 2cfbc4c..8e17ddf 100644 --- a/src/main/java/com/chargify/model/Subscription.java +++ b/src/main/java/com/chargify/model/Subscription.java @@ -18,7 +18,6 @@ package com.chargify.model; -import com.chargify.model.product.Product; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; @@ -160,7 +159,7 @@ public class Subscription implements Serializable private String nextProductHandle; @JsonProperty( "next_product_price_point_id" ) - private String nextProductPricePointId; + private Integer nextProductPricePointId; @JsonProperty( "coupon_use_count" ) private Integer couponUseCount; diff --git a/src/main/java/com/chargify/model/SubscriptionProduct.java b/src/main/java/com/chargify/model/SubscriptionProduct.java index 735d75f..cb02a5a 100644 --- a/src/main/java/com/chargify/model/SubscriptionProduct.java +++ b/src/main/java/com/chargify/model/SubscriptionProduct.java @@ -19,6 +19,8 @@ public class SubscriptionProduct extends BaseProduct implements Serializable { @JsonProperty( "archived_at" ) private Date archivedAt; + @JsonProperty( "product_price_point_handle" ) + private String productPricePointHandle; @JsonCreator public SubscriptionProduct( @JsonProperty( "name" ) final String name, From 95d606d65d8787443c08106ea8c54d10ae99a1f7 Mon Sep 17 00:00:00 2001 From: kao78 Date: Mon, 1 Mar 2021 11:42:23 +0200 Subject: [PATCH 17/58] Removed productId from Subscription since it is not returned by Chargify API --- pom.xml | 2 +- src/main/java/com/chargify/model/Subscription.java | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index dc1464e..22abe4f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.10 + 0.11 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java index 8e17ddf..69af942 100644 --- a/src/main/java/com/chargify/model/Subscription.java +++ b/src/main/java/com/chargify/model/Subscription.java @@ -109,9 +109,6 @@ public class Subscription implements Serializable @JsonProperty( "product_handle" ) private String productHandle; - @JsonProperty( "product_id" ) - private String productId; - @JsonProperty( "signup_payment_id" ) private Integer signupPaymentId; From 817eac5ab4d34893e771ca11b04ecb6ec3c97031 Mon Sep 17 00:00:00 2001 From: kao78 Date: Tue, 2 Mar 2021 16:34:08 +0200 Subject: [PATCH 18/58] Added method for cancellation of scheduled product change --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 2 ++ src/main/java/com/chargify/ChargifyService.java | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 22abe4f..82e0b29 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.11 + 0.12 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 78376a9..4898dca 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -66,6 +66,8 @@ ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subsc List bulkUpdateSubscriptionComponentPricePoint( String subscriptionId, List items ); + Subscription cancelScheduledSubscriptionProductChange( String subscriptionId ); + Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, boolean delayed ); Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, String pricePointHandle, boolean delayed ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index ec4ebb5..a184f10 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -389,6 +389,23 @@ public Subscription changeSubscriptionProduct( String subscriptionId, String pro .getSubscription(); } + @Override + public Subscription cancelScheduledSubscriptionProductChange( String subscriptionId ) + { + return httpClient.exchange( "/subscriptions/" + subscriptionId + ".json", HttpMethod.PUT, + new HttpEntity<>( + Map.of( + "subscription", + Map.of( + "next_product_id", "", + "next_product_price_point_id", "" + ) + ) + ), SubscriptionWrapper.class ) + .getBody() + .getSubscription(); + } + @Override public Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, String pricePointHandle, boolean delayed ) { From 01186d1ee863101209bb657073c4f729eca723a8 Mon Sep 17 00:00:00 2001 From: kao78 Date: Mon, 9 Aug 2021 14:21:53 +0300 Subject: [PATCH 19/58] Added ability to preserve subscription balance / Updated dependencies to the latest versions --- pom.xml | 6 +++--- src/main/java/com/chargify/Chargify.java | 2 +- src/main/java/com/chargify/ChargifyService.java | 14 ++++++++------ 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 82e0b29..9cf9953 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.12 + 0.14 jar Chargify SDK for Java @@ -48,13 +48,13 @@ org.springframework spring-web - 5.0.5.RELEASE + 5.3.9 org.springframework.boot spring-boot - 2.0.1.RELEASE + 2.5.2 diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 4898dca..1c7ecf8 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -57,7 +57,7 @@ public interface Chargify Subscription migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ); - Subscription reactivateSubscription( String subscriptionId ); + Subscription reactivateSubscription( String subscriptionId, boolean preserveBalance ); Subscription reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index a184f10..4343e9c 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -17,6 +17,7 @@ import org.springframework.web.util.UriUtils; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -34,7 +35,7 @@ public ChargifyService( final String domain, final String apiKey ) { this.httpClient = new RestTemplateBuilder() .uriTemplateHandler( new RootUriTemplateHandler( "https://" + domain + ".chargify.com" ) ) - .basicAuthorization( apiKey, "x" ) + .basicAuthentication( apiKey, "x" ) .errorHandler( new ChargifyResponseErrorHandler() ) .build(); @@ -50,9 +51,9 @@ public ChargifyService( final String domain, final String apiKey, int connectTim { this.httpClient = new RestTemplateBuilder() .uriTemplateHandler( new RootUriTemplateHandler( "https://" + domain + ".chargify.com" ) ) - .basicAuthorization( apiKey, "x" ) - .setConnectTimeout( connectTimeoutInMillis ) - .setReadTimeout( readTimeoutInMillis ) + .basicAuthentication( apiKey, "x" ) + .setConnectTimeout( Duration.ofMillis( connectTimeoutInMillis ) ) + .setReadTimeout( Duration.ofMillis( readTimeoutInMillis ) ) .errorHandler( new ChargifyResponseErrorHandler() ) .build(); @@ -335,10 +336,11 @@ public Subscription migrateSubscription( String subscriptionId, String productHa } @Override - public Subscription reactivateSubscription( String subscriptionId ) + public Subscription reactivateSubscription( String subscriptionId, boolean preserveBalance ) { return httpClient.exchange( "/subscriptions/" + subscriptionId + "/reactivate.json", HttpMethod.PUT, - HttpEntity.EMPTY, SubscriptionWrapper.class ) + new HttpEntity<>( Map.of( "preserve_balance", preserveBalance ) ), + SubscriptionWrapper.class ) .getBody() .getSubscription(); } From b696fa871b04d9540c8a699115d3ffefd71885c4 Mon Sep 17 00:00:00 2001 From: Vladimir Yalovy Date: Wed, 11 Aug 2021 11:47:59 +0300 Subject: [PATCH 20/58] [BKNDLSS-26119]: ChargifyError Unrecognized field "error" --- src/main/java/com/chargify/exceptions/ChargifyError.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/chargify/exceptions/ChargifyError.java b/src/main/java/com/chargify/exceptions/ChargifyError.java index fb75b7a..eb0c689 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyError.java +++ b/src/main/java/com/chargify/exceptions/ChargifyError.java @@ -1,5 +1,6 @@ package com.chargify.exceptions; +import com.fasterxml.jackson.annotation.JsonAlias; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; @@ -14,7 +15,7 @@ public final class ChargifyError private final Object errors; @JsonCreator - public ChargifyError( @JsonProperty( "errors" ) Object errors ) + public ChargifyError( @JsonProperty( "errors" ) @JsonAlias( "error" ) Object errors ) { this.errors = errors; } From a151c80cab8ed960c3a562aff56b144385a3f983 Mon Sep 17 00:00:00 2001 From: Vladimir Yalovy Date: Wed, 11 Aug 2021 12:15:18 +0300 Subject: [PATCH 21/58] [BKNDLSS-26119]: Change version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 9cf9953..172fca4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.14 + 0.15 jar Chargify SDK for Java @@ -147,4 +147,4 @@ - \ No newline at end of file + From 1e78b2232f72e54fdf5d2cb37237a9079dfdfaf5 Mon Sep 17 00:00:00 2001 From: Vladimir Yalovy Date: Wed, 1 Sep 2021 17:55:40 +0300 Subject: [PATCH 22/58] [BKNDLSS-26106]: Purge subscription --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 2 ++ src/main/java/com/chargify/ChargifyService.java | 9 +++++++++ .../com/chargify/model/SubscriptionStateEnum.java | 15 +++++++++++++++ .../com/chargify/model/SubscriptionStates.java | 1 + 5 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/chargify/model/SubscriptionStateEnum.java diff --git a/pom.xml b/pom.xml index 172fca4..831f7a8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.15 + 0.16 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 1c7ecf8..3074359 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -47,6 +47,8 @@ public interface Chargify List findAllSubscriptions(); + Subscription purgeSubscription( Subscription subscription ); + List findSubscriptionsByState( String state, int pageNumber, int pageSize ); Subscription cancelSubscriptionById( String id ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 4343e9c..edb7d04 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -274,6 +274,15 @@ public List findAllSubscriptions() .collect( Collectors.toList() ); } + @Override + public Subscription purgeSubscription( Subscription subscription ) + { + return httpClient.postForObject( "/subscriptions/" + subscription.getId() + "/purge.json?ack=" + subscription.getCustomerId() + + "&cascade[]=customer&cascade[]=payment_profile", + HttpEntity.EMPTY, SubscriptionWrapper.class ) + .getSubscription(); + } + @Override public List findSubscriptionsByState( String state, int pageNumber, int pageSize ) { diff --git a/src/main/java/com/chargify/model/SubscriptionStateEnum.java b/src/main/java/com/chargify/model/SubscriptionStateEnum.java new file mode 100644 index 0000000..9dd6f0a --- /dev/null +++ b/src/main/java/com/chargify/model/SubscriptionStateEnum.java @@ -0,0 +1,15 @@ +package com.chargify.model; + +public enum SubscriptionStateEnum +{ + ACTIVE, + CANCELED, + EXPIRED, + ON_HOLD, + PAST_DUE, + SOFT_FAILURE, + TRAILING, + TRIAL_ENDED, + UNPAID, + SUSPENDED; +} diff --git a/src/main/java/com/chargify/model/SubscriptionStates.java b/src/main/java/com/chargify/model/SubscriptionStates.java index 7b0abe3..a3aceda 100644 --- a/src/main/java/com/chargify/model/SubscriptionStates.java +++ b/src/main/java/com/chargify/model/SubscriptionStates.java @@ -16,4 +16,5 @@ public final class SubscriptionStates public static final String TRAILING = "trialing"; public static final String TRIAL_ENDED = "trial_ended"; public static final String UNPAID = "unpaid"; + public static final String SUSPENDED = "suspended"; } From 2e74f5987f85de34049e975a4dfaa39d259c18af Mon Sep 17 00:00:00 2001 From: Vladimir Yalovy Date: Thu, 2 Sep 2021 09:30:12 +0300 Subject: [PATCH 23/58] [BKNDLSS-26106]: Remove SubscriptionStateEnum --- .../com/chargify/model/SubscriptionStateEnum.java | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 src/main/java/com/chargify/model/SubscriptionStateEnum.java diff --git a/src/main/java/com/chargify/model/SubscriptionStateEnum.java b/src/main/java/com/chargify/model/SubscriptionStateEnum.java deleted file mode 100644 index 9dd6f0a..0000000 --- a/src/main/java/com/chargify/model/SubscriptionStateEnum.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.chargify.model; - -public enum SubscriptionStateEnum -{ - ACTIVE, - CANCELED, - EXPIRED, - ON_HOLD, - PAST_DUE, - SOFT_FAILURE, - TRAILING, - TRIAL_ENDED, - UNPAID, - SUSPENDED; -} From c78674413ed22f3be1c6a337815bb01f65ac4b54 Mon Sep 17 00:00:00 2001 From: Vladimir Yalovy Date: Thu, 2 Sep 2021 10:59:31 +0300 Subject: [PATCH 24/58] [BKNDLSS-26106]: Fix getting customer_id --- src/main/java/com/chargify/ChargifyService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index edb7d04..80d9705 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -277,7 +277,7 @@ public List findAllSubscriptions() @Override public Subscription purgeSubscription( Subscription subscription ) { - return httpClient.postForObject( "/subscriptions/" + subscription.getId() + "/purge.json?ack=" + subscription.getCustomerId() + + return httpClient.postForObject( "/subscriptions/" + subscription.getId() + "/purge.json?ack=" + subscription.getCustomer().getId() + "&cascade[]=customer&cascade[]=payment_profile", HttpEntity.EMPTY, SubscriptionWrapper.class ) .getSubscription(); From 4d910362d9cd7cb1f2101ba33d10e7b4d8af012d Mon Sep 17 00:00:00 2001 From: Vladimir Yalovy Date: Wed, 27 Oct 2021 16:48:59 +0300 Subject: [PATCH 25/58] [BKNDLSS-25817]: Add email setter to Customer --- src/main/java/com/chargify/model/Customer.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/chargify/model/Customer.java b/src/main/java/com/chargify/model/Customer.java index c322822..657acf6 100644 --- a/src/main/java/com/chargify/model/Customer.java +++ b/src/main/java/com/chargify/model/Customer.java @@ -106,6 +106,11 @@ public String getEmail() return email; } + public void setEmail( String email ) + { + this.email = email; + } + public String getCcEmails() { return ccEmails; From 87d8bb3a959773f462146aee05177d1c0830c188 Mon Sep 17 00:00:00 2001 From: Vladimir Yalovy Date: Thu, 28 Oct 2021 10:46:23 +0300 Subject: [PATCH 26/58] [BKNDLSS-25817]: Add findCustomersBy method --- src/main/java/com/chargify/Chargify.java | 9 +++++++++ src/main/java/com/chargify/ChargifyService.java | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 3074359..3bb613e 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -108,6 +108,15 @@ ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subsc Customer findCustomerByReference( String reference ); + /** + * Search to retrieve a single or group of customers. + * + * @param criterion (string or integer) - can be email, Chargify ID, Reference (Your App), Organization + * @param pageNumber (start from 1) the page parameter via the query string to access subsequent pages of 50 transactions + * @return List of customers + */ + List findCustomersBy( Object criterion, int pageNumber ); + List findAllCustomers(); void deleteCustomerById( String id ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 80d9705..c398f79 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -629,6 +629,15 @@ public Customer findCustomerByReference( String reference ) } } + @Override + public List findCustomersBy( Object criterion, int pageNumber ) + { + return Arrays.stream( httpClient.getForObject( "/customers.json?q={criterion}&page={pageNumber}", + CustomerWrapper[].class, criterion, pageNumber ) ) + .map( CustomerWrapper::getCustomer ) + .collect( Collectors.toList() ); + } + @Override public List findAllCustomers() { From 28698ba52bf5b5e117d2a5f0540c4c00340d5f90 Mon Sep 17 00:00:00 2001 From: Vladimir Yalovy Date: Thu, 28 Oct 2021 11:17:32 +0300 Subject: [PATCH 27/58] [BKNDLSS-25817]: Add findCustomersBy method --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 831f7a8..75d477a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.16 + 0.17 jar Chargify SDK for Java From d100cb420f0908c1cc09159987ed7e8ce7206be0 Mon Sep 17 00:00:00 2001 From: kao78 Date: Fri, 14 Jan 2022 12:40:23 +0200 Subject: [PATCH 28/58] Added method for customer payment profiles retrieval --- pom.xml | 4 +- src/main/java/com/chargify/Chargify.java | 2 + .../java/com/chargify/ChargifyService.java | 15 ++ .../com/chargify/model/PaymentProfile.java | 55 ++++ .../model/PaymentProfileAttributes.java | 248 ------------------ .../model/wrappers/PaymentProfileWrapper.java | 19 ++ 6 files changed, 94 insertions(+), 249 deletions(-) create mode 100644 src/main/java/com/chargify/model/PaymentProfile.java delete mode 100644 src/main/java/com/chargify/model/PaymentProfileAttributes.java create mode 100644 src/main/java/com/chargify/model/wrappers/PaymentProfileWrapper.java diff --git a/pom.xml b/pom.xml index 75d477a..74e95cc 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.17 + 0.18 jar Chargify SDK for Java @@ -115,6 +115,7 @@ org.apache.maven.plugins maven-source-plugin + 3.2.1 attach-sources @@ -127,6 +128,7 @@ org.apache.maven.plugins maven-javadoc-plugin + 3.3.1 attach-javadocs diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 3bb613e..c49163c 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -43,6 +43,8 @@ public interface Chargify Subscription findSubscriptionById( String id ); + List findPaymentProfilesForCustomer( String customerId ); + List findSubscriptionsByCustomerId( String customerId ); List findAllSubscriptions(); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index c398f79..e383e44 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -257,6 +257,21 @@ public Subscription findSubscriptionById( String id ) } } + @Override + public List findPaymentProfilesForCustomer( String customerId ) + { + try + { + return Arrays.stream( httpClient.getForObject( "/payment_profiles.json?customer_id=" + customerId, PaymentProfileWrapper[].class ) ) + .map( PaymentProfileWrapper::getPaymentProfile ) + .collect( Collectors.toList() ); + } + catch( ResourceNotFoundException e ) + { + return List.of(); + } + } + @Override public List findSubscriptionsByCustomerId( String customerId ) { diff --git a/src/main/java/com/chargify/model/PaymentProfile.java b/src/main/java/com/chargify/model/PaymentProfile.java new file mode 100644 index 0000000..a8d3fc7 --- /dev/null +++ b/src/main/java/com/chargify/model/PaymentProfile.java @@ -0,0 +1,55 @@ +/* + * ******************************************************************************************************************** + *

+ * BACKENDLESS.COM CONFIDENTIAL + *

+ * ******************************************************************************************************************** + *

+ * Copyright 2012 BACKENDLESS.COM. All Rights Reserved. + *

+ * NOTICE:  All information contained herein is, and remains the property of Backendless.com and its suppliers, + * if any.  The intellectual and technical concepts contained herein are proprietary to Backendless.com and its + * suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret + * or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden + * unless prior written permission is obtained from Backendless.com. + *

+ * ******************************************************************************************************************** + */ + +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +@JsonIgnoreProperties( ignoreUnknown = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class PaymentProfile +{ + @JsonProperty( "id" ) + private String id; + + @JsonProperty( "first_name" ) + private String firstName; + + @JsonProperty( "last_name" ) + private String lastName; + + @JsonProperty( "masked_card_number" ) + private String masked_card_number; + + @JsonProperty( "card_type" ) + private String cardType; + + @JsonProperty( "expiration_month" ) + private String expirationMonth; + + @JsonProperty( "expiration_year" ) + private String expirationYear; + + @JsonProperty( "customer_id" ) + private String customerId; +} diff --git a/src/main/java/com/chargify/model/PaymentProfileAttributes.java b/src/main/java/com/chargify/model/PaymentProfileAttributes.java deleted file mode 100644 index de06a08..0000000 --- a/src/main/java/com/chargify/model/PaymentProfileAttributes.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * ******************************************************************************************************************** - *

- * BACKENDLESS.COM CONFIDENTIAL - *

- * ******************************************************************************************************************** - *

- * Copyright 2012 BACKENDLESS.COM. All Rights Reserved. - *

- * NOTICE:  All information contained herein is, and remains the property of Backendless.com and its suppliers, - * if any.  The intellectual and technical concepts contained herein are proprietary to Backendless.com and its - * suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret - * or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden - * unless prior written permission is obtained from Backendless.com. - *

- * ******************************************************************************************************************** - */ - -package com.chargify.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties( ignoreUnknown = true ) -@JsonInclude( JsonInclude.Include.NON_NULL ) -public class PaymentProfileAttributes -{ - @JsonProperty( "first_name" ) - private String firstName; - - @JsonProperty( "last_name" ) - private String lastName; - - @JsonProperty( "full_number" ) - private String fullNumber; - - @JsonProperty( "expiration_month" ) - private String expirationMonth; - - @JsonProperty( "expiration_year" ) - private String expirationYear; - - private String cvv; - - @JsonProperty( "billing_address" ) - private String billingAddress; - - @JsonProperty( "billing_address_2" ) - private String billingAddress2; - - @JsonProperty( "billing_city" ) - private String billingCity; - - @JsonProperty( "billing_state" ) - private String billingState; - - @JsonProperty( "billing_zip" ) - private String billingZip; - - @JsonProperty( "billing_country" ) - private String billingCountry; - - @JsonProperty( "vault_token" ) - private String vaultToken; - - @JsonProperty( "customer_vault_token" ) - private String customerVaultToken; - - @JsonProperty( "current_vault" ) - private String currentVault; - - @JsonProperty( "last_four" ) - private String lastFour; - - @JsonProperty( "card_type" ) - private String cardType; - - public String getFirstName() - { - return firstName; - } - - public void setFirstName( String firstName ) - { - this.firstName = firstName; - } - - public String getLastName() - { - return lastName; - } - - public void setLastName( String lastName ) - { - this.lastName = lastName; - } - - public String getFullNumber() - { - return fullNumber; - } - - public void setFullNumber( String fullNumber ) - { - this.fullNumber = fullNumber; - } - - public String getExpirationMonth() - { - return expirationMonth; - } - - public void setExpirationMonth( String expirationMonth ) - { - this.expirationMonth = expirationMonth; - } - - public String getExpirationYear() - { - return expirationYear; - } - - public void setExpirationYear( String expirationYear ) - { - this.expirationYear = expirationYear; - } - - public String getCvv() - { - return cvv; - } - - public void setCvv( String cvv ) - { - this.cvv = cvv; - } - - public String getBillingAddress() - { - return billingAddress; - } - - public void setBillingAddress( String billingAddress ) - { - this.billingAddress = billingAddress; - } - - public String getBillingAddress2() - { - return billingAddress2; - } - - public void setBillingAddress2( String billingAddress2 ) - { - this.billingAddress2 = billingAddress2; - } - - public String getBillingCity() - { - return billingCity; - } - - public void setBillingCity( String billingCity ) - { - this.billingCity = billingCity; - } - - public String getBillingState() - { - return billingState; - } - - public void setBillingState( String billingState ) - { - this.billingState = billingState; - } - - public String getBillingZip() - { - return billingZip; - } - - public void setBillingZip( String billingZip ) - { - this.billingZip = billingZip; - } - - public String getBillingCountry() - { - return billingCountry; - } - - public void setBillingCountry( String billingCountry ) - { - this.billingCountry = billingCountry; - } - - public String getVaultToken() - { - return vaultToken; - } - - public void setVaultToken( String vaultToken ) - { - this.vaultToken = vaultToken; - } - - public String getCustomerVaultToken() - { - return customerVaultToken; - } - - public void setCustomerVaultToken( String customerVaultToken ) - { - this.customerVaultToken = customerVaultToken; - } - - public String getCurrentVault() - { - return currentVault; - } - - public void setCurrentVault( String currentVault ) - { - this.currentVault = currentVault; - } - - public String getLastFour() - { - return lastFour; - } - - public void setLastFour( String lastFour ) - { - this.lastFour = lastFour; - } - - public String getCardType() - { - return cardType; - } - - public void setCardType( String cardType ) - { - this.cardType = cardType; - } -} diff --git a/src/main/java/com/chargify/model/wrappers/PaymentProfileWrapper.java b/src/main/java/com/chargify/model/wrappers/PaymentProfileWrapper.java new file mode 100644 index 0000000..ee98e0b --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/PaymentProfileWrapper.java @@ -0,0 +1,19 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.PaymentProfile; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + + +public final class PaymentProfileWrapper +{ + @Getter + private final PaymentProfile paymentProfile; + + @JsonCreator + public PaymentProfileWrapper( @JsonProperty( "payment_profile" ) PaymentProfile paymentProfile ) + { + this.paymentProfile = paymentProfile; + } +} From b925d124e303ab87aedfe08bb6bdd92297c43be9 Mon Sep 17 00:00:00 2001 From: kao78 Date: Mon, 17 Jan 2022 19:05:22 +0200 Subject: [PATCH 29/58] Added possibility to reference client subscription-related entities --- pom.xml | 2 +- src/main/java/com/chargify/model/CreateSubscription.java | 3 +++ src/main/java/com/chargify/model/Subscription.java | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 74e95cc..39979fc 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.18 + 0.19 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/CreateSubscription.java b/src/main/java/com/chargify/model/CreateSubscription.java index 6a8ff9f..3951952 100644 --- a/src/main/java/com/chargify/model/CreateSubscription.java +++ b/src/main/java/com/chargify/model/CreateSubscription.java @@ -59,6 +59,9 @@ public class CreateSubscription implements Serializable private String paymentProfileId; @JsonProperty( "ref" ) + private String referralCode; + + @JsonProperty( "reference" ) private String reference; @JsonProperty( "customer_attributes" ) diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java index 69af942..f655674 100644 --- a/src/main/java/com/chargify/model/Subscription.java +++ b/src/main/java/com/chargify/model/Subscription.java @@ -146,7 +146,7 @@ public class Subscription implements Serializable @JsonProperty( "referral_code" ) private String referralCode; - @JsonProperty( "ref" ) + @JsonProperty( "reference" ) private String reference; @JsonProperty( "next_product_id" ) From a933ac20087ea434b8046ffb6b72c82195413eb9 Mon Sep 17 00:00:00 2001 From: kao78 Date: Tue, 18 Jan 2022 12:43:48 +0200 Subject: [PATCH 30/58] Added method for subscription update --- src/main/java/com/chargify/Chargify.java | 2 ++ .../java/com/chargify/ChargifyService.java | 20 +++++++++----- .../chargify/model/UpdateSubscription.java | 27 +++++++++++++++++++ .../wrappers/UpdateSubscriptionWrapper.java | 18 +++++++++++++ 4 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 src/main/java/com/chargify/model/UpdateSubscription.java create mode 100644 src/main/java/com/chargify/model/wrappers/UpdateSubscriptionWrapper.java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index c49163c..f843513 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -37,6 +37,8 @@ public interface Chargify Subscription createSubscription( CreateSubscription subscription ); + void updateSubscription( String subscriptionId, UpdateSubscription subscription ); + void updateSubscriptionNextBillingDate( String subscriptionId, LocalDateTime nextBillingDate ); SubscriptionChargeResult createSubscriptionCharge( String subscriptionId, SubscriptionCharge subscriptionCharge ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index e383e44..e82af73 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -219,19 +219,25 @@ public Subscription createSubscription( CreateSubscription subscription ) } @Override - public void updateSubscriptionNextBillingDate( String subscriptionId, LocalDateTime nextBillingDate ) + public void updateSubscription( String subscriptionId, UpdateSubscription subscription ) { httpClient.put( "/subscriptions/" + subscriptionId + ".json", - Map.of( - "subscription", - Map.of( - "next_billing_at", + new UpdateSubscriptionWrapper( subscription ) + ); + } + + @Override + public void updateSubscriptionNextBillingDate( String subscriptionId, LocalDateTime nextBillingDate ) + { + updateSubscription( + subscriptionId, + UpdateSubscription.builder() + .nextBillingAt( nextBillingDate.atZone( ZoneId.systemDefault() ) .withZoneSameInstant( ZoneId.of( "UTC" ) ) .toLocalDateTime() - .format( DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'") ) ) - ) + .format( DateTimeFormatter.ofPattern( "yyyy-MM-dd'T'HH:mm:ss'Z'" ) ) ).build() ); } diff --git a/src/main/java/com/chargify/model/UpdateSubscription.java b/src/main/java/com/chargify/model/UpdateSubscription.java new file mode 100644 index 0000000..d03d1ff --- /dev/null +++ b/src/main/java/com/chargify/model/UpdateSubscription.java @@ -0,0 +1,27 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Builder; +import lombok.Data; + +import java.io.Serializable; + +@Builder +@Data +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class UpdateSubscription implements Serializable +{ + + @JsonProperty( "product_handle" ) + private String productHandle; + + @JsonProperty( "product_id" ) + private String productId; + + @JsonProperty( "reference" ) + private String reference; + + @JsonProperty( "next_billing_at" ) + private String nextBillingAt; +} diff --git a/src/main/java/com/chargify/model/wrappers/UpdateSubscriptionWrapper.java b/src/main/java/com/chargify/model/wrappers/UpdateSubscriptionWrapper.java new file mode 100644 index 0000000..0e2bc8c --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/UpdateSubscriptionWrapper.java @@ -0,0 +1,18 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.UpdateSubscription; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +@Getter +public final class UpdateSubscriptionWrapper +{ + private final UpdateSubscription subscription; + + @JsonCreator + public UpdateSubscriptionWrapper( @JsonProperty( "subscription" ) UpdateSubscription wrappedSubscription ) + { + this.subscription = wrappedSubscription; + } +} From 97326a33f59530c2af57e49e119011b1fff18e0d Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Mon, 24 Jan 2022 16:43:19 +0200 Subject: [PATCH 31/58] Added method for subscription payments search --- pom.xml | 18 +- src/main/java/com/chargify/Chargify.java | 3 + .../java/com/chargify/ChargifyService.java | 22 ++ src/main/java/com/chargify/model/Event.java | 24 ++ .../com/chargify/model/EventSpecificData.java | 17 ++ .../chargify/model/SubscriptionStatement.java | 73 +++++++ .../java/com/chargify/model/Transaction.java | 205 ++---------------- .../SubscriptionStatementWrapper.java | 18 ++ 8 files changed, 185 insertions(+), 195 deletions(-) create mode 100644 src/main/java/com/chargify/model/Event.java create mode 100644 src/main/java/com/chargify/model/EventSpecificData.java create mode 100644 src/main/java/com/chargify/model/SubscriptionStatement.java create mode 100644 src/main/java/com/chargify/model/wrappers/SubscriptionStatementWrapper.java diff --git a/pom.xml b/pom.xml index 39979fc..2733c51 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.19 + 0.20 jar Chargify SDK for Java @@ -48,52 +48,52 @@ org.springframework spring-web - 5.3.9 + 5.3.14 org.springframework.boot spring-boot - 2.5.2 + 2.6.2 com.fasterxml.jackson.core jackson-databind - 2.9.5 + 2.13.1 com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.9.5 + 2.13.1 ch.qos.logback logback-classic - 1.2.3 + 1.2.10 org.projectlombok lombok - 1.18.12 + 1.18.22 provided junit junit - 4.12 + 4.13.2 test org.springframework spring-test - 5.0.5.RELEASE + 5.3.14 test diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index f843513..4ed367f 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -100,6 +100,9 @@ ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subsc List findSubscriptionComponents( String subscriptionId ); + List findSubscriptionStatements( + String subscriptionId, int page, int pageSize, String sort, String direction ); + SubscriptionComponent findSubscriptionComponentById( String subscriptionId, int componentId ); Usage reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index e82af73..7ce09e5 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -580,6 +580,28 @@ public List findSubscriptionComponents( String subscripti .collect( Collectors.toList() ); } + @Override + public List findSubscriptionStatements( + String subscriptionId, int page, int pageSize, String sort, String direction ) + { + if( pageSize > 200 ) + throw new IllegalArgumentException( "Page size can't be bigger than 200" ); + + StringBuilder uriBuilder = new StringBuilder(); + uriBuilder.append( "page=" ).append( page ); + uriBuilder.append( "&per_page=" ).append( pageSize ); + if( sort != null ) + uriBuilder.append( "&sort=" ).append( sort ); + if( direction != null ) + uriBuilder.append( "&direction=" ).append( direction ); + + + return Arrays.stream( httpClient.getForObject( + "/subscriptions/" + subscriptionId + "/statements.json?" + uriBuilder, SubscriptionStatementWrapper[].class ) ) + .map( SubscriptionStatementWrapper::getStatement ) + .collect( Collectors.toList() ); + } + @Override public SubscriptionComponent findSubscriptionComponentById( String subscriptionId, int componentId ) { diff --git a/src/main/java/com/chargify/model/Event.java b/src/main/java/com/chargify/model/Event.java new file mode 100644 index 0000000..fa2c127 --- /dev/null +++ b/src/main/java/com/chargify/model/Event.java @@ -0,0 +1,24 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@JsonIgnoreProperties( ignoreUnknown = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class Event +{ + private Integer id; + private String key; + private String message; + @JsonProperty( "subscription_id" ) + private Integer subscriptionId; + @JsonProperty( "created_at" ) + private LocalDateTime createdAt; + @JsonProperty( "event_specific_data" ) + private EventSpecificData eventSpecificData; +} diff --git a/src/main/java/com/chargify/model/EventSpecificData.java b/src/main/java/com/chargify/model/EventSpecificData.java new file mode 100644 index 0000000..be971c2 --- /dev/null +++ b/src/main/java/com/chargify/model/EventSpecificData.java @@ -0,0 +1,17 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + +@Data +@JsonIgnoreProperties( ignoreUnknown = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class EventSpecificData +{ + @JsonProperty( "product_id" ) + private Integer productId; + @JsonProperty( "account_transaction_id" ) + private Integer accountTransactionId; +} diff --git a/src/main/java/com/chargify/model/SubscriptionStatement.java b/src/main/java/com/chargify/model/SubscriptionStatement.java new file mode 100644 index 0000000..98ea9fe --- /dev/null +++ b/src/main/java/com/chargify/model/SubscriptionStatement.java @@ -0,0 +1,73 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import lombok.Data; + +import java.io.Serializable; +import java.time.LocalDateTime; +import java.util.List; + +@JsonIgnoreProperties( ignoreUnknown = true ) +@Data +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class SubscriptionStatement implements Serializable +{ + @JsonProperty( "id" ) + private Integer id; + @JsonProperty( "created_at" ) + private LocalDateTime closedAt; + @JsonProperty( "opened_at" ) + private LocalDateTime openedAt; + @JsonProperty( "settled_at" ) + private LocalDateTime settledAt; + @JsonProperty( "created_at" ) + private LocalDateTime createdAt; + @JsonProperty( "updated_at" ) + private LocalDateTime updatedAt; + @JsonProperty( "customer_first_name" ) + private String customerFirstName; + @JsonProperty( "customer_last_name" ) + private String customerLastName; + @JsonProperty( "customer_billing_address" ) + private String customerBillingAddress; + @JsonProperty( "customer_billing_address_2" ) + private String customerBillingAddress2; + @JsonProperty( "customer_billing_city" ) + private String customerBillingCity; + @JsonProperty( "customer_billing_country" ) + private String customerBillingCountry; + @JsonProperty( "customer_billing_state" ) + private String customerBillingState; + @JsonProperty( "customer_billing_zip" ) + private String customerBillingZip; + @JsonProperty( "customer_organization" ) + private String customerOrganization; + @JsonProperty( "customer_shipping_address" ) + private String customerShippingAddress; + @JsonProperty( "customer_shipping_address_2" ) + private String customerShippingAddress2; + @JsonProperty( "customer_shipping_city" ) + private String customerShippingCity; + @JsonProperty( "customer_shipping_country" ) + private String customerShippingCountry; + @JsonProperty( "customer_shipping_state" ) + private String customerShippingState; + @JsonProperty( "customer_shipping_zip" ) + private String customerShippingZip; + @JsonProperty( "starting_balance_in_cents" ) + private Integer startingBalanceInCents; + @JsonProperty( "ending_balance_in_cents" ) + private Integer endingBalanceInCents; + @JsonProperty( "memo" ) + private String memo; + @JsonProperty( "subscription_id" ) + private Integer subscriptionId; + @JsonProperty( "total_in_cents" ) + private Integer totalInCents; + @JsonDeserialize(contentAs = Transaction.class) + private List transactions; + +} diff --git a/src/main/java/com/chargify/model/Transaction.java b/src/main/java/com/chargify/model/Transaction.java index d249469..7806eb4 100644 --- a/src/main/java/com/chargify/model/Transaction.java +++ b/src/main/java/com/chargify/model/Transaction.java @@ -3,207 +3,40 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; -import java.util.Date; +import java.time.LocalDateTime; +@Data @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) public class Transaction { + private Integer id; + @JsonProperty( "subscription_id" ) + private String subscriptionId; + private String type; + private String kind; + @JsonProperty( "transaction_type" ) + private String transactionType; + private boolean success; @JsonProperty( "amount_in_cents" ) private int amountInCents; - + private String memo; @JsonProperty( "created_at" ) - private Date createdAt; - + private LocalDateTime createdAt; @JsonProperty( "starting_balance_in_cents" ) private int startingBalanceInCents; - @JsonProperty( "ending_balance_in_cents" ) private int endingBalanceInCents; - - private String id; - - private String kind; - - private String memo; - + @JsonProperty( "gateway_used" ) + private String gatewayUsed; + @JsonProperty( "gateway_transaction_id" ) + private String gatewayTransactionId; + @JsonProperty( "gateway_order_id" ) + private String gatewayOrderId; @JsonProperty( "payment_id" ) private String paymentId; - @JsonProperty( "product_id" ) private String productId; - - @JsonProperty( "subscription_id" ) - private String subscriptionId; - - private boolean success; - - private String type; - - @JsonProperty( "transaction_type" ) - private String transactionType; - - @JsonProperty( "gateway_transaction_id" ) - private String gatewayTransactionId; - - public int getAmountInCents() - { - return amountInCents; - } - - public void setAmountInCents( int amountInCents ) - { - this.amountInCents = amountInCents; - } - - public Date getCreatedAt() - { - return createdAt; - } - - public void setCreatedAt( Date createdAt ) - { - this.createdAt = createdAt; - } - - public int getEndingBalanceInCents() - { - return endingBalanceInCents; - } - - public void setEndingBalanceInCents( int endingBalanceInCents ) - { - this.endingBalanceInCents = endingBalanceInCents; - } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getKind() - { - return kind; - } - - public void setKind( String kind ) - { - this.kind = kind; - } - - public String getMemo() - { - return memo; - } - - public void setMemo( String memo ) - { - this.memo = memo; - } - - public String getPaymentId() - { - return paymentId; - } - - public void setPaymentId( String paymentId ) - { - this.paymentId = paymentId; - } - - public String getProductId() - { - return productId; - } - - public void setProductId( String productId ) - { - this.productId = productId; - } - - public int getStartingBalanceInCents() - { - return startingBalanceInCents; - } - - public void setStartingBalanceInCents( int startingBalanceInCents ) - { - this.startingBalanceInCents = startingBalanceInCents; - } - - public String getSubscriptionId() - { - return subscriptionId; - } - - public void setSubscriptionId( String subscriptionId ) - { - this.subscriptionId = subscriptionId; - } - - public boolean getSuccess() - { - return success; - } - - public void setSuccess( boolean success ) - { - this.success = success; - } - - public String getType() - { - return type; - } - - public void setType( String type ) - { - this.type = type; - } - - public String getTransactionType() - { - return transactionType; - } - - public void setTransactionType( String transactionType ) - { - this.transactionType = transactionType; - } - - public String getGatewayTransactionId() - { - return gatewayTransactionId; - } - - public void setGatewayTransactionId( String gatewayTransactionId ) - { - this.gatewayTransactionId = gatewayTransactionId; - } - - @Override - public String toString() - { - return "Transaction{" + - "amountInCents=" + amountInCents + - ", createdAt=" + createdAt + - ", startingBalanceInCents=" + startingBalanceInCents + - ", endingBalanceInCents=" + endingBalanceInCents + - ", id='" + id + '\'' + - ", kind='" + kind + '\'' + - ", memo='" + memo + '\'' + - ", paymentId='" + paymentId + '\'' + - ", productId='" + productId + '\'' + - ", subscriptionId='" + subscriptionId + '\'' + - ", success=" + success + - ", type='" + type + '\'' + - ", transactionType='" + transactionType + '\'' + - ", gatewayTransactionId='" + gatewayTransactionId + '\'' + '}'; - } } diff --git a/src/main/java/com/chargify/model/wrappers/SubscriptionStatementWrapper.java b/src/main/java/com/chargify/model/wrappers/SubscriptionStatementWrapper.java new file mode 100644 index 0000000..98d3ef1 --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/SubscriptionStatementWrapper.java @@ -0,0 +1,18 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.SubscriptionStatement; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +@Getter +public final class SubscriptionStatementWrapper +{ + private final SubscriptionStatement statement; + + @JsonCreator + public SubscriptionStatementWrapper( @JsonProperty( "statement" ) SubscriptionStatement statement ) + { + this.statement = statement; + } +} From c82a1b1857a09d8ed625cf1fbe401eb806e66bc9 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Thu, 3 Feb 2022 11:43:35 +0200 Subject: [PATCH 32/58] Added methods for credit card management --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 12 + .../java/com/chargify/ChargifyService.java | 54 +++++ .../exceptions/ChargifyException.java | 2 + .../PaymentProfileInUseException.java | 11 + .../model/BaseUpsertPaymentProfile.java | 54 +++++ .../chargify/model/CreatePaymentProfile.java | 34 +++ .../java/com/chargify/model/CreditCard.java | 213 +----------------- .../com/chargify/model/PaymentProfile.java | 13 +- .../java/com/chargify/model/PaymentType.java | 12 + .../chargify/model/UpdatePaymentProfile.java | 31 +++ 11 files changed, 226 insertions(+), 212 deletions(-) create mode 100644 src/main/java/com/chargify/exceptions/PaymentProfileInUseException.java create mode 100644 src/main/java/com/chargify/model/BaseUpsertPaymentProfile.java create mode 100644 src/main/java/com/chargify/model/CreatePaymentProfile.java create mode 100644 src/main/java/com/chargify/model/PaymentType.java create mode 100644 src/main/java/com/chargify/model/UpdatePaymentProfile.java diff --git a/pom.xml b/pom.xml index 2733c51..e546260 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.20 + 0.21 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 4ed367f..8d8b6af 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -47,6 +47,18 @@ public interface Chargify List findPaymentProfilesForCustomer( String customerId ); + PaymentProfile createPaymentProfile( CreatePaymentProfile paymentProfile ); + + void updatePaymentProfile( String paymentProfileId, UpdatePaymentProfile paymentProfile ); + + PaymentProfile updateSubscriptionPaymentProfile( String subscriptionId, String paymentProfileId ); + + PaymentProfile findPaymentProfileById( String paymentProfileId ); + + void deleteUnusedPaymentProfile( String paymentProfileId ); + + void deletePaymentProfile( String subscriptionId, String paymentProfileId ); + List findSubscriptionsByCustomerId( String customerId ); List findAllSubscriptions(); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 7ce09e5..2625309 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -22,6 +22,7 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -278,6 +279,59 @@ public List findPaymentProfilesForCustomer( String customerId ) } } + @Override + public PaymentProfile createPaymentProfile( CreatePaymentProfile paymentProfile ) + { + Map body = new HashMap<>(); + body.put( "payment_profile", paymentProfile ); + return httpClient.postForObject( + "/payment_profiles.json", body, PaymentProfileWrapper.class ).getPaymentProfile(); + } + + @Override + public void updatePaymentProfile( String paymentProfileId, UpdatePaymentProfile paymentProfile ) + { + Map body = new HashMap<>(); + body.put( "payment_profile", paymentProfile ); + + httpClient.put( "/payment_profiles/" + paymentProfileId + ".json", body ); + } + + + @Override + public PaymentProfile updateSubscriptionPaymentProfile( String subscriptionId, String paymentProfileId ) + { + return httpClient.postForObject( + "/subscriptions/" + subscriptionId + "/payment_profiles/" + paymentProfileId + "/change_payment_profile.json", + Map.of(), PaymentProfileWrapper.class ).getPaymentProfile(); + } + + @Override + public PaymentProfile findPaymentProfileById( String paymentProfileId ) + { + try + { + return httpClient.getForObject( "/payment_profiles/" + paymentProfileId + ".json", PaymentProfileWrapper.class ) + .getPaymentProfile(); + } + catch( ResourceNotFoundException e ) + { + return null; + } + } + + @Override + public void deleteUnusedPaymentProfile( String paymentProfileId ) + { + httpClient.delete( "/payment_profiles/" + paymentProfileId + ".json" ); + } + + @Override + public void deletePaymentProfile( String subscriptionId, String paymentProfileId ) + { + httpClient.delete( "/subscriptions/" + subscriptionId + "/payment_profiles/" + paymentProfileId + ".json" ); + } + @Override public List findSubscriptionsByCustomerId( String customerId ) { diff --git a/src/main/java/com/chargify/exceptions/ChargifyException.java b/src/main/java/com/chargify/exceptions/ChargifyException.java index 86359d1..be82f4e 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyException.java +++ b/src/main/java/com/chargify/exceptions/ChargifyException.java @@ -30,6 +30,8 @@ private static ChargifyException fromError( String errorMessage ) { switch( errorMessage ) { + case PaymentProfileInUseException.MESSAGE: + return new PaymentProfileInUseException(); case MissingNameException.MESSAGE: return new MissingNameException(); case ApiHandleNotUniqueException.MESSAGE: diff --git a/src/main/java/com/chargify/exceptions/PaymentProfileInUseException.java b/src/main/java/com/chargify/exceptions/PaymentProfileInUseException.java new file mode 100644 index 0000000..52b4f1e --- /dev/null +++ b/src/main/java/com/chargify/exceptions/PaymentProfileInUseException.java @@ -0,0 +1,11 @@ +package com.chargify.exceptions; + +public final class PaymentProfileInUseException extends ChargifyException +{ + static final String MESSAGE = "The payment profile is in use by one or more subscriptions and cannot be deleted"; + + PaymentProfileInUseException() + { + super( MESSAGE ); + } +} diff --git a/src/main/java/com/chargify/model/BaseUpsertPaymentProfile.java b/src/main/java/com/chargify/model/BaseUpsertPaymentProfile.java new file mode 100644 index 0000000..17ad169 --- /dev/null +++ b/src/main/java/com/chargify/model/BaseUpsertPaymentProfile.java @@ -0,0 +1,54 @@ +/* + * ******************************************************************************************************************** + *

+ * BACKENDLESS.COM CONFIDENTIAL + *

+ * ******************************************************************************************************************** + *

+ * Copyright 2012 BACKENDLESS.COM. All Rights Reserved. + *

+ * NOTICE:  All information contained herein is, and remains the property of Backendless.com and its suppliers, + * if any.  The intellectual and technical concepts contained herein are proprietary to Backendless.com and its + * suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret + * or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden + * unless prior written permission is obtained from Backendless.com. + *

+ * ******************************************************************************************************************** + */ + +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +@JsonIgnoreProperties( ignoreUnknown = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public abstract class BaseUpsertPaymentProfile +{ + @JsonProperty( "first_name" ) + private String firstName; + + @JsonProperty( "last_name" ) + private String lastName; + + @JsonProperty( "payment_type" ) + private String paymentType; + + @JsonProperty( "full_number" ) + private String cardNumber; + + @JsonProperty( "expiration_month" ) + private Integer expirationMonth; + + @JsonProperty( "expiration_year" ) + private Integer expirationYear; + + @JsonProperty( "billing_zip" ) + private String billingZip; + + private String cvv; +} diff --git a/src/main/java/com/chargify/model/CreatePaymentProfile.java b/src/main/java/com/chargify/model/CreatePaymentProfile.java new file mode 100644 index 0000000..bf02c24 --- /dev/null +++ b/src/main/java/com/chargify/model/CreatePaymentProfile.java @@ -0,0 +1,34 @@ +/* + * ******************************************************************************************************************** + *

+ * BACKENDLESS.COM CONFIDENTIAL + *

+ * ******************************************************************************************************************** + *

+ * Copyright 2012 BACKENDLESS.COM. All Rights Reserved. + *

+ * NOTICE:  All information contained herein is, and remains the property of Backendless.com and its suppliers, + * if any.  The intellectual and technical concepts contained herein are proprietary to Backendless.com and its + * suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret + * or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden + * unless prior written permission is obtained from Backendless.com. + *

+ * ******************************************************************************************************************** + */ + +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +@JsonIgnoreProperties( ignoreUnknown = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class CreatePaymentProfile extends BaseUpsertPaymentProfile +{ + @JsonProperty( "customer_id" ) + private String customerId; +} diff --git a/src/main/java/com/chargify/model/CreditCard.java b/src/main/java/com/chargify/model/CreditCard.java index 07d28c3..3c798bb 100644 --- a/src/main/java/com/chargify/model/CreditCard.java +++ b/src/main/java/com/chargify/model/CreditCard.java @@ -20,9 +20,13 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; +@NoArgsConstructor +@Data @JsonInclude( JsonInclude.Include.NON_NULL ) public class CreditCard implements Serializable { @@ -44,10 +48,10 @@ public class CreditCard implements Serializable private String cardType; @JsonProperty( "expiration_month" ) - private String expirationMonth; + private Integer expirationMonth; @JsonProperty( "expiration_year" ) - private String expirationYear; + private Integer expirationYear; @JsonProperty( "billing_address" ) private String billingAddress; @@ -78,209 +82,4 @@ public class CreditCard implements Serializable @JsonProperty( "customer_id" ) private String customerId; - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getCardType() - { - return cardType; - } - - public void setCardType( String cardType ) - { - this.cardType = cardType; - } - - public String getExpirationMonth() - { - return expirationMonth; - } - - public void setExpirationMonth( String expirationMonth ) - { - this.expirationMonth = expirationMonth; - } - - public String getExpirationYear() - { - return expirationYear; - } - - public void setExpirationYear( String expirationYear ) - { - this.expirationYear = expirationYear; - } - - public String getFirstName() - { - return firstName; - } - - public void setFirstName( String firstName ) - { - this.firstName = firstName; - } - - public String getLastName() - { - return lastName; - } - - public void setLastName( String lastName ) - { - this.lastName = lastName; - } - - public String getMaskedCardNumber() - { - return maskedCardNumber; - } - - public void setMaskedCardNumber( String maskedCardNumber ) - { - this.maskedCardNumber = maskedCardNumber; - } - - public String getCustomerId() - { - return customerId; - } - - public void setCustomerId( String customerId ) - { - this.customerId = customerId; - } - - public String getCustomerVaultToken() - { - return customerVaultToken; - } - - public void setCustomerVaultToken( String customerVaultToken ) - { - this.customerVaultToken = customerVaultToken; - } - - public String getVaultToken() - { - return vaultToken; - } - - public void setVaultToken( String vaultToken ) - { - this.vaultToken = vaultToken; - } - - public String getCurrentVault() - { - return currentVault; - } - - public void setCurrentVault( String currentVault ) - { - this.currentVault = currentVault; - } - - public String getBillingAddress() - { - return billingAddress; - } - - public void setBillingAddress( String billingAddress ) - { - this.billingAddress = billingAddress; - } - - public String getBillingAddress2() - { - return billingAddress2; - } - - public void setBillingAddress2( String billingAddress2 ) - { - this.billingAddress2 = billingAddress2; - } - - public String getBillingCity() - { - return billingCity; - } - - public void setBillingCity( String billingCity ) - { - this.billingCity = billingCity; - } - - public String getBillingState() - { - return billingState; - } - - public void setBillingState( String billingState ) - { - this.billingState = billingState; - } - - public String getBillingZip() - { - return billingZip; - } - - public void setBillingZip( String billingZip ) - { - this.billingZip = billingZip; - } - - public String getBillingCountry() - { - return billingCountry; - } - - public void setBillingCountry( String billingCountry ) - { - this.billingCountry = billingCountry; - } - - public String getPaymentType() - { - return paymentType; - } - - public void setPaymentType( String paymentType ) - { - this.paymentType = paymentType; - } - - @Override - public String toString() - { - return "CreditCard{" + - "id='" + id + '\'' + - ", paymentType='" + paymentType + '\'' + - ", firstName='" + firstName + '\'' + - ", lastName='" + lastName + '\'' + - ", maskedCardNumber='" + maskedCardNumber + '\'' + - ", cardType='" + cardType + '\'' + - ", expirationMonth='" + expirationMonth + '\'' + - ", expirationYear='" + expirationYear + '\'' + - ", billingAddress='" + billingAddress + '\'' + - ", billingAddress2='" + billingAddress2 + '\'' + - ", billingCity='" + billingCity + '\'' + - ", billingState='" + billingState + '\'' + - ", billingCountry='" + billingCountry + '\'' + - ", billingZip='" + billingZip + '\'' + - ", currentVault='" + currentVault + '\'' + - ", vaultToken='" + vaultToken + '\'' + - ", customerVaultToken='" + customerVaultToken + '\'' + - ", customerId='" + customerId + '\'' + - '}'; - } } diff --git a/src/main/java/com/chargify/model/PaymentProfile.java b/src/main/java/com/chargify/model/PaymentProfile.java index a8d3fc7..057f91d 100644 --- a/src/main/java/com/chargify/model/PaymentProfile.java +++ b/src/main/java/com/chargify/model/PaymentProfile.java @@ -24,10 +24,12 @@ import lombok.Getter; import lombok.Setter; +import java.io.Serializable; + @Getter @Setter @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) -public class PaymentProfile +public class PaymentProfile implements Serializable { @JsonProperty( "id" ) private String id; @@ -38,17 +40,20 @@ public class PaymentProfile @JsonProperty( "last_name" ) private String lastName; + @JsonProperty( "payment_type" ) + private String paymentType; + @JsonProperty( "masked_card_number" ) - private String masked_card_number; + private String maskedCardNumber; @JsonProperty( "card_type" ) private String cardType; @JsonProperty( "expiration_month" ) - private String expirationMonth; + private Integer expirationMonth; @JsonProperty( "expiration_year" ) - private String expirationYear; + private Integer expirationYear; @JsonProperty( "customer_id" ) private String customerId; diff --git a/src/main/java/com/chargify/model/PaymentType.java b/src/main/java/com/chargify/model/PaymentType.java new file mode 100644 index 0000000..fa106ee --- /dev/null +++ b/src/main/java/com/chargify/model/PaymentType.java @@ -0,0 +1,12 @@ +package com.chargify.model; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor( access = AccessLevel.PRIVATE ) +public final class PaymentType +{ + public static final String CREDIT_CARD = "credit_card"; + public static final String BANK_ACCOUNT = "bank_account"; + public static final String PAYPAL_ACCOUNT = "paypal_account"; +} diff --git a/src/main/java/com/chargify/model/UpdatePaymentProfile.java b/src/main/java/com/chargify/model/UpdatePaymentProfile.java new file mode 100644 index 0000000..db42326 --- /dev/null +++ b/src/main/java/com/chargify/model/UpdatePaymentProfile.java @@ -0,0 +1,31 @@ +/* + * ******************************************************************************************************************** + *

+ * BACKENDLESS.COM CONFIDENTIAL + *

+ * ******************************************************************************************************************** + *

+ * Copyright 2012 BACKENDLESS.COM. All Rights Reserved. + *

+ * NOTICE:  All information contained herein is, and remains the property of Backendless.com and its suppliers, + * if any.  The intellectual and technical concepts contained herein are proprietary to Backendless.com and its + * suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret + * or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden + * unless prior written permission is obtained from Backendless.com. + *

+ * ******************************************************************************************************************** + */ + +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Getter; +import lombok.Setter; + +@Getter @Setter +@JsonIgnoreProperties( ignoreUnknown = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class UpdatePaymentProfile extends BaseUpsertPaymentProfile +{ +} From 4b2b0a6a01ccac8757f279cf24479350e7864c44 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Thu, 3 Feb 2022 15:01:13 +0200 Subject: [PATCH 33/58] Added "billingZip" field to PaymentProfile --- src/main/java/com/chargify/model/PaymentProfile.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/chargify/model/PaymentProfile.java b/src/main/java/com/chargify/model/PaymentProfile.java index 057f91d..588381f 100644 --- a/src/main/java/com/chargify/model/PaymentProfile.java +++ b/src/main/java/com/chargify/model/PaymentProfile.java @@ -57,4 +57,7 @@ public class PaymentProfile implements Serializable @JsonProperty( "customer_id" ) private String customerId; + + @JsonProperty( "billing_zip" ) + private String billingZip; } From 336fb91b149edacfd68f7f0efb8285a199932d8d Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Wed, 2 Mar 2022 16:29:49 +0200 Subject: [PATCH 34/58] Added "findSubscriptionByReference" method --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 2 ++ src/main/java/com/chargify/ChargifyService.java | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e546260..0518b17 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.21 + 0.22 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 8d8b6af..449e3ca 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -127,6 +127,8 @@ List findSubscriptionStatements( Customer findCustomerByReference( String reference ); + Subscription findSubscriptionByReference( String reference ); + /** * Search to retrieve a single or group of customers. * diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 2625309..9545eb0 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -726,6 +726,21 @@ public Customer findCustomerByReference( String reference ) } } + @Override + public Subscription findSubscriptionByReference( String reference ) + { + try + { + return httpClient.getForObject( "/subscriptions/lookup.json?reference={reference}", + SubscriptionWrapper.class, reference ) + .getSubscription(); + } + catch( ResourceNotFoundException e ) + { + return null; + } + } + @Override public List findCustomersBy( Object criterion, int pageNumber ) { From 9f40c4c0a30f448ca11c13cb30bc3f66e073732a Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Fri, 13 May 2022 11:22:35 +0300 Subject: [PATCH 35/58] Include null fields while updating customer to allow already added data removal --- pom.xml | 16 +- .../java/com/chargify/model/Customer.java | 253 +----------------- 2 files changed, 15 insertions(+), 254 deletions(-) diff --git a/pom.xml b/pom.xml index 0518b17..8c91418 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.22 + 0.23 jar Chargify SDK for Java @@ -48,38 +48,38 @@ org.springframework spring-web - 5.3.14 + 5.3.19 org.springframework.boot spring-boot - 2.6.2 + 2.6.7 com.fasterxml.jackson.core jackson-databind - 2.13.1 + 2.13.2.2 com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.13.1 + 2.13.2 ch.qos.logback logback-classic - 1.2.10 + 1.2.11 org.projectlombok lombok - 1.18.22 + 1.18.24 provided @@ -93,7 +93,7 @@ org.springframework spring-test - 5.3.14 + 5.3.19 test diff --git a/src/main/java/com/chargify/model/Customer.java b/src/main/java/com/chargify/model/Customer.java index 657acf6..8946eef 100644 --- a/src/main/java/com/chargify/model/Customer.java +++ b/src/main/java/com/chargify/model/Customer.java @@ -1,37 +1,23 @@ -/* - * ******************************************************************************************************************** - *

- * BACKENDLESS.COM CONFIDENTIAL - *

- * ******************************************************************************************************************** - *

- * Copyright 2012 BACKENDLESS.COM. All Rights Reserved. - *

- * NOTICE:  All information contained herein is, and remains the property of Backendless.com and its suppliers, - * if any.  The intellectual and technical concepts contained herein are proprietary to Backendless.com and its - * suppliers and may be covered by U.S. and Foreign Patents, patents in process, and are protected by trade secret - * or copyright law. Dissemination of this information or reproduction of this material is strictly forbidden - * unless prior written permission is obtained from Backendless.com. - *

- * ******************************************************************************************************************** - */ - package com.chargify.model; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; import java.util.Date; -@JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data public class Customer implements Serializable { + @JsonProperty( "first_name" ) private String firstName; + @JsonProperty( "last_name" ) private String lastName; + @JsonProperty( "email" ) private String email; - @JsonProperty( "cc_emails" ) private String ccEmails; @@ -82,229 +68,4 @@ public Customer( @JsonProperty( "first_name" ) String firstName, this.lastName = lastName; this.email = email; } - - public Customer() - { - - } - - @JsonProperty( "first_name" ) - public String getFirstName() - { - return firstName; - } - - @JsonProperty( "last_name" ) - public String getLastName() - { - return lastName; - } - - @JsonProperty( "email" ) - public String getEmail() - { - return email; - } - - public void setEmail( String email ) - { - this.email = email; - } - - public String getCcEmails() - { - return ccEmails; - } - - public void setCcEmails( String ccEmails ) - { - this.ccEmails = ccEmails; - } - - public String getOrganization() - { - return organization; - } - - public void setOrganization( String organization ) - { - this.organization = organization; - } - - public String getReference() - { - return reference; - } - - public void setReference( String reference ) - { - this.reference = reference; - } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public Date getCreatedAt() - { - return createdAt; - } - - public void setCreatedAt( Date createdAt ) - { - this.createdAt = createdAt; - } - - public Date getUpdatedAt() - { - return updatedAt; - } - - public void setUpdatedAt( Date updatedAt ) - { - this.updatedAt = updatedAt; - } - - public String getAddress() - { - return address; - } - - public void setAddress( String address ) - { - this.address = address; - } - - public String getAddress2() - { - return address2; - } - - public void setAddress2( String address2 ) - { - this.address2 = address2; - } - - public String getCity() - { - return city; - } - - public void setCity( String city ) - { - this.city = city; - } - - public String getState() - { - return state; - } - - public void setState( String state ) - { - this.state = state; - } - - public String getZip() - { - return zip; - } - - public void setZip( String zip ) - { - this.zip = zip; - } - - public String getCountry() - { - return country; - } - - public void setCountry( String country ) - { - this.country = country; - } - - public String getPhone() - { - return phone; - } - - public void setPhone( String phone ) - { - this.phone = phone; - } - - public Boolean getVerified() - { - return verified; - } - - public void setVerified( Boolean verified ) - { - this.verified = verified; - } - - public Date getPortalCustomerCreatedAt() - { - return portalCustomerCreatedAt; - } - - public void setPortalCustomerCreatedAt( Date portalCustomerCreatedAt ) - { - this.portalCustomerCreatedAt = portalCustomerCreatedAt; - } - - public Date getPortalInviteLastSentAt() - { - return portalInviteLastSentAt; - } - - public void setPortalInviteLastSentAt( Date portalInviteLastSentAt ) - { - this.portalInviteLastSentAt = portalInviteLastSentAt; - } - - public Date getPortalInviteLastAcceptedAt() - { - return portalInviteLastAcceptedAt; - } - - public void setPortalInviteLastAcceptedAt( Date portalInviteLastAcceptedAt ) - { - this.portalInviteLastAcceptedAt = portalInviteLastAcceptedAt; - } - - @Override - public String toString() - { - return "Customer{" + - "firstName='" + firstName + '\'' + - ", lastName='" + lastName + '\'' + - ", email='" + email + '\'' + - ", ccEmails='" + ccEmails + '\'' + - ", organization='" + organization + '\'' + - ", reference='" + reference + '\'' + - ", id='" + id + '\'' + - ", createdAt=" + createdAt + - ", updatedAt=" + updatedAt + - ", address='" + address + '\'' + - ", address2='" + address2 + '\'' + - ", city='" + city + '\'' + - ", state='" + state + '\'' + - ", zip='" + zip + '\'' + - ", country='" + country + '\'' + - ", phone='" + phone + '\'' + - ", verified=" + verified + - ", portalCustomerCreatedAt=" + portalCustomerCreatedAt + - ", portalInviteLastSentAt=" + portalInviteLastSentAt + - ", portalInviteLastAcceptedAt=" + portalInviteLastAcceptedAt + - '}'; - } } From 76098fb87b6da427f0f105fb2958d28c03f8c190 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Mon, 15 Aug 2022 10:42:52 +0300 Subject: [PATCH 36/58] [BKNDLSS-29334] Billing Service. Obtaining of Chargify subscription by ID should be async --- pom.xml | 8 +- src/main/java/com/chargify/Chargify.java | 3 +- .../java/com/chargify/ChargifyService.java | 125 ++++++++++++++---- .../ChargifyResponseErrorHandler.java | 44 +++++- .../exceptions/HttpServerErrorException.java | 18 +++ .../UnknownHttpStatusCodeException.java | 17 +++ 6 files changed, 178 insertions(+), 37 deletions(-) create mode 100644 src/main/java/com/chargify/exceptions/HttpServerErrorException.java create mode 100644 src/main/java/com/chargify/exceptions/UnknownHttpStatusCodeException.java diff --git a/pom.xml b/pom.xml index 8c91418..6b450d6 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.23 + 0.24 jar Chargify SDK for Java @@ -75,6 +75,12 @@ 1.2.11 + + org.apache.commons + commons-lang3 + 3.12.0 + + org.projectlombok diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 449e3ca..65b9d1d 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -8,6 +8,7 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Set; +import java.util.concurrent.CompletableFuture; public interface Chargify { @@ -43,7 +44,7 @@ public interface Chargify SubscriptionChargeResult createSubscriptionCharge( String subscriptionId, SubscriptionCharge subscriptionCharge ); - Subscription findSubscriptionById( String id ); + CompletableFuture findSubscriptionById( String id ); List findPaymentProfilesForCustomer( String customerId ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 9545eb0..6a65184 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -7,7 +7,12 @@ import com.chargify.model.product.ProductFamily; import com.chargify.model.product.ProductPricePoint; import com.chargify.model.wrappers.*; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RootUriTemplateHandler; import org.springframework.http.HttpEntity; @@ -16,53 +21,81 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriUtils; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.HttpRequest; +import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Arrays; +import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; public final class ChargifyService implements Chargify { private final RestTemplate httpClient; + private final String chargifyApiUrl; + private final HttpClient nativeHttpClient; + private final String basicAuthHeaderValue; + private final ObjectMapper objectMapper; + public ChargifyService( final String domain, final String apiKey ) { - this.httpClient = new RestTemplateBuilder() - .uriTemplateHandler( new RootUriTemplateHandler( "https://" + domain + ".chargify.com" ) ) - .basicAuthentication( apiKey, "x" ) - .errorHandler( new ChargifyResponseErrorHandler() ) - .build(); - - this.httpClient.getMessageConverters().stream() - .filter( AbstractJackson2HttpMessageConverter.class::isInstance ) - .map( AbstractJackson2HttpMessageConverter.class::cast ) - .map( AbstractJackson2HttpMessageConverter::getObjectMapper ) - .forEach( mapper -> mapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ) ); + this( "https://" + domain + ".chargify.com", apiKey, + new RestTemplateBuilder() + .uriTemplateHandler( new RootUriTemplateHandler( "https://" + domain + ".chargify.com" ) ) + .basicAuthentication( apiKey, "x" ) + .errorHandler( new ChargifyResponseErrorHandler() ) + .build() ); } public ChargifyService( final String domain, final String apiKey, int connectTimeoutInMillis, int readTimeoutInMillis ) { - this.httpClient = new RestTemplateBuilder() - .uriTemplateHandler( new RootUriTemplateHandler( "https://" + domain + ".chargify.com" ) ) - .basicAuthentication( apiKey, "x" ) - .setConnectTimeout( Duration.ofMillis( connectTimeoutInMillis ) ) - .setReadTimeout( Duration.ofMillis( readTimeoutInMillis ) ) - .errorHandler( new ChargifyResponseErrorHandler() ) - .build(); + this( "https://" + domain + ".chargify.com", apiKey, + new RestTemplateBuilder() + .uriTemplateHandler( new RootUriTemplateHandler( "https://" + domain + ".chargify.com" ) ) + .basicAuthentication( apiKey, "x" ) + .setConnectTimeout( Duration.ofMillis( connectTimeoutInMillis ) ) + .setReadTimeout( Duration.ofMillis( readTimeoutInMillis ) ) + .errorHandler( new ChargifyResponseErrorHandler() ) + .build() ); + } + + private ChargifyService( String chargifyApiUrl, String apiKey, RestTemplate httpClient ) + { + this.chargifyApiUrl = chargifyApiUrl; + this.httpClient = httpClient; this.httpClient.getMessageConverters().stream() .filter( AbstractJackson2HttpMessageConverter.class::isInstance ) .map( AbstractJackson2HttpMessageConverter.class::cast ) .map( AbstractJackson2HttpMessageConverter::getObjectMapper ) .forEach( mapper -> mapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ) ); + + this.nativeHttpClient = HttpClient.newBuilder() + .version( HttpClient.Version.HTTP_2 ) + .followRedirects( HttpClient.Redirect.ALWAYS ) + .build(); + + String plainCreds = apiKey + ":x"; + String base64Creds = Base64.getEncoder().encodeToString( plainCreds.getBytes() ); + + basicAuthHeaderValue = "Basic " + base64Creds; + + this.objectMapper = new ObjectMapper(); + this.objectMapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ); + this.objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + this.objectMapper.registerModules( new JavaTimeModule() ); } @Override @@ -251,17 +284,26 @@ public SubscriptionChargeResult createSubscriptionCharge( String subscriptionId, } @Override - public Subscription findSubscriptionById( String id ) + public CompletableFuture findSubscriptionById( String id ) { - try - { - return httpClient.getForObject( "/subscriptions/" + id + ".json", SubscriptionWrapper.class ) - .getSubscription(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + HttpRequest request = HttpRequest.newBuilder() + .uri( URI.create( chargifyApiUrl + "/subscriptions/" + id + ".json" ) ) + .header( "Authorization", basicAuthHeaderValue ) + .GET() + .build(); + + return nativeHttpClient.sendAsync( request, HttpResponse.BodyHandlers.ofString() ) + .thenApply( response -> handleResponse( response, SubscriptionWrapper.class ) ) + .thenApply( SubscriptionWrapper::getSubscription ) + .exceptionally( e -> { + Throwable rootCause = ExceptionUtils.getRootCause( e ); + if( rootCause instanceof ResourceNotFoundException ) + return null; + else if( rootCause instanceof RuntimeException ) + throw (RuntimeException) rootCause; + else + throw new RuntimeException( rootCause ); + } ); } @Override @@ -815,4 +857,31 @@ private String prepareSubscriptionReactivationURI( String subscriptionId, Subscr return urlBuilder.toString(); } + + public T handleResponse( HttpResponse response, Class type ) + { + final E body = response.body(); + + if( !(body instanceof String) && !(body instanceof byte[]) ) + { + throw new IllegalArgumentException( "Body should be String or byte[]" ); + } + + final String strBody = body instanceof String ? (String) body : new String( (byte[]) body ); + final int statusCode = response.statusCode(); + + ChargifyResponseErrorHandler.handleError( statusCode, strBody ); + + if( type == Void.class ) + return null; + + try + { + return objectMapper.readValue( strBody, type ); + } + catch( JsonProcessingException e ) + { + throw new RuntimeException( e ); + } + } } diff --git a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java index 39ff2ef..f349cc6 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java +++ b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java @@ -1,18 +1,50 @@ package com.chargify.exceptions; +import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.DefaultResponseErrorHandler; -import org.springframework.web.client.HttpServerErrorException; -import org.springframework.web.client.UnknownHttpStatusCodeException; import java.io.IOException; import java.io.InputStream; public final class ChargifyResponseErrorHandler extends DefaultResponseErrorHandler { - private ObjectMapper objectMapper = new ObjectMapper(); + private static final ObjectMapper objectMapper = new ObjectMapper(); + + public static void handleError( int statusCode, String strBody ) + { + if( statusCode >= 200 && statusCode < 300 ) + return; + + if( statusCode >= 300 && statusCode < 400 ) + { + if( statusCode == HttpStatus.NOT_FOUND.value() ) + throw new ResourceNotFoundException(); + else if( statusCode == HttpStatus.FORBIDDEN.value() ) // TODO: see issue https://chargify.zendesk.com/hc/en-us/requests/69553 + throw new ChargifyException( strBody ); + else + { + try + { + throw objectMapper.readValue( strBody, ChargifyError.class ).exception(); + } + catch( JsonProcessingException e ) + { + throw new RuntimeException( e ); + } + } + } + else if( statusCode >= 400 && statusCode < 500 ) + { + throw new HttpServerErrorException( statusCode, strBody ); + } + else + { + throw new UnknownHttpStatusCodeException( statusCode, strBody ); + } + } @Override protected void handleError( ClientHttpResponse response, HttpStatus statusCode ) throws IOException @@ -27,11 +59,9 @@ else if( statusCode == HttpStatus.FORBIDDEN ) // TODO: see issue https://chargif else throw objectMapper.readValue( response.getBody(), ChargifyError.class ).exception(); case SERVER_ERROR: - throw new HttpServerErrorException( statusCode, response.getStatusText(), - response.getHeaders(), getResponseBody( response ), getCharset( response ) ); + throw new HttpServerErrorException( statusCode.value(), readInputStream( response.getBody() ) ); default: - throw new UnknownHttpStatusCodeException( statusCode.value(), response.getStatusText(), - response.getHeaders(), getResponseBody( response ), getCharset( response ) ); + throw new UnknownHttpStatusCodeException( statusCode.value(), readInputStream( response.getBody() ) ); } } diff --git a/src/main/java/com/chargify/exceptions/HttpServerErrorException.java b/src/main/java/com/chargify/exceptions/HttpServerErrorException.java new file mode 100644 index 0000000..fbba436 --- /dev/null +++ b/src/main/java/com/chargify/exceptions/HttpServerErrorException.java @@ -0,0 +1,18 @@ +package com.chargify.exceptions; + +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +public class HttpServerErrorException extends RuntimeException +{ + private final int statusCode; + private final String responseBody; + + public HttpServerErrorException( int statusCode, String responseBody ) + { + super( HttpStatus.resolve( statusCode ).getReasonPhrase() + ". Body: " + responseBody ); + this.statusCode = statusCode; + this.responseBody = responseBody; + } +} diff --git a/src/main/java/com/chargify/exceptions/UnknownHttpStatusCodeException.java b/src/main/java/com/chargify/exceptions/UnknownHttpStatusCodeException.java new file mode 100644 index 0000000..a0f5d05 --- /dev/null +++ b/src/main/java/com/chargify/exceptions/UnknownHttpStatusCodeException.java @@ -0,0 +1,17 @@ +package com.chargify.exceptions; + +import lombok.Getter; + +@Getter +public class UnknownHttpStatusCodeException extends RuntimeException +{ + private final int statusCode; + private final String responseBody; + + public UnknownHttpStatusCodeException( int statusCode, String responseBody ) + { + super( "Unknown status code [" + statusCode + "] Body: " + responseBody ); + this.statusCode = statusCode; + this.responseBody = responseBody; + } +} From e2d7e5b2a312e52110f0480348a051ace7160baa Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Tue, 6 Sep 2022 19:39:55 +0300 Subject: [PATCH 37/58] Fixed bug related to errors handling --- pom.xml | 28 +++++++++---------- .../ChargifyResponseErrorHandler.java | 4 +-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 6b450d6..4f2e95b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.24 + 0.25 jar Chargify SDK for Java @@ -131,19 +131,19 @@ - - org.apache.maven.plugins - maven-javadoc-plugin - 3.3.1 - - - attach-javadocs - - jar - - - - + + + + + + + + + + + + + org.apache.maven.plugins maven-compiler-plugin diff --git a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java index f349cc6..a8b1f5f 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java +++ b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java @@ -18,7 +18,7 @@ public static void handleError( int statusCode, String strBody ) if( statusCode >= 200 && statusCode < 300 ) return; - if( statusCode >= 300 && statusCode < 400 ) + if( statusCode >= 400 && statusCode < 500 ) { if( statusCode == HttpStatus.NOT_FOUND.value() ) throw new ResourceNotFoundException(); @@ -36,7 +36,7 @@ else if( statusCode == HttpStatus.FORBIDDEN.value() ) // TODO: see issue https:/ } } } - else if( statusCode >= 400 && statusCode < 500 ) + else if( statusCode >= 500 && statusCode < 600 ) { throw new HttpServerErrorException( statusCode, strBody ); } From 65eeb4ab3cf0edab6d4b1565f408cd193c2b4108 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Wed, 7 Sep 2022 17:11:39 +0300 Subject: [PATCH 38/58] uncommented javadoc plugin --- pom.xml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 4f2e95b..c71ca7f 100644 --- a/pom.xml +++ b/pom.xml @@ -131,19 +131,19 @@ - - - - - - - - - - - - - + + org.apache.maven.plugins + maven-javadoc-plugin + 3.3.1 + + + attach-javadocs + + jar + + + + org.apache.maven.plugins maven-compiler-plugin From 61a03bcf8dcafe97da95a7467d0e25152e0b5db1 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Wed, 21 Sep 2022 15:10:10 +0300 Subject: [PATCH 39/58] Added 'findSubscriptionsByCustomerId' with pagination --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 2 ++ src/main/java/com/chargify/ChargifyService.java | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c71ca7f..92ffc32 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.25 + 0.26 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 65b9d1d..5d70d1d 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -62,6 +62,8 @@ public interface Chargify List findSubscriptionsByCustomerId( String customerId ); + List findSubscriptionsByCustomerId( String customerId, int pageNumber, int pageSize ); + List findAllSubscriptions(); Subscription purgeSubscription( Subscription subscription ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 6a65184..5d6b7cc 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -377,7 +377,14 @@ public void deletePaymentProfile( String subscriptionId, String paymentProfileId @Override public List findSubscriptionsByCustomerId( String customerId ) { - return Arrays.stream( httpClient.getForObject( "/customers/" + customerId + "/subscriptions.json", + return findSubscriptionsByCustomerId( customerId, 0, 200 ); + } + + @Override + public List findSubscriptionsByCustomerId( String customerId, int pageNumber, int pageSize ) + { + return Arrays.stream( httpClient.getForObject( + "/customers/" + customerId + "/subscriptions.json?page=" + pageNumber + "&" + "per_page=" + pageSize, SubscriptionWrapper[].class ) ) .map( SubscriptionWrapper::getSubscription ) .collect( Collectors.toList() ); From 96e0d2dab71a069964b7a4f6bcddaeb8dd676081 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Fri, 23 Sep 2022 18:01:18 +0300 Subject: [PATCH 40/58] Replaced Java HttpClient by Spring WebClient --- pom.xml | 26 +- src/main/java/com/chargify/Chargify.java | 18 +- .../java/com/chargify/ChargifyService.java | 222 +++++++----------- .../ChargifyResponseErrorHandler.java | 51 ++++ src/test/java/com/chargify/ChargifyTest.java | 2 +- 5 files changed, 161 insertions(+), 158 deletions(-) diff --git a/pom.xml b/pom.xml index 92ffc32..d4792f3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.26 + 0.27 jar Chargify SDK for Java @@ -48,31 +48,37 @@ org.springframework spring-web - 5.3.19 + 5.3.22 + + + + org.springframework + spring-webflux + 5.3.23 org.springframework.boot spring-boot - 2.6.7 + 2.7.3 com.fasterxml.jackson.core jackson-databind - 2.13.2.2 + 2.13.4 com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.13.2 + 2.13.4 ch.qos.logback logback-classic - 1.2.11 + 1.4.0 @@ -99,10 +105,16 @@ org.springframework spring-test - 5.3.19 + 5.3.22 test + + io.projectreactor.netty + reactor-netty + 1.0.23 + + diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 5d70d1d..e2da474 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -4,11 +4,11 @@ import com.chargify.model.product.Product; import com.chargify.model.product.ProductFamily; import com.chargify.model.product.ProductPricePoint; +import reactor.core.publisher.Mono; import java.time.LocalDateTime; import java.util.List; import java.util.Set; -import java.util.concurrent.CompletableFuture; public interface Chargify { @@ -28,7 +28,7 @@ public interface Chargify Set findProductPricePointsByProductId( String productId ); - Set findComponentPricePoints( int componentId ); + Mono> findComponentPricePoints( int componentId ); List findAllProducts(); @@ -44,7 +44,7 @@ public interface Chargify SubscriptionChargeResult createSubscriptionCharge( String subscriptionId, SubscriptionCharge subscriptionCharge ); - CompletableFuture findSubscriptionById( String id ); + Mono findSubscriptionById( String id ); List findPaymentProfilesForCustomer( String customerId ); @@ -78,9 +78,9 @@ public interface Chargify Subscription migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ); - Subscription reactivateSubscription( String subscriptionId, boolean preserveBalance ); + Mono reactivateSubscription( String subscriptionId, boolean preserveBalance ); - Subscription reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ); + Mono reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ); ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subscriptionId, int componentId, String pricePointHandle ); @@ -109,18 +109,18 @@ ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subsc List findComponentsByProductFamily( String productFamilyId ); - Component findComponentByIdAndProductFamily( int componentId, String productFamilyId ); + Mono findComponentByIdAndProductFamily( int componentId, String productFamilyId ); - ComponentWithPricePoints findComponentWithPricePointsByIdAndProductFamily( int componentId, String productFamilyId ); + Mono findComponentWithPricePointsByIdAndProductFamily( int componentId, String productFamilyId ); List findSubscriptionComponents( String subscriptionId ); List findSubscriptionStatements( String subscriptionId, int page, int pageSize, String sort, String direction ); - SubscriptionComponent findSubscriptionComponentById( String subscriptionId, int componentId ); + Mono findSubscriptionComponentById( String subscriptionId, int componentId ); - Usage reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ); + Mono reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ); Customer createCustomer( Customer customer ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 5d6b7cc..f444a4f 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -12,18 +12,23 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import io.netty.channel.ChannelOption; import org.apache.commons.lang3.exception.ExceptionUtils; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.client.RootUriTemplateHandler; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.http.codec.json.Jackson2JsonDecoder; +import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; import org.springframework.web.client.RestTemplate; +import org.springframework.web.reactive.function.client.ExchangeStrategies; +import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.util.UriUtils; +import reactor.core.publisher.Mono; -import java.net.URI; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.time.Duration; @@ -36,45 +41,26 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; public final class ChargifyService implements Chargify { private final RestTemplate httpClient; + private final WebClient client; - private final String chargifyApiUrl; - private final HttpClient nativeHttpClient; - private final String basicAuthHeaderValue; private final ObjectMapper objectMapper; - public ChargifyService( final String domain, final String apiKey ) - { - this( "https://" + domain + ".chargify.com", apiKey, - new RestTemplateBuilder() - .uriTemplateHandler( new RootUriTemplateHandler( "https://" + domain + ".chargify.com" ) ) - .basicAuthentication( apiKey, "x" ) - .errorHandler( new ChargifyResponseErrorHandler() ) - .build() ); - } - public ChargifyService( final String domain, final String apiKey, int connectTimeoutInMillis, int readTimeoutInMillis ) { - this( "https://" + domain + ".chargify.com", apiKey, - new RestTemplateBuilder() - .uriTemplateHandler( new RootUriTemplateHandler( "https://" + domain + ".chargify.com" ) ) - .basicAuthentication( apiKey, "x" ) - .setConnectTimeout( Duration.ofMillis( connectTimeoutInMillis ) ) - .setReadTimeout( Duration.ofMillis( readTimeoutInMillis ) ) - .errorHandler( new ChargifyResponseErrorHandler() ) - .build() ); - } - - private ChargifyService( String chargifyApiUrl, String apiKey, RestTemplate httpClient ) - { - this.chargifyApiUrl = chargifyApiUrl; - this.httpClient = httpClient; + String chargifyApiUrl = "https://" + domain + ".chargify.com"; + this.httpClient = new RestTemplateBuilder() + .uriTemplateHandler( new RootUriTemplateHandler( chargifyApiUrl ) ) + .basicAuthentication( apiKey, "x" ) + .setConnectTimeout( Duration.ofMillis( connectTimeoutInMillis ) ) + .setReadTimeout( Duration.ofMillis( readTimeoutInMillis ) ) + .errorHandler( new ChargifyResponseErrorHandler() ) + .build(); this.httpClient.getMessageConverters().stream() .filter( AbstractJackson2HttpMessageConverter.class::isInstance ) @@ -82,20 +68,36 @@ private ChargifyService( String chargifyApiUrl, String apiKey, RestTemplate http .map( AbstractJackson2HttpMessageConverter::getObjectMapper ) .forEach( mapper -> mapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ) ); - this.nativeHttpClient = HttpClient.newBuilder() - .version( HttpClient.Version.HTTP_2 ) - .followRedirects( HttpClient.Redirect.ALWAYS ) - .build(); - String plainCreds = apiKey + ":x"; String base64Creds = Base64.getEncoder().encodeToString( plainCreds.getBytes() ); - basicAuthHeaderValue = "Basic " + base64Creds; + String basicAuthHeaderValue = "Basic " + base64Creds; this.objectMapper = new ObjectMapper(); this.objectMapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ); this.objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); this.objectMapper.registerModules( new JavaTimeModule() ); + + final int size = 16 * 1024 * 1024; + final ExchangeStrategies strategies = ExchangeStrategies.builder() + .codecs( codecs -> codecs.defaultCodecs().maxInMemorySize( size ) ) + .build(); + + this.client = WebClient.builder() + .baseUrl( chargifyApiUrl ) + .exchangeStrategies( strategies ) + .defaultHeader( "Authorization", basicAuthHeaderValue ) + .clientConnector( new ReactorClientHttpConnector( + reactor.netty.http.client.HttpClient.create() + .followRedirect( true ) + .option( ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutInMillis ) + .responseTimeout( Duration.ofMillis( readTimeoutInMillis ) ) + ) ) + .codecs( clientDefaultCodecsConfigurer -> { + clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder( new Jackson2JsonEncoder( objectMapper, MediaType.APPLICATION_JSON ) ); + clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder( new Jackson2JsonDecoder( objectMapper, MediaType.APPLICATION_JSON ) ); + } ) + .build(); } @Override @@ -198,18 +200,12 @@ public Set findProductPricePointsByProductId( String productI } @Override - public Set findComponentPricePoints( int componentId ) + public Mono> findComponentPricePoints( int componentId ) { - try - { - return httpClient.getForObject( - "/components/" + componentId + "/price_points.json", ComponentPricePointsWrapper.class ) - .getPricePoints(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/components/" + componentId + "/price_points.json" ).retrieve() ) + .bodyToMono( ComponentPricePointsWrapper.class ) + .map( ComponentPricePointsWrapper::getPricePoints ); } @Override @@ -284,26 +280,12 @@ public SubscriptionChargeResult createSubscriptionCharge( String subscriptionId, } @Override - public CompletableFuture findSubscriptionById( String id ) + public Mono findSubscriptionById( String id ) { - HttpRequest request = HttpRequest.newBuilder() - .uri( URI.create( chargifyApiUrl + "/subscriptions/" + id + ".json" ) ) - .header( "Authorization", basicAuthHeaderValue ) - .GET() - .build(); - - return nativeHttpClient.sendAsync( request, HttpResponse.BodyHandlers.ofString() ) - .thenApply( response -> handleResponse( response, SubscriptionWrapper.class ) ) - .thenApply( SubscriptionWrapper::getSubscription ) - .exceptionally( e -> { - Throwable rootCause = ExceptionUtils.getRootCause( e ); - if( rootCause instanceof ResourceNotFoundException ) - return null; - else if( rootCause instanceof RuntimeException ) - throw (RuntimeException) rootCause; - else - throw new RuntimeException( rootCause ); - } ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/subscriptions/" + id + ".json" ).retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ); } @Override @@ -469,26 +451,23 @@ public Subscription migrateSubscription( String subscriptionId, String productHa } @Override - public Subscription reactivateSubscription( String subscriptionId, boolean preserveBalance ) + public Mono reactivateSubscription( String subscriptionId, boolean preserveBalance ) { - return httpClient.exchange( "/subscriptions/" + subscriptionId + "/reactivate.json", HttpMethod.PUT, - new HttpEntity<>( Map.of( "preserve_balance", preserveBalance ) ), - SubscriptionWrapper.class ) - .getBody() - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/subscriptions/" + subscriptionId + "/reactivate.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of( "preserve_balance", preserveBalance ) ), Map.class ) + .retrieve() ).bodyToMono( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); } @Override - public Subscription reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ) + public Mono reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ) { - return httpClient.exchange( - prepareSubscriptionReactivationURI( subscriptionId, reactivationData ), - HttpMethod.PUT, - HttpEntity.EMPTY, - SubscriptionWrapper.class - ) - .getBody() - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( prepareSubscriptionReactivationURI( subscriptionId, reactivationData ) ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of() ), Map.class ) + .retrieve() ).bodyToMono( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); } @Override @@ -652,26 +631,20 @@ public List findComponentsByProductFamily( String productFamilyId ) } @Override - public Component findComponentByIdAndProductFamily( int componentId, String productFamilyId ) + public Mono findComponentByIdAndProductFamily( int componentId, String productFamilyId ) { - try - { - return httpClient.getForObject( "/product_families/" + productFamilyId + - "/components/" + componentId + ".json", - AnyComponentWrapper.class ) - .getComponent(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/product_families/" + productFamilyId + "/components/" + componentId + ".json" ).retrieve() ) + .bodyToMono( AnyComponentWrapper.class ) + .map( AnyComponentWrapper::getComponent ); } @Override - public ComponentWithPricePoints findComponentWithPricePointsByIdAndProductFamily( int componentId, String productFamilyId ) + public Mono findComponentWithPricePointsByIdAndProductFamily( int componentId, String productFamilyId ) { - return new ComponentWithPricePoints( findComponentByIdAndProductFamily( componentId, productFamilyId ), - findComponentPricePoints( componentId ) ); + return findComponentByIdAndProductFamily( componentId, productFamilyId ) + .flatMap( component -> findComponentPricePoints( componentId ) + .map( componentPricePoints -> new ComponentWithPricePoints( component, componentPricePoints ) ) ); } @Override @@ -706,28 +679,22 @@ public List findSubscriptionStatements( } @Override - public SubscriptionComponent findSubscriptionComponentById( String subscriptionId, int componentId ) + public Mono findSubscriptionComponentById( String subscriptionId, int componentId ) { - try - { - return httpClient.getForObject( "/subscriptions/" + subscriptionId + - "/components/" + componentId + ".json", - SubscriptionComponentWrapper.class ) - .getComponent(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/subscriptions/" + subscriptionId + "/components/" + componentId + ".json" ).retrieve() ) + .bodyToMono( SubscriptionComponentWrapper.class ) + .map( SubscriptionComponentWrapper::getComponent ); } @Override - public Usage reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ) + public Mono reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ) { - return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/components/" + componentId + - "/usages.json", - new UsageWrapper( usage ), UsageWrapper.class ) - .getUsage(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/components/" + componentId + "/usages.json" ) + .body( Mono.just( new UsageWrapper( usage ) ), UsageWrapper.class ).retrieve() ) + .bodyToMono( UsageWrapper.class ) + .map( UsageWrapper::getUsage ); } @Override @@ -864,31 +831,4 @@ private String prepareSubscriptionReactivationURI( String subscriptionId, Subscr return urlBuilder.toString(); } - - public T handleResponse( HttpResponse response, Class type ) - { - final E body = response.body(); - - if( !(body instanceof String) && !(body instanceof byte[]) ) - { - throw new IllegalArgumentException( "Body should be String or byte[]" ); - } - - final String strBody = body instanceof String ? (String) body : new String( (byte[]) body ); - final int statusCode = response.statusCode(); - - ChargifyResponseErrorHandler.handleError( statusCode, strBody ); - - if( type == Void.class ) - return null; - - try - { - return objectMapper.readValue( strBody, type ); - } - catch( JsonProcessingException e ) - { - throw new RuntimeException( e ); - } - } } diff --git a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java index a8b1f5f..46d7d9b 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java +++ b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java @@ -1,10 +1,15 @@ package com.chargify.exceptions; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.DefaultResponseErrorHandler; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; import java.io.IOException; import java.io.InputStream; @@ -13,6 +18,12 @@ public final class ChargifyResponseErrorHandler extends DefaultResponseErrorHand { private static final ObjectMapper objectMapper = new ObjectMapper(); + static { + objectMapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ); + objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + objectMapper.registerModules( new JavaTimeModule() ); + } + public static void handleError( int statusCode, String strBody ) { if( statusCode >= 200 && statusCode < 300 ) @@ -46,6 +57,46 @@ else if( statusCode >= 500 && statusCode < 600 ) } } + public static WebClient.ResponseSpec handleError( WebClient.ResponseSpec response ) + { + response.onStatus( HttpStatus::is4xxClientError, clientResponse -> { + HttpStatus statusCode = clientResponse.statusCode(); + if( statusCode == HttpStatus.NOT_FOUND ) + return Mono.empty(); + else if( statusCode == HttpStatus.FORBIDDEN ) // TODO: see issue https://chargify.zendesk.com/hc/en-us/requests/69553 + return clientResponse.bodyToMono( String.class ).map( ChargifyException::new ).flatMap( Mono::error ); + else + { + return clientResponse.bodyToMono( String.class ) + .map( body -> { + try + { + return objectMapper.readValue( body, ChargifyError.class ).exception(); + } + catch( JsonProcessingException e ) + { + throw new RuntimeException( e ); + } + } ) + .flatMap( Mono::error ); + } + } ); + + response.onStatus( + HttpStatus::is5xxServerError, + clientResponse -> clientResponse.bodyToMono( String.class ) + .map( message -> new HttpServerErrorException( clientResponse.statusCode().value(), message ) ) + .flatMap( Mono::error ) ); + + response.onStatus( + HttpStatus::isError, + clientResponse -> response.bodyToMono( String.class ) + .map( message -> new UnknownHttpStatusCodeException( clientResponse.statusCode().value(), message ) ) + .flatMap( Mono::error ) ); + + return response; + } + @Override protected void handleError( ClientHttpResponse response, HttpStatus statusCode ) throws IOException { diff --git a/src/test/java/com/chargify/ChargifyTest.java b/src/test/java/com/chargify/ChargifyTest.java index 6161bea..e49661a 100644 --- a/src/test/java/com/chargify/ChargifyTest.java +++ b/src/test/java/com/chargify/ChargifyTest.java @@ -16,7 +16,7 @@ public abstract class ChargifyTest "-Dchargify.domain=XXX -Dchargify.apikey=YYY" ); } - chargify = new ChargifyService( domain, apiKey ); + chargify = new ChargifyService( domain, apiKey, 5000, 5000 ); } protected static String randomName() From b27c2105140b8504b5712d679b04dccf218d7c75 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Tue, 4 Oct 2022 11:49:32 +0300 Subject: [PATCH 41/58] [BKNDLSS-29663] Reactive API for Chargify --- pom.xml | 18 +- src/main/java/com/chargify/Chargify.java | 116 +-- .../java/com/chargify/ChargifyService.java | 833 +++++++++--------- .../java/com/chargify/ComponentsTest.java | 10 +- src/test/java/com/chargify/CustomersTest.java | 18 +- .../com/chargify/ProductFamiliesTest.java | 14 +- src/test/java/com/chargify/ProductsTest.java | 28 +- .../SubscriptionDelayedChangeTest.java | 22 +- .../java/com/chargify/SubscriptionsTest.java | 30 +- 9 files changed, 533 insertions(+), 556 deletions(-) diff --git a/pom.xml b/pom.xml index d4792f3..d4b6488 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.27 + 0.28 jar Chargify SDK for Java @@ -45,24 +45,12 @@ - - org.springframework - spring-web - 5.3.22 - - org.springframework spring-webflux 5.3.23 - - org.springframework.boot - spring-boot - 2.7.3 - - com.fasterxml.jackson.core jackson-databind @@ -78,7 +66,7 @@ ch.qos.logback logback-classic - 1.4.0 + 1.4.1 @@ -105,7 +93,7 @@ org.springframework spring-test - 5.3.22 + 5.3.23 test diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index e2da474..d80f303 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -4,133 +4,133 @@ import com.chargify.model.product.Product; import com.chargify.model.product.ProductFamily; import com.chargify.model.product.ProductPricePoint; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.time.LocalDateTime; import java.util.List; -import java.util.Set; public interface Chargify { - ProductFamily createProductFamily( ProductFamily productFamily ); + Mono createProductFamily( ProductFamily productFamily ); - ProductFamily findProductFamilyById( String id ); + Mono findProductFamilyById( String id ); - List findAllProductFamilies(); + Flux findAllProductFamilies(); - ProductFamily archiveProductFamilyById( String id ); + Mono archiveProductFamilyById( String id ); - Product createProduct( String productFamilyId, Product product ); + Mono createProduct( String productFamilyId, Product product ); - Product findProductById( String id ); + Mono findProductById( String id ); - Product findProductByApiHandle( String apiHandle ); + Mono findProductByApiHandle( String apiHandle ); - Set findProductPricePointsByProductId( String productId ); + Flux findProductPricePointsByProductId( String productId ); - Mono> findComponentPricePoints( int componentId ); + Flux findComponentPricePoints( int componentId ); - List findAllProducts(); + Flux findAllProducts(); - List findProductsByProductFamilyId( String productFamilyId ); + Flux findProductsByProductFamilyId( String productFamilyId ); - Product archiveProductById( String id ); + Mono archiveProductById( String id ); - Subscription createSubscription( CreateSubscription subscription ); + Mono createSubscription( CreateSubscription subscription ); - void updateSubscription( String subscriptionId, UpdateSubscription subscription ); + Mono updateSubscription( String subscriptionId, UpdateSubscription subscription ); - void updateSubscriptionNextBillingDate( String subscriptionId, LocalDateTime nextBillingDate ); + Mono updateSubscriptionNextBillingDate( String subscriptionId, LocalDateTime nextBillingDate ); - SubscriptionChargeResult createSubscriptionCharge( String subscriptionId, SubscriptionCharge subscriptionCharge ); + Mono createSubscriptionCharge( String subscriptionId, SubscriptionCharge subscriptionCharge ); Mono findSubscriptionById( String id ); - List findPaymentProfilesForCustomer( String customerId ); + Flux findPaymentProfilesForCustomer( String customerId ); - PaymentProfile createPaymentProfile( CreatePaymentProfile paymentProfile ); + Mono createPaymentProfile( CreatePaymentProfile paymentProfile ); - void updatePaymentProfile( String paymentProfileId, UpdatePaymentProfile paymentProfile ); + Mono updatePaymentProfile( String paymentProfileId, UpdatePaymentProfile paymentProfile ); - PaymentProfile updateSubscriptionPaymentProfile( String subscriptionId, String paymentProfileId ); + Mono updateSubscriptionPaymentProfile( String subscriptionId, String paymentProfileId ); - PaymentProfile findPaymentProfileById( String paymentProfileId ); + Mono findPaymentProfileById( String paymentProfileId ); - void deleteUnusedPaymentProfile( String paymentProfileId ); + Mono deleteUnusedPaymentProfile( String paymentProfileId ); - void deletePaymentProfile( String subscriptionId, String paymentProfileId ); + Mono deletePaymentProfile( String subscriptionId, String paymentProfileId ); - List findSubscriptionsByCustomerId( String customerId ); + Flux findSubscriptionsByCustomerId( String customerId ); - List findSubscriptionsByCustomerId( String customerId, int pageNumber, int pageSize ); + Flux findSubscriptionsByCustomerId( String customerId, int pageNumber, int pageSize ); - List findAllSubscriptions(); + Flux findAllSubscriptions(); - Subscription purgeSubscription( Subscription subscription ); + Mono purgeSubscription( Subscription subscription ); - List findSubscriptionsByState( String state, int pageNumber, int pageSize ); + Flux findSubscriptionsByState( String state, int pageNumber, int pageSize ); - Subscription cancelSubscriptionById( String id ); + Mono cancelSubscriptionById( String id ); - Subscription cancelSubscriptionProductChange( String subscriptionId ); + Mono cancelSubscriptionProductChange( String subscriptionId ); - Subscription migrateSubscription( String subscriptionId, String productHandle ); + Mono migrateSubscription( String subscriptionId, String productHandle ); - Subscription migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ); + Mono migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ); Mono reactivateSubscription( String subscriptionId, boolean preserveBalance ); Mono reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ); - ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subscriptionId, int componentId, + Mono migrateSubscriptionComponentToPricePoint( String subscriptionId, int componentId, String pricePointHandle ); - List bulkUpdateSubscriptionComponentPricePoint( String subscriptionId, List items ); + Flux bulkUpdateSubscriptionComponentPricePoint( String subscriptionId, List items ); - Subscription cancelScheduledSubscriptionProductChange( String subscriptionId ); + Mono cancelScheduledSubscriptionProductChange( String subscriptionId ); - Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, boolean delayed ); + Mono changeSubscriptionProduct( String subscriptionId, String productHandle, boolean delayed ); - Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, String pricePointHandle, boolean delayed ); + Mono changeSubscriptionProduct( String subscriptionId, String productHandle, String pricePointHandle, boolean delayed ); - RenewalPreview previewSubscriptionRenewal( String subscriptionId ); + Mono previewSubscriptionRenewal( String subscriptionId ); - List createSubscriptionMetadata( String subscriptionId, Metadata... metadata ); + Flux createSubscriptionMetadata( String subscriptionId, Metadata... metadata ); - SubscriptionMetadata readSubscriptionMetadata( String subscriptionId ); + Mono readSubscriptionMetadata( String subscriptionId ); - List updateSubscriptionMetadata( String subscriptionId, Metadata... metadata ); + Flux updateSubscriptionMetadata( String subscriptionId, Metadata... metadata ); - Component createComponent( String productFamilyId, Component component ); + Mono createComponent( String productFamilyId, Component component ); - Allocation createComponentAllocation( String subscriptionId, int componentId, Allocation allocation ); + Mono createComponentAllocation( String subscriptionId, int componentId, Allocation allocation ); - AllocationPreview previewComponentAllocation( String subscriptionId, int componentId, int quantity ); + Mono previewComponentAllocation( String subscriptionId, int componentId, int quantity ); - List findComponentsByProductFamily( String productFamilyId ); + Flux findComponentsByProductFamily( String productFamilyId ); Mono findComponentByIdAndProductFamily( int componentId, String productFamilyId ); Mono findComponentWithPricePointsByIdAndProductFamily( int componentId, String productFamilyId ); - List findSubscriptionComponents( String subscriptionId ); + Flux findSubscriptionComponents( String subscriptionId ); - List findSubscriptionStatements( + Flux findSubscriptionStatements( String subscriptionId, int page, int pageSize, String sort, String direction ); Mono findSubscriptionComponentById( String subscriptionId, int componentId ); Mono reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ); - Customer createCustomer( Customer customer ); + Mono createCustomer( Customer customer ); - Customer updateCustomer( Customer customer ); + Mono updateCustomer( Customer customer ); - Customer findCustomerById( String id ); + Mono findCustomerById( String id ); - Customer findCustomerByReference( String reference ); + Mono findCustomerByReference( String reference ); - Subscription findSubscriptionByReference( String reference ); + Mono findSubscriptionByReference( String reference ); /** * Search to retrieve a single or group of customers. @@ -139,13 +139,13 @@ List findSubscriptionStatements( * @param pageNumber (start from 1) the page parameter via the query string to access subsequent pages of 50 transactions * @return List of customers */ - List findCustomersBy( Object criterion, int pageNumber ); + Flux findCustomersBy( Object criterion, int pageNumber ); - List findAllCustomers(); + Flux findAllCustomers(); - void deleteCustomerById( String id ); + Mono deleteCustomerById( String id ); - ReferralCode validateReferralCode( String code ); + Mono validateReferralCode( String code ); - Adjustment adjust( String subscriptionId, Adjustment adjustment ); + Mono adjust( String subscriptionId, Adjustment adjustment ); } diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index f444a4f..3c026b8 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -7,45 +7,34 @@ import com.chargify.model.product.ProductFamily; import com.chargify.model.product.ProductPricePoint; import com.chargify.model.wrappers.*; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import io.netty.channel.ChannelOption; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.boot.web.client.RootUriTemplateHandler; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.json.Jackson2JsonEncoder; -import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; -import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.function.client.ExchangeStrategies; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.util.UriUtils; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.net.http.HttpResponse; import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.Arrays; import java.util.Base64; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.stream.Collectors; public final class ChargifyService implements Chargify { - private final RestTemplate httpClient; private final WebClient client; private final ObjectMapper objectMapper; @@ -54,229 +43,191 @@ public ChargifyService( final String domain, final String apiKey, int connectTim int readTimeoutInMillis ) { String chargifyApiUrl = "https://" + domain + ".chargify.com"; - this.httpClient = new RestTemplateBuilder() - .uriTemplateHandler( new RootUriTemplateHandler( chargifyApiUrl ) ) - .basicAuthentication( apiKey, "x" ) - .setConnectTimeout( Duration.ofMillis( connectTimeoutInMillis ) ) - .setReadTimeout( Duration.ofMillis( readTimeoutInMillis ) ) - .errorHandler( new ChargifyResponseErrorHandler() ) - .build(); - - this.httpClient.getMessageConverters().stream() - .filter( AbstractJackson2HttpMessageConverter.class::isInstance ) - .map( AbstractJackson2HttpMessageConverter.class::cast ) - .map( AbstractJackson2HttpMessageConverter::getObjectMapper ) - .forEach( mapper -> mapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ) ); - String plainCreds = apiKey + ":x"; String base64Creds = Base64.getEncoder().encodeToString( plainCreds.getBytes() ); - String basicAuthHeaderValue = "Basic " + base64Creds; this.objectMapper = new ObjectMapper(); this.objectMapper.disable( SerializationFeature.WRITE_DATES_AS_TIMESTAMPS ); - this.objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + this.objectMapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false ); this.objectMapper.registerModules( new JavaTimeModule() ); final int size = 16 * 1024 * 1024; final ExchangeStrategies strategies = ExchangeStrategies.builder() - .codecs( codecs -> codecs.defaultCodecs().maxInMemorySize( size ) ) - .build(); + .codecs( codecs -> codecs.defaultCodecs().maxInMemorySize( size ) ) + .build(); this.client = WebClient.builder() - .baseUrl( chargifyApiUrl ) - .exchangeStrategies( strategies ) - .defaultHeader( "Authorization", basicAuthHeaderValue ) - .clientConnector( new ReactorClientHttpConnector( - reactor.netty.http.client.HttpClient.create() - .followRedirect( true ) - .option( ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutInMillis ) - .responseTimeout( Duration.ofMillis( readTimeoutInMillis ) ) - ) ) - .codecs( clientDefaultCodecsConfigurer -> { - clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder( new Jackson2JsonEncoder( objectMapper, MediaType.APPLICATION_JSON ) ); - clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder( new Jackson2JsonDecoder( objectMapper, MediaType.APPLICATION_JSON ) ); - } ) - .build(); + .baseUrl( chargifyApiUrl ) + .exchangeStrategies( strategies ) + .defaultHeader( "Authorization", basicAuthHeaderValue ) + .clientConnector( new ReactorClientHttpConnector( + reactor.netty.http.client.HttpClient.create() + .followRedirect( true ) + .option( ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutInMillis ) + .responseTimeout( Duration.ofMillis( readTimeoutInMillis ) ) + ) ) + .codecs( clientDefaultCodecsConfigurer -> { + clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonEncoder( new Jackson2JsonEncoder( objectMapper, MediaType.APPLICATION_JSON ) ); + clientDefaultCodecsConfigurer.defaultCodecs().jackson2JsonDecoder( new Jackson2JsonDecoder( objectMapper, MediaType.APPLICATION_JSON ) ); + } ) + .build(); } @Override - public ProductFamily createProductFamily( ProductFamily productFamily ) + public Mono createProductFamily( ProductFamily productFamily ) { - return httpClient.postForObject( "/product_families.json", - new ProductFamilyWrapper( productFamily ), ProductFamilyWrapper.class ) - .getProductFamily(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/product_families.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new ProductFamilyWrapper( productFamily ) ), ProductFamilyWrapper.class ) + .retrieve() ).bodyToMono( ProductFamilyWrapper.class ).map( ProductFamilyWrapper::getProductFamily ); } @Override - public ProductFamily findProductFamilyById( String id ) + public Mono findProductFamilyById( String id ) { - try - { - return httpClient.getForObject( "/product_families/" + id + ".json", - ProductFamilyWrapper.class ) - .getProductFamily(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/product_families/" + id + ".json" ).retrieve() ) + .bodyToMono( ProductFamilyWrapper.class ).map( ProductFamilyWrapper::getProductFamily ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public List findAllProductFamilies() + public Flux findAllProductFamilies() { - return Arrays.stream( httpClient.getForObject( "/product_families.json", ProductFamilyWrapper[].class ) ) - .map( ProductFamilyWrapper::getProductFamily ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/product_families.json" ).retrieve() ) + .bodyToFlux( ProductFamilyWrapper.class ).map( ProductFamilyWrapper::getProductFamily ); } @Override - public ProductFamily archiveProductFamilyById( String id ) + public Mono archiveProductFamilyById( String id ) { - try - { - return httpClient.exchange( "/product_families/" + id + ".json", HttpMethod.DELETE, - HttpEntity.EMPTY, ProductFamilyWrapper.class ) - .getBody() - .getProductFamily(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.delete().uri( "/product_families/" + id + ".json" ).retrieve() ) + .bodyToMono( ProductFamilyWrapper.class ).map( ProductFamilyWrapper::getProductFamily ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Product createProduct( String productFamilyId, Product product ) + public Mono createProduct( String productFamilyId, Product product ) { - return httpClient.postForObject( "/product_families/" + productFamilyId + "/products.json", - new ProductWrapper( product ), ProductWrapper.class ) - .getProduct(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/product_families/" + productFamilyId + "/products.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new ProductWrapper( product ) ), ProductWrapper.class ) + .retrieve() ).bodyToMono( ProductWrapper.class ).map( ProductWrapper::getProduct ); } @Override - public Product findProductById( String id ) + public Mono findProductById( String id ) { - try - { - return httpClient.getForObject( "/products/" + id + ".json", ProductWrapper.class ) - .getProduct(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/products/" + id + ".json" ).retrieve() ) + .bodyToMono( ProductWrapper.class ).map( ProductWrapper::getProduct ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Product findProductByApiHandle( String apiHandle ) + public Mono findProductByApiHandle( String apiHandle ) { - try - { - return httpClient.getForObject( "/products/handle/" + apiHandle + ".json", - ProductWrapper.class ) - .getProduct(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/products/handle/" + apiHandle + ".json" ).retrieve() ) + .bodyToMono( ProductWrapper.class ).map( ProductWrapper::getProduct ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Set findProductPricePointsByProductId( String productId ) + public Flux findProductPricePointsByProductId( String productId ) { - try - { - return httpClient.getForObject( - "/products/" + productId + "/price_points.json", ProductPricePointsWrapper.class ) - .getPricePoints(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/products/" + productId + "/price_points.json" ).retrieve() ) + .bodyToMono( ProductPricePointsWrapper.class ).map( ProductPricePointsWrapper::getPricePoints ) + .flatMapMany( Flux::fromIterable ) + .onErrorResume( ResourceNotFoundException.class, ex -> Flux.empty() ); } @Override - public Mono> findComponentPricePoints( int componentId ) + public Flux findComponentPricePoints( int componentId ) { return ChargifyResponseErrorHandler.handleError( client.get().uri( "/components/" + componentId + "/price_points.json" ).retrieve() ) - .bodyToMono( ComponentPricePointsWrapper.class ) - .map( ComponentPricePointsWrapper::getPricePoints ); + .bodyToMono( ComponentPricePointsWrapper.class ) + .map( ComponentPricePointsWrapper::getPricePoints ) + .flatMapMany( Flux::fromIterable ); } @Override - public List findAllProducts() + public Flux findAllProducts() { - return Arrays.stream( httpClient.getForObject( "/products.json", ProductWrapper[].class ) ) - .map( ProductWrapper::getProduct ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/products.json" ).retrieve() ) + .bodyToFlux( ProductWrapper.class ).map( ProductWrapper::getProduct ); } @Override - public List findProductsByProductFamilyId( String productFamilyId ) + public Flux findProductsByProductFamilyId( String productFamilyId ) { - return Arrays.stream( httpClient.getForObject( "/product_families/" + productFamilyId + "/products.json", - ProductWrapper[].class ) ) - .map( ProductWrapper::getProduct ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/product_families/" + productFamilyId + "/products.json" ).retrieve() ) + .bodyToFlux( ProductWrapper.class ).map( ProductWrapper::getProduct ); } @Override - public Product archiveProductById( String id ) + public Mono archiveProductById( String id ) { - try - { - return httpClient.exchange( "/products/" + id + ".json", HttpMethod.DELETE, - HttpEntity.EMPTY, ProductWrapper.class ) - .getBody() - .getProduct(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.delete().uri( "/products/" + id + ".json" ).retrieve() ) + .bodyToMono( ProductWrapper.class ).map( ProductWrapper::getProduct ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Subscription createSubscription( CreateSubscription subscription ) + public Mono createSubscription( CreateSubscription subscription ) { - return httpClient.postForObject( "/subscriptions.json", new CreateSubscriptionWrapper( subscription ), SubscriptionWrapper.class ) - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new CreateSubscriptionWrapper( subscription ) ), SubscriptionWrapper.class ) + .retrieve() ).bodyToMono( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); } @Override - public void updateSubscription( String subscriptionId, UpdateSubscription subscription ) + public Mono updateSubscription( String subscriptionId, UpdateSubscription subscription ) { - httpClient.put( - "/subscriptions/" + subscriptionId + ".json", - new UpdateSubscriptionWrapper( subscription ) - ); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/subscriptions/" + subscriptionId + ".json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new UpdateSubscriptionWrapper( subscription ) ), UpdateSubscriptionWrapper.class ) + .retrieve() ).bodyToMono( Map.class ).then(); } @Override - public void updateSubscriptionNextBillingDate( String subscriptionId, LocalDateTime nextBillingDate ) + public Mono updateSubscriptionNextBillingDate( String subscriptionId, LocalDateTime nextBillingDate ) { - updateSubscription( - subscriptionId, - UpdateSubscription.builder() - .nextBillingAt( - nextBillingDate.atZone( ZoneId.systemDefault() ) - .withZoneSameInstant( ZoneId.of( "UTC" ) ) - .toLocalDateTime() - .format( DateTimeFormatter.ofPattern( "yyyy-MM-dd'T'HH:mm:ss'Z'" ) ) ).build() + return updateSubscription( + subscriptionId, + UpdateSubscription.builder() + .nextBillingAt( + nextBillingDate.atZone( ZoneId.systemDefault() ) + .withZoneSameInstant( ZoneId.of( "UTC" ) ) + .toLocalDateTime() + .format( DateTimeFormatter.ofPattern( "yyyy-MM-dd'T'HH:mm:ss'Z'" ) ) ).build() ); } @Override - public SubscriptionChargeResult createSubscriptionCharge( String subscriptionId, SubscriptionCharge subscriptionCharge ) + public Mono createSubscriptionCharge( String subscriptionId, + SubscriptionCharge subscriptionCharge ) { - return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/charges.json", - Map.of( "charge", subscriptionCharge ), SubscriptionChargeWrapper.class ) - .getSubscriptionChargeResult(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/charges.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of( "charge", subscriptionCharge ) ), Map.class ) + .retrieve() ) + .bodyToMono( SubscriptionChargeWrapper.class ) + .map( SubscriptionChargeWrapper::getSubscriptionChargeResult ); } @Override @@ -284,296 +235,336 @@ public Mono findSubscriptionById( String id ) { return ChargifyResponseErrorHandler.handleError( client.get().uri( "/subscriptions/" + id + ".json" ).retrieve() ) - .bodyToMono( SubscriptionWrapper.class ) - .map( SubscriptionWrapper::getSubscription ); + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ); } @Override - public List findPaymentProfilesForCustomer( String customerId ) + public Flux findPaymentProfilesForCustomer( String customerId ) { - try - { - return Arrays.stream( httpClient.getForObject( "/payment_profiles.json?customer_id=" + customerId, PaymentProfileWrapper[].class ) ) - .map( PaymentProfileWrapper::getPaymentProfile ) - .collect( Collectors.toList() ); - } - catch( ResourceNotFoundException e ) - { - return List.of(); - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/payment_profiles.json?customer_id=" + customerId ).retrieve() ) + .bodyToFlux( PaymentProfileWrapper.class ).map( PaymentProfileWrapper::getPaymentProfile ) + .onErrorResume( ResourceNotFoundException.class, ex -> Flux.empty() ); } @Override - public PaymentProfile createPaymentProfile( CreatePaymentProfile paymentProfile ) + public Mono createPaymentProfile( CreatePaymentProfile paymentProfile ) { Map body = new HashMap<>(); body.put( "payment_profile", paymentProfile ); - return httpClient.postForObject( - "/payment_profiles.json", body, PaymentProfileWrapper.class ).getPaymentProfile(); + + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/payment_profiles.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( body ), Map.class ) + .retrieve() ) + .bodyToMono( PaymentProfileWrapper.class ) + .map( PaymentProfileWrapper::getPaymentProfile ); } @Override - public void updatePaymentProfile( String paymentProfileId, UpdatePaymentProfile paymentProfile ) + public Mono updatePaymentProfile( String paymentProfileId, UpdatePaymentProfile paymentProfile ) { Map body = new HashMap<>(); body.put( "payment_profile", paymentProfile ); - httpClient.put( "/payment_profiles/" + paymentProfileId + ".json", body ); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/payment_profiles/" + paymentProfileId + ".json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( body ), Map.class ) + .retrieve() ) + .bodyToMono( Map.class ) + .then(); } - @Override - public PaymentProfile updateSubscriptionPaymentProfile( String subscriptionId, String paymentProfileId ) + public Mono updateSubscriptionPaymentProfile( String subscriptionId, String paymentProfileId ) { - return httpClient.postForObject( - "/subscriptions/" + subscriptionId + "/payment_profiles/" + paymentProfileId + "/change_payment_profile.json", - Map.of(), PaymentProfileWrapper.class ).getPaymentProfile(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/payment_profiles/" + paymentProfileId + "/change_payment_profile.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of() ), Map.class ) + .retrieve() ) + .bodyToMono( PaymentProfileWrapper.class ) + .map( PaymentProfileWrapper::getPaymentProfile ); } @Override - public PaymentProfile findPaymentProfileById( String paymentProfileId ) + public Mono findPaymentProfileById( String paymentProfileId ) { - try - { - return httpClient.getForObject( "/payment_profiles/" + paymentProfileId + ".json", PaymentProfileWrapper.class ) - .getPaymentProfile(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/payment_profiles/" + paymentProfileId + ".json" ).retrieve() ) + .bodyToMono( PaymentProfileWrapper.class ).map( PaymentProfileWrapper::getPaymentProfile ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public void deleteUnusedPaymentProfile( String paymentProfileId ) + public Mono deleteUnusedPaymentProfile( String paymentProfileId ) { - httpClient.delete( "/payment_profiles/" + paymentProfileId + ".json" ); + return ChargifyResponseErrorHandler.handleError( + client.delete().uri( "/payment_profiles/" + paymentProfileId + ".json" ).retrieve() ) + .bodyToMono( Map.class ).then(); } @Override - public void deletePaymentProfile( String subscriptionId, String paymentProfileId ) + public Mono deletePaymentProfile( String subscriptionId, String paymentProfileId ) { - httpClient.delete( "/subscriptions/" + subscriptionId + "/payment_profiles/" + paymentProfileId + ".json" ); + return ChargifyResponseErrorHandler.handleError( + client.delete().uri( "/subscriptions/" + subscriptionId + "/payment_profiles/" + paymentProfileId + ".json" ).retrieve() ) + .bodyToMono( Map.class ).then(); } @Override - public List findSubscriptionsByCustomerId( String customerId ) + public Flux findSubscriptionsByCustomerId( String customerId ) { return findSubscriptionsByCustomerId( customerId, 0, 200 ); } @Override - public List findSubscriptionsByCustomerId( String customerId, int pageNumber, int pageSize ) + public Flux findSubscriptionsByCustomerId( String customerId, int pageNumber, int pageSize ) { - return Arrays.stream( httpClient.getForObject( - "/customers/" + customerId + "/subscriptions.json?page=" + pageNumber + "&" + "per_page=" + pageSize, - SubscriptionWrapper[].class ) ) - .map( SubscriptionWrapper::getSubscription ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/customers/" + customerId + "/subscriptions.json?page=" + pageNumber + "&" + "per_page=" + pageSize ).retrieve() ) + .bodyToFlux( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); } @Override - public List findAllSubscriptions() + public Flux findAllSubscriptions() { - return Arrays.stream( httpClient.getForObject( "/subscriptions.json", SubscriptionWrapper[].class ) ) - .map( SubscriptionWrapper::getSubscription ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/subscriptions.json" ).retrieve() ) + .bodyToFlux( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); } @Override - public Subscription purgeSubscription( Subscription subscription ) + public Mono purgeSubscription( Subscription subscription ) { - return httpClient.postForObject( "/subscriptions/" + subscription.getId() + "/purge.json?ack=" + subscription.getCustomer().getId() + - "&cascade[]=customer&cascade[]=payment_profile", - HttpEntity.EMPTY, SubscriptionWrapper.class ) - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscription.getId() + "/purge.json?ack=" + subscription.getCustomer().getId() + + "&cascade[]=customer&cascade[]=payment_profile" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of() ), Map.class ) + .retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ); } @Override - public List findSubscriptionsByState( String state, int pageNumber, int pageSize ) + public Flux findSubscriptionsByState( String state, int pageNumber, int pageSize ) { - return Arrays.stream( httpClient.getForObject( "/subscriptions.json?page=" + pageNumber + "&" + - "per_page=" + pageSize + "&state=" + state, - SubscriptionWrapper[].class ) ) - .map( SubscriptionWrapper::getSubscription ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/subscriptions.json?page=" + pageNumber + "&" + + "per_page=" + pageSize + "&state=" + state ).retrieve() ) + .bodyToFlux( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); } @Override - public Subscription cancelSubscriptionById( String id ) + public Mono cancelSubscriptionById( String id ) { - try - { - return httpClient.exchange( "/subscriptions/" + id + ".json", HttpMethod.DELETE, - HttpEntity.EMPTY, SubscriptionWrapper.class ) - .getBody() - .getSubscription(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.delete().uri( "/subscriptions/" + id + ".json" ).retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Subscription cancelSubscriptionProductChange( String subscriptionId ) + public Mono cancelSubscriptionProductChange( String subscriptionId ) { final Subscription subscription = new Subscription(); subscription.setNextProductId( "" ); - return httpClient.exchange( "/subscriptions/" + subscriptionId + ".json", HttpMethod.PUT, - new HttpEntity<>( new SubscriptionWrapper( subscription ) ), SubscriptionWrapper.class ) - .getBody() - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/subscriptions/" + subscriptionId + ".json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new SubscriptionWrapper( subscription ) ), SubscriptionWrapper.class ) + .retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Subscription migrateSubscription( String subscriptionId, String productHandle ) + public Mono migrateSubscription( String subscriptionId, String productHandle ) { final Migration migration = new Migration(); migration.setProductHandle( productHandle ); - return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/migrations.json", - new MigrationWrapper( migration ), SubscriptionWrapper.class ) - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/migrations.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new MigrationWrapper( migration ) ), MigrationWrapper.class ) + .retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Subscription migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ) + public Mono migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ) { final Migration migration = new Migration(); migration.setProductHandle( productHandle ); migration.setPricePointHandle( pricePointHandle ); - return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/migrations.json", - new MigrationWrapper( migration ), SubscriptionWrapper.class ) - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/migrations.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new MigrationWrapper( migration ) ), MigrationWrapper.class ) + .retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override public Mono reactivateSubscription( String subscriptionId, boolean preserveBalance ) { return ChargifyResponseErrorHandler.handleError( - client.put().uri( "/subscriptions/" + subscriptionId + "/reactivate.json" ) - .contentType( MediaType.APPLICATION_JSON ) - .body( Mono.just( Map.of( "preserve_balance", preserveBalance ) ), Map.class ) - .retrieve() ).bodyToMono( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); + client.put().uri( "/subscriptions/" + subscriptionId + "/reactivate.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of( "preserve_balance", preserveBalance ) ), Map.class ) + .retrieve() ).bodyToMono( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); } @Override - public Mono reactivateSubscription( String subscriptionId, SubscriptionReactivationData reactivationData ) + public Mono reactivateSubscription( String subscriptionId, + SubscriptionReactivationData reactivationData ) { return ChargifyResponseErrorHandler.handleError( - client.put().uri( prepareSubscriptionReactivationURI( subscriptionId, reactivationData ) ) - .contentType( MediaType.APPLICATION_JSON ) - .body( Mono.just( Map.of() ), Map.class ) - .retrieve() ).bodyToMono( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); + client.put().uri( prepareSubscriptionReactivationURI( subscriptionId, reactivationData ) ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of() ), Map.class ) + .retrieve() ).bodyToMono( SubscriptionWrapper.class ).map( SubscriptionWrapper::getSubscription ); } @Override - public ComponentPricePointUpdate migrateSubscriptionComponentToPricePoint( String subscriptionId, int componentId, - String pricePointHandle ) + public Mono migrateSubscriptionComponentToPricePoint( String subscriptionId, + int componentId, + String pricePointHandle ) { - return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/price_points.json", - new ComponentPricePointUpdatesWrapper( - List.of( new ComponentPricePointUpdate( componentId, pricePointHandle ) ) ), - ComponentPricePointUpdatesWrapper.class ) - .getPricePointUpdates().get( 0 ); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/price_points.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new ComponentPricePointUpdatesWrapper( + List.of( new ComponentPricePointUpdate( componentId, pricePointHandle ) ) ) ), ComponentPricePointUpdatesWrapper.class ) + .retrieve() ) + .bodyToMono( ComponentPricePointUpdatesWrapper.class ) + .map( wrapper -> wrapper.getPricePointUpdates().get( 0 ) ); } @Override - public List bulkUpdateSubscriptionComponentPricePoint( String subscriptionId, List items ) + public Flux bulkUpdateSubscriptionComponentPricePoint( String subscriptionId, + List items ) { - return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/price_points.json", - new ComponentPricePointUpdatesWrapper( items ), - ComponentPricePointUpdatesWrapper.class ) - .getPricePointUpdates(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/price_points.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new ComponentPricePointUpdatesWrapper( items ) ), ComponentPricePointUpdatesWrapper.class ) + .retrieve() ) + .bodyToMono( ComponentPricePointUpdatesWrapper.class ) + .map( ComponentPricePointUpdatesWrapper::getPricePointUpdates ) + .flatMapMany( Flux::fromIterable ); } @Override - public Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, boolean delayed ) + public Mono changeSubscriptionProduct( String subscriptionId, String productHandle, boolean delayed ) { final SubscriptionProductUpdate productUpdate = new SubscriptionProductUpdate(); productUpdate.setProductHandle( productHandle ); productUpdate.setChangeDelayed( delayed ); - return httpClient.exchange( "/subscriptions/" + subscriptionId + ".json", HttpMethod.PUT, - new HttpEntity<>( new SubscriptionProductUpdateWrapper( productUpdate ) ), SubscriptionWrapper.class ) - .getBody() - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/subscriptions/" + subscriptionId + ".json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new SubscriptionProductUpdateWrapper( productUpdate ) ), SubscriptionProductUpdateWrapper.class ) + .retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ); } @Override - public Subscription cancelScheduledSubscriptionProductChange( String subscriptionId ) + public Mono cancelScheduledSubscriptionProductChange( String subscriptionId ) { - return httpClient.exchange( "/subscriptions/" + subscriptionId + ".json", HttpMethod.PUT, - new HttpEntity<>( - Map.of( - "subscription", - Map.of( - "next_product_id", "", - "next_product_price_point_id", "" - ) - ) - ), SubscriptionWrapper.class ) - .getBody() - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/subscriptions/" + subscriptionId + ".json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of( + "subscription", + Map.of( + "next_product_id", "", + "next_product_price_point_id", "" + ) + ) ), Map.class ) + .retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ); } @Override - public Subscription changeSubscriptionProduct( String subscriptionId, String productHandle, String pricePointHandle, boolean delayed ) + public Mono changeSubscriptionProduct( String subscriptionId, String productHandle, + String pricePointHandle, boolean delayed ) { final SubscriptionProductUpdate productUpdate = new SubscriptionProductUpdate(); productUpdate.setProductHandle( productHandle ); productUpdate.setChangeDelayed( delayed ); productUpdate.setPricePointHandle( pricePointHandle ); - return httpClient.exchange( "/subscriptions/" + subscriptionId + ".json", HttpMethod.PUT, - new HttpEntity<>( new SubscriptionProductUpdateWrapper( productUpdate ) ), SubscriptionWrapper.class ) - .getBody() - .getSubscription(); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/subscriptions/" + subscriptionId + ".json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new SubscriptionProductUpdateWrapper( productUpdate ) ), SubscriptionProductUpdateWrapper.class ) + .retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ); } @Override - public RenewalPreview previewSubscriptionRenewal( String subscriptionId ) + public Mono previewSubscriptionRenewal( String subscriptionId ) { - return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/renewals/preview.json", - HttpEntity.EMPTY, RenewalPreviewWrapper.class ) - .getRenewalPreview(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/renewals/preview.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of() ), Map.class ) + .retrieve() ) + .bodyToMono( RenewalPreviewWrapper.class ) + .map( RenewalPreviewWrapper::getRenewalPreview ); } @Override - public List createSubscriptionMetadata( String subscriptionId, Metadata... metadata ) + public Flux createSubscriptionMetadata( String subscriptionId, Metadata... metadata ) { - return Arrays.asList( httpClient.postForObject( "/subscriptions/" + subscriptionId + "/metadata.json", - new MetadataWrapper( metadata ), Metadata[].class ) ); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/metadata.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new MetadataWrapper( metadata ) ), MetadataWrapper.class ) + .retrieve() ) + .bodyToFlux( Metadata.class ); } @Override - public SubscriptionMetadata readSubscriptionMetadata( String subscriptionId ) + public Mono readSubscriptionMetadata( String subscriptionId ) { - try - { - return httpClient.getForObject( "/subscriptions/" + subscriptionId + "/metadata.json", - SubscriptionMetadata.class ); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/subscriptions/" + subscriptionId + "/metadata.json" ).retrieve() ) + .bodyToMono( SubscriptionMetadata.class ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public List updateSubscriptionMetadata( String subscriptionId, Metadata... metadata ) + public Flux updateSubscriptionMetadata( String subscriptionId, Metadata... metadata ) { - return Arrays.asList( httpClient.exchange( "/subscriptions/" + subscriptionId + "/metadata.json", - HttpMethod.PUT, - new HttpEntity<>( new MetadataWrapper( metadata ) ), Metadata[].class ) - .getBody() ); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/subscriptions/" + subscriptionId + "/metadata.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new MetadataWrapper( metadata ) ), MetadataWrapper.class ) + .retrieve() ) + .bodyToFlux( Metadata.class ); } @Override - public Component createComponent( String productFamilyId, Component component ) + public Mono createComponent( String productFamilyId, Component component ) { if( component.getKind() == null ) throw new IllegalArgumentException( "Component Kind must not be null" ); @@ -598,36 +589,47 @@ public Component createComponent( String productFamilyId, Component component ) throw new IllegalArgumentException( "Invalid component kind - " + component.getKind() ); } - return httpClient.postForObject( "/product_families/" + productFamilyId + "/" + pluralKindPathParam + ".json", - componentWrapper, AnyComponentWrapper.class ) - .getComponent(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/product_families/" + productFamilyId + "/" + pluralKindPathParam + ".json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( componentWrapper ), ComponentWrapper.class ) + .retrieve() ) + .bodyToMono( AnyComponentWrapper.class ) + .map( AnyComponentWrapper::getComponent ); } @Override - public Allocation createComponentAllocation( String subscriptionId, int componentId, Allocation allocation ) + public Mono createComponentAllocation( String subscriptionId, int componentId, Allocation allocation ) { - return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/components/" + componentId + - "/allocations.json", - new AllocationWrapper( allocation ), AllocationWrapper.class ) - .getAllocation(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/components/" + componentId + + "/allocations.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new AllocationWrapper( allocation ) ), AllocationWrapper.class ) + .retrieve() ). + bodyToMono( AllocationWrapper.class ) + .map( AllocationWrapper::getAllocation ); } @Override - public AllocationPreview previewComponentAllocation( String subscriptionId, int componentId, int quantity ) + public Mono previewComponentAllocation( String subscriptionId, int componentId, int quantity ) { - return httpClient.postForObject( "/subscriptions/" + subscriptionId + "/allocations/preview.json", - Map.of( "allocations", List.of( new AllocationPreview.ComponentAllocationDTO( componentId, quantity ) ) ), - AllocationPreviewWrapper.class ) - .getAllocationPreview(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/subscriptions/" + subscriptionId + "/allocations/preview.json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( Map.of( "allocations", List.of( new AllocationPreview.ComponentAllocationDTO( componentId, quantity ) ) ) ), Map.class ) + .retrieve() ) + .bodyToMono( AllocationPreviewWrapper.class ) + .map( AllocationPreviewWrapper::getAllocationPreview ); } @Override - public List findComponentsByProductFamily( String productFamilyId ) + public Flux findComponentsByProductFamily( String productFamilyId ) { - return Arrays.stream( httpClient.getForObject( "/product_families/" + productFamilyId + "/components.json", - AnyComponentWrapper[].class ) ) - .map( AnyComponentWrapper::getComponent ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/product_families/" + productFamilyId + "/components.json" ).retrieve() ) + .bodyToFlux( AnyComponentWrapper.class ) + .map( AnyComponentWrapper::getComponent ); } @Override @@ -635,30 +637,32 @@ public Mono findComponentByIdAndProductFamily( int componentId, Strin { return ChargifyResponseErrorHandler.handleError( client.get().uri( "/product_families/" + productFamilyId + "/components/" + componentId + ".json" ).retrieve() ) - .bodyToMono( AnyComponentWrapper.class ) - .map( AnyComponentWrapper::getComponent ); + .bodyToMono( AnyComponentWrapper.class ) + .map( AnyComponentWrapper::getComponent ); } @Override - public Mono findComponentWithPricePointsByIdAndProductFamily( int componentId, String productFamilyId ) + public Mono findComponentWithPricePointsByIdAndProductFamily( int componentId, + String productFamilyId ) { return findComponentByIdAndProductFamily( componentId, productFamilyId ) - .flatMap( component -> findComponentPricePoints( componentId ) - .map( componentPricePoints -> new ComponentWithPricePoints( component, componentPricePoints ) ) ); + .flatMap( component -> findComponentPricePoints( componentId ) + .collect( Collectors.toSet() ) + .map( componentPricePoints -> new ComponentWithPricePoints( component, componentPricePoints ) ) ); } @Override - public List findSubscriptionComponents( String subscriptionId ) + public Flux findSubscriptionComponents( String subscriptionId ) { - return Arrays.stream( httpClient.getForObject( "/subscriptions/" + subscriptionId + "/components.json", - SubscriptionComponentWrapper[].class ) ) - .map( SubscriptionComponentWrapper::getComponent ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/subscriptions/" + subscriptionId + "/components.json" ).retrieve() ) + .bodyToFlux( SubscriptionComponentWrapper.class ) + .map( SubscriptionComponentWrapper::getComponent ); } @Override - public List findSubscriptionStatements( - String subscriptionId, int page, int pageSize, String sort, String direction ) + public Flux findSubscriptionStatements( + String subscriptionId, int page, int pageSize, String sort, String direction ) { if( pageSize > 200 ) throw new IllegalArgumentException( "Page size can't be bigger than 200" ); @@ -671,11 +675,10 @@ public List findSubscriptionStatements( if( direction != null ) uriBuilder.append( "&direction=" ).append( direction ); - - return Arrays.stream( httpClient.getForObject( - "/subscriptions/" + subscriptionId + "/statements.json?" + uriBuilder, SubscriptionStatementWrapper[].class ) ) - .map( SubscriptionStatementWrapper::getStatement ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/subscriptions/" + subscriptionId + "/statements.json?" + uriBuilder ).retrieve() ) + .bodyToFlux( SubscriptionStatementWrapper.class ) + .map( SubscriptionStatementWrapper::getStatement ); } @Override @@ -683,134 +686,120 @@ public Mono findSubscriptionComponentById( String subscri { return ChargifyResponseErrorHandler.handleError( client.get().uri( "/subscriptions/" + subscriptionId + "/components/" + componentId + ".json" ).retrieve() ) - .bodyToMono( SubscriptionComponentWrapper.class ) - .map( SubscriptionComponentWrapper::getComponent ); + .bodyToMono( SubscriptionComponentWrapper.class ) + .map( SubscriptionComponentWrapper::getComponent ); } @Override public Mono reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ) { return ChargifyResponseErrorHandler.handleError( - client.post().uri( "/subscriptions/" + subscriptionId + "/components/" + componentId + "/usages.json" ) - .body( Mono.just( new UsageWrapper( usage ) ), UsageWrapper.class ).retrieve() ) - .bodyToMono( UsageWrapper.class ) - .map( UsageWrapper::getUsage ); + client.post().uri( "/subscriptions/" + subscriptionId + "/components/" + componentId + "/usages.json" ) + .body( Mono.just( new UsageWrapper( usage ) ), UsageWrapper.class ).retrieve() ) + .bodyToMono( UsageWrapper.class ) + .map( UsageWrapper::getUsage ); } @Override - public Customer createCustomer( Customer customer ) + public Mono createCustomer( Customer customer ) { - return httpClient.postForObject( "/customers.json", new CustomerWrapper( customer ), CustomerWrapper.class ) - .getCustomer(); + return ChargifyResponseErrorHandler.handleError( + client.post().uri( "/customers.json" ) + .body( Mono.just( new CustomerWrapper( customer ) ), CustomerWrapper.class ).retrieve() ) + .bodyToMono( CustomerWrapper.class ) + .map( CustomerWrapper::getCustomer ); } @Override - public Customer updateCustomer( Customer customer ) + public Mono updateCustomer( Customer customer ) { - return httpClient.exchange( "/customers/" + customer.getId() + ".json", HttpMethod.PUT, - new HttpEntity<>( new CustomerWrapper( customer ) ), CustomerWrapper.class ) - .getBody() - .getCustomer(); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/customers/" + customer.getId() + ".json" ) + .body( Mono.just( new CustomerWrapper( customer ) ), CustomerWrapper.class ).retrieve() ) + .bodyToMono( CustomerWrapper.class ) + .map( CustomerWrapper::getCustomer ); } @Override - public Customer findCustomerById( String id ) + public Mono findCustomerById( String id ) { - try - { - return httpClient.getForObject( "/customers/" + id + ".json", CustomerWrapper.class ) - .getCustomer(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/customers/" + id + ".json" ).retrieve() ) + .bodyToMono( CustomerWrapper.class ) + .map( CustomerWrapper::getCustomer ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Customer findCustomerByReference( String reference ) + public Mono findCustomerByReference( String reference ) { - try - { - return httpClient.getForObject( "/customers/lookup.json?reference={reference}", - CustomerWrapper.class, reference ) - .getCustomer(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/customers/lookup.json?reference={reference}", reference ).retrieve() ) + .bodyToMono( CustomerWrapper.class ) + .map( CustomerWrapper::getCustomer ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Subscription findSubscriptionByReference( String reference ) + public Mono findSubscriptionByReference( String reference ) { - try - { - return httpClient.getForObject( "/subscriptions/lookup.json?reference={reference}", - SubscriptionWrapper.class, reference ) - .getSubscription(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/subscriptions/lookup.json?reference={reference}", reference ).retrieve() ) + .bodyToMono( SubscriptionWrapper.class ) + .map( SubscriptionWrapper::getSubscription ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public List findCustomersBy( Object criterion, int pageNumber ) + public Flux findCustomersBy( Object criterion, int pageNumber ) { - return Arrays.stream( httpClient.getForObject( "/customers.json?q={criterion}&page={pageNumber}", - CustomerWrapper[].class, criterion, pageNumber ) ) - .map( CustomerWrapper::getCustomer ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/customers.json?q={criterion}&page={pageNumber}", criterion, pageNumber ).retrieve() ) + .bodyToFlux( CustomerWrapper.class ) + .map( CustomerWrapper::getCustomer ); } @Override - public List findAllCustomers() + public Flux findAllCustomers() { - return Arrays.stream( httpClient.getForObject( "/customers.json", CustomerWrapper[].class ) ) - .map( CustomerWrapper::getCustomer ) - .collect( Collectors.toList() ); + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/customers.json" ).retrieve() ) + .bodyToFlux( CustomerWrapper.class ) + .map( CustomerWrapper::getCustomer ); } @Override - public void deleteCustomerById( String id ) + public Mono deleteCustomerById( String id ) { - try - { - httpClient.delete( "/customers/" + id + ".json" ); - } - catch( ResourceNotFoundException ignored ) - { - } + return ChargifyResponseErrorHandler.handleError( + client.delete().uri( "/customers/" + id + ".json" ).retrieve() ) + .bodyToMono( Map.class ) + .then() + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.just( "stub" ).then() ); } @Override - public ReferralCode validateReferralCode( String code ) + public Mono validateReferralCode( String code ) { - try - { - return httpClient.getForObject( "/referral_codes/validate.json?code=" + code, - ReferralCodeWrapper.class ) - .getReferralCode(); - } - catch( ResourceNotFoundException e ) - { - return null; - } + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/referral_codes/validate.json?code=" + code ).retrieve() ) + .bodyToMono( ReferralCodeWrapper.class ) + .map( ReferralCodeWrapper::getReferralCode ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override - public Adjustment adjust( String subscriptionId, Adjustment adjustment ) + public Mono adjust( String subscriptionId, Adjustment adjustment ) { - return httpClient.exchange( "/subscriptions/" + subscriptionId + "/adjustments.json", HttpMethod.POST, - new HttpEntity<>( new AdjustmentWrapper( adjustment ) ), AdjustmentWrapper.class ) - .getBody() - .getAdjustment(); + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/subscriptions/" + subscriptionId + "/adjustments.json" ) + .body( Mono.just( new AdjustmentWrapper( adjustment ) ), AdjustmentWrapper.class ).retrieve() ) + .bodyToMono( AdjustmentWrapper.class ) + .map( AdjustmentWrapper::getAdjustment ); } - private String prepareSubscriptionReactivationURI( String subscriptionId, SubscriptionReactivationData reactivationData ) + private String prepareSubscriptionReactivationURI( String subscriptionId, + SubscriptionReactivationData reactivationData ) { StringBuilder urlBuilder = new StringBuilder( "/subscriptions/" ).append( subscriptionId ).append( "/reactivate.json" ); diff --git a/src/test/java/com/chargify/ComponentsTest.java b/src/test/java/com/chargify/ComponentsTest.java index 61e71dd..09e7975 100644 --- a/src/test/java/com/chargify/ComponentsTest.java +++ b/src/test/java/com/chargify/ComponentsTest.java @@ -16,7 +16,7 @@ public class ComponentsTest extends ChargifyTest @BeforeClass public static void setup() { - productFamily = chargify.createProductFamily( new ProductFamily( randomName() ) ); + productFamily = chargify.createProductFamily( new ProductFamily( randomName() ) ).block(); } @Test @@ -28,7 +28,7 @@ public void createQuantityBasedComponent() component.setUnitName( randomName() ); component.setPricingScheme( "per_unit" ); component.setUnitPrice( 10. ); - final Component createdComponent = chargify.createComponent( productFamily.getId(), component ); + final Component createdComponent = chargify.createComponent( productFamily.getId(), component ).block(); assertEquals( "Wrong component kind", ComponentKind.quantity_based_component, createdComponent.getKind() ); } @@ -41,7 +41,7 @@ public void createMeteredComponent() component.setUnitName( randomName() ); component.setPricingScheme( "per_unit" ); component.setUnitPrice( 10. ); - final Component createdComponent = chargify.createComponent( productFamily.getId(), component ); + final Component createdComponent = chargify.createComponent( productFamily.getId(), component ).block(); assertEquals( "Wrong component kind", ComponentKind.metered_component, createdComponent.getKind() ); } @@ -52,13 +52,13 @@ public void createOnOffComponent() component.setKind( ComponentKind.on_off_component ); component.setName( randomName() ); component.setUnitPrice( 10. ); - final Component createdComponent = chargify.createComponent( productFamily.getId(), component ); + final Component createdComponent = chargify.createComponent( productFamily.getId(), component ).block(); assertEquals( "Wrong component kind", ComponentKind.on_off_component, createdComponent.getKind() ); } @AfterClass public static void cleanup() { - chargify.archiveProductFamilyById( productFamily.getId() ); + chargify.archiveProductFamilyById( productFamily.getId() ).block(); } } diff --git a/src/test/java/com/chargify/CustomersTest.java b/src/test/java/com/chargify/CustomersTest.java index 46badc2..f37fd1d 100644 --- a/src/test/java/com/chargify/CustomersTest.java +++ b/src/test/java/com/chargify/CustomersTest.java @@ -20,52 +20,52 @@ public class CustomersTest extends ChargifyTest public static void setup() { customerUnderTest = chargify.createCustomer( new Customer( "Andy", "Panda", - "andypanda@email.com" ) ); + "andypanda@email.com" ) ).block(); final Customer customer = new Customer( "Martha", "Washington", "martha@example.com" ); customer.setReference( randomName() ); - customerWithReferenceUnderTest = chargify.createCustomer( customer ); + customerWithReferenceUnderTest = chargify.createCustomer( customer ).block(); } @AfterClass public static void cleanup() { - chargify.deleteCustomerById( customerUnderTest.getId() ); - chargify.deleteCustomerById( customerWithReferenceUnderTest.getId() ); + chargify.deleteCustomerById( customerUnderTest.getId() ).block(); + chargify.deleteCustomerById( customerWithReferenceUnderTest.getId() ).block(); } @Test public void customerShouldBeFoundByValidId() { - final Customer customer = chargify.findCustomerById( customerUnderTest.getId() ); + final Customer customer = chargify.findCustomerById( customerUnderTest.getId() ).block(); assertNotNull( "Customer not found", customer ); } @Test public void customerShouldNotBeFoundByInvalidId() { - final Customer customer = chargify.findCustomerById( "nonexisting" ); + final Customer customer = chargify.findCustomerById( "nonexisting" ).block(); assertNull( "Customer should not have been found", customer ); } @Test public void findAllShouldFindAtLeastOne() { - final List customers = chargify.findAllCustomers(); + final List customers = chargify.findAllCustomers().collectList().block(); assertTrue( "No customers found", customers.size() > 0 ); } @Test public void customerShouldBeFoundByValidReference() { - final Customer customer = chargify.findCustomerByReference( customerWithReferenceUnderTest.getReference() ); + final Customer customer = chargify.findCustomerByReference( customerWithReferenceUnderTest.getReference() ).block(); assertNotNull( "Customer not found by reference", customer ); } @Test public void customerShouldNotBeFoundByInvalidReference() { - final Customer customer = chargify.findCustomerByReference( "invalid" ); + final Customer customer = chargify.findCustomerByReference( "invalid" ).block(); assertNull( "Customer should not have been found", customer ); } } diff --git a/src/test/java/com/chargify/ProductFamiliesTest.java b/src/test/java/com/chargify/ProductFamiliesTest.java index 1dcffe5..ed10228 100644 --- a/src/test/java/com/chargify/ProductFamiliesTest.java +++ b/src/test/java/com/chargify/ProductFamiliesTest.java @@ -14,25 +14,25 @@ public class ProductFamiliesTest extends ChargifyTest @BeforeClass public static void setup() { - existingProductFamily = chargify.createProductFamily( new ProductFamily( randomName() ) ); + existingProductFamily = chargify.createProductFamily( new ProductFamily( randomName() ) ).block(); } @AfterClass public static void cleanup() { - chargify.archiveProductFamilyById( existingProductFamily.getId() ); + chargify.archiveProductFamilyById( existingProductFamily.getId() ).block(); } @Test( expected = ApiHandleNotUniqueException.class ) public void productFamilyApiHandleShouldBeUnique() { - chargify.createProductFamily( existingProductFamily ); + chargify.createProductFamily( existingProductFamily ).block(); } @Test public void productFamilyRetrievedByIdShouldHaveProperHandle() { - final ProductFamily retrievedProductFamily = chargify.findProductFamilyById( existingProductFamily.getId() ); + final ProductFamily retrievedProductFamily = chargify.findProductFamilyById( existingProductFamily.getId() ).block(); Assert.assertNotNull( "Product family not found by ID " + existingProductFamily.getId(), retrievedProductFamily ); @@ -44,13 +44,13 @@ public void productFamilyRetrievedByIdShouldHaveProperHandle() public void readAllShouldRetrieveAtLeastOneProductFamily() { Assert.assertTrue( "At least one product family should exist", - chargify.findAllProductFamilies().size() > 0 ); + chargify.findAllProductFamilies().collectList().block().size() > 0 ); } @Test public void readNonExistingShouldReturnEmptyOptional() { - final ProductFamily productFamily = chargify.findProductFamilyById( "nonexisting" ); + final ProductFamily productFamily = chargify.findProductFamilyById( "nonexisting" ).block(); Assert.assertNull( "Non existing product family found", productFamily ); } @@ -58,7 +58,7 @@ public void readNonExistingShouldReturnEmptyOptional() @Test public void archiveNonExistingShouldReturnEmptyOptional() { - final ProductFamily archivedProductFamily = chargify.archiveProductFamilyById( "nonexisting" ); + final ProductFamily archivedProductFamily = chargify.archiveProductFamilyById( "nonexisting" ).block(); Assert.assertNull( "Non existing product family found", archivedProductFamily ); } diff --git a/src/test/java/com/chargify/ProductsTest.java b/src/test/java/com/chargify/ProductsTest.java index 1d9cb17..23bcc0f 100644 --- a/src/test/java/com/chargify/ProductsTest.java +++ b/src/test/java/com/chargify/ProductsTest.java @@ -20,29 +20,29 @@ public class ProductsTest extends ChargifyTest @BeforeClass public static void setup() { - productFamilyUnderTest = chargify.createProductFamily( new ProductFamily( randomName() ) ); + productFamilyUnderTest = chargify.createProductFamily( new ProductFamily( randomName() ) ).block(); productUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), new Product( randomName(), 0, 1, - PricePointIntervalUnit.month ) ); + PricePointIntervalUnit.month ) ).block(); final Product productWithHandle = new Product( randomName(), 0, 1, PricePointIntervalUnit.month ); productWithHandle.setHandle( randomName() ); - productWithHandleUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), productWithHandle ); + productWithHandleUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), productWithHandle ).block(); } @AfterClass public static void cleanup() { - chargify.archiveProductById( productUnderTest.getId() ); - chargify.archiveProductById( productWithHandleUnderTest.getId() ); - chargify.archiveProductFamilyById( productFamilyUnderTest.getId() ); + chargify.archiveProductById( productUnderTest.getId() ).block(); + chargify.archiveProductById( productWithHandleUnderTest.getId() ).block(); + chargify.archiveProductFamilyById( productFamilyUnderTest.getId() ).block(); } @Test public void productShouldBeFoundById() { - final Product product = chargify.findProductById( productUnderTest.getId() ); + final Product product = chargify.findProductById( productUnderTest.getId() ).block(); Assert.assertNotNull( "Product not found", product ); } @@ -50,7 +50,7 @@ public void productShouldBeFoundById() @Test public void productShouldNotBeFoundByInvalidId() { - final Product product = chargify.findProductById( "nonexisting" ); + final Product product = chargify.findProductById( "nonexisting" ).block(); Assert.assertNull( "Product should not be found by invalid ID", product ); } @@ -58,7 +58,7 @@ public void productShouldNotBeFoundByInvalidId() @Test public void productShouldBeFoundByApiHandle() { - final Product product = chargify.findProductByApiHandle( productWithHandleUnderTest.getHandle() ); + final Product product = chargify.findProductByApiHandle( productWithHandleUnderTest.getHandle() ).block(); Assert.assertNotNull( "Product not found", product ); } @@ -66,7 +66,7 @@ public void productShouldBeFoundByApiHandle() @Test public void productShouldNotBeFoundByInvalidApiHandle() { - final Product product = chargify.findProductByApiHandle( productUnderTest.getHandle() ); + final Product product = chargify.findProductByApiHandle( productUnderTest.getHandle() ).block(); Assert.assertNull( "Product should not be found by invalid ID", product ); } @@ -74,7 +74,7 @@ public void productShouldNotBeFoundByInvalidApiHandle() @Test public void readAllShouldRetrieveAtLeastOne() { - final List products = chargify.findAllProducts(); + final List products = chargify.findAllProducts().collectList().block(); Assert.assertTrue( "At least one product should be present", products.size() > 0 ); } @@ -82,7 +82,7 @@ public void readAllShouldRetrieveAtLeastOne() @Test public void readAllByFamilyIdShouldRetrieveAtLeastOne() { - final List familyProducts = chargify.findProductsByProductFamilyId( productFamilyUnderTest.getId() ); + final List familyProducts = chargify.findProductsByProductFamilyId( productFamilyUnderTest.getId() ).collectList().block(); Assert.assertTrue( "At least one product should be present in the family", familyProducts.size() > 0 ); @@ -92,13 +92,13 @@ public void readAllByFamilyIdShouldRetrieveAtLeastOne() @Test( expected = ChargifyException.class ) public void readByNonExistingFamilyShouldThrowException() { - chargify.findProductFamilyById( "nonexisting" ); + chargify.findProductFamilyById( "nonexisting" ).block(); } @Test public void archiveNonExisting() { - final Product archivedProduct = chargify.archiveProductById( "nonexisting" ); + final Product archivedProduct = chargify.archiveProductById( "nonexisting" ).block(); Assert.assertNull( "Non existing product has been archived", archivedProduct ); } diff --git a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java index 092079f..f0fc569 100644 --- a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java +++ b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java @@ -24,25 +24,25 @@ public class SubscriptionDelayedChangeTest extends ChargifyTest @BeforeClass public static void setup() { - productFamily = chargify.createProductFamily( new ProductFamily( randomName() ) ); + productFamily = chargify.createProductFamily( new ProductFamily( randomName() ) ).block(); final Product initialProduct = new Product( randomName(), 0, 1, PricePointIntervalUnit.month ); initialProduct.setRequestCreditCard( false ); initialProduct.setRequireCreditCard( false ); - SubscriptionDelayedChangeTest.initialProduct = chargify.createProduct( productFamily.getId(), initialProduct ); + SubscriptionDelayedChangeTest.initialProduct = chargify.createProduct( productFamily.getId(), initialProduct ).block(); final Product targetProduct = new Product( randomName(), 0, 1, PricePointIntervalUnit.month ); targetProduct.setRequestCreditCard( false ); targetProduct.setRequireCreditCard( false ); targetProduct.setHandle( randomName() ); - SubscriptionDelayedChangeTest.targetProduct = chargify.createProduct( productFamily.getId(), targetProduct ); + SubscriptionDelayedChangeTest.targetProduct = chargify.createProduct( productFamily.getId(), targetProduct ).block(); - customer = chargify.createCustomer( new Customer( randomName(), randomName(), randomEmail() ) ); + customer = chargify.createCustomer( new Customer( randomName(), randomName(), randomEmail() ) ).block(); final CreateSubscription subscription = new CreateSubscription(); subscription.setProductId( SubscriptionDelayedChangeTest.initialProduct.getId() ); subscription.setCustomerId( customer.getId() ); - SubscriptionDelayedChangeTest.subscription = chargify.createSubscription( subscription ); + SubscriptionDelayedChangeTest.subscription = chargify.createSubscription( subscription ).block(); } @Test @@ -50,7 +50,7 @@ public void delayedProductChangeShouldModifyNextProductIdAndNotChangeCurrentProd { final Subscription resultSubscription = chargify.changeSubscriptionProduct( subscription.getId(), targetProduct.getHandle(), - true ); + true ).block(); assertNotNull( "Product change not scheduled", resultSubscription.getNextProductId() ); assertEquals( "Scheduled change to wrong product", targetProduct.getId(), resultSubscription.getNextProductId() ); assertEquals( "Current product changed", initialProduct.getId(), resultSubscription.getProduct().getId() ); @@ -59,11 +59,11 @@ public void delayedProductChangeShouldModifyNextProductIdAndNotChangeCurrentProd @AfterClass public static void cleanup() { - chargify.cancelSubscriptionProductChange( subscription.getId() ); - chargify.cancelSubscriptionById( subscription.getId() ); - chargify.archiveProductById( targetProduct.getId() ); - chargify.archiveProductById( initialProduct.getId() ); - chargify.archiveProductFamilyById( productFamily.getId() ); + chargify.cancelSubscriptionProductChange( subscription.getId() ).block(); + chargify.cancelSubscriptionById( subscription.getId() ).block(); + chargify.archiveProductById( targetProduct.getId() ).block(); + chargify.archiveProductById( initialProduct.getId() ).block(); + chargify.archiveProductFamilyById( productFamily.getId() ).block(); // The customer could not be deleted because there are subscriptions associated with this account. You may want to delete the individual subscriptions first. // chargify.deleteCustomerById( customer.getId() ); } diff --git a/src/test/java/com/chargify/SubscriptionsTest.java b/src/test/java/com/chargify/SubscriptionsTest.java index 6fc2a68..254a5f4 100644 --- a/src/test/java/com/chargify/SubscriptionsTest.java +++ b/src/test/java/com/chargify/SubscriptionsTest.java @@ -30,36 +30,36 @@ public class SubscriptionsTest extends ChargifyTest @BeforeClass public static void setup() { - productFamilyUnderTest = chargify.createProductFamily( new ProductFamily( randomName() ) ); + productFamilyUnderTest = chargify.createProductFamily( new ProductFamily( randomName() ) ).block(); final Product product = new Product( randomName(), 0, 1, PricePointIntervalUnit.month ); product.setRequestCreditCard( false ); product.setRequireCreditCard( false ); - productUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), product ); + productUnderTest = chargify.createProduct( productFamilyUnderTest.getId(), product ).block(); product.setHandle( randomName() ); - productForDelayedChange = chargify.createProduct( productFamilyUnderTest.getId(), product ); + productForDelayedChange = chargify.createProduct( productFamilyUnderTest.getId(), product ).block(); product.setHandle( randomName() ); - productForImmediateChange = chargify.createProduct( productFamilyUnderTest.getId(), product ); + productForImmediateChange = chargify.createProduct( productFamilyUnderTest.getId(), product ).block(); product.setHandle( randomName() ); - productForMigration = chargify.createProduct( productFamilyUnderTest.getId(), product ); + productForMigration = chargify.createProduct( productFamilyUnderTest.getId(), product ).block(); customerUnderTest = chargify.createCustomer( new Customer( "Andy", "Panda", - "andypanda@example.com" ) ); + "andypanda@example.com" ) ).block(); final CreateSubscription subscription = new CreateSubscription(); subscription.setProductId( productUnderTest.getId() ); subscription.setCustomerId( customerUnderTest.getId() ); - subscriptionUnderTest = chargify.createSubscription( subscription ); + subscriptionUnderTest = chargify.createSubscription( subscription ).block(); } @AfterClass public static void cleanup() { - chargify.cancelSubscriptionById( subscriptionUnderTest.getId() ); - chargify.archiveProductById( productUnderTest.getId() ); + chargify.cancelSubscriptionById( subscriptionUnderTest.getId() ).block(); + chargify.archiveProductById( productUnderTest.getId() ).block(); // cannot be archived - subscription change pending // chargify.archiveProductById( productForDelayedChange.getId() ); // cannot be archived - product still exists @@ -71,28 +71,28 @@ public static void cleanup() @Test public void subscriptionShouldBeFoundByValidId() { - final Subscription subscription = chargify.findSubscriptionById( subscriptionUnderTest.getId() ); + final Subscription subscription = chargify.findSubscriptionById( subscriptionUnderTest.getId() ).block(); assertNotNull( "Subscription not found", subscription ); } @Test public void subscriptionShoudNotBeFoundByInvalidId() { - final Subscription subscription = chargify.findSubscriptionById( "invalid" ); + final Subscription subscription = chargify.findSubscriptionById( "invalid" ).block(); assertNull( "Subscription should not have been found", subscription ); } @Test public void customerShouldHaveAtLeastOneSubscription() { - final List subscriptions = chargify.findSubscriptionsByCustomerId( customerUnderTest.getId() ); + final List subscriptions = chargify.findSubscriptionsByCustomerId( customerUnderTest.getId() ).collectList().block(); assertTrue( "No subscriptions found for customer", subscriptions.size() > 0 ); } @Test public void findAllShouldReturnAtLeastOne() { - final List subscriptions = chargify.findAllSubscriptions(); + final List subscriptions = chargify.findAllSubscriptions().collectList().block(); assertTrue( "No subscriptions found", subscriptions.size() > 0 ); } @@ -101,7 +101,7 @@ public void immediateProductChangeShouldChangeProduct() { final Subscription subscription = chargify.changeSubscriptionProduct( subscriptionUnderTest.getId(), productForImmediateChange.getHandle(), - false ); + false ).block(); assertNull( "Product change scheduled", subscription.getNextProductId() ); assertEquals( "Product should have been changed", productForImmediateChange.getId(), subscription.getProduct().getId() ); } @@ -110,7 +110,7 @@ public void immediateProductChangeShouldChangeProduct() public void migrationShouldChangeProduct() { final Subscription subscription = chargify.migrateSubscription( subscriptionUnderTest.getId(), - productForMigration.getHandle() ); + productForMigration.getHandle() ).block(); assertNull( "Product change scheduled", subscription.getNextProductId() ); assertEquals( "Product has not been migrated", productForMigration.getHandle(), subscription.getProduct().getHandle() ); } From 8e91c8da5607cb5bd75df72347c8997bcac428d9 Mon Sep 17 00:00:00 2001 From: Sergii Kukurudziak Date: Mon, 17 Oct 2022 19:12:21 +0300 Subject: [PATCH 42/58] BKNDLSS-30088 Cannot publish deployment model --- pom.xml | 2 +- src/main/java/com/chargify/ChargifyService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d4b6488..a9ba9c4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.28 + 0.29 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 3c026b8..c9d3930 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -592,7 +592,7 @@ public Mono createComponent( String productFamilyId, Component compon return ChargifyResponseErrorHandler.handleError( client.post().uri( "/product_families/" + productFamilyId + "/" + pluralKindPathParam + ".json" ) .contentType( MediaType.APPLICATION_JSON ) - .body( Mono.just( componentWrapper ), ComponentWrapper.class ) + .body( Mono.just( componentWrapper ), Object.class ) .retrieve() ) .bodyToMono( AnyComponentWrapper.class ) .map( AnyComponentWrapper::getComponent ); From 1cebffb47f1991c4511fa78025f65ceb63b7d13c Mon Sep 17 00:00:00 2001 From: Sergii Kukurudziak Date: Tue, 18 Oct 2022 16:25:17 +0300 Subject: [PATCH 43/58] changed developer --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a9ba9c4..581e1e8 100644 --- a/pom.xml +++ b/pom.xml @@ -22,8 +22,8 @@ - Sergey Chupov - scadgek@live.com + Backendless + chargify-sdk-for-java@backendless.com Backendless https://backendless.com/ From ac32c02a39b75334cd04a4b0c067f2f26ffbd7fe Mon Sep 17 00:00:00 2001 From: Sergii Kukurudziak Date: Wed, 19 Oct 2022 19:20:55 +0300 Subject: [PATCH 44/58] BKNDLSS-30118 Current balance does not change after exchanging BBs --- pom.xml | 3 ++- src/main/java/com/chargify/ChargifyService.java | 2 +- .../com/chargify/exceptions/ChargifyResponseErrorHandler.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 581e1e8..2c0466b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.29 + 0.30 jar Chargify SDK for Java @@ -151,6 +151,7 @@ 11 11 + diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index c9d3930..3eaee3f 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -792,7 +792,7 @@ public Mono validateReferralCode( String code ) public Mono adjust( String subscriptionId, Adjustment adjustment ) { return ChargifyResponseErrorHandler.handleError( - client.put().uri( "/subscriptions/" + subscriptionId + "/adjustments.json" ) + client.post().uri( "/subscriptions/" + subscriptionId + "/adjustments.json" ) .body( Mono.just( new AdjustmentWrapper( adjustment ) ), AdjustmentWrapper.class ).retrieve() ) .bodyToMono( AdjustmentWrapper.class ) .map( AdjustmentWrapper::getAdjustment ); diff --git a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java index 46d7d9b..fecfae8 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java +++ b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java @@ -62,7 +62,7 @@ public static WebClient.ResponseSpec handleError( WebClient.ResponseSpec respons response.onStatus( HttpStatus::is4xxClientError, clientResponse -> { HttpStatus statusCode = clientResponse.statusCode(); if( statusCode == HttpStatus.NOT_FOUND ) - return Mono.empty(); + return Mono.error( new ResourceNotFoundException() ); else if( statusCode == HttpStatus.FORBIDDEN ) // TODO: see issue https://chargify.zendesk.com/hc/en-us/requests/69553 return clientResponse.bodyToMono( String.class ).map( ChargifyException::new ).flatMap( Mono::error ); else From 7e35a38e764099dce4fcd78cdc6063404dc45b58 Mon Sep 17 00:00:00 2001 From: Sergii Kukurudziak Date: Fri, 28 Oct 2022 17:35:38 +0300 Subject: [PATCH 45/58] BKNDLSS-30259 Unable to activate "Cookie-based Authorization" on the "Users/Login" page --- pom.xml | 2 +- src/main/java/com/chargify/ChargifyService.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 2c0466b..7a53ea8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.30 + 0.31 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 3eaee3f..a86e59d 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -687,7 +687,8 @@ public Mono findSubscriptionComponentById( String subscri return ChargifyResponseErrorHandler.handleError( client.get().uri( "/subscriptions/" + subscriptionId + "/components/" + componentId + ".json" ).retrieve() ) .bodyToMono( SubscriptionComponentWrapper.class ) - .map( SubscriptionComponentWrapper::getComponent ); + .map( SubscriptionComponentWrapper::getComponent ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override From 792925ca2277463e82dd2552a9f2818f0be87a9b Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Thu, 3 Nov 2022 17:39:56 +0200 Subject: [PATCH 46/58] [BKNDLSS-30309] Billing. "Get status" endpoint returns error instead of default value --- pom.xml | 2 +- src/main/java/com/chargify/ChargifyService.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 7a53ea8..8c9a82f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.31 + 0.32 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index a86e59d..d66391b 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -236,7 +236,8 @@ public Mono findSubscriptionById( String id ) return ChargifyResponseErrorHandler.handleError( client.get().uri( "/subscriptions/" + id + ".json" ).retrieve() ) .bodyToMono( SubscriptionWrapper.class ) - .map( SubscriptionWrapper::getSubscription ); + .map( SubscriptionWrapper::getSubscription ) + .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); } @Override From 1880dd4202b14152cf9aa6249190d0366cc2aef8 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Sun, 27 Nov 2022 16:36:09 +0200 Subject: [PATCH 47/58] [BKNDLSS-29769] Developer payout --- pom.xml | 4 +- src/main/java/com/chargify/Chargify.java | 2 + .../java/com/chargify/ChargifyService.java | 30 +++++++++++++++ src/main/java/com/chargify/SortDirection.java | 13 +++++++ ...SubscriptionTransactionsSearchOptions.java | 38 +++++++++++++++++++ .../java/com/chargify/model/Subscription.java | 21 +++++----- .../java/com/chargify/model/Transaction.java | 2 + .../com/chargify/model/TransactionsKinds.java | 14 +++++++ .../model/wrappers/TransactionWrapper.java | 18 +++++++++ 9 files changed, 129 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/chargify/SortDirection.java create mode 100644 src/main/java/com/chargify/SubscriptionTransactionsSearchOptions.java create mode 100644 src/main/java/com/chargify/model/TransactionsKinds.java create mode 100644 src/main/java/com/chargify/model/wrappers/TransactionWrapper.java diff --git a/pom.xml b/pom.xml index 8c9a82f..3b8eb4e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.32 + 0.33 jar Chargify SDK for Java @@ -60,7 +60,7 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.13.4 + 2.14.1 diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index d80f303..0132e1b 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -118,6 +118,8 @@ Mono migrateSubscriptionComponentToPricePoint( String Flux findSubscriptionStatements( String subscriptionId, int page, int pageSize, String sort, String direction ); + Flux findSubscriptionTransactions( String subscriptionId, SubscriptionTransactionsSearchOptions options ); + Mono findSubscriptionComponentById( String subscriptionId, int componentId ); Mono reportSubscriptionComponentUsage( String subscriptionId, int componentId, Usage usage ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index d66391b..0c9ac3c 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -682,6 +682,36 @@ public Flux findSubscriptionStatements( .map( SubscriptionStatementWrapper::getStatement ); } + @Override + public Flux findSubscriptionTransactions( String subscriptionId, SubscriptionTransactionsSearchOptions options ) + { + if( options.getPageSize() > 200 ) + throw new IllegalArgumentException( "Page size can't be bigger than 200" ); + + StringBuilder uriBuilder = new StringBuilder(); + uriBuilder.append( "page=" ).append( options.getPage() ); + uriBuilder.append( "&per_page=" ).append( options.getPageSize() ); + uriBuilder.append( "&direction=" ).append( options.getDirection().getValue() ); + if( options.getMaxId() != null ) + uriBuilder.append( "&max_id=" ).append( options.getMaxId() ); + if( options.getSinceId() != null ) + uriBuilder.append( "&since_id=" ).append( options.getSinceId() ); + if( options.getKinds() != null ) + options.getKinds().forEach( kind -> uriBuilder.append( "&kinds[]=" ).append( kind ) ); + + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern( "yyyy-MM-dd"); + if( options.getSinceDate() != null ) + uriBuilder.append( "&since_date=" ).append( options.getSinceDate().format( dateFormatter ) ); + if( options.getUntilDate() != null ) + uriBuilder.append( "&until_date=" ).append( options.getUntilDate().format( dateFormatter ) ); + + + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/subscriptions/" + subscriptionId + "/transactions.json?" + uriBuilder ).retrieve() ) + .bodyToFlux( TransactionWrapper.class ) + .map( TransactionWrapper::getTransaction ); + } + @Override public Mono findSubscriptionComponentById( String subscriptionId, int componentId ) { diff --git a/src/main/java/com/chargify/SortDirection.java b/src/main/java/com/chargify/SortDirection.java new file mode 100644 index 0000000..fdc1793 --- /dev/null +++ b/src/main/java/com/chargify/SortDirection.java @@ -0,0 +1,13 @@ +package com.chargify; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum SortDirection +{ + ASC( "asc" ), DESC( "desc" ); + + private final String value; +} diff --git a/src/main/java/com/chargify/SubscriptionTransactionsSearchOptions.java b/src/main/java/com/chargify/SubscriptionTransactionsSearchOptions.java new file mode 100644 index 0000000..c2be27a --- /dev/null +++ b/src/main/java/com/chargify/SubscriptionTransactionsSearchOptions.java @@ -0,0 +1,38 @@ +package com.chargify; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDate; +import java.util.List; + +@Getter +@Builder +public class SubscriptionTransactionsSearchOptions +{ + @Builder.Default + private SortDirection direction = SortDirection.DESC; + private List kinds; + private Integer maxId; + @Builder.Default + private int page = 1; + @Builder.Default + private int pageSize = 20; + private LocalDate sinceDate; + private Integer sinceId; + private LocalDate untilDate; + + public SubscriptionTransactionsSearchOptions nextPage() + { + page++; + return this; + } + + public SubscriptionTransactionsSearchOptions previousPage() + { + if( (page - 1) < 1 ) + throw new IllegalStateException( "Page can't be less than 1" ); + page--; + return this; + } +} diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java index f655674..55a0234 100644 --- a/src/main/java/com/chargify/model/Subscription.java +++ b/src/main/java/com/chargify/model/Subscription.java @@ -24,7 +24,6 @@ import java.io.Serializable; import java.time.ZonedDateTime; -import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -50,7 +49,7 @@ public class Subscription implements Serializable private Integer productVersionNumber; @JsonProperty( "current_period_ends_at" ) - private Date currentPeriodEndsAt; + private ZonedDateTime currentPeriodEndsAt; @JsonProperty( "next_assessment_at" ) private ZonedDateTime nextAssessmentAt; @@ -59,22 +58,22 @@ public class Subscription implements Serializable private ZonedDateTime nextBillingAt; @JsonProperty( "trial_started_at" ) - private Date trialStartedAt; + private ZonedDateTime trialStartedAt; @JsonProperty( "trial_ended_at" ) - private Date trialEndedAt; + private ZonedDateTime trialEndedAt; @JsonProperty( "activated_at" ) - private Date activatedAt; + private ZonedDateTime activatedAt; @JsonProperty( "expires_at" ) - private Date expiresAt; + private ZonedDateTime expiresAt; @JsonProperty( "created_at" ) - private Date createdAt; + private ZonedDateTime createdAt; @JsonProperty( "updated_at" ) - private Date updatedAt; + private ZonedDateTime updatedAt; @JsonProperty( "cancellation_message" ) private String cancellationMessage; @@ -86,10 +85,10 @@ public class Subscription implements Serializable private Boolean cancelAtEndOfPeriod; @JsonProperty( "canceled_at" ) - private Date canceledAt; + private ZonedDateTime canceledAt; @JsonProperty( "current_period_started_at" ) - private Date currentPeriodStartedAt; + private ZonedDateTime currentPeriodStartedAt; @JsonProperty( "customer_attributes" ) private Customer customerAttributes; @@ -116,7 +115,7 @@ public class Subscription implements Serializable private String signupRevenue; @JsonProperty( "delayed_cancel_at" ) - private Date delayedCancelAt; + private ZonedDateTime delayedCancelAt; @JsonProperty( "coupon_code" ) private String couponCode; diff --git a/src/main/java/com/chargify/model/Transaction.java b/src/main/java/com/chargify/model/Transaction.java index 7806eb4..2fc807b 100644 --- a/src/main/java/com/chargify/model/Transaction.java +++ b/src/main/java/com/chargify/model/Transaction.java @@ -39,4 +39,6 @@ public class Transaction private String paymentId; @JsonProperty( "product_id" ) private String productId; + @JsonProperty( "component_id" ) + private String componentId; } diff --git a/src/main/java/com/chargify/model/TransactionsKinds.java b/src/main/java/com/chargify/model/TransactionsKinds.java new file mode 100644 index 0000000..4e3332e --- /dev/null +++ b/src/main/java/com/chargify/model/TransactionsKinds.java @@ -0,0 +1,14 @@ +package com.chargify.model; + +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + +@NoArgsConstructor( access = AccessLevel.PRIVATE ) +public final class TransactionsKinds +{ + public static final String CHARGE = "charge"; + public static final String CREDIT = "credit"; + public static final String ADJUSTMENT = "adjustment"; + public static final String PAYMENT = "payment"; + public static final String REFUND = "refund"; +} diff --git a/src/main/java/com/chargify/model/wrappers/TransactionWrapper.java b/src/main/java/com/chargify/model/wrappers/TransactionWrapper.java new file mode 100644 index 0000000..7a5100f --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/TransactionWrapper.java @@ -0,0 +1,18 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.Transaction; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; + +@Getter +public final class TransactionWrapper +{ + private final Transaction transaction; + + @JsonCreator + public TransactionWrapper( @JsonProperty( "transaction" ) Transaction transaction ) + { + this.transaction = transaction; + } +} From 1f4f901007c1853815316dc95bd18894348f1554 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Tue, 29 Nov 2022 16:54:25 +0200 Subject: [PATCH 48/58] [BKNDLSS-30458] Billing. Numeric value out of range for some subscriptions on devtest --- pom.xml | 2 +- src/main/java/com/chargify/model/Subscription.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3b8eb4e..094d2ab 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.33 + 0.34 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java index 55a0234..c84d2db 100644 --- a/src/main/java/com/chargify/model/Subscription.java +++ b/src/main/java/com/chargify/model/Subscription.java @@ -40,7 +40,7 @@ public class Subscription implements Serializable private Integer balanceInCents; @JsonProperty( "total_revenue_in_cents" ) - private Integer totalRevenueInCents; + private Long totalRevenueInCents; @JsonProperty( "product_price_in_cents" ) private Integer productPriceInCents; From 8977f28ecdb5631509c1a88df0af1a6ce499f622 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Thu, 1 Dec 2022 19:17:54 +0200 Subject: [PATCH 49/58] [BKNDLSS-30458] Billing. Numeric value out of range for some subscriptions on devtest --- pom.xml | 2 +- .../java/com/chargify/model/Adjustment.java | 155 ++---------------- .../com/chargify/model/RenewalPreview.java | 44 ++--- 3 files changed, 28 insertions(+), 173 deletions(-) diff --git a/pom.xml b/pom.xml index 094d2ab..8c68eab 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.34 + 0.35 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/Adjustment.java b/src/main/java/com/chargify/model/Adjustment.java index d217789..85b04cb 100644 --- a/src/main/java/com/chargify/model/Adjustment.java +++ b/src/main/java/com/chargify/model/Adjustment.java @@ -3,11 +3,19 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; -import java.util.Date; +import java.time.ZonedDateTime; @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data +@EqualsAndHashCode +@ToString public class Adjustment { private String id; @@ -15,155 +23,24 @@ public class Adjustment private String memo; @JsonProperty( "amount_in_cents" ) - private Integer amount_in_cents; + private Long amountInCents; @JsonProperty( "ending_balance_in_cents" ) - private Integer ending_balance_in_cents; + private Long endingBalanceInCents; private String type; @JsonProperty( "transaction_type" ) - private String transaction_type; + private String transactionType; @JsonProperty( "subscription_id" ) - private String subscription_id; + private String subscriptionId; @JsonProperty( "product_id" ) - private String product_id; + private String productId; @JsonProperty( "created_at" ) - private Date created_at; + private ZonedDateTime createdAt; @JsonProperty( "payment_id" ) - private String payment_id; - - public Adjustment() - { - } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public Boolean getSuccess() - { - return success; - } - - public void setSuccess( Boolean success ) - { - this.success = success; - } - - public String getMemo() - { - return memo; - } - - public void setMemo( String memo ) - { - this.memo = memo; - } - - public Integer getAmount_in_cents() - { - return amount_in_cents; - } - - public void setAmount_in_cents( Integer amount_in_cents ) - { - this.amount_in_cents = amount_in_cents; - } - - public Integer getEnding_balance_in_cents() - { - return ending_balance_in_cents; - } - - public void setEnding_balance_in_cents( Integer ending_balance_in_cents ) - { - this.ending_balance_in_cents = ending_balance_in_cents; - } - - public String getType() - { - return type; - } - - public void setType( String type ) - { - this.type = type; - } - - public String getTransaction_type() - { - return transaction_type; - } - - public void setTransaction_type( String transaction_type ) - { - this.transaction_type = transaction_type; - } - - public String getSubscription_id() - { - return subscription_id; - } - - public void setSubscription_id( String subscription_id ) - { - this.subscription_id = subscription_id; - } - - public String getProduct_id() - { - return product_id; - } - - public void setProduct_id( String product_id ) - { - this.product_id = product_id; - } - - public Date getCreated_at() - { - return created_at; - } - - public void setCreated_at( Date created_at ) - { - this.created_at = created_at; - } - - public String getPayment_id() - { - return payment_id; - } - - public void setPayment_id( String payment_id ) - { - this.payment_id = payment_id; - } - - @Override - public String toString() - { - return "Adjustment{" + - "id='" + id + '\'' + - ", success=" + success + - ", memo='" + memo + '\'' + - ", amount_in_cents=" + amount_in_cents + - ", ending_balance_in_cents=" + ending_balance_in_cents + - ", type='" + type + '\'' + - ", transaction_type='" + transaction_type + '\'' + - ", subscription_id='" + subscription_id + '\'' + - ", product_id='" + product_id + '\'' + - ", created_at=" + created_at + - ", payment_id='" + payment_id + '\'' + '}'; - } + private String paymentId; } diff --git a/src/main/java/com/chargify/model/RenewalPreview.java b/src/main/java/com/chargify/model/RenewalPreview.java index 057e389..ca5261a 100644 --- a/src/main/java/com/chargify/model/RenewalPreview.java +++ b/src/main/java/com/chargify/model/RenewalPreview.java @@ -2,46 +2,24 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import lombok.ToString; @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data +@EqualsAndHashCode +@ToString public class RenewalPreview { @JsonProperty( "subtotal_in_cents" ) - private Integer subtotalInCents; + private Long subtotalInCents; @JsonProperty( "total_amount_due_in_cents" ) - private Integer totalAmountDureInCents; + private Long totalAmountDueInCents; @JsonProperty( "existing_balance_in_cents" ) - private Integer existingBalanceInCents; - - public Integer getSubtotalInCents() - { - return subtotalInCents; - } - - public void setSubtotalInCents( Integer subtotalInCents ) - { - this.subtotalInCents = subtotalInCents; - } - - public Integer getTotalAmountDueInCents() - { - return totalAmountDureInCents; - } - - public void setTotalAmountDureInCents( Integer totalAmountDureInCents ) - { - this.totalAmountDureInCents = totalAmountDureInCents; - } - - public Integer getExistingBalanceInCents() - { - return existingBalanceInCents; - } - - public void setExistingBalanceInCents( Integer existingBalanceInCents ) - { - this.existingBalanceInCents = existingBalanceInCents; - } + private Long existingBalanceInCents; } From 2c82fd0d93cd4841d7d2da716e13b48276c1eaab Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Tue, 6 Dec 2022 14:20:17 +0200 Subject: [PATCH 50/58] [BKNDLSS-30531] Next billing date should be preserved when billing plan is changed --- pom.xml | 14 ++--- src/main/java/com/chargify/Chargify.java | 8 +-- .../java/com/chargify/ChargifyService.java | 56 ++----------------- src/main/java/com/chargify/ChargifyUtil.java | 26 +++++++++ .../java/com/chargify/model/Migration.java | 12 +++- .../model/SubscriptionProductUpdate.java | 7 +++ src/test/java/com/chargify/ProductsTest.java | 7 +-- .../SubscriptionDelayedChangeTest.java | 10 +++- .../java/com/chargify/SubscriptionsTest.java | 14 +++-- 9 files changed, 76 insertions(+), 78 deletions(-) create mode 100644 src/main/java/com/chargify/ChargifyUtil.java diff --git a/pom.xml b/pom.xml index 8c68eab..0dc01d4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.35 + 0.36 jar Chargify SDK for Java @@ -16,7 +16,7 @@ The Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt + https://www.apache.org/licenses/LICENSE-2.0.txt @@ -32,7 +32,7 @@ scm:git:git://github.com/scadgek/chargify-java-sdk.git scm:git:ssh://github.com:scadgek/chargify-java-sdk.git - http://github.com/github.com/scadgek/chargify-java-sdk/tree/master + https://github.com/github.com/scadgek/chargify-java-sdk/tree/master @@ -40,7 +40,7 @@ 1.8 1.8 backendless_private - http://maven.backendless.com/repository/backendless_private/ + https://maven.backendless.com/repository/backendless_private/ @@ -60,13 +60,13 @@ com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.14.1 + 2.13.4 ch.qos.logback logback-classic - 1.4.1 + 1.4.5 @@ -100,7 +100,7 @@ io.projectreactor.netty reactor-netty - 1.0.23 + 1.0.24 diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 0132e1b..8b6a35f 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -74,9 +74,7 @@ public interface Chargify Mono cancelSubscriptionProductChange( String subscriptionId ); - Mono migrateSubscription( String subscriptionId, String productHandle ); - - Mono migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ); + Mono migrateSubscription( String subscriptionId, Migration migration ); Mono reactivateSubscription( String subscriptionId, boolean preserveBalance ); @@ -89,9 +87,7 @@ Mono migrateSubscriptionComponentToPricePoint( String Mono cancelScheduledSubscriptionProductChange( String subscriptionId ); - Mono changeSubscriptionProduct( String subscriptionId, String productHandle, boolean delayed ); - - Mono changeSubscriptionProduct( String subscriptionId, String productHandle, String pricePointHandle, boolean delayed ); + Mono changeSubscriptionProduct( String subscriptionId, SubscriptionProductUpdate payload ); Mono previewSubscriptionRenewal( String subscriptionId ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 0c9ac3c..6dd9ff5 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -25,7 +25,6 @@ import java.nio.charset.StandardCharsets; import java.time.Duration; import java.time.LocalDateTime; -import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.Base64; import java.util.HashMap; @@ -208,12 +207,7 @@ public Mono updateSubscriptionNextBillingDate( String subscriptionId, Loca { return updateSubscription( subscriptionId, - UpdateSubscription.builder() - .nextBillingAt( - nextBillingDate.atZone( ZoneId.systemDefault() ) - .withZoneSameInstant( ZoneId.of( "UTC" ) ) - .toLocalDateTime() - .format( DateTimeFormatter.ofPattern( "yyyy-MM-dd'T'HH:mm:ss'Z'" ) ) ).build() + UpdateSubscription.builder().nextBillingAt( ChargifyUtil.toChargifyDateString( nextBillingDate ) ).build() ); } @@ -387,28 +381,8 @@ public Mono cancelSubscriptionProductChange( String subscriptionId } @Override - public Mono migrateSubscription( String subscriptionId, String productHandle ) + public Mono migrateSubscription( String subscriptionId, Migration migration ) { - final Migration migration = new Migration(); - migration.setProductHandle( productHandle ); - - return ChargifyResponseErrorHandler.handleError( - client.post().uri( "/subscriptions/" + subscriptionId + "/migrations.json" ) - .contentType( MediaType.APPLICATION_JSON ) - .body( Mono.just( new MigrationWrapper( migration ) ), MigrationWrapper.class ) - .retrieve() ) - .bodyToMono( SubscriptionWrapper.class ) - .map( SubscriptionWrapper::getSubscription ) - .onErrorResume( ResourceNotFoundException.class, ex -> Mono.empty() ); - } - - @Override - public Mono migrateSubscription( String subscriptionId, String productHandle, String pricePointHandle ) - { - final Migration migration = new Migration(); - migration.setProductHandle( productHandle ); - migration.setPricePointHandle( pricePointHandle ); - return ChargifyResponseErrorHandler.handleError( client.post().uri( "/subscriptions/" + subscriptionId + "/migrations.json" ) .contentType( MediaType.APPLICATION_JSON ) @@ -469,22 +443,6 @@ public Flux bulkUpdateSubscriptionComponentPricePoint .flatMapMany( Flux::fromIterable ); } - @Override - public Mono changeSubscriptionProduct( String subscriptionId, String productHandle, boolean delayed ) - { - final SubscriptionProductUpdate productUpdate = new SubscriptionProductUpdate(); - productUpdate.setProductHandle( productHandle ); - productUpdate.setChangeDelayed( delayed ); - - return ChargifyResponseErrorHandler.handleError( - client.put().uri( "/subscriptions/" + subscriptionId + ".json" ) - .contentType( MediaType.APPLICATION_JSON ) - .body( Mono.just( new SubscriptionProductUpdateWrapper( productUpdate ) ), SubscriptionProductUpdateWrapper.class ) - .retrieve() ) - .bodyToMono( SubscriptionWrapper.class ) - .map( SubscriptionWrapper::getSubscription ); - } - @Override public Mono cancelScheduledSubscriptionProductChange( String subscriptionId ) { @@ -504,18 +462,12 @@ public Mono cancelScheduledSubscriptionProductChange( String subsc } @Override - public Mono changeSubscriptionProduct( String subscriptionId, String productHandle, - String pricePointHandle, boolean delayed ) + public Mono changeSubscriptionProduct( String subscriptionId, SubscriptionProductUpdate payload ) { - final SubscriptionProductUpdate productUpdate = new SubscriptionProductUpdate(); - productUpdate.setProductHandle( productHandle ); - productUpdate.setChangeDelayed( delayed ); - productUpdate.setPricePointHandle( pricePointHandle ); - return ChargifyResponseErrorHandler.handleError( client.put().uri( "/subscriptions/" + subscriptionId + ".json" ) .contentType( MediaType.APPLICATION_JSON ) - .body( Mono.just( new SubscriptionProductUpdateWrapper( productUpdate ) ), SubscriptionProductUpdateWrapper.class ) + .body( Mono.just( new SubscriptionProductUpdateWrapper( payload ) ), SubscriptionProductUpdateWrapper.class ) .retrieve() ) .bodyToMono( SubscriptionWrapper.class ) .map( SubscriptionWrapper::getSubscription ); diff --git a/src/main/java/com/chargify/ChargifyUtil.java b/src/main/java/com/chargify/ChargifyUtil.java new file mode 100644 index 0000000..c8e12f4 --- /dev/null +++ b/src/main/java/com/chargify/ChargifyUtil.java @@ -0,0 +1,26 @@ +package com.chargify; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +public class ChargifyUtil +{ + private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern( "yyyy-MM-dd'T'HH:mm:ss'Z'" ); + + public static String toChargifyDateString( LocalDateTime date ) + { + return date.atZone( ZoneId.systemDefault() ) + .withZoneSameInstant( ZoneId.of( "UTC" ) ) + .toLocalDateTime() + .format( DATE_FORMATTER ); + } + public static String toChargifyDateString( ZonedDateTime date ) + { + return date + .withZoneSameInstant( ZoneId.of( "UTC" ) ) + .toLocalDateTime() + .format( DATE_FORMATTER ); + } +} diff --git a/src/main/java/com/chargify/model/Migration.java b/src/main/java/com/chargify/model/Migration.java index 18195d5..924f63f 100644 --- a/src/main/java/com/chargify/model/Migration.java +++ b/src/main/java/com/chargify/model/Migration.java @@ -2,8 +2,15 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; +@Builder +@AllArgsConstructor( access = AccessLevel.PRIVATE ) +@NoArgsConstructor @Data @JsonInclude( JsonInclude.Include.NON_NULL ) public class Migration @@ -12,7 +19,10 @@ public class Migration private String productHandle; @JsonProperty( "include_trial") - private Integer includeTrial; + private Boolean includeTrial; + + @JsonProperty( "preserve_period") + private Boolean preservePeriod; @JsonProperty( "product_price_point_handle") private String pricePointHandle; diff --git a/src/main/java/com/chargify/model/SubscriptionProductUpdate.java b/src/main/java/com/chargify/model/SubscriptionProductUpdate.java index e9c2853..2a7181f 100644 --- a/src/main/java/com/chargify/model/SubscriptionProductUpdate.java +++ b/src/main/java/com/chargify/model/SubscriptionProductUpdate.java @@ -2,10 +2,17 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AccessLevel; +import lombok.AllArgsConstructor; +import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; +@Builder +@NoArgsConstructor +@AllArgsConstructor( access = AccessLevel.PRIVATE ) @Data @JsonInclude( JsonInclude.Include.NON_NULL ) public class SubscriptionProductUpdate implements Serializable diff --git a/src/test/java/com/chargify/ProductsTest.java b/src/test/java/com/chargify/ProductsTest.java index 23bcc0f..2fa37e7 100644 --- a/src/test/java/com/chargify/ProductsTest.java +++ b/src/test/java/com/chargify/ProductsTest.java @@ -88,11 +88,10 @@ public void readAllByFamilyIdShouldRetrieveAtLeastOne() familyProducts.size() > 0 ); } - // TODO: see issue https://chargify.zendesk.com/hc/en-us/requests/69553 - @Test( expected = ChargifyException.class ) - public void readByNonExistingFamilyShouldThrowException() + @Test + public void readByNonExistingFamilyShouldReturnNull() { - chargify.findProductFamilyById( "nonexisting" ).block(); + Assert.assertNull( chargify.findProductFamilyById( "nonexisting" ).block() ); } @Test diff --git a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java index f0fc569..0dddc99 100644 --- a/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java +++ b/src/test/java/com/chargify/SubscriptionDelayedChangeTest.java @@ -3,6 +3,7 @@ import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; import com.chargify.model.PricePointIntervalUnit; +import com.chargify.model.SubscriptionProductUpdate; import com.chargify.model.product.Product; import com.chargify.model.product.ProductFamily; import com.chargify.model.Subscription; @@ -48,9 +49,12 @@ public static void setup() @Test public void delayedProductChangeShouldModifyNextProductIdAndNotChangeCurrentProduct() { - final Subscription resultSubscription = chargify.changeSubscriptionProduct( subscription.getId(), - targetProduct.getHandle(), - true ).block(); + final Subscription resultSubscription = chargify.changeSubscriptionProduct( + subscription.getId(), + SubscriptionProductUpdate.builder() + .productHandle( targetProduct.getHandle() ) + .changeDelayed( true ).build() + ).block(); assertNotNull( "Product change not scheduled", resultSubscription.getNextProductId() ); assertEquals( "Scheduled change to wrong product", targetProduct.getId(), resultSubscription.getNextProductId() ); assertEquals( "Current product changed", initialProduct.getId(), resultSubscription.getProduct().getId() ); diff --git a/src/test/java/com/chargify/SubscriptionsTest.java b/src/test/java/com/chargify/SubscriptionsTest.java index 254a5f4..9d05a9a 100644 --- a/src/test/java/com/chargify/SubscriptionsTest.java +++ b/src/test/java/com/chargify/SubscriptionsTest.java @@ -2,7 +2,9 @@ import com.chargify.model.CreateSubscription; import com.chargify.model.Customer; +import com.chargify.model.Migration; import com.chargify.model.PricePointIntervalUnit; +import com.chargify.model.SubscriptionProductUpdate; import com.chargify.model.product.Product; import com.chargify.model.product.ProductFamily; import com.chargify.model.Subscription; @@ -99,9 +101,11 @@ public void findAllShouldReturnAtLeastOne() @Test public void immediateProductChangeShouldChangeProduct() { - final Subscription subscription = chargify.changeSubscriptionProduct( subscriptionUnderTest.getId(), - productForImmediateChange.getHandle(), - false ).block(); + final Subscription subscription = chargify.changeSubscriptionProduct( + subscriptionUnderTest.getId(), SubscriptionProductUpdate.builder() + .productHandle( productForImmediateChange.getHandle() ) + .changeDelayed( false ).build() + ).block(); assertNull( "Product change scheduled", subscription.getNextProductId() ); assertEquals( "Product should have been changed", productForImmediateChange.getId(), subscription.getProduct().getId() ); } @@ -109,8 +113,8 @@ public void immediateProductChangeShouldChangeProduct() @Test public void migrationShouldChangeProduct() { - final Subscription subscription = chargify.migrateSubscription( subscriptionUnderTest.getId(), - productForMigration.getHandle() ).block(); + final Subscription subscription = chargify.migrateSubscription( + subscriptionUnderTest.getId(), Migration.builder().productHandle( productForMigration.getHandle() ).build() ).block(); assertNull( "Product change scheduled", subscription.getNextProductId() ); assertEquals( "Product has not been migrated", productForMigration.getHandle(), subscription.getProduct().getHandle() ); } From bccc23df410a8aa8bd808615b99293f9e9e90c1b Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Fri, 23 Dec 2022 12:49:03 +0200 Subject: [PATCH 51/58] [BKNDLSS-30720] New backendless billing --- pom.xml | 2 +- .../java/com/chargify/ChargifyService.java | 5 +- .../chargify/model/SubscriptionCharge.java | 20 ++++---- .../model/SubscriptionChargePayload.java | 47 +++++++++++++++++++ 4 files changed, 60 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/chargify/model/SubscriptionChargePayload.java diff --git a/pom.xml b/pom.xml index 0dc01d4..f950a78 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.36 + 0.37 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 6dd9ff5..019d951 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -212,13 +212,12 @@ public Mono updateSubscriptionNextBillingDate( String subscriptionId, Loca } @Override - public Mono createSubscriptionCharge( String subscriptionId, - SubscriptionCharge subscriptionCharge ) + public Mono createSubscriptionCharge( String subscriptionId, SubscriptionCharge subscriptionCharge ) { return ChargifyResponseErrorHandler.handleError( client.post().uri( "/subscriptions/" + subscriptionId + "/charges.json" ) .contentType( MediaType.APPLICATION_JSON ) - .body( Mono.just( Map.of( "charge", subscriptionCharge ) ), Map.class ) + .body( Mono.just( Map.of( "charge", SubscriptionChargePayload.from( subscriptionCharge ) ) ), Map.class ) .retrieve() ) .bodyToMono( SubscriptionChargeWrapper.class ) .map( SubscriptionChargeWrapper::getSubscriptionChargeResult ); diff --git a/src/main/java/com/chargify/model/SubscriptionCharge.java b/src/main/java/com/chargify/model/SubscriptionCharge.java index a759a4f..a22f080 100644 --- a/src/main/java/com/chargify/model/SubscriptionCharge.java +++ b/src/main/java/com/chargify/model/SubscriptionCharge.java @@ -1,9 +1,5 @@ package com.chargify.model; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -11,16 +7,20 @@ @NoArgsConstructor -@AllArgsConstructor @Data -@JsonIgnoreProperties( ignoreUnknown = true ) -@JsonInclude( JsonInclude.Include.NON_NULL ) public class SubscriptionCharge implements Serializable { - private String amount; + private Double amount; + private Long amountInCents; private String memo; - @JsonProperty( "period_range_start" ) private String periodRangeStart; - @JsonProperty( "period_range_end" ) private String periodRangeEnd; + private Boolean delayCapture; + private Boolean accrueOnFailure = true; + + public SubscriptionCharge( Long amountInCents, String memo ) + { + this.amountInCents = amountInCents; + this.memo = memo; + } } diff --git a/src/main/java/com/chargify/model/SubscriptionChargePayload.java b/src/main/java/com/chargify/model/SubscriptionChargePayload.java new file mode 100644 index 0000000..6f180e9 --- /dev/null +++ b/src/main/java/com/chargify/model/SubscriptionChargePayload.java @@ -0,0 +1,47 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@NoArgsConstructor +@Data +@JsonIgnoreProperties( ignoreUnknown = true ) +@JsonInclude( JsonInclude.Include.NON_NULL ) +public class SubscriptionChargePayload implements Serializable +{ + private String amount; + @JsonProperty( "amount_in_cents" ) + private String amountInCents; + private String memo; + @JsonProperty( "period_range_start" ) + private String periodRangeStart; + @JsonProperty( "period_range_end" ) + private String periodRangeEnd; + @JsonProperty( "delay_capture" ) + private String delayCapture; + @JsonProperty( "accrue_on_failure" ) + private String accrueOnFailure = "true"; + + public static SubscriptionChargePayload from( SubscriptionCharge subscriptionCharge ) + { + SubscriptionChargePayload payload = new SubscriptionChargePayload(); + if( subscriptionCharge.getAmount() != null ) + payload.setAmount( String.valueOf( subscriptionCharge.getAmount() ) ); + if( subscriptionCharge.getAmountInCents() != null ) + payload.setAmountInCents( String.valueOf( subscriptionCharge.getAmountInCents() ) ); + payload.setMemo( String.valueOf( subscriptionCharge.getMemo() ) ); + payload.setPeriodRangeStart( subscriptionCharge.getPeriodRangeStart() ); + payload.setPeriodRangeEnd( subscriptionCharge.getPeriodRangeEnd() ); + if( subscriptionCharge.getDelayCapture() != null ) + payload.setDelayCapture( String.valueOf( subscriptionCharge.getDelayCapture() ) ); + if( subscriptionCharge.getAccrueOnFailure() != null ) + payload.setAccrueOnFailure( String.valueOf( subscriptionCharge.getAccrueOnFailure() ) ); + + return payload; + } +} From 42107b8383fead40a95847c6d2c5884b88b799d3 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Tue, 27 Dec 2022 10:54:57 +0200 Subject: [PATCH 52/58] [BKNDLSS-30821] Billing. Try to charge existing depth on import/export/clone attempt instead of not allowing these operations --- pom.xml | 2 +- src/main/java/com/chargify/model/SubscriptionCharge.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f950a78..3935145 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.37 + 0.38 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/SubscriptionCharge.java b/src/main/java/com/chargify/model/SubscriptionCharge.java index a22f080..c105327 100644 --- a/src/main/java/com/chargify/model/SubscriptionCharge.java +++ b/src/main/java/com/chargify/model/SubscriptionCharge.java @@ -16,7 +16,7 @@ public class SubscriptionCharge implements Serializable private String periodRangeStart; private String periodRangeEnd; private Boolean delayCapture; - private Boolean accrueOnFailure = true; + private Boolean accrueOnFailure = false; public SubscriptionCharge( Long amountInCents, String memo ) { From 303eca826c2ff1285301b24ab93b108d9114339c Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Wed, 4 Jan 2023 16:02:13 +0200 Subject: [PATCH 53/58] [BKNDLSS-30795] Record one-time charges for custom developer products --- pom.xml | 6 +++--- src/main/java/com/chargify/model/Transaction.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 3935145..b23bfc1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.38 + 0.39 jar Chargify SDK for Java @@ -54,7 +54,7 @@ com.fasterxml.jackson.core jackson-databind - 2.13.4 + 2.13.4.2 @@ -100,7 +100,7 @@ io.projectreactor.netty reactor-netty - 1.0.24 + 1.0.26 diff --git a/src/main/java/com/chargify/model/Transaction.java b/src/main/java/com/chargify/model/Transaction.java index 2fc807b..14ca296 100644 --- a/src/main/java/com/chargify/model/Transaction.java +++ b/src/main/java/com/chargify/model/Transaction.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; -import java.time.LocalDateTime; +import java.time.ZonedDateTime; @Data @JsonIgnoreProperties( ignoreUnknown = true ) @@ -24,7 +24,7 @@ public class Transaction private int amountInCents; private String memo; @JsonProperty( "created_at" ) - private LocalDateTime createdAt; + private ZonedDateTime createdAt; @JsonProperty( "starting_balance_in_cents" ) private int startingBalanceInCents; @JsonProperty( "ending_balance_in_cents" ) From 297affa83ec4115cc0e4dfeccbfc2e91bdbe83c3 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Fri, 3 Feb 2023 11:07:36 +0200 Subject: [PATCH 54/58] [BKNDLSS-31271] Billing. Errors during subscription info decoding --- pom.xml | 2 +- .../com/chargify/model/AllocationPreview.java | 2 +- src/main/java/com/chargify/model/Charge.java | 289 +----------------- .../java/com/chargify/model/Subscription.java | 2 +- .../model/SubscriptionChargeResult.java | 4 +- .../chargify/model/SubscriptionStatement.java | 4 +- .../java/com/chargify/model/Transaction.java | 4 +- src/test/java/com/chargify/ProductsTest.java | 1 - 8 files changed, 21 insertions(+), 287 deletions(-) diff --git a/pom.xml b/pom.xml index b23bfc1..1cb6b87 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.39 + 0.40 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/model/AllocationPreview.java b/src/main/java/com/chargify/model/AllocationPreview.java index c4ced35..9345854 100644 --- a/src/main/java/com/chargify/model/AllocationPreview.java +++ b/src/main/java/com/chargify/model/AllocationPreview.java @@ -30,7 +30,7 @@ public class AllocationPreview @JsonProperty( "subtotal_in_cents" ) private Integer subtotalInCents; @JsonProperty( "existing_balance_in_cents" ) - private Integer existingBalanceInCents; + private Long existingBalanceInCents; @JsonProperty( "direction" ) private String direction; @JsonProperty( "proration_scheme" ) diff --git a/src/main/java/com/chargify/model/Charge.java b/src/main/java/com/chargify/model/Charge.java index c482630..61893af 100644 --- a/src/main/java/com/chargify/model/Charge.java +++ b/src/main/java/com/chargify/model/Charge.java @@ -3,10 +3,19 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; -import java.util.Arrays; import java.util.Date; +@NoArgsConstructor +@Getter +@Setter +@ToString +@EqualsAndHashCode @JsonIgnoreProperties(ignoreUnknown = true) @JsonInclude( JsonInclude.Include.NON_NULL ) public class Charge @@ -34,10 +43,10 @@ public class Charge private Date createdAt; @JsonProperty( "starting_balance_in_cents" ) - private int startingBalanceInCents; + private long startingBalanceInCents; @JsonProperty( "ending_balance_in_cents" ) - private int endingBalanceInCents; + private long endingBalanceInCents; @JsonProperty( "gateway_used" ) private String gatewayUsed; @@ -76,278 +85,4 @@ public class Charge private int taxableAmountInCents; private String[] taxations; - - public Charge() - { - } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getSubscriptionId() - { - return subscriptionId; - } - - public void setSubscriptionId( String subscriptionId ) - { - this.subscriptionId = subscriptionId; - } - - public String getType() - { - return type; - } - - public void setType( String type ) - { - this.type = type; - } - - public String getKind() - { - return kind; - } - - public void setKind( String kind ) - { - this.kind = kind; - } - - public String getTransactionType() - { - return transactionType; - } - - public void setTransactionType( String transactionType ) - { - this.transactionType = transactionType; - } - - public Boolean getSuccess() - { - return success; - } - - public void setSuccess( Boolean success ) - { - this.success = success; - } - - public int getAmountInCents() - { - return amountInCents; - } - - public void setAmountInCents( int amountInCents ) - { - this.amountInCents = amountInCents; - } - - public String getMemo() - { - return memo; - } - - public void setMemo( String memo ) - { - this.memo = memo; - } - - public Date getCreatedAt() - { - return createdAt; - } - - public void setCreatedAt( Date createdAt ) - { - this.createdAt = createdAt; - } - - public int getStartingBalanceInCents() - { - return startingBalanceInCents; - } - - public void setStartingBalanceInCents( int startingBalanceInCents ) - { - this.startingBalanceInCents = startingBalanceInCents; - } - - public int getEndingBalanceInCents() - { - return endingBalanceInCents; - } - - public void setEndingBalanceInCents( int endingBalanceInCents ) - { - this.endingBalanceInCents = endingBalanceInCents; - } - - public String getGatewayUsed() - { - return gatewayUsed; - } - - public void setGatewayUsed( String gatewayUsed ) - { - this.gatewayUsed = gatewayUsed; - } - - public String getGatewayTransactionId() - { - return gatewayTransactionId; - } - - public void setGatewayTransactionId( String gatewayTransactionId ) - { - this.gatewayTransactionId = gatewayTransactionId; - } - - public String getGatewayOrderId() - { - return gatewayOrderId; - } - - public void setGatewayOrderId( String gatewayOrderId ) - { - this.gatewayOrderId = gatewayOrderId; - } - - public String getPaymentId() - { - return paymentId; - } - - public void setPaymentId( String paymentId ) - { - this.paymentId = paymentId; - } - - public String getProductId() - { - return productId; - } - - public void setProductId( String productId ) - { - this.productId = productId; - } - - public String getTaxId() - { - return taxId; - } - - public void setTaxId( String taxId ) - { - this.taxId = taxId; - } - - public String getComponentId() - { - return componentId; - } - - public void setComponentId( String componentId ) - { - this.componentId = componentId; - } - - public String getStatementId() - { - return statementId; - } - - public void setStatementId( String statementId ) - { - this.statementId = statementId; - } - - public String getCustomerId() - { - return customerId; - } - - public void setCustomerId( String customerId ) - { - this.customerId = customerId; - } - - public int getOriginalAmountInCents() - { - return originalAmountInCents; - } - - public void setOriginalAmountInCents( int originalAmountInCents ) - { - this.originalAmountInCents = originalAmountInCents; - } - - public int getDiscountAmountInCents() - { - return discountAmountInCents; - } - - public void setDiscountAmountInCents( int discountAmountInCents ) - { - this.discountAmountInCents = discountAmountInCents; - } - - public int getTaxableAmountInCents() - { - return taxableAmountInCents; - } - - public void setTaxableAmountInCents( int taxableAmountInCents ) - { - this.taxableAmountInCents = taxableAmountInCents; - } - - public String[] getTaxations() - { - return taxations; - } - - public void setTaxations( String[] taxations ) - { - this.taxations = taxations; - } - - @Override - public String toString() - { - return "Charge{" + - "id='" + id + '\'' + - ", subscriptionId='" + subscriptionId + '\'' + - ", type='" + type + '\'' + - ", kind='" + kind + '\'' + - ", transactionType='" + transactionType + '\'' + - ", success=" + success + - ", amountInCents=" + amountInCents + - ", memo='" + memo + '\'' + - ", createdAt=" + createdAt + - ", startingBalanceInCents=" + startingBalanceInCents + - ", endingBalanceInCents=" + endingBalanceInCents + - ", gatewayUsed='" + gatewayUsed + '\'' + - ", gatewayTransactionId='" + gatewayTransactionId + '\'' + - ", gatewayOrderId='" + gatewayOrderId + '\'' + - ", paymentId='" + paymentId + '\'' + - ", productId='" + productId + '\'' + - ", taxId='" + taxId + '\'' + - ", componentId='" + componentId + '\'' + - ", statementId='" + statementId + '\'' + - ", customerId='" + customerId + '\'' + - ", originalAmountInCents=" + originalAmountInCents + - ", discountAmountInCents=" + discountAmountInCents + - ", taxableAmountInCents=" + taxableAmountInCents + - ", taxations=" + Arrays.toString( taxations ) + '}'; - } } diff --git a/src/main/java/com/chargify/model/Subscription.java b/src/main/java/com/chargify/model/Subscription.java index c84d2db..3a201af 100644 --- a/src/main/java/com/chargify/model/Subscription.java +++ b/src/main/java/com/chargify/model/Subscription.java @@ -37,7 +37,7 @@ public class Subscription implements Serializable private String state; @JsonProperty( "balance_in_cents" ) - private Integer balanceInCents; + private Long balanceInCents; @JsonProperty( "total_revenue_in_cents" ) private Long totalRevenueInCents; diff --git a/src/main/java/com/chargify/model/SubscriptionChargeResult.java b/src/main/java/com/chargify/model/SubscriptionChargeResult.java index 8088d66..2d05a13 100644 --- a/src/main/java/com/chargify/model/SubscriptionChargeResult.java +++ b/src/main/java/com/chargify/model/SubscriptionChargeResult.java @@ -31,9 +31,9 @@ public class SubscriptionChargeResult implements Serializable @JsonProperty( "created_at" ) private String createdAt; @JsonProperty( "starting_balance_in_cents" ) - private Integer startingBalanceInCents; + private Long startingBalanceInCents; @JsonProperty( "ending_balance_in_cents" ) - private Integer endingBalanceInCents; + private Long endingBalanceInCents; @JsonProperty( "product_id" ) private Integer productId; @JsonProperty( "statement_id" ) diff --git a/src/main/java/com/chargify/model/SubscriptionStatement.java b/src/main/java/com/chargify/model/SubscriptionStatement.java index 98ea9fe..1d39c42 100644 --- a/src/main/java/com/chargify/model/SubscriptionStatement.java +++ b/src/main/java/com/chargify/model/SubscriptionStatement.java @@ -58,9 +58,9 @@ public class SubscriptionStatement implements Serializable @JsonProperty( "customer_shipping_zip" ) private String customerShippingZip; @JsonProperty( "starting_balance_in_cents" ) - private Integer startingBalanceInCents; + private Long startingBalanceInCents; @JsonProperty( "ending_balance_in_cents" ) - private Integer endingBalanceInCents; + private Long endingBalanceInCents; @JsonProperty( "memo" ) private String memo; @JsonProperty( "subscription_id" ) diff --git a/src/main/java/com/chargify/model/Transaction.java b/src/main/java/com/chargify/model/Transaction.java index 14ca296..7599784 100644 --- a/src/main/java/com/chargify/model/Transaction.java +++ b/src/main/java/com/chargify/model/Transaction.java @@ -26,9 +26,9 @@ public class Transaction @JsonProperty( "created_at" ) private ZonedDateTime createdAt; @JsonProperty( "starting_balance_in_cents" ) - private int startingBalanceInCents; + private long startingBalanceInCents; @JsonProperty( "ending_balance_in_cents" ) - private int endingBalanceInCents; + private long endingBalanceInCents; @JsonProperty( "gateway_used" ) private String gatewayUsed; @JsonProperty( "gateway_transaction_id" ) diff --git a/src/test/java/com/chargify/ProductsTest.java b/src/test/java/com/chargify/ProductsTest.java index 2fa37e7..6a61542 100644 --- a/src/test/java/com/chargify/ProductsTest.java +++ b/src/test/java/com/chargify/ProductsTest.java @@ -1,6 +1,5 @@ package com.chargify; -import com.chargify.exceptions.ChargifyException; import com.chargify.model.PricePointIntervalUnit; import com.chargify.model.product.Product; import com.chargify.model.product.ProductFamily; From 52ba318361ff58e3cda7047b3b305f7bd5fbfcdb Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Wed, 5 Apr 2023 18:59:18 +0300 Subject: [PATCH 55/58] BKNDLSS-31948 Add route to update pricing for subscription-based products --- pom.xml | 20 +++++----- src/main/java/com/chargify/Chargify.java | 2 + .../java/com/chargify/ChargifyService.java | 12 ++++++ src/main/java/com/chargify/model/Price.java | 39 +++---------------- .../com/chargify/model/PricePointUpdate.java | 19 +++++++++ .../PricePointUpdateResultWrapper.java | 23 +++++++++++ .../wrappers/PricePointUpdateWrapper.java | 24 ++++++++++++ 7 files changed, 96 insertions(+), 43 deletions(-) create mode 100644 src/main/java/com/chargify/model/PricePointUpdate.java create mode 100644 src/main/java/com/chargify/model/wrappers/PricePointUpdateResultWrapper.java create mode 100644 src/main/java/com/chargify/model/wrappers/PricePointUpdateWrapper.java diff --git a/pom.xml b/pom.xml index 1cb6b87..8580229 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.40 + 0.41 jar Chargify SDK for Java @@ -37,8 +37,8 @@ UTF-8 - 1.8 - 1.8 + 17 + 17 backendless_private https://maven.backendless.com/repository/backendless_private/ @@ -48,7 +48,7 @@ org.springframework spring-webflux - 5.3.23 + 5.3.26 @@ -66,7 +66,7 @@ ch.qos.logback logback-classic - 1.4.5 + 1.4.6 @@ -79,7 +79,7 @@ org.projectlombok lombok - 1.18.24 + 1.18.26 provided @@ -93,14 +93,14 @@ org.springframework spring-test - 5.3.23 + 5.3.26 test io.projectreactor.netty reactor-netty - 1.0.26 + 1.0.30 @@ -148,8 +148,8 @@ org.apache.maven.plugins maven-compiler-plugin - 11 - 11 + 17 + 17 diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 8b6a35f..99bd6cd 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -30,6 +30,8 @@ public interface Chargify Flux findComponentPricePoints( int componentId ); + Mono updatePricePoint( int componentId, int pricePointId, PricePointUpdate pricePointUpdate ); + Flux findAllProducts(); Flux findProductsByProductFamilyId( String productFamilyId ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 019d951..0db8d47 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -157,6 +157,18 @@ public Flux findComponentPricePoints( int componentId ) .flatMapMany( Flux::fromIterable ); } + @Override + public Mono updatePricePoint( int componentId, int pricePointId, PricePointUpdate pricePointUpdate ) + { + return ChargifyResponseErrorHandler.handleError( + client.put().uri( "/components/" + componentId + "/price_points/" + pricePointId + ".json" ) + .contentType( MediaType.APPLICATION_JSON ) + .body( Mono.just( new PricePointUpdateWrapper( pricePointUpdate ) ), PricePointUpdateWrapper.class ) + .retrieve() ) + .bodyToMono( PricePointUpdateResultWrapper.class ) + .map( PricePointUpdateResultWrapper::getPricePoint ); + } + @Override public Flux findAllProducts() { diff --git a/src/main/java/com/chargify/model/Price.java b/src/main/java/com/chargify/model/Price.java index 70ccd03..9e49f09 100644 --- a/src/main/java/com/chargify/model/Price.java +++ b/src/main/java/com/chargify/model/Price.java @@ -4,52 +4,25 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; +import lombok.Data; import java.io.Serializable; @AllArgsConstructor @JsonInclude( JsonInclude.Include.NON_NULL ) +@Data public final class Price implements Serializable { + private Integer id; + @JsonProperty( "starting_quantity" ) private Integer startingQuantity; + @JsonProperty( "ending_quantity" ) private Integer endingQuantity; + @JsonProperty( "unit_price" ) private Double unitPrice; @JsonCreator public Price() { } - - @JsonProperty( "starting_quantity" ) - public Integer getStartingQuantity() - { - return startingQuantity; - } - - public void setStartingQuantity( Integer startingQuantity ) - { - this.startingQuantity = startingQuantity; - } - - @JsonProperty( "ending_quantity" ) - public Integer getEndingQuantity() - { - return endingQuantity; - } - - public void setEndingQuantity( Integer endingQuantity ) - { - this.endingQuantity = endingQuantity; - } - - @JsonProperty( "unit_price" ) - public Double getUnitPrice() - { - return unitPrice; - } - - public void setUnitPrice( Double unitPrice ) - { - this.unitPrice = unitPrice; - } } diff --git a/src/main/java/com/chargify/model/PricePointUpdate.java b/src/main/java/com/chargify/model/PricePointUpdate.java new file mode 100644 index 0000000..2f8ab3e --- /dev/null +++ b/src/main/java/com/chargify/model/PricePointUpdate.java @@ -0,0 +1,19 @@ +package com.chargify.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; + +@JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@AllArgsConstructor +@Data +public final class PricePointUpdate implements Serializable +{ + private String name; + private Price[] prices; +} diff --git a/src/main/java/com/chargify/model/wrappers/PricePointUpdateResultWrapper.java b/src/main/java/com/chargify/model/wrappers/PricePointUpdateResultWrapper.java new file mode 100644 index 0000000..8881d9a --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/PricePointUpdateResultWrapper.java @@ -0,0 +1,23 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.PricePoint; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + +@EqualsAndHashCode +@ToString +public final class PricePointUpdateResultWrapper +{ + @Getter + @JsonProperty( "price_point" ) + private final PricePoint pricePoint; + + @JsonCreator + public PricePointUpdateResultWrapper( @JsonProperty( "price_point" ) PricePoint pricePoint ) + { + this.pricePoint = pricePoint; + } +} diff --git a/src/main/java/com/chargify/model/wrappers/PricePointUpdateWrapper.java b/src/main/java/com/chargify/model/wrappers/PricePointUpdateWrapper.java new file mode 100644 index 0000000..fe0329a --- /dev/null +++ b/src/main/java/com/chargify/model/wrappers/PricePointUpdateWrapper.java @@ -0,0 +1,24 @@ +package com.chargify.model.wrappers; + +import com.chargify.model.PricePoint; +import com.chargify.model.PricePointUpdate; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + +@EqualsAndHashCode +@ToString +public final class PricePointUpdateWrapper +{ + @Getter + @JsonProperty( "price_point" ) + private final PricePointUpdate pricePoint; + + @JsonCreator + public PricePointUpdateWrapper( @JsonProperty( "price_point" ) PricePointUpdate pricePoint ) + { + this.pricePoint = pricePoint; + } +} From f733ebdd798bdfff150cf8f882107caf7de6ec97 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Tue, 18 Jul 2023 16:23:26 +0300 Subject: [PATCH 56/58] BKNDLSS-33056 Balance decreases if you buy a product from a non-valid card --- pom.xml | 6 +- .../java/com/chargify/model/Allocation.java | 124 ++---------------- 2 files changed, 15 insertions(+), 115 deletions(-) diff --git a/pom.xml b/pom.xml index 8580229..6156bdf 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.41 + 0.42 jar Chargify SDK for Java @@ -48,7 +48,7 @@ org.springframework spring-webflux - 5.3.26 + 5.3.29 @@ -79,7 +79,7 @@ org.projectlombok lombok - 1.18.26 + 1.18.28 provided diff --git a/src/main/java/com/chargify/model/Allocation.java b/src/main/java/com/chargify/model/Allocation.java index d76b87e..a31118d 100644 --- a/src/main/java/com/chargify/model/Allocation.java +++ b/src/main/java/com/chargify/model/Allocation.java @@ -2,9 +2,15 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; -import java.util.Date; +import java.time.ZonedDateTime; +@ToString +@Getter +@Setter @JsonInclude( JsonInclude.Include.NON_NULL ) public class Allocation { @@ -21,119 +27,13 @@ public class Allocation private String memo; - private Date timestamp; + private ZonedDateTime timestamp; - @JsonProperty( "proration_upgrade_scheme" ) - private String prorationUpgradeScheme; + @JsonProperty( "upgrade_charge" ) + private String upgradeCharge; - @JsonProperty( "proration_downgrade_scheme" ) - private String prorationDowngradeScheme; + @JsonProperty( "downgrade_credit" ) + private String downgradeCredit; private Payment payment; - - public String getComponentId() - { - return componentId; - } - - public void setComponentId( String componentId ) - { - this.componentId = componentId; - } - - public String getSubscriptionId() - { - return subscriptionId; - } - - public void setSubscriptionId( String subscriptionId ) - { - this.subscriptionId = subscriptionId; - } - - public Integer getQuantity() - { - return quantity; - } - - public void setQuantity( Integer quantity ) - { - this.quantity = quantity; - } - - public Integer getPreviousQuantity() - { - return previousQuantity; - } - - public void setPreviousQuantity( Integer previousQuantity ) - { - this.previousQuantity = previousQuantity; - } - - public String getMemo() - { - return memo; - } - - public void setMemo( String memo ) - { - this.memo = memo; - } - - public Date getTimestamp() - { - return timestamp; - } - - public void setTimestamp( Date timestamp ) - { - this.timestamp = timestamp; - } - - public String getProrationUpgradeScheme() - { - return prorationUpgradeScheme; - } - - public void setProrationUpgradeScheme( String prorationUpgradeScheme ) - { - this.prorationUpgradeScheme = prorationUpgradeScheme; - } - - public String getProrationDowngradeScheme() - { - return prorationDowngradeScheme; - } - - public void setProrationDowngradeScheme( String prorationDowngradeScheme ) - { - this.prorationDowngradeScheme = prorationDowngradeScheme; - } - - public Payment getPayment() - { - return payment; - } - - public void setPayment( Payment payment ) - { - this.payment = payment; - } - - @Override - public String toString() - { - return "Allocation{" + - "componentId='" + componentId + '\'' + - ", subscriptionId='" + subscriptionId + '\'' + - ", quantity=" + quantity + - ", previousQuantity=" + previousQuantity + - ", memo='" + memo + '\'' + - ", timestamp=" + timestamp + - ", prorationUpgradeScheme='" + prorationUpgradeScheme + '\'' + - ", prorationDowngradeScheme='" + prorationDowngradeScheme + '\'' + - ", payment=" + payment + - '}'; - } } From b17346847354e25b274556423e0839eff3ddae67 Mon Sep 17 00:00:00 2001 From: Andriy Konoz Date: Tue, 3 Oct 2023 10:52:42 +0300 Subject: [PATCH 57/58] BKNDLSS-34024 The request to create a new application does not finish in devtest. Updated Spring dependencies to match those from billing. --- pom.xml | 28 ++++---- .../java/com/chargify/ChargifyService.java | 26 ++++---- .../chargify/exceptions/ChargifyError.java | 8 +-- .../exceptions/ChargifyException.java | 20 +++--- .../ChargifyResponseErrorHandler.java | 56 ++++++++-------- .../java/com/chargify/model/Metadata.java | 54 ++------------- src/main/java/com/chargify/model/Payment.java | 58 ++-------------- .../com/chargify/model/PricePointUpdate.java | 1 - .../com/chargify/model/PublicSignupPage.java | 55 ++-------------- .../java/com/chargify/model/ReferralCode.java | 50 ++------------ .../java/com/chargify/model/RefundInput.java | 56 ++-------------- .../java/com/chargify/model/RefundOutput.java | 58 ++-------------- .../chargify/model/SubscriptionMetadata.java | 55 ++-------------- src/main/java/com/chargify/model/Usage.java | 66 ++----------------- .../model/product/ProductComponentItem.java | 34 ++-------- .../chargify/model/product/ProductFamily.java | 61 ++--------------- .../model/wrappers/AdjustmentWrapper.java | 11 ++-- .../wrappers/AllocationPreviewWrapper.java | 6 +- .../model/wrappers/AllocationWrapper.java | 11 ++-- .../model/wrappers/AnyComponentWrapper.java | 19 ++---- .../wrappers/ComponentPricePointsWrapper.java | 4 +- .../wrappers/CreateSubscriptionWrapper.java | 12 ++-- .../model/wrappers/CustomerWrapper.java | 15 ++--- .../model/wrappers/MetadataWrapper.java | 11 ++-- .../model/wrappers/MigrationWrapper.java | 11 ++-- .../model/wrappers/PaymentProfileWrapper.java | 7 +- .../PricePointUpdateResultWrapper.java | 2 +- .../wrappers/PricePointUpdateWrapper.java | 3 +- .../wrappers/ProductPricePointsWrapper.java | 2 +- .../model/wrappers/ProductWrapper.java | 17 ++--- .../model/wrappers/ReferralCodeWrapper.java | 21 ++---- .../model/wrappers/RenewalPreviewWrapper.java | 7 +- .../wrappers/SubscriptionChargeWrapper.java | 2 +- .../SubscriptionComponentWrapper.java | 7 +- .../SubscriptionProductUpdateWrapper.java | 5 +- .../model/wrappers/SubscriptionWrapper.java | 11 +--- .../chargify/model/wrappers/UsageWrapper.java | 7 +- src/test/java/com/chargify/CustomersTest.java | 6 +- .../com/chargify/ProductFamiliesTest.java | 7 +- src/test/java/com/chargify/ProductsTest.java | 11 ++-- .../java/com/chargify/SubscriptionsTest.java | 8 +-- 41 files changed, 209 insertions(+), 700 deletions(-) diff --git a/pom.xml b/pom.xml index 6156bdf..4596ae4 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.42 + 0.43 jar Chargify SDK for Java @@ -48,25 +48,28 @@ org.springframework spring-webflux - 5.3.29 + 6.0.12 + provided com.fasterxml.jackson.core jackson-databind - 2.13.4.2 + 2.14.3 + provided com.fasterxml.jackson.datatype jackson-datatype-jsr310 - 2.13.4 + 2.14.3 + provided ch.qos.logback logback-classic - 1.4.6 + 1.4.11 @@ -75,6 +78,13 @@ 3.12.0 + + io.projectreactor.netty + reactor-netty + 1.1.11 + provided + + org.projectlombok @@ -93,16 +103,10 @@ org.springframework spring-test - 5.3.26 + 6.0.12 test - - io.projectreactor.netty - reactor-netty - 1.0.30 - - diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index 0db8d47..eef8feb 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -534,24 +534,22 @@ public Mono createComponent( String productFamilyId, Component compon throw new IllegalArgumentException( "Component Kind must not be null" ); final String pluralKindPathParam; - final ComponentWrapper componentWrapper; - switch( component.getKind() ) + final ComponentWrapper componentWrapper = switch( component.getKind() ) { - case quantity_based_component: + case quantity_based_component -> { pluralKindPathParam = "quantity_based_components"; - componentWrapper = new QuantityBasedComponentWrapper( component ); - break; - case metered_component: + yield new QuantityBasedComponentWrapper( component ); + } + case metered_component -> { pluralKindPathParam = "metered_components"; - componentWrapper = new MeteredComponentWrapper( component ); - break; - case on_off_component: + yield new MeteredComponentWrapper( component ); + } + case on_off_component -> { pluralKindPathParam = "on_off_components"; - componentWrapper = new OnOffComponentWrapper( component ); - break; - default: - throw new IllegalArgumentException( "Invalid component kind - " + component.getKind() ); - } + yield new OnOffComponentWrapper( component ); + } + default -> throw new IllegalArgumentException( "Invalid component kind - " + component.getKind() ); + }; return ChargifyResponseErrorHandler.handleError( client.post().uri( "/product_families/" + productFamilyId + "/" + pluralKindPathParam + ".json" ) diff --git a/src/main/java/com/chargify/exceptions/ChargifyError.java b/src/main/java/com/chargify/exceptions/ChargifyError.java index eb0c689..85dbd74 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyError.java +++ b/src/main/java/com/chargify/exceptions/ChargifyError.java @@ -22,14 +22,14 @@ public ChargifyError( @JsonProperty( "errors" ) @JsonAlias( "error" ) Object err ChargifyException exception() { - if( errors instanceof Collection ) + if( errors instanceof Collection errorsAsStrings ) { - return ChargifyException.fromErrors( (Collection) errors ); + return ChargifyException.fromErrors( errorsAsStrings ); } - else if( errors instanceof Map ) + else if( errors instanceof Map errorsAsMap ) { List errorsList = new ArrayList<>(); - ((Map) errors).forEach( ( key, value ) -> errorsList.add( key + ": " + value ) ); + errorsAsMap.forEach( ( key, value ) -> errorsList.add( key + ": " + value ) ); return ChargifyException.fromErrors( errorsList ); } else diff --git a/src/main/java/com/chargify/exceptions/ChargifyException.java b/src/main/java/com/chargify/exceptions/ChargifyException.java index be82f4e..b8e02a6 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyException.java +++ b/src/main/java/com/chargify/exceptions/ChargifyException.java @@ -9,12 +9,12 @@ public class ChargifyException extends RuntimeException super( errorMessage ); } - private ChargifyException( Collection errorMessages ) + private ChargifyException( Collection errorMessages ) { super( String.join( " && ", errorMessages.toString() ) ); } - static ChargifyException fromErrors( Collection errorMessages ) + static ChargifyException fromErrors( Collection errorMessages ) { if( errorMessages.size() == 1 ) { @@ -28,16 +28,12 @@ static ChargifyException fromErrors( Collection errorMessages ) private static ChargifyException fromError( String errorMessage ) { - switch( errorMessage ) + return switch( errorMessage ) { - case PaymentProfileInUseException.MESSAGE: - return new PaymentProfileInUseException(); - case MissingNameException.MESSAGE: - return new MissingNameException(); - case ApiHandleNotUniqueException.MESSAGE: - return new ApiHandleNotUniqueException(); - default: - return new ChargifyException( errorMessage ); - } + case PaymentProfileInUseException.MESSAGE -> new PaymentProfileInUseException(); + case MissingNameException.MESSAGE -> new MissingNameException(); + case ApiHandleNotUniqueException.MESSAGE -> new ApiHandleNotUniqueException(); + default -> new ChargifyException( errorMessage ); + }; } } diff --git a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java index fecfae8..2d4a717 100644 --- a/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java +++ b/src/main/java/com/chargify/exceptions/ChargifyResponseErrorHandler.java @@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.springframework.http.HttpStatus; +import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.reactive.function.client.WebClient; @@ -59,8 +60,8 @@ else if( statusCode >= 500 && statusCode < 600 ) public static WebClient.ResponseSpec handleError( WebClient.ResponseSpec response ) { - response.onStatus( HttpStatus::is4xxClientError, clientResponse -> { - HttpStatus statusCode = clientResponse.statusCode(); + response.onStatus( HttpStatusCode::is4xxClientError, clientResponse -> { + HttpStatusCode statusCode = clientResponse.statusCode(); if( statusCode == HttpStatus.NOT_FOUND ) return Mono.error( new ResourceNotFoundException() ); else if( statusCode == HttpStatus.FORBIDDEN ) // TODO: see issue https://chargify.zendesk.com/hc/en-us/requests/69553 @@ -68,28 +69,28 @@ else if( statusCode == HttpStatus.FORBIDDEN ) // TODO: see issue https://chargif else { return clientResponse.bodyToMono( String.class ) - .map( body -> { - try - { - return objectMapper.readValue( body, ChargifyError.class ).exception(); - } - catch( JsonProcessingException e ) - { - throw new RuntimeException( e ); - } - } ) - .flatMap( Mono::error ); + .handle( ( body, sink ) -> { + try + { + sink.next( objectMapper.readValue( body, ChargifyError.class ).exception() ); + } + catch( JsonProcessingException e ) + { + sink.error( new RuntimeException( e ) ); + } + } ) + .flatMap( Mono::error ); } } ); response.onStatus( - HttpStatus::is5xxServerError, + HttpStatusCode::is5xxServerError, clientResponse -> clientResponse.bodyToMono( String.class ) .map( message -> new HttpServerErrorException( clientResponse.statusCode().value(), message ) ) .flatMap( Mono::error ) ); response.onStatus( - HttpStatus::isError, + HttpStatusCode::isError, clientResponse -> response.bodyToMono( String.class ) .map( message -> new UnknownHttpStatusCodeException( clientResponse.statusCode().value(), message ) ) .flatMap( Mono::error ) ); @@ -98,22 +99,21 @@ else if( statusCode == HttpStatus.FORBIDDEN ) // TODO: see issue https://chargif } @Override - protected void handleError( ClientHttpResponse response, HttpStatus statusCode ) throws IOException + protected void handleError( ClientHttpResponse response, HttpStatusCode statusCode ) throws IOException { - switch( statusCode.series() ) + if( statusCode.is4xxClientError() ) { - case CLIENT_ERROR: - if( statusCode == HttpStatus.NOT_FOUND ) - throw new ResourceNotFoundException(); - else if( statusCode == HttpStatus.FORBIDDEN ) // TODO: see issue https://chargify.zendesk.com/hc/en-us/requests/69553 - throw new ChargifyException( readInputStream( response.getBody() ) ); - else - throw objectMapper.readValue( response.getBody(), ChargifyError.class ).exception(); - case SERVER_ERROR: - throw new HttpServerErrorException( statusCode.value(), readInputStream( response.getBody() ) ); - default: - throw new UnknownHttpStatusCodeException( statusCode.value(), readInputStream( response.getBody() ) ); + if( statusCode == HttpStatus.NOT_FOUND ) + throw new ResourceNotFoundException(); + else if( statusCode == HttpStatus.FORBIDDEN ) // TODO: see issue https://chargify.zendesk.com/hc/en-us/requests/69553 + throw new ChargifyException( readInputStream( response.getBody() ) ); + else + throw objectMapper.readValue( response.getBody(), ChargifyError.class ).exception(); } + else if( statusCode.is5xxServerError() ) + throw new HttpServerErrorException( statusCode.value(), readInputStream( response.getBody() ) ); + else + throw new UnknownHttpStatusCodeException( statusCode.value(), readInputStream( response.getBody() ) ); } private String readInputStream( final InputStream stream ) diff --git a/src/main/java/com/chargify/model/Metadata.java b/src/main/java/com/chargify/model/Metadata.java index 65ef49f..7fef6e1 100644 --- a/src/main/java/com/chargify/model/Metadata.java +++ b/src/main/java/com/chargify/model/Metadata.java @@ -3,11 +3,15 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data public class Metadata implements Serializable { private String value; @@ -19,54 +23,4 @@ public class Metadata implements Serializable @JsonProperty( "current_name" ) private String currentName; - - public String getValue() - { - return value; - } - - public void setValue( String value ) - { - this.value = value; - } - - public String getResourceId() - { - return resourceId; - } - - public void setResourceId( String resourceId ) - { - this.resourceId = resourceId; - } - - public String getName() - { - return name; - } - - public void setName( String name ) - { - this.name = name; - } - - @Override - public String toString() - { - return "Metadata{" + - "value='" + value + '\'' + - ", resourceId='" + resourceId + '\'' + - ", name='" + name + '\'' + - '}'; - } - - public String getCurrentName() - { - return currentName; - } - - public void setCurrentName( String currentName ) - { - this.currentName = currentName; - } } diff --git a/src/main/java/com/chargify/model/Payment.java b/src/main/java/com/chargify/model/Payment.java index 973aced..1516c49 100644 --- a/src/main/java/com/chargify/model/Payment.java +++ b/src/main/java/com/chargify/model/Payment.java @@ -3,9 +3,13 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data public class Payment { private String id; @@ -17,62 +21,8 @@ public class Payment private String memo; - public Payment() - { - } - public Payment( String id ) { this.id = id; } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public Boolean getSuccess() - { - return success; - } - - public void setSuccess( Boolean success ) - { - this.success = success; - } - - public int getAmountInCents() - { - return amountInCents; - } - - public void setAmountInCents( int amountInCents ) - { - this.amountInCents = amountInCents; - } - - public String getMemo() - { - return memo; - } - - public void setMemo( String memo ) - { - this.memo = memo; - } - - @Override - public String toString() - { - return "Payment{" + - "id='" + id + '\'' + - ", success=" + success + - ", amountInCents=" + amountInCents + - ", memo='" + memo + '\'' + '}'; - } } diff --git a/src/main/java/com/chargify/model/PricePointUpdate.java b/src/main/java/com/chargify/model/PricePointUpdate.java index 2f8ab3e..bec53ff 100644 --- a/src/main/java/com/chargify/model/PricePointUpdate.java +++ b/src/main/java/com/chargify/model/PricePointUpdate.java @@ -1,7 +1,6 @@ package com.chargify.model; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/chargify/model/PublicSignupPage.java b/src/main/java/com/chargify/model/PublicSignupPage.java index 7f8a5e5..3da305d 100644 --- a/src/main/java/com/chargify/model/PublicSignupPage.java +++ b/src/main/java/com/chargify/model/PublicSignupPage.java @@ -2,10 +2,14 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data public class PublicSignupPage implements Serializable { private String id; @@ -17,55 +21,4 @@ public class PublicSignupPage implements Serializable private String returnParams; private String url; - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getReturnUrl() - { - return returnUrl; - } - - public void setReturnUrl( String returnUrl ) - { - this.returnUrl = returnUrl; - } - - public String getReturnParams() - { - return returnParams; - } - - public void setReturnParams( String returnParams ) - { - this.returnParams = returnParams; - } - - public String getUrl() - { - return url; - } - - public void setUrl( String url ) - { - this.url = url; - } - - @Override - public String toString() - { - return "PublicSignupPage{" + - "id='" + id + '\'' + - ", returnUrl='" + returnUrl + '\'' + - ", returnParams='" + returnParams + '\'' + - ", url='" + url + '\'' + - '}'; - } } diff --git a/src/main/java/com/chargify/model/ReferralCode.java b/src/main/java/com/chargify/model/ReferralCode.java index 813564e..776e90a 100644 --- a/src/main/java/com/chargify/model/ReferralCode.java +++ b/src/main/java/com/chargify/model/ReferralCode.java @@ -2,8 +2,14 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data +@Accessors( chain = true ) public class ReferralCode { private String id; @@ -15,48 +21,4 @@ public class ReferralCode private String subscriptionId; private String code; - - public String getId() - { - return id; - } - - public ReferralCode setId( String id ) - { - this.id = id; - return this; - } - - public String getSiteId() - { - return siteId; - } - - public ReferralCode setSiteId( String siteId ) - { - this.siteId = siteId; - return this; - } - - public String getSubscriptionId() - { - return subscriptionId; - } - - public ReferralCode setSubscriptionId( String subscriptionId ) - { - this.subscriptionId = subscriptionId; - return this; - } - - public String getCode() - { - return code; - } - - public ReferralCode setCode( String code ) - { - this.code = code; - return this; - } } diff --git a/src/main/java/com/chargify/model/RefundInput.java b/src/main/java/com/chargify/model/RefundInput.java index 8231841..85f37ec 100644 --- a/src/main/java/com/chargify/model/RefundInput.java +++ b/src/main/java/com/chargify/model/RefundInput.java @@ -3,9 +3,15 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@AllArgsConstructor +@Data public class RefundInput { @JsonProperty( "payment_id" ) @@ -16,54 +22,4 @@ public class RefundInput @JsonProperty( "memo" ) private String memo; - - public RefundInput() - { - } - - public RefundInput( String paymentId, int amountInCents, String memo ) - { - this.paymentId = paymentId; - this.amountInCents = amountInCents; - this.memo = memo; - } - - public String getPaymentId() - { - return paymentId; - } - - public void setPaymentId( String paymentId ) - { - this.paymentId = paymentId; - } - - public int getAmountInCents() - { - return amountInCents; - } - - public void setAmountInCents( int amountInCents ) - { - this.amountInCents = amountInCents; - } - - public String getMemo() - { - return memo; - } - - public void setMemo( String memo ) - { - this.memo = memo; - } - - @Override - public String toString() - { - return "RefundInput{" + - "paymentId='" + paymentId + '\'' + - ", amountInCents=" + amountInCents + - ", memo='" + memo + '\'' + '}'; - } } diff --git a/src/main/java/com/chargify/model/RefundOutput.java b/src/main/java/com/chargify/model/RefundOutput.java index fd29586..ac2aaf6 100644 --- a/src/main/java/com/chargify/model/RefundOutput.java +++ b/src/main/java/com/chargify/model/RefundOutput.java @@ -3,9 +3,13 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data public class RefundOutput { private String id; @@ -16,58 +20,4 @@ public class RefundOutput private int amountInCents; private String memo; - - public RefundOutput() - { - } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public Boolean getSuccess() - { - return success; - } - - public void setSuccess( Boolean success ) - { - this.success = success; - } - - public int getAmountInCents() - { - return amountInCents; - } - - public void setAmountInCents( int amountInCents ) - { - this.amountInCents = amountInCents; - } - - public String getMemo() - { - return memo; - } - - public void setMemo( String memo ) - { - this.memo = memo; - } - - @Override - public String toString() - { - return "RefundOutput{" + - "id='" + id + '\'' + - ", success=" + success + - ", amountInCents=" + amountInCents + - ", memo='" + memo + '\'' + '}'; - } } diff --git a/src/main/java/com/chargify/model/SubscriptionMetadata.java b/src/main/java/com/chargify/model/SubscriptionMetadata.java index 603ae22..38a4d18 100644 --- a/src/main/java/com/chargify/model/SubscriptionMetadata.java +++ b/src/main/java/com/chargify/model/SubscriptionMetadata.java @@ -3,12 +3,17 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import java.io.Serializable; import java.util.Arrays; @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Getter @Setter public class SubscriptionMetadata implements Serializable { @JsonProperty( "total_count" ) @@ -25,56 +30,6 @@ public class SubscriptionMetadata implements Serializable private Metadata[] metadata; - public int getTotalCount() - { - return totalCount; - } - - public void setTotalCount( int totalCount ) - { - this.totalCount = totalCount; - } - - public int getCurrentPage() - { - return currentPage; - } - - public void setCurrentPage( int currentPage ) - { - this.currentPage = currentPage; - } - - public int getTotalPages() - { - return totalPages; - } - - public void setTotalPages( int totalPages ) - { - this.totalPages = totalPages; - } - - public int getPerPage() - { - return perPage; - } - - public void setPerPage( int perPage ) - { - this.perPage = perPage; - } - - public Metadata[] getMetadata() - { - return metadata; - } - - public void setMetadata( Metadata[] metadata ) - { - this.metadata = metadata; - } - @Override public String toString() { diff --git a/src/main/java/com/chargify/model/Usage.java b/src/main/java/com/chargify/model/Usage.java index 3b6f0c4..5926d2a 100644 --- a/src/main/java/com/chargify/model/Usage.java +++ b/src/main/java/com/chargify/model/Usage.java @@ -3,11 +3,15 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; import java.util.Date; @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data public class Usage { @JsonProperty( "created_at" ) @@ -21,66 +25,4 @@ public class Usage @JsonProperty( "price_point_id" ) private Integer pricePointId; - - public Date getCreatedAt() - { - return createdAt; - } - - public void setCreatedAt( Date createdAt ) - { - this.createdAt = createdAt; - } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getMemo() - { - return memo; - } - - public void setMemo( String memo ) - { - this.memo = memo; - } - - public Integer getQuantity() - { - return quantity; - } - - public void setQuantity( Integer quantity ) - { - this.quantity = quantity; - } - - public Integer getPricePointId() - { - return pricePointId; - } - - public void setPricePointId( Integer pricePointId ) - { - this.pricePointId = pricePointId; - } - - @Override - public String toString() - { - return "Usage{" + - "createdAt=" + createdAt + - ", id='" + id + '\'' + - ", memo='" + memo + '\'' + - ", quantity=" + quantity + - ", pricePointId=" + pricePointId + - '}'; - } } diff --git a/src/main/java/com/chargify/model/product/ProductComponentItem.java b/src/main/java/com/chargify/model/product/ProductComponentItem.java index ee155a8..8bfcea8 100644 --- a/src/main/java/com/chargify/model/product/ProductComponentItem.java +++ b/src/main/java/com/chargify/model/product/ProductComponentItem.java @@ -21,9 +21,13 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; @JsonIgnoreProperties( ignoreUnknown = true ) @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data public class ProductComponentItem { @JsonProperty( "component_id" ) @@ -33,34 +37,4 @@ public class ProductComponentItem private int allocatedQuantity; private boolean enabled; - - public String getComponentId() - { - return componentId; - } - - public void setComponentId( String componentId ) - { - this.componentId = componentId; - } - - public int getAllocatedQuantity() - { - return allocatedQuantity; - } - - public void setAllocatedQuantity( int allocatedQuantity ) - { - this.allocatedQuantity = allocatedQuantity; - } - - public boolean isEnabled() - { - return enabled; - } - - public void setEnabled( boolean enabled ) - { - this.enabled = enabled; - } } diff --git a/src/main/java/com/chargify/model/product/ProductFamily.java b/src/main/java/com/chargify/model/product/ProductFamily.java index 9986c2f..ce72bac 100644 --- a/src/main/java/com/chargify/model/product/ProductFamily.java +++ b/src/main/java/com/chargify/model/product/ProductFamily.java @@ -3,10 +3,14 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; +import lombok.NoArgsConstructor; import java.io.Serializable; @JsonInclude( JsonInclude.Include.NON_NULL ) +@NoArgsConstructor +@Data public class ProductFamily implements Serializable { private String id; @@ -25,61 +29,4 @@ public ProductFamily( @JsonProperty( "name" ) String name ) { this.name = name; } - - public String getId() - { - return id; - } - - public void setId( String id ) - { - this.id = id; - } - - public String getName() - { - return name; - } - - public String getDescription() - { - return description; - } - - public void setDescription( String description ) - { - this.description = description; - } - - public String getHandle() - { - return handle; - } - - public void setHandle( String handle ) - { - this.handle = handle; - } - - public String getAccountingCode() - { - return accountingCode; - } - - public void setAccountingCode( String accountingCode ) - { - this.accountingCode = accountingCode; - } - - @Override - public String toString() - { - return "ProductFamily{" + - "id='" + id + '\'' + - ", name='" + name + '\'' + - ", description='" + description + '\'' + - ", handle='" + handle + '\'' + - ", accountingCode='" + accountingCode + '\'' + - '}'; - } } diff --git a/src/main/java/com/chargify/model/wrappers/AdjustmentWrapper.java b/src/main/java/com/chargify/model/wrappers/AdjustmentWrapper.java index 1abf496..db769df 100644 --- a/src/main/java/com/chargify/model/wrappers/AdjustmentWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/AdjustmentWrapper.java @@ -3,7 +3,13 @@ import com.chargify.model.Adjustment; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +@Getter +@EqualsAndHashCode +@ToString public final class AdjustmentWrapper { private final Adjustment adjustment; @@ -13,9 +19,4 @@ public AdjustmentWrapper( @JsonProperty( "adjustment" ) Adjustment wrappedAdjust { this.adjustment = wrappedAdjustment; } - - public Adjustment getAdjustment() - { - return adjustment; - } } diff --git a/src/main/java/com/chargify/model/wrappers/AllocationPreviewWrapper.java b/src/main/java/com/chargify/model/wrappers/AllocationPreviewWrapper.java index 61528ee..f5c81fd 100644 --- a/src/main/java/com/chargify/model/wrappers/AllocationPreviewWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/AllocationPreviewWrapper.java @@ -3,11 +3,15 @@ import com.chargify.model.AllocationPreview; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; +@Getter +@EqualsAndHashCode +@ToString public final class AllocationPreviewWrapper { - @Getter private final AllocationPreview allocationPreview; @JsonCreator diff --git a/src/main/java/com/chargify/model/wrappers/AllocationWrapper.java b/src/main/java/com/chargify/model/wrappers/AllocationWrapper.java index f6561a8..63401e9 100644 --- a/src/main/java/com/chargify/model/wrappers/AllocationWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/AllocationWrapper.java @@ -3,7 +3,13 @@ import com.chargify.model.Allocation; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +@Getter +@EqualsAndHashCode +@ToString public final class AllocationWrapper { private final Allocation allocation; @@ -13,9 +19,4 @@ public AllocationWrapper( @JsonProperty( "allocation" ) Allocation wrappedAlloca { this.allocation = wrappedAllocation; } - - public Allocation getAllocation() - { - return allocation; - } } diff --git a/src/main/java/com/chargify/model/wrappers/AnyComponentWrapper.java b/src/main/java/com/chargify/model/wrappers/AnyComponentWrapper.java index 7ed7afb..0b67034 100644 --- a/src/main/java/com/chargify/model/wrappers/AnyComponentWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/AnyComponentWrapper.java @@ -3,7 +3,13 @@ import com.chargify.model.Component; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +@Getter +@EqualsAndHashCode +@ToString public final class AnyComponentWrapper { private final Component component; @@ -13,17 +19,4 @@ public AnyComponentWrapper( @JsonProperty( "component" ) Component wrappedCompon { this.component = wrappedComponent; } - - public Component getComponent() - { - return component; - } - - @Override - public String toString() - { - return "AnyComponentWrapper{" + - "component=" + component + - '}'; - } } diff --git a/src/main/java/com/chargify/model/wrappers/ComponentPricePointsWrapper.java b/src/main/java/com/chargify/model/wrappers/ComponentPricePointsWrapper.java index d88db76..1fac0e1 100644 --- a/src/main/java/com/chargify/model/wrappers/ComponentPricePointsWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/ComponentPricePointsWrapper.java @@ -3,15 +3,17 @@ import com.chargify.model.PricePoint; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; import java.util.Set; +@Getter +@EqualsAndHashCode @ToString public final class ComponentPricePointsWrapper { - @Getter private final Set pricePoints; @JsonCreator diff --git a/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java b/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java index 8a939f4..4b7f280 100644 --- a/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/CreateSubscriptionWrapper.java @@ -3,8 +3,13 @@ import com.chargify.model.CreateSubscription; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; - +@Getter +@EqualsAndHashCode +@ToString public final class CreateSubscriptionWrapper { private final CreateSubscription subscription; @@ -14,9 +19,4 @@ public CreateSubscriptionWrapper( @JsonProperty( "subscription" ) CreateSubscrip { this.subscription = wrappedSubscription; } - - public CreateSubscription getSubscription() - { - return subscription; - } } diff --git a/src/main/java/com/chargify/model/wrappers/CustomerWrapper.java b/src/main/java/com/chargify/model/wrappers/CustomerWrapper.java index a5ebf8a..0d8be38 100644 --- a/src/main/java/com/chargify/model/wrappers/CustomerWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/CustomerWrapper.java @@ -3,21 +3,20 @@ import com.chargify.model.Customer; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +@Getter +@EqualsAndHashCode +@ToString public final class CustomerWrapper { private final Customer customer; @JsonCreator - public CustomerWrapper( - @JsonProperty( "customer" ) - Customer wrappedCustomer ) + public CustomerWrapper( @JsonProperty( "customer" ) Customer wrappedCustomer ) { this.customer = wrappedCustomer; } - - public Customer getCustomer() - { - return customer; - } } diff --git a/src/main/java/com/chargify/model/wrappers/MetadataWrapper.java b/src/main/java/com/chargify/model/wrappers/MetadataWrapper.java index 50851e7..52477d7 100644 --- a/src/main/java/com/chargify/model/wrappers/MetadataWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/MetadataWrapper.java @@ -3,7 +3,13 @@ import com.chargify.model.Metadata; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +@Getter +@ToString +@EqualsAndHashCode public final class MetadataWrapper { private final Metadata[] metadata; @@ -13,9 +19,4 @@ public MetadataWrapper( @JsonProperty( "metadata" ) Metadata[] wrappedMetadata ) { this.metadata = wrappedMetadata; } - - public Metadata[] getMetadata() - { - return metadata; - } } diff --git a/src/main/java/com/chargify/model/wrappers/MigrationWrapper.java b/src/main/java/com/chargify/model/wrappers/MigrationWrapper.java index 70b6454..3512f1f 100644 --- a/src/main/java/com/chargify/model/wrappers/MigrationWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/MigrationWrapper.java @@ -3,7 +3,13 @@ import com.chargify.model.Migration; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; +@Getter +@ToString +@EqualsAndHashCode public final class MigrationWrapper { private final Migration migration; @@ -13,9 +19,4 @@ public MigrationWrapper( @JsonProperty( "migration" ) Migration wrappedMigration { this.migration = wrappedMigration; } - - public Migration getMigration() - { - return migration; - } } diff --git a/src/main/java/com/chargify/model/wrappers/PaymentProfileWrapper.java b/src/main/java/com/chargify/model/wrappers/PaymentProfileWrapper.java index ee98e0b..5004036 100644 --- a/src/main/java/com/chargify/model/wrappers/PaymentProfileWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/PaymentProfileWrapper.java @@ -3,12 +3,15 @@ import com.chargify.model.PaymentProfile; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.EqualsAndHashCode; import lombok.Getter; +import lombok.ToString; - +@Getter +@ToString +@EqualsAndHashCode public final class PaymentProfileWrapper { - @Getter private final PaymentProfile paymentProfile; @JsonCreator diff --git a/src/main/java/com/chargify/model/wrappers/PricePointUpdateResultWrapper.java b/src/main/java/com/chargify/model/wrappers/PricePointUpdateResultWrapper.java index 8881d9a..1988793 100644 --- a/src/main/java/com/chargify/model/wrappers/PricePointUpdateResultWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/PricePointUpdateResultWrapper.java @@ -7,11 +7,11 @@ import lombok.Getter; import lombok.ToString; +@Getter @EqualsAndHashCode @ToString public final class PricePointUpdateResultWrapper { - @Getter @JsonProperty( "price_point" ) private final PricePoint pricePoint; diff --git a/src/main/java/com/chargify/model/wrappers/PricePointUpdateWrapper.java b/src/main/java/com/chargify/model/wrappers/PricePointUpdateWrapper.java index fe0329a..b374d24 100644 --- a/src/main/java/com/chargify/model/wrappers/PricePointUpdateWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/PricePointUpdateWrapper.java @@ -1,6 +1,5 @@ package com.chargify.model.wrappers; -import com.chargify.model.PricePoint; import com.chargify.model.PricePointUpdate; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; @@ -8,11 +7,11 @@ import lombok.Getter; import lombok.ToString; +@Getter @EqualsAndHashCode @ToString public final class PricePointUpdateWrapper { - @Getter @JsonProperty( "price_point" ) private final PricePointUpdate pricePoint; diff --git a/src/main/java/com/chargify/model/wrappers/ProductPricePointsWrapper.java b/src/main/java/com/chargify/model/wrappers/ProductPricePointsWrapper.java index f365730..971cf0c 100644 --- a/src/main/java/com/chargify/model/wrappers/ProductPricePointsWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/ProductPricePointsWrapper.java @@ -8,10 +8,10 @@ import java.util.Set; +@Getter @ToString public final class ProductPricePointsWrapper { - @Getter private final Set pricePoints; @JsonCreator diff --git a/src/main/java/com/chargify/model/wrappers/ProductWrapper.java b/src/main/java/com/chargify/model/wrappers/ProductWrapper.java index 09e1482..4cb9232 100644 --- a/src/main/java/com/chargify/model/wrappers/ProductWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/ProductWrapper.java @@ -3,7 +3,11 @@ import com.chargify.model.product.Product; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.ToString; +@Getter +@ToString public final class ProductWrapper { private final Product product; @@ -13,17 +17,4 @@ public ProductWrapper( @JsonProperty( "product" ) Product wrappedProduct ) { this.product = wrappedProduct; } - - public Product getProduct() - { - return product; - } - - @Override - public String toString() - { - return "ProductWrapper{" + - "product=" + product + - '}'; - } } diff --git a/src/main/java/com/chargify/model/wrappers/ReferralCodeWrapper.java b/src/main/java/com/chargify/model/wrappers/ReferralCodeWrapper.java index 3143b93..696e0b8 100644 --- a/src/main/java/com/chargify/model/wrappers/ReferralCodeWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/ReferralCodeWrapper.java @@ -3,27 +3,18 @@ import com.chargify.model.ReferralCode; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +import lombok.ToString; +@Getter +@ToString public final class ReferralCodeWrapper { private final ReferralCode referralCode; @JsonCreator - public ReferralCodeWrapper( @JsonProperty( "referral_code" ) ReferralCode wrappedReferalCode ) + public ReferralCodeWrapper( @JsonProperty( "referral_code" ) ReferralCode wrappedReferralCode ) { - this.referralCode = wrappedReferalCode; - } - - public ReferralCode getReferralCode() - { - return referralCode; - } - - @Override - public String toString() - { - return "ReferralCodeWrapper{" + - "referralCode=" + referralCode + - '}'; + this.referralCode = wrappedReferralCode; } } diff --git a/src/main/java/com/chargify/model/wrappers/RenewalPreviewWrapper.java b/src/main/java/com/chargify/model/wrappers/RenewalPreviewWrapper.java index 31b7089..47d98e2 100644 --- a/src/main/java/com/chargify/model/wrappers/RenewalPreviewWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/RenewalPreviewWrapper.java @@ -3,7 +3,9 @@ import com.chargify.model.RenewalPreview; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +@Getter public final class RenewalPreviewWrapper { private final RenewalPreview renewalPreview; @@ -13,9 +15,4 @@ public RenewalPreviewWrapper( @JsonProperty( "renewal_preview" ) RenewalPreview { this.renewalPreview = renewalPreview; } - - public RenewalPreview getRenewalPreview() - { - return renewalPreview; - } } diff --git a/src/main/java/com/chargify/model/wrappers/SubscriptionChargeWrapper.java b/src/main/java/com/chargify/model/wrappers/SubscriptionChargeWrapper.java index b54a188..1996834 100644 --- a/src/main/java/com/chargify/model/wrappers/SubscriptionChargeWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/SubscriptionChargeWrapper.java @@ -7,10 +7,10 @@ import lombok.ToString; +@Getter @ToString public final class SubscriptionChargeWrapper { - @Getter private final SubscriptionChargeResult subscriptionChargeResult; @JsonCreator diff --git a/src/main/java/com/chargify/model/wrappers/SubscriptionComponentWrapper.java b/src/main/java/com/chargify/model/wrappers/SubscriptionComponentWrapper.java index 55ccf4a..550a699 100644 --- a/src/main/java/com/chargify/model/wrappers/SubscriptionComponentWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/SubscriptionComponentWrapper.java @@ -3,7 +3,9 @@ import com.chargify.model.SubscriptionComponent; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +@Getter public final class SubscriptionComponentWrapper { private final SubscriptionComponent component; @@ -13,9 +15,4 @@ public SubscriptionComponentWrapper( @JsonProperty( "component" ) SubscriptionCo { this.component = wrappedComponent; } - - public SubscriptionComponent getComponent() - { - return component; - } } diff --git a/src/main/java/com/chargify/model/wrappers/SubscriptionProductUpdateWrapper.java b/src/main/java/com/chargify/model/wrappers/SubscriptionProductUpdateWrapper.java index 4a66e2c..cef3230 100644 --- a/src/main/java/com/chargify/model/wrappers/SubscriptionProductUpdateWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/SubscriptionProductUpdateWrapper.java @@ -5,14 +5,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; +@Getter public final class SubscriptionProductUpdateWrapper { - @Getter private final SubscriptionProductUpdate subscription; @JsonCreator - public SubscriptionProductUpdateWrapper( @JsonProperty( "subscription" ) - SubscriptionProductUpdate wrappedSubscription ) + public SubscriptionProductUpdateWrapper( @JsonProperty( "subscription" ) SubscriptionProductUpdate wrappedSubscription ) { this.subscription = wrappedSubscription; } diff --git a/src/main/java/com/chargify/model/wrappers/SubscriptionWrapper.java b/src/main/java/com/chargify/model/wrappers/SubscriptionWrapper.java index 70fd480..c2d9230 100644 --- a/src/main/java/com/chargify/model/wrappers/SubscriptionWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/SubscriptionWrapper.java @@ -3,21 +3,16 @@ import com.chargify.model.Subscription; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +@Getter public final class SubscriptionWrapper { private final Subscription subscription; @JsonCreator - public SubscriptionWrapper( - @JsonProperty( "subscription" ) - Subscription wrappedSubscription ) + public SubscriptionWrapper( @JsonProperty( "subscription" ) Subscription wrappedSubscription ) { this.subscription = wrappedSubscription; } - - public Subscription getSubscription() - { - return subscription; - } } diff --git a/src/main/java/com/chargify/model/wrappers/UsageWrapper.java b/src/main/java/com/chargify/model/wrappers/UsageWrapper.java index cd03f16..e92f4a9 100644 --- a/src/main/java/com/chargify/model/wrappers/UsageWrapper.java +++ b/src/main/java/com/chargify/model/wrappers/UsageWrapper.java @@ -3,7 +3,9 @@ import com.chargify.model.Usage; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Getter; +@Getter public final class UsageWrapper { private final Usage usage; @@ -13,9 +15,4 @@ public UsageWrapper( @JsonProperty( "usage" ) Usage wrappedUsage ) { this.usage = wrappedUsage; } - - public Usage getUsage() - { - return usage; - } } diff --git a/src/test/java/com/chargify/CustomersTest.java b/src/test/java/com/chargify/CustomersTest.java index f37fd1d..74bcfb8 100644 --- a/src/test/java/com/chargify/CustomersTest.java +++ b/src/test/java/com/chargify/CustomersTest.java @@ -7,9 +7,9 @@ import java.util.List; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; public class CustomersTest extends ChargifyTest { @@ -44,7 +44,7 @@ public void customerShouldBeFoundByValidId() @Test public void customerShouldNotBeFoundByInvalidId() { - final Customer customer = chargify.findCustomerById( "nonexisting" ).block(); + final Customer customer = chargify.findCustomerById( "nonexistent" ).block(); assertNull( "Customer should not have been found", customer ); } @@ -52,7 +52,7 @@ public void customerShouldNotBeFoundByInvalidId() public void findAllShouldFindAtLeastOne() { final List customers = chargify.findAllCustomers().collectList().block(); - assertTrue( "No customers found", customers.size() > 0 ); + assertFalse( "No customers found", customers.isEmpty() ); } @Test diff --git a/src/test/java/com/chargify/ProductFamiliesTest.java b/src/test/java/com/chargify/ProductFamiliesTest.java index ed10228..9f42352 100644 --- a/src/test/java/com/chargify/ProductFamiliesTest.java +++ b/src/test/java/com/chargify/ProductFamiliesTest.java @@ -43,14 +43,13 @@ public void productFamilyRetrievedByIdShouldHaveProperHandle() @Test public void readAllShouldRetrieveAtLeastOneProductFamily() { - Assert.assertTrue( "At least one product family should exist", - chargify.findAllProductFamilies().collectList().block().size() > 0 ); + Assert.assertFalse( "At least one product family should exist", chargify.findAllProductFamilies().collectList().block().isEmpty() ); } @Test public void readNonExistingShouldReturnEmptyOptional() { - final ProductFamily productFamily = chargify.findProductFamilyById( "nonexisting" ).block(); + final ProductFamily productFamily = chargify.findProductFamilyById( "nonexistent" ).block(); Assert.assertNull( "Non existing product family found", productFamily ); } @@ -58,7 +57,7 @@ public void readNonExistingShouldReturnEmptyOptional() @Test public void archiveNonExistingShouldReturnEmptyOptional() { - final ProductFamily archivedProductFamily = chargify.archiveProductFamilyById( "nonexisting" ).block(); + final ProductFamily archivedProductFamily = chargify.archiveProductFamilyById( "nonexistent" ).block(); Assert.assertNull( "Non existing product family found", archivedProductFamily ); } diff --git a/src/test/java/com/chargify/ProductsTest.java b/src/test/java/com/chargify/ProductsTest.java index 6a61542..56522c0 100644 --- a/src/test/java/com/chargify/ProductsTest.java +++ b/src/test/java/com/chargify/ProductsTest.java @@ -49,7 +49,7 @@ public void productShouldBeFoundById() @Test public void productShouldNotBeFoundByInvalidId() { - final Product product = chargify.findProductById( "nonexisting" ).block(); + final Product product = chargify.findProductById( "nonexistent" ).block(); Assert.assertNull( "Product should not be found by invalid ID", product ); } @@ -75,7 +75,7 @@ public void readAllShouldRetrieveAtLeastOne() { final List products = chargify.findAllProducts().collectList().block(); - Assert.assertTrue( "At least one product should be present", products.size() > 0 ); + Assert.assertFalse( "At least one product should be present", products.isEmpty() ); } @Test @@ -83,20 +83,19 @@ public void readAllByFamilyIdShouldRetrieveAtLeastOne() { final List familyProducts = chargify.findProductsByProductFamilyId( productFamilyUnderTest.getId() ).collectList().block(); - Assert.assertTrue( "At least one product should be present in the family", - familyProducts.size() > 0 ); + Assert.assertFalse( "At least one product should be present in the family", familyProducts.isEmpty() ); } @Test public void readByNonExistingFamilyShouldReturnNull() { - Assert.assertNull( chargify.findProductFamilyById( "nonexisting" ).block() ); + Assert.assertNull( chargify.findProductFamilyById( "nonexistent" ).block() ); } @Test public void archiveNonExisting() { - final Product archivedProduct = chargify.archiveProductById( "nonexisting" ).block(); + final Product archivedProduct = chargify.archiveProductById( "nonexistent" ).block(); Assert.assertNull( "Non existing product has been archived", archivedProduct ); } diff --git a/src/test/java/com/chargify/SubscriptionsTest.java b/src/test/java/com/chargify/SubscriptionsTest.java index 9d05a9a..859a19d 100644 --- a/src/test/java/com/chargify/SubscriptionsTest.java +++ b/src/test/java/com/chargify/SubscriptionsTest.java @@ -15,9 +15,9 @@ import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; public class SubscriptionsTest extends ChargifyTest { @@ -78,7 +78,7 @@ public void subscriptionShouldBeFoundByValidId() } @Test - public void subscriptionShoudNotBeFoundByInvalidId() + public void subscriptionShouldNotBeFoundByInvalidId() { final Subscription subscription = chargify.findSubscriptionById( "invalid" ).block(); assertNull( "Subscription should not have been found", subscription ); @@ -88,14 +88,14 @@ public void subscriptionShoudNotBeFoundByInvalidId() public void customerShouldHaveAtLeastOneSubscription() { final List subscriptions = chargify.findSubscriptionsByCustomerId( customerUnderTest.getId() ).collectList().block(); - assertTrue( "No subscriptions found for customer", subscriptions.size() > 0 ); + assertFalse( "No subscriptions found for customer", subscriptions.isEmpty() ); } @Test public void findAllShouldReturnAtLeastOne() { final List subscriptions = chargify.findAllSubscriptions().collectList().block(); - assertTrue( "No subscriptions found", subscriptions.size() > 0 ); + assertFalse( "No subscriptions found", subscriptions.isEmpty() ); } @Test From 54f9d8eaa19c076c6c4e0d0c087e092c7e16073b Mon Sep 17 00:00:00 2001 From: "vladimir.yalovy" Date: Thu, 7 Dec 2023 10:35:42 +0200 Subject: [PATCH 58/58] [BKNDLSS-34230]: Add findCustomers method --- pom.xml | 2 +- src/main/java/com/chargify/Chargify.java | 8 ++++++++ src/main/java/com/chargify/ChargifyService.java | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4596ae4..795d3d7 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.chargify chargify-sdk - 0.43 + 0.44 jar Chargify SDK for Java diff --git a/src/main/java/com/chargify/Chargify.java b/src/main/java/com/chargify/Chargify.java index 99bd6cd..d7f757c 100644 --- a/src/main/java/com/chargify/Chargify.java +++ b/src/main/java/com/chargify/Chargify.java @@ -141,8 +141,16 @@ Flux findSubscriptionStatements( */ Flux findCustomersBy( Object criterion, int pageNumber ); + /** + * The first page of results is displayed + * Default value for per_page is 50 + * For page settings and how many records to fetch in each request (perPage), use + * {@link #findCustomers(int pageNumber, int perPage )} + */ Flux findAllCustomers(); + Flux findCustomers( int pageNumber, int perPage ); + Mono deleteCustomerById( String id ); Mono validateReferralCode( String code ); diff --git a/src/main/java/com/chargify/ChargifyService.java b/src/main/java/com/chargify/ChargifyService.java index eef8feb..d4f971c 100644 --- a/src/main/java/com/chargify/ChargifyService.java +++ b/src/main/java/com/chargify/ChargifyService.java @@ -761,6 +761,15 @@ public Flux findAllCustomers() .map( CustomerWrapper::getCustomer ); } + @Override + public Flux findCustomers( int pageNumber, int perPage ) + { + return ChargifyResponseErrorHandler.handleError( + client.get().uri( "/customers.json?page={pageNumber}&per_page={perPage}", pageNumber, perPage ).retrieve() ) + .bodyToFlux( CustomerWrapper.class ) + .map( CustomerWrapper::getCustomer ); + } + @Override public Mono deleteCustomerById( String id ) {