验证免费增值产品中的订阅服务是否有效的方法

发布于 2024-07-11 18:38:51 字数 282 浏览 8 评论 0原文

我们有一个免费增值产品,这意味着如果按月付费就可以使用某些功能; 如果未付费,则免费功能仍然可用。

以下是我正在考虑的处理方式,但想检查一下:

1)当有人购买订阅时,会创建一个定期计费计划。

2) 用户将有一个字段 (paid_up) 设置为“y”

3) 当用户重新登录时,身份验证脚本检查paid_up 是否为“y”。 如果是,它会创建一个会话令牌

4)我想我需要一个批处理脚本来切换切换。 想知道如何做吗? 存储上次成功处理信用卡的日期?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

柠栀 2024-07-18 18:38:51

当然,您将创建一个名为“last_ payment”的列。 如果使用 MySQL,您可以将其创建为日期字段。 每次您收到每月付款时,我假设信用卡计费公司都会将一些内容发布到您网站上的脚本中。 (即 paypal 发送 IPN)。 每次收到此消息时,您都会执行一个查询,例如:

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

我建议在 CRON 上运行一个每 24 小时运行一次的脚本,并执行此查询:

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

这将更新 30 天或更长时间未付款的所有记录,并将 pay_up 字段设置为 N。然后您的正常登录代码就可以工作了。

如果您不想使用 CRON,您可以将您的登录查询更改为如下所示:

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

顺便说一句,您的信用卡处理公司可能有一种在取消订阅时向您发送 POST 的方法,这将使您能够将 pay_up 字段设置为 N。

希望这会有所帮助。 如果您有任何疑问,请随时发表评论:)

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 :)

初与友歌 2024-07-18 18:38:51

我将从另一端进行此操作,并有一个付费字段,其中存储了付费更新日期。 这样,您就可以让用户取消该子项目,但仍然可以享受他们所付款项的好处。

I'd work this from the other end and have a paid-to field with a paid up date stored there. That way you could have users cancel there sub and still get the benefit of the payment they did make.

樱娆 2024-07-18 18:38:51

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

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

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

If the recurring billing process is something you run on your side, you can include these checks as part of your process. The way I would think about this algorithmically is something like:

For each customer that's due
    Run billing on their account
    If successful:
        Reset retries to 0
        Mark them as a paid customer
        Continue to the next account
    Otherwise:
        Increment their retry counter
        Send an alert to the customer
        If their retry counter reaches a maximum:
            
Toggle the switch to mark them as free

You can do the same in batch if something else runs the billing and just tells you the results, just replace "Run billing on their account" with "Read results from last billing attempt". Your retry counter would implement something like a grace period, assuming your billing runs on a daily schedule, so they'd have a chance to fix the billing problem rather than just having their premium features revoked just because their card expired or some such.

情绪 2024-07-18 18:38:51

之前已经写过其中一些内容,您应该做一些事情。

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

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

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

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

我认为这涵盖了大部分重要内容,但计费系统中总是存在一些需要注意的小问题。

Having written a few of these before, there's a couple of things you should do.

First, as mentioned by others, you want some kind of paid_through_date field. This is important for a number of reasons, but the main one is that it gives you additional flexibility in case of, say, your servers going down, and you decide users should be credited with an additional day of free service. Just push back their paid_through_date value by a day. This also makes free trials simple to implement.

Second, don't use stuff like Authorize.net's Automated Recurring Billing, even if you're working on a subscription system. You want to be in full control over when the payment gets scheduled, and offloading that responsibility to your gateway is just a bad idea in most cases. Most gateways will allow you to store a credit card on their servers. They'll give you back an ID for that card, and you can issue charges against that intermediate ID instead of the card itself.

Third, LOG ALL TRANSACTIONS. I can't overemphasize this enough. In fact, you should probably expose this log to the user as well. Basically just a table of all of the payments they've made, the amounts, and the final balance. It's common to put invoices into this table as well. Invoices have a positive amount, payments and credits have a negative amount, and just sum everything for the user to obtain the final balance. You can introduce arbitrary credits to this table very easily if so desired.

Run a cron script that fires every 24 hours that checks what users need to have an invoice generated. This cron script should have three critical properties: First, if it doesn't run for some reason, you shouldn't lose a day's worth of charges. Second, if it runs more than once in a day, or if it gets aborted mid-way through and rerun, it shouldn't charge people twice. And third, if the date on the server gets changed to 2090 by accident, it shouldn't automatically bill all of your users for millions of dollars. Similarly, resets to dates in the past (Notably, Jan 1, 1970) should also cause it to raise hell. Daylight savings, in my experience, is rarely an issue.

I think that covers most of the big stuff, but there are always little gotchas in billing systems that you have to watch out for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文