#ykuro
1 messages · Page 1 of 1 (latest)
Hi there, user can only enter a promo code in a checkout page.
Yes,
On the payment page, when the user enters the promo code (in this case ’NAVI2023') I want to update an existing subscription (sub_1MdmiKKhZM6vApyYo6sPOZPb).
I was able to get the promo info on the front end, but I don't know how to set this up and update the subscription.
Ideally I would like to show the updated price from the price I am showing now.
I assume this promo code is tied to a coupon called Moribus Navi, so I imagine I can get 20% off the price.
Are you using Stripe Checkout? (https://stripe.com/docs/payments/checkout) Because the screenshot doesn't look like a checkout page to me
No, I am using Stripe Elements and using the following sample demo.
https://github.com/stripe-samples/subscription-use-cases
Stripe Element doesn't support promo code I'm afraid
Im expanding it based on this demo.
Can't we use elements to get a discount on prices?
No. You can only update the subscription from backend and apply a coupon (https://stripe.com/docs/api/subscriptions/update#update_subscription-coupon) or promo_code (https://stripe.com/docs/api/subscriptions/update#update_subscription-promotion_code)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Yes, could you tell me how to apply and update coupons from the back end using element? Is there like a sample code or something.
I don't understand what you mean by update coupons from the back end using element
Element is frontend, not backend.
Oh sorry. Could you tell me how to apply and update coupons from the back end ?
Sure, you can open the link that I've shared earlier. If you are using node.js, the code will be something like
'sub_1M7DIyKmcV1mkkRSb5h9B4gr',
{coupon: 'COUPON_ID'}
);```
BTW This is the API that you can call to create a coupon (https://stripe.com/docs/api/coupons/create?lang=node#create_coupon)
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
I have already created coupon(name is Moribus Navi) and promo code(NAVI2023). I am now tied to them. I want to renew an existing subscription when the user enters "NAVI2023". Im using Java in back end.
Is there any sample code that matches this case?
btw for reference, It may not be relevant, but there was a method called update-subscription in the sample demo.
post( "/update-subscription", (request, response) -> { response.type("application/json"); // Set the default payment method on the customer UpdateSubscriptionRequest postBody = gson.fromJson( request.body(), UpdateSubscriptionRequest.class ); // The ID of the price the subscription will be upgraded or downgraded to. String newPriceId = dotenv.get(postBody.getNewPriceLookupKey().toUpperCase()); // Retrieve the subscription to access related subscription item ID // to update. Subscription subscription = Subscription.retrieve( postBody.getSubscriptionId() ); // Build params to update the Subscription. SubscriptionUpdateParams params = SubscriptionUpdateParams .builder() .addItem( SubscriptionUpdateParams .Item.builder() .setId(subscription.getItems().getData().get(0).getId()) .setPrice(newPriceId) .build() ) .setCancelAtPeriodEnd(false) .build(); // update the subscription. subscription.update(params); Map<String, Object> responseData = new HashMap<>(); responseData.put("subscription", subscription); return StripeObject.PRETTY_PRINT_GSON.toJson(responseData); } );