Skip to content

Commit

Permalink
Update s2 Vars parser for ClickBank IPN v6. See: wpsharks/s2member#256
Browse files Browse the repository at this point in the history
  • Loading branch information
JasWSInc committed Oct 2, 2014
1 parent dd0aa67 commit f9c8cd6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function clickbank_notify()
$clickbank['s2member_log'][] = 'IPN received on: '.date('D M j, Y g:i:s a T');
$clickbank['s2member_log'][] = 's2Member POST vars verified with ClickBank.';

$s2vars = c_ws_plugin__s2member_pro_clickbank_utilities::clickbank_parse_s2vars($clickbank['cvendthru'], $clickbank['ctransaction']);
$s2vars = c_ws_plugin__s2member_pro_clickbank_utilities::clickbank_parse_s2vars_v2_1($clickbank['cvendthru'], $clickbank['ctransaction']);

if(isset ($s2vars['s2_p1'], $s2vars['s2_p3']) && $s2vars['s2_p1'] === '0 D') // No Trial defaults to Regular Period.
$s2vars['s2_p1'] = $s2vars['s2_p3']; // Initial Period. No Trial defaults to Regular Period.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function clickbank_return()

if(!empty($_GET['s2member_pro_clickbank_return']) && $GLOBALS['WS_PLUGIN__']['s2member']['o']['pro_clickbank_username'])
{
if(is_array($clickbank = c_ws_plugin__s2member_pro_clickbank_utilities::clickbank_postvars()) && ($_clickbank = $clickbank))
if(is_array($clickbank = c_ws_plugin__s2member_pro_clickbank_utilities::clickbank_postvars_v2_1()) && ($_clickbank = $clickbank))
{
$clickbank['s2member_log'][] = 'Return-Data received on: '.date('D M j, Y g:i:s a T');
$clickbank['s2member_log'][] = 's2Member POST vars verified with ClickBank.';
Expand All @@ -77,7 +77,7 @@ public static function clickbank_return()

$clickbank['s2member_log'][] = 'Order API variables have been obtained from ClickBank.';

$s2vars = c_ws_plugin__s2member_pro_clickbank_utilities::clickbank_parse_s2vars(http_build_query($clickbank, NULL, '&'), $order['txnType']);
$s2vars = c_ws_plugin__s2member_pro_clickbank_utilities::clickbank_parse_s2vars_v2_1(http_build_query($clickbank, NULL, '&'), $order['txnType']);

if(!empty($s2vars['s2_p1']) && !empty($s2vars['s2_p3']) && $s2vars['s2_p1'] === '0 D')
// Initial Period. No Trial defaults to Regular Period.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ public static function clickbank_postvars_v2_1()
return FALSE;
}

/**
* Parses s2Vars passed through by ClickBank.
*
* @package s2Member\ClickBank
* @since 111205
*
* @param string $query Expects the URL-encoded query string of s2Vars located in the `downloadUrl` property, including `_s2member_sig`.
* @param string $type Optional. The type of ClickBank transaction. This deals with backward compatibility.
* For SALE transactions, do NOT accept the older format. For others, remain backward compatible.
*
* @return array Array of s2Vars. Possibly an empty array.
*/
public static function clickbank_parse_s2vars($query = '', $type = '')
{
if(strpos($query, '?') !== FALSE) // A full URL or URI?
$query = ltrim((string)strstr($query, '?'), '?');

wp_parse_str((string)$query, $s2vars);
$s2vars = c_ws_plugin__s2member_utils_strings::trim_deep($s2vars);

foreach($s2vars as $var => $value /* Pulls out `s2_|_s2member_sig` vars. */)
if(!in_array($var, array('cbskin', 'cbfid', 'cbur', 'cbf', 'tid', 'vtid'), TRUE)) // These may be included in a signature too.
if(!preg_match('/^(?:s2_|_s2member_sig)/', $var)) // These will always be included in a signature.
unset($s2vars[$var]);

$is_sale = preg_match('/^(?:TEST_)?SALE$/i', (string)$type);
if(!$is_sale || c_ws_plugin__s2member_utils_urls::s2member_sig_ok(http_build_query($s2vars, NULL, '&')))
return $s2vars; // Looks good. Return ``$s2vars``.

return array(); // Default empty array.
}

/**
* Parses s2Vars passed through by ClickBank.
*
Expand All @@ -152,7 +184,7 @@ public static function clickbank_postvars_v2_1()
*
* @return array Array of s2Vars. Possibly an empty array.
*/
public static function clickbank_parse_s2vars($cvendthru = '', $type = '')
public static function clickbank_parse_s2vars_v2_1($cvendthru = '', $type = '')
{
wp_parse_str((string)$cvendthru, $s2vars);
$s2vars = c_ws_plugin__s2member_utils_strings::trim_deep($s2vars);
Expand Down

0 comments on commit f9c8cd6

Please sign in to comment.