Created
June 18, 2011 01:00
-
-
Save sproutventure/1032689 to your computer and use it in GitHub Desktop.
WP Affiliate + GBS +Payfast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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