Closed KatieP closed 11 years ago
<?php
//Bill clients weekly based on thier click throughs from posts
$date_1weekago = date() - 604800; $date2_now = date();
//The advertiser to who creates a post, get all their posts in an array
$author = ;
for the $author
get all post name by $author
//Get the total clicks for the posts for the last 7 days
between $date2_now and $date_1weekago
return google analytics for the outbound clicks for all the posts for the author
add the clicks together, return a total
$post_click_sum = ;
//Link the author ID to the chargify client ID
$author_as_advertiser = ;
//Check what cap plan they are on
$cap = ;
//Work out sum to bill client as clicks x CPC
$weekly_clicks = $post_click_sum;
//Check is under cap
if $weekly_clicks < $cap {
return $weekly_clicks as $quantity;
} elseif $weekly_clicks > $cap {
return $cap return $quantity;
}
//We only send the amount of clicks to chargify. It does the billing.
//Variables for chargify
$subscription_id = ;
$component_id = ;
//Send a post request with Json data to this URL
$url = 'https://greenpages.chargify.com/subscriptions/' . $subscription_id . '/components/' . $component_id . '/usages.json';
curl -v -H "Content-Type: application/json" -X POST -d ' "usage":{ "id": $subscription_id, "quantity":$quantity }' $url
Feature: Chargify Metered Component Usage JSON API In order integrate my app with Chargify As a developer I want to record metered usage for a subscription
Background: Given I am a valid API user And I send and accept json
Scenario: Record metered usage Given I have 1 product And the product family has a metered component And I have an active subscription to the first product And I have this json usage data """ { "usage":{ "quantity":5, "memo":"My memo" } } """ When I send a POST request with the json data to https://[@subdomain].chargify.com/subscriptions/[@subscription.id]/components/[@component.id]/usages.json Then the response status should be "200 OK" And the response should be the json: """ { "usage":{ "id":@auto generated@, "quantity":5, "memo":"My memo" } } """ And a usage will have been recorded
?>
'INSERT INTO wp_usermeta SET meta_key="advertiser_status", meta_value="active", user_id = "2"'
'INSERT INTO wp_usermeta
SET meta_key="productID", meta_value="27023", user_id = "2"'
'INSERT INTO wp_usermeta
SET meta_key="chargifyID", meta_value="27023", user_id = "2"'
Done.
Hook google analytics into chargify cost per click for clients and charge clients weekly.