针对不同的价格模型多次重复使用计划 ID
Re-use a plan ID multiple times for different price models
我正在开发具有付费功能的软件工具。我打算使用 braintree 来处理付款部分,但目前只能使用网络创建计划 UI.
由于我的功能价格因国家/地区而异,我想我可以简单地创建一个计划 xyzd
并将其与功能相关联:
INSERT INTO tool_feature (billing_plan_id, name) VALUES ('xyzd', 'Basic feature');
SET @basicFeatureId = 1;
另一个 table 定义了每个国家/地区的价格:
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
);
看来我可以做到,但问题是这样使用 Plan
/Subscription
是否是个好主意。
我想要这样做的主要原因是因为我不想为所有国家/地区创建一个计划并将所有这些 ID 放入我的数据库等。
这样我就可以为每个功能制定一个计划,其余的将由我处理。
完全披露:我在 Braintree 工作。如果您有任何其他问题,请随时联系 support.
您上面概述的方法是正确的,是设置 Subscriptions
不同价格的正确方法。
我正在开发具有付费功能的软件工具。我打算使用 braintree 来处理付款部分,但目前只能使用网络创建计划 UI.
由于我的功能价格因国家/地区而异,我想我可以简单地创建一个计划 xyzd
并将其与功能相关联:
INSERT INTO tool_feature (billing_plan_id, name) VALUES ('xyzd', 'Basic feature');
SET @basicFeatureId = 1;
另一个 table 定义了每个国家/地区的价格:
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
);
看来我可以做到,但问题是这样使用 Plan
/Subscription
是否是个好主意。
我想要这样做的主要原因是因为我不想为所有国家/地区创建一个计划并将所有这些 ID 放入我的数据库等。
这样我就可以为每个功能制定一个计划,其余的将由我处理。
完全披露:我在 Braintree 工作。如果您有任何其他问题,请随时联系 support.
您上面概述的方法是正确的,是设置 Subscriptions
不同价格的正确方法。