TinyPass Developer's Resources

Scheduled/Windowed Pricing

In this example, a publisher wants to offer discounted prices until a certain date and then return to the original price levels. Here are the discounted prices for the next 3 days:

  • $0.03 per 24 hour access
  • $0.06 per 72 hour access
  • $0.30 per 30 day access

//provide a startDate and endDate (in seconds the Unix Epoch (January 1 1970 00:00:00 GMT)
$startDate = time();
$endDate = time() + 60 * 60 * 24 * 3;
 
//Create 3 discounted price options, which will expire on the endDate
$poNew1 = new TPPriceOption("0.03", "24 hours", $startDate, $endDate);
$poNew2 = new TPPriceOption("0.06", "72 hours", $startDate, $endDate);
$poNew3 = new TPPriceOption("0.30", "30 days", $startDate, $endDate);
$offer = new TPOffer($resource, $poNew1, $poNew2, $poNew3);
 
//Create 3 regular price option price options which will become active on endDate
$po1 = new TPPriceOption("0.05", "24 hours", $endDate);
$po2 = new TPPriceOption("0.10", "72 hours", $endDate);
$po3 = new TPPriceOption("0.50", "30 days", $endDate);
 
$offer->addPriceOptions($po1, $po2, $po3);
 
...

// Calculate the date/time in seconds when the prices change (in 3 days)
int startDateSecs = (int) (System.currentTimeMillis() / 1000L);
int datePriceChangeSecs = startDate + 60 * 60 * 24 * 3;
 
//Create 3 discounted price options, which will expire on the endDate
PriceOption poNew1 = new PriceOption("0.03", "24 hours", startDateSecs, datePriceChangeSecs);
PriceOption poNew2 = new PriceOption("0.06", "72 hours", startDateSecs, datePriceChangeSecs);
PriceOption poNew3 = new PriceOption("0.30", "30 days", startDateSecs, datePriceChangeSecs);
Offer offer = new Offer(resource, poNew1, poNew2, poNew3);
 
//Create 3 regular price option price options which will become active on datePriceChangeSecs
PriceOption po1 = new PriceOption("0.05", "24 hours", datePriceChangeSecs);
PriceOption po2 = new PriceOption("0.10", "72 hours", datePriceChangeSecs);
PriceOption po3 = new PriceOption("0.50", "30 days", datePriceChangeSecs);
offer.addPriceOptions(po1, po2, po3);
 
...

//get milliseconds from the date, which will be the date when discounted price options become active
var Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var startDateSecs = (DateTime.UtcNow - Jan1st1970).TotalSeconds;
var datePriceChangeSecs = startDate + 60 * 60 * 24 * 3;
 
//Create 3 discounted price options, which will expire on the datePriceChangeSecs
var poNew1 = new PriceOption("0.03", "24 hours", startDateSecs, datePriceChangeSecs );
var poNew2 = new PriceOption("0.06", "72 hours", startDateSecs, datePriceChangeSecs );
var poNew3 = new PriceOption("0.30", "30 days", startDateSecs, datePriceChangeSecs );
offer.AddPriceOptions(poNew1, poNew2, poNew3);
 
//Create 3 regular price option price options which will become active on datePriceChangeSecs
var po1 = new PriceOption("0.05", "24 hours", datePriceChangeSecs );
var po2 = new PriceOption("0.10", "72 hours", datePriceChangeSecs );
var po3 = new PriceOption("0.50", "30 days", datePriceChangeSecs );
offer.AddPriceOptions(po1, po2, po3);
 
...

# provide a startDate and endDate (in seconds the Unix Epoch (January 1 1970 00:00:00 GMT)
start_date_in_secs = Time.now
end_date_in_secs = Time.now + 60 * 60 * 24 * 3
 
# Create 3 discounted price options, which will expire on the endDate
price_option1 = Tinypass::PriceOption.new('0.03', '24 hours', start_date_in_secs, end_date_in_secs)
price_option2 = Tinypass::PriceOption.new('0.06', '72 hours', start_date_in_secs, end_date_in_secs)
price_option3 = Tinypass::PriceOption.new('0.30', '30 days', start_date_in_secs, end_date_in_secs)
offer = Tinypass::Offer.new(resource, price_option1, price_option2, price_option3)
 
# Create 3 regular price option price options which will become active on endDate
price_option1 = Tinypass::PriceOption.new('0.03', '24 hours', end_date_in_secs)
price_option2 = Tinypass::PriceOption.new('0.06', '72 hours', end_date_in_secs)
price_option3 = Tinypass::PriceOption.new('0.30', '30 days', end_date_in_secs)
offer = Tinypass::Offer.new(resource, price_option1, price_option2, price_option3)
 
...