2

We have a freemium product, which menas that some functionality is available if the monthly subscription has been paid; if not paid, then the free capabilities remain available.

Here is how I am thinking of processing it, but wanted to check:

1) When someone purchased their subscription, a recurring billing schedule is created.

2) The user will have a field (paid_up) set to "y"

3) When the user logs back in, the authentication script checks if paid_up is "y". If it is, it creates a session token

4) I think I need a batch script which will switch the toggle. Wondering how to do it? Store the date of the last credit card successfully processed?

4

4 回答 4

0

Sure, you would create a column called 'last_payment'. If using MySQL, you could create this as a DATE field. Each tme you receive a monthly payment, I'm assuming the credit card billing company would post something to a script on your website. (i.e paypal sends IPNs). Each time this is received, you would do a query such as:

UPDATE members SET `last_payment`=CURDATE() WHERE user_id='$user_id';

I would suggest running a script on CRON that runs once every 24 hours, and does this query:

UPDATE members SET paid_up='N' WHERE DATEDIFF(CURDATE(),last_payment) > '30';

This would update all the records where payment hasnt been made for 30 days or more, and set the paid_up field to N. Then your normal login code would work.

If you don't want to use CRON, you could change your login query to something like this:

SELECT 1 FROM members WHERE 
username='$user' AND password='$password'
AND DATEDIFF(last_payment) <= '30';

By the way, your credit card processing company might have a way of sending you a POST when a subscription is canceled, which would enable you to set the paid_up field to N.

Hope this helps. Feel free to comment if you have any questions :)

于 2008-12-30T21:43:55.750 回答
0

之前写过其中的一些,你应该做几件事。

首先,正如其他人所提到的,您需要某种paid_through_date 字段。出于多种原因,这很重要,但最主要的原因是它为您提供了额外的灵活性,以防万一,例如,您的服务器出现故障,并且您决定用户应该获得额外一天的免费服务。只需将他们的paid_through_date 值推后一天。这也使免费试用易于实施。

其次,即使您正在使用订阅系统,也不要使用 Authorize.net 的自动定期计费之类的东西。您希望完全控制何时安排付款,而在大多数情况下,将该责任转移给您的网关只是一个坏主意。大多数网关将允许您在其服务器上存储信用卡。他们会为您返还该卡的 ID,您可以针对该中间 ID 而不是卡本身开具费用。

第三,记录所有交易。我怎么强调都不过分。事实上,您可能也应该将此日志公开给用户。基本上只是一张他们已经支付的所有款项、金额和最终余额的表格。通常也将发票放入此表中。发票的金额为正数,付款和信用的金额为负数,用户只需将所有内容相加即可获得最终余额。如果需要,您可以非常轻松地将任意学分引入此表。

运行每 24 小时触发一次的 cron 脚本,检查用户需要哪些内容才能生成发票。这个 cron 脚本应该具有三个关键属性:首先,如果它由于某种原因没有运行,您不应该损失一天的费用。其次,如果它一天运行一次以上,或者它在中途中止并重新运行,它不应该向人们收取两次费用。第三,如果服务器上的日期意外更改为 2090,它不应该自动向所有用户收取数百万美元的费用。同样,重置为过去的日期(特别是 1970 年 1 月 1 日)也应该导致它引发地狱。根据我的经验,夏令时很少成为问题。

我认为这涵盖了大部分重要内容,但是您必须注意计费系统中的小问题。

于 2009-04-15T20:28:24.007 回答
0

我会从另一端开始工作,并有一个付费字段,其中存储了付费日期。这样,您可以让用户在那里取消订阅,但仍然可以从他们支付的款项中受益。

于 2008-12-30T22:23:04.813 回答
0

如果定期计费流程是您自己运行的,您可以将这些检查作为您流程的一部分。我在算法上考虑这个的方式是这样的:

对于每个到期的客户
    对其帐户运行计费
    如果成功:
        将重试次数重置为 0
        将他们标记为付费客户
        继续下一个帐户
    否则:
        增加他们的重试计数器
        向客户发送警报
        如果他们的重试计数器达到最大值:
             切换切换以将它们标记为免费

如果其他东西运行计费并告诉您结果,您可以批量执行相同操作,只需将“在他们的帐户上运行计费”替换为“读取上次计费尝试的结果”。您的重试计数器将实施类似于宽限期的东西,假设您的计费按每日计划运行,因此他们有机会解决计费问题,而不是仅仅因为他们的卡过期或诸如此类而撤销他们的高级功能。

于 2009-04-14T17:31:45.123 回答