Skip to content

Commit

Permalink
fix stripe price not being able to update
Browse files Browse the repository at this point in the history
  • Loading branch information
Osiris-Team committed Jan 10, 2023
1 parent 9f3b28c commit 383c31e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/com/osiris/payhook/PayHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,18 @@ public static Product putProduct(int id, long charge,
if (Stripe.apiKey != null) {
com.stripe.model.Product stripeProduct = com.stripe.model.Product.retrieve(product.stripeProductId);
stripeProduct.update(converter.toStripeProduct(product));
com.stripe.model.Price stripePrice = com.stripe.model.Price.retrieve(product.stripePriceId);
stripePrice.update(converter.toStripePrice(product));
// Is there a price change?
if(newProduct.charge != product.charge){
// Sadly prices cannot be updated in stripe
// thus the old one must be deactivated first (can't delete it either)
com.stripe.model.Price oldPrice = com.stripe.model.Price.retrieve(product.stripePriceId);
// Deactivate old
Map<String, Object> params = new HashMap<>();
params.put("active", false);
oldPrice.update(params);
// Activate/Create new
com.stripe.model.Price.create(converter.toStripePrice(newProduct));
}
}

Product.update(product);
Expand Down

0 comments on commit 383c31e

Please sign in to comment.