From 383c31eeb1482f8882416a06e42565a234be606c Mon Sep 17 00:00:00 2001 From: Osiris Team Date: Wed, 11 Jan 2023 00:55:58 +0100 Subject: [PATCH] fix stripe price not being able to update --- src/main/java/com/osiris/payhook/PayHook.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/osiris/payhook/PayHook.java b/src/main/java/com/osiris/payhook/PayHook.java index ac28384..f3a8d9d 100644 --- a/src/main/java/com/osiris/payhook/PayHook.java +++ b/src/main/java/com/osiris/payhook/PayHook.java @@ -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 params = new HashMap<>(); + params.put("active", false); + oldPrice.update(params); + // Activate/Create new + com.stripe.model.Price.create(converter.toStripePrice(newProduct)); + } } Product.update(product);