Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Paid Links - detecting and expiring

Quote Reply
Paid Links - detecting and expiring
Implementing payments in 2.21 for the first time.

I've been doing a lot of reading about paid links and I'm hoping that my research skills are useless because I'm not too encouraged by my results on a couple of queries. So I have to check my understanding here.

1) How to tell if a link is paid or not.
I've seen ways to tell if its free, if its expired, but I can't see an easy way while looping through links to detect if one is paid and therefore do things like display fields or not based on that. Surely there is some simple piece of synyax to do that?

2) What happens when paid links don't get renewed
I've seen several references that suggest that a paid link becomes "expired" rather than free if the renewal payment isn't made. In a directory with optional paid links that just seems too crazy to be the case. Please tell me it's not .... or at least how to display expired links as free :)

Thanks

Stewart
Quote Reply
Re: [CrazyGuy] Paid Links - detecting and expiring In reply to
1) In Gossamer Links 3.x, you can use the tag isPaidLink and isFreeLink (added in 3.0.4). However, since those tags don't exist in Links SQL 2.x, you'll have to write a global to check. Something like this should do it:
Code:
sub {
my $expiry = shift;
if ($expiry > UNPAID and $expiry < FREE) {
return 1;
}
return 0;
}

2) Once paid links expire, they don't show up in the directory. Unfortunately, to change this behaviour, you'll have to change the code (most of the SQL queries have a where clause ExpiryDate > time, so you'll have to remove it). This is on our todo list to improve upon this in a future release.

Adrian
Quote Reply
Re: [brewt] Paid Links - detecting and expiring In reply to
Thinking about 2) some more, it actually shouldn't be too much of a change to display expired links in the category listings (ie. just the category listing, not search, etc). If you open up Links/Build.pm, around line 624 (659 in 3.0.4), you'll see:
Code:
if ($payment_info->{mode} == OPTIONAL) {
...
$cond->add(ExpiryDate => '=' => FREE);
If you remove that last line and change it to something like:
Code:
my $pcond = GT::SQL::Condition->new(
ExpiryDate => '=' => FREE,
GT::SQL::Condition->new(
ExpiryDate => '>' => UNPAID,
ExpiryDate => '<' => time
)
);
$pcond->bool('or');
$cond->add($pcond);
That way if payments in that category are optional, it will show free links OR links which have expired, but aren't unpaid.

Adrian
Quote Reply
Re: [brewt] Paid Links - detecting and expiring In reply to
Thankyou very much Adrian - it's at least some consolation to get confirmation that I hadn't badly misunderstood things :)

Those look like workable fixes, I'll give them a try and report back.

I know I probably should upgrade to 3 but have so much time and effort invested into making 2 look and work the way I want that I feel the risk of upgrade is very high. At some point I guess the thing to do will be to try and recreate a parallel site under 3 and then switch. But that reminds me (I'd almost forgot about this) - when I looked at 3 a while ago, the whole licence check/auto upgrade scenario (can't remember the details now of how it works) gave me the heebie jeebies. Call me a control freak, but I do like to be in complete control of my own installations and can't live with the idea that an important site might stop working because some hook into someone else's system misbehaves.

Stewart
Quote Reply
Re: [CrazyGuy] Paid Links - detecting and expiring In reply to
Ha!

I chose my nickname because this stuff drives me crazy Crazy

Implementing 1) above:

Created global called isEnhanced (my paid links will be "enhanced") and created 2 test links, 1 with an expiry date a year away, the other as payment not required.

If I put in the template:
<%isEnhanced($ExpiryDate)%>, it does display 1 or 0 as I would expect.

However, if I put in the template:
<% if isEnhanced($ExpiryDate) eq '1' %>enhanced<%else%>standard<%endif%>
both links display "enhanced"
this remains the case if I try
eq "1"
=1

I also modified the global to output yes or no - again, this does display the correct result with the just the <%isEnhanced($ExpiryDate)%> tag, but I can't make it work with a conditional eq 'yes' or eq "yes".

I guess I'm doing something stupid with the testing of the condition but I can't find another example of testing the output of a global with a passed parameter to compare with and I'm sure I'm now going round in circles repeating the same errors.
Quote Reply
Re: [CrazyGuy] Paid Links - detecting and expiring In reply to
Try changing

<% if isEnhanced($ExpiryDate) eq '1' %>

to

<%set temp=isEnhanced($ExpiryDate)%>
<%if temp eq '1' %>
Quote Reply
Re: [afinlr] Paid Links - detecting and expiring In reply to
Tada !

Thanks Thanks Thanks

I've passed parameters to globals before, and I've done conditionals before - but I guess I've never combined the two (or something) as I've never had to do this 2-step before.

... and I don't think I'd ever have guessed it.

Did I say thanks?

Stewart
Quote Reply
Re: [CrazyGuy] Paid Links - detecting and expiring In reply to
Fun and games, fun and games ...

Solution 1 working

Solution 2 working (it doesn't display links that have asked for paid status but haven't actually been paid for yet but that's not too much of a problem)

Then I set a link with a past expiry date to test Solution 2 ... works fine.
But - Solution 1 still thinks its "enhanced" so it still gets the bonuses.

I *think* this is because ...

if ($expiry > UNPAID and $expiry < FREE)

... is saying "if the expiry date for this link is greater than -1 (which I think I read somewhere is the value of the UNPAID flag) and less than some massive number (that FREE is set to) then it's a paid link".

But of course that is also true of an expired link isn't it?

So I changed that line to be:

if ($expiry > UNPAID and $expiry > time() and $expiry < FREE)

It seems to be working - I need to load up a wider variety of test links to be sure, but hopefully this has become a way to test for links that are paid up to date. Unless someone can see a hole my logic.
Quote Reply
Re: [CrazyGuy] Paid Links - detecting and expiring In reply to
In Reply To:
Solution 2 working (it doesn't display links that have asked for paid status but haven't actually been paid for yet but that's not too much of a problem)
That's an easy change, just remove the requirement that the link is paid:
Code:
my $pcond = GT::SQL::Condition->new(
ExpiryDate => '=' => FREE,
ExpiryDate => '<' => time
);
$pcond->bool('or');
$cond->add($pcond);

Adrian