我正在开发一个具有付费功能的软件工具。我计划使用 Braintree 来处理付款部分,但目前只能使用 Web UI 创建计划。
由于我的功能的价格因国家/地区而异,我想我可以简单地创建一个计划 xyzd
并将其与功能关联起来:
INSERT INTO tool_feature (billing_plan_id, name) VALUES ('xyzd', 'Basic feature');
SET @basicFeatureId = 1;
另一个表定义了我拥有的每个国家/地区的价格:
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
这将允许我做类似的事情
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
);
看来我可以做到这一点,但问题是以这种方式使用计划
/订阅
是否是一个好主意。
我想要这样做的主要原因是因为我不想为所有国家/地区创建一个计划并将所有这些 ID 放入我的数据库等。
这样我就可以为每个功能制定一个计划,其余的将由我来处理。
最佳答案
全面披露:我在 Braintree 工作。如果您还有任何疑问,请随时联系support .
您上面概述的方法是正确的,并且是设置不同价格的订阅
的正确方法。
关于braintree - 针对不同的价格模型多次重复使用计划 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38708923/