#ykuro

1 messages · Page 1 of 1 (latest)

dim ermineBOT
young pollen
#

Hi there, user can only enter a promo code in a checkout page.

eternal moon
#

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.

young pollen
eternal moon
young pollen
#

Stripe Element doesn't support promo code I'm afraid

eternal moon
#

Im expanding it based on this demo.

#

Can't we use elements to get a discount on prices?

young pollen
eternal moon
#

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.

young pollen
#

I don't understand what you mean by update coupons from the back end using element

#

Element is frontend, not backend.

eternal moon
#

Oh sorry. Could you tell me how to apply and update coupons from the back end ?

young pollen
#

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)
eternal moon
#

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);
  }
);