Search code examples
braintree

Re-use a plan ID multiple times for different price models


I'm working on a software-tool with payable features. I'm planning to use braintree to handle the payment part but at the moment it's only possible to create plans using the web UI.

Since the prices of my features vary depending on the country, I was thinking that I could simply create a plan xyzd and associate that with a feature:

INSERT INTO tool_feature (billing_plan_id, name) VALUES ('xyzd', 'Basic feature');

SET @basicFeatureId = 1;

and for another table which defines the prices for each country I'd have:

SET @germany = 1;
SET @italy= 2;

INSERT INTO tool_feature_billing_plan 
    (country_id, tool_feature_id, price) 
VALUES 
    (@germany, @basicFeatureId, 9.9); -- € 9.90 in Germany

INSERT INTO tool_feature_billing_plan 
    (country_id, tool_feature_id, price) 
VALUES 
    (@italy, @basicFeatureId, 19.9);  -- € 19.90 in Italy

This would allow me to do something like

Long countryId = countryRepository.getCountryIdByAlpha2Code("de");
Float price = toolFeatureBillingPlanRepository.getPriceForCountry(countryId);

SubscriptionRequest request = new SubscriptionRequest()
    .id("new_id")
    .paymentMethodToken(paymentMethodToken)
    .price(new BigDecimal("" + price ))     // The price fetched from the database
    .planId(planId)
    .merchantAccountId(merchantAccountId);

Result<Subscription> result = gateway.subscription().update(
  subscriptionId,
  request
);

It seems that I can do that but the question is if it's a good idea to use a Plan/Subscription in such a way.

The main reason why I want to do that is because I don't want to create for all countries a plan and get all those IDs into my database etc.

This way I'd have one plan only for each feature and the rest would be handled on my side.


Solution

  • Full disclosure: I work at Braintree. If you have any further questions, feel free to contact support.

    The method you outlined above is correct and is a proper way of setting up Subscriptions with differing prices.