Skip to content

Instantly share code, notes, and snippets.

@dancameron
Forked from sproutventure/gist:1032689
Created March 21, 2012 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancameron/2148648 to your computer and use it in GitHub Desktop.
Save dancameron/2148648 to your computer and use it in GitHub Desktop.
GBS: WP Affiliate + GBS +Payfast
<?php
add_filter( 'purchase_record_array', 'affiliate_post');
function affiliate_post( $record_array ) {
// Config
$post_url = "http://www.youdeal.co.za/wp-content/plugins/wp-affiliate-platform/api/post.php";
$key = "ijweol383h538t34t9j";
if ( isset($_COOKIE['ap_id'])) {
$app_id = $_COOKIE['ap_id'];
} else {
$response_detail = $record_array['response_detail'];
$app_id = $response_detail['custom_str5'];
}
// Prepare the data
$data = array ();
$data['secret'] = $key;
$data['ap_id'] = $app_id;
$data['sale_amt'] = $record_array['total'];
$data['txn_id'] = $record_array['transID'];
$data['item_id'] = $record_array['postID'];
$response = wp_remote_post( $post_url, array(
'method' => 'POST',
'body' => $data,
'timeout' => 15,
'sslverify' => false
));
$response = wp_parse_args(wp_remote_retrieve_body($response));
// might as well create a record since we got a response
$record_array['wpAffiliate'] = TRUE;
// always return the record_array, otherwise the sky will fall.
return $record_array;
}
add_filter( 'payfastCheckoutUrl', 'payfastCheckoutUrl_WPAffiliate');
/**
* Add the app_id to the custom string of payfast
*/
function payfastCheckoutUrl_WPAffiliate( $payfast_url ) { // Add the app_id to payfast
return add_query_arg (
array(
'custom_str5' => $_COOKIE['ap_id'],
),
$payfast_url );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment