Source Code Documentation


pro\s2member-pro\includes\classes\gateways\google\google-co-in.inc.php


  1. <?php
  2. /**
  3. * Google® Checkout (inner processing routines).
  4. *
  5. * Copyright: © 2009-2011
  6. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  7. * (coded in the USA)
  8. *
  9. * This WordPress® plugin (s2Member Pro) is comprised of two parts:
  10. *
  11. * o (1) Its PHP code is licensed under the GPL license, as is WordPress®.
  12. * You should have received a copy of the GNU General Public License,
  13. * along with this software. In the main directory, see: /licensing/
  14. * If not, see: {@link http://www.gnu.org/licenses/}.
  15. *
  16. * o (2) All other parts of (s2Member Pro); including, but not limited to:
  17. * the CSS code, some JavaScript code, images, and design;
  18. * are licensed according to the license purchased.
  19. * See: {@link http://www.s2member.com/prices/}
  20. *
  21. * Unless you have our prior written consent, you must NOT directly or indirectly license,
  22. * sub-license, sell, resell, or provide for free; part (2) of the s2Member Pro Module;
  23. * or make an offer to do any of these things. All of these things are strictly
  24. * prohibited with part (2) of the s2Member Pro Module.
  25. *
  26. * Your purchase of s2Member Pro includes free lifetime upgrades via s2Member.com
  27. * (i.e. new features, bug fixes, updates, improvements); along with full access
  28. * to our video tutorial library: {@link http://www.s2member.com/videos/}
  29. *
  30. * @package s2Member\Google
  31. * @since 1.5
  32. */
  33. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  34. exit("Do not access this file directly.");
  35.  
  36. if (!class_exists ("c_ws_plugin__s2member_pro_google_co_in"))
  37. {
  38. /**
  39. * Google® Checkout (inner processing routines).
  40. *
  41. * @package s2Member\Google
  42. * @since 1.5
  43. */
  44. class c_ws_plugin__s2member_pro_google_co_in
  45. {
  46. /**
  47. * Handles Google® XML Checkout redirections.
  48. *
  49. * @package s2Member\Google
  50. * @since 1.5
  51. *
  52. * @attaches-to ``add_action("init");``
  53. *
  54. * @return null Or exits script execution after redirection to Google® Checkout.
  55. */
  56. public static function google_co ()
  57. {
  58. global /* For Multisite support. */ $current_site, $current_blog;
  59.  
  60. if (!empty ($_GET["s2member_pro_google_co"]) && c_ws_plugin__s2member_utils_urls::s2member_sig_ok ($_SERVER["REQUEST_URI"]) && !empty ($_GET["co"]) && is_array ($attr = c_ws_plugin__s2member_utils_strings::trim_deep (stripslashes_deep ($_GET["co"]))) && $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_merchant_id"])
  61. {
  62. $attr = shortcode_atts (array ("ids" => "0", "exp" => "72", "level" => "1", "ccaps" => "", "desc" => "", "cc" => "USD", "custom" => $_SERVER["HTTP_HOST"], "ta" => "0", "tp" => "0", "tt" => "D", "ra" => "0.01", "rp" => "1", "rt" => "M", "rr" => "1", "rrt" => "", "modify" => "0", "cancel" => "0", "sp" => "0", "image" => "default", "output" => "anchor"), $attr);
  63.  
  64. $attr["tt"] = strtoupper ($attr["tt"]); // Term lengths absolutely must be provided in upper-case format. Only after running shortcode_atts().
  65. $attr["rt"] = strtoupper ($attr["rt"]); // Term lengths absolutely must be provided in upper-case format. Only after running shortcode_atts().
  66. $attr["rr"] = strtoupper ($attr["rr"]); // Must be provided in upper-case format. Numerical, or BN value. Only after running shortcode_atts().
  67. $attr["ccaps"] = strtolower ($attr["ccaps"]); // Custom Capabilities must be typed in lower-case format. Only after running shortcode_atts().
  68. $attr["rr"] = ($attr["rt"] === "L") ? "BN" : $attr["rr"]; // Lifetime Subscriptions require Buy Now. Only after running shortcode_atts().
  69. $attr["rr"] = ($attr["level"] === "*") ? "BN" : $attr["rr"]; // Independent Ccaps do NOT recur. Only after running shortcode_atts().
  70. $attr["rr"] = (!$attr["tp"] && !$attr["rr"]) ? "BN" : $attr["rr"]; // No Trial / non-recurring. Only after running shortcode_atts().
  71.  
  72. if ($attr["modify"] || $attr["cancel"]) // This is a special routine for Google® Modifications/Cancellations (one in the same).
  73. {
  74. $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_sandbox"]) ? "sandbox.google.com/checkout" : "checkout.google.com";
  75.  
  76. wp_redirect("https://" . $endpoint . "/");
  77. }
  78.  
  79. else if ($attr["sp"]) // Specific Posts/Pages.
  80. {
  81. $attr["uniqid"] = uniqid (); // Unique ID.
  82. $attr["referencing"] = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id ();
  83.  
  84. $attr["sp_ids_exp"] = "sp:" . $attr["ids"] . ":" . $attr["exp"]; // Combined "sp:ids:expiration hours".
  85. $attr["sp_access_link"] = c_ws_plugin__s2member_sp_access::sp_access_link_gen ($attr["ids"], $attr["exp"]);
  86.  
  87. $xml = '<?xml version="1.0" encoding="UTF-8"?>';
  88. $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">';
  89. $xml .= '<shopping-cart>';
  90. $xml .= '<items>';
  91.  
  92. $xml .= '<item>';
  93.  
  94. $xml .= '<quantity>1</quantity>';
  95. $xml .= '<item-name>' . esc_html ($attr["desc"]) . '</item-name>';
  96. $xml .= '<item-description>(TID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (_x ("Grants you immediate access.", "s2member-front", "s2member")) . '</item-description>';
  97. $xml .= '<unit-price currency="' . esc_attr ($attr["cc"]) . '">' . esc_html ($attr["ra"]) . '</unit-price>';
  98.  
  99. $xml .= '<merchant-private-item-data>';
  100. $xml .= '<s2_txn_id>s2-' . esc_html ($attr["uniqid"]) . '</s2_txn_id>';
  101. $xml .= '<s2_custom>' . esc_html ($attr["custom"]) . '</s2_custom>';
  102. $xml .= '<s2_item_number>' . esc_html ($attr["sp_ids_exp"]) . '</s2_item_number>';
  103. $xml .= '<s2_customer_ip>' . esc_html ($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>';
  104. $xml .= ($attr["referencing"]) ? '<s2_referencing>' . esc_html ($attr["referencing"]) . '</s2_referencing>' : '';
  105. $xml .= '</merchant-private-item-data>';
  106.  
  107. $xml .= '<digital-content>';
  108. $xml .= '<display-disposition>PESSIMISTIC</display-disposition>';
  109. $xml .= '<description>' . esc_html ($attr["desc"]) . '</description>';
  110. $xml .= '<url>' . esc_html ($attr["sp_access_link"]) . '</url>';
  111. $xml .= '</digital-content>';
  112.  
  113. $xml .= '</item>';
  114.  
  115. $xml .= '</items>';
  116. $xml .= '</shopping-cart>';
  117.  
  118. $xml .= '<checkout-flow-support>';
  119. $xml .= '<merchant-checkout-flow-support>';
  120. $xml .= '<edit-cart-url>' . esc_html (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])) . '</edit-cart-url>';
  121. $xml .= '<continue-shopping-url>' . esc_html ($attr["sp_access_link"]) . '</continue-shopping-url>';
  122. $xml .= '</merchant-checkout-flow-support>';
  123. $xml .= '</checkout-flow-support>';
  124.  
  125. $xml .= '</checkout-shopping-cart>';
  126.  
  127. $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_sandbox"]) ? "sandbox.google.com/checkout" : "checkout.google.com";
  128.  
  129. if (($xml = c_ws_plugin__s2member_utils_urls::remote ("https://" . $endpoint . "/api/checkout/v2/merchantCheckout/Merchant/" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_merchant_id"], $xml, array_merge (c_ws_plugin__s2member_pro_google_utilities::google_api_headers (), array ("timeout" => 20)))) && preg_match ("/\<redirect-url\>(.+?)\<\/redirect-url\>/i", preg_replace ("/[\r\n\t]+/", "", $xml), $m) && ($google = $m[1]))
  130. wp_redirect(wp_specialchars_decode ($google, ENT_QUOTES)); // Redirect to Google® Checkout.
  131. else // Display error message.
  132. echo strip_tags ($xml);
  133. }
  134.  
  135. else if ($attr["level"] === "*") // Independent Custom Capabilities.
  136. {
  137. $attr["uniqid"] = uniqid (); // Unique ID.
  138. $attr["referencing"] = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id ();
  139.  
  140. $attr["level_ccaps_eotper"] = ($attr["rt"] !== "L") ? $attr["level"] . ":" . $attr["ccaps"] . ":" . $attr["rp"] . " " . $attr["rt"] : $attr["level"] . ":" . $attr["ccaps"];
  141. $attr["level_ccaps_eotper"] = rtrim ($attr["level_ccaps_eotper"], ":"); // Right-trim separators from this string so we don't have trailing colons.
  142.  
  143. $xml = '<?xml version="1.0" encoding="UTF-8"?>';
  144. $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">';
  145. $xml .= '<shopping-cart>';
  146. $xml .= '<items>';
  147.  
  148. $xml .= '<item>';
  149.  
  150. $xml .= '<quantity>1</quantity>';
  151. $xml .= '<item-name>' . esc_html ($attr["desc"]) . '</item-name>';
  152. $xml .= '<item-description>(TID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (_x ("Grants you immediate access.", "s2member-front", "s2member")) . '</item-description>';
  153. $xml .= '<unit-price currency="' . esc_attr ($attr["cc"]) . '">' . esc_html ($attr["ra"]) . '</unit-price>';
  154.  
  155. $xml .= '<merchant-private-item-data>';
  156. $xml .= '<s2_txn_id>s2-' . esc_html ($attr["uniqid"]) . '</s2_txn_id>';
  157. $xml .= '<s2_custom>' . esc_html ($attr["custom"]) . '</s2_custom>';
  158. $xml .= '<s2_customer_ip>' . esc_html ($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>';
  159. $xml .= '<s2_item_number>' . esc_html ($attr["level_ccaps_eotper"]) . '</s2_item_number>';
  160. $xml .= '<s2_referencing>' . esc_html ($attr["referencing"]) . '</s2_referencing>';
  161. $xml .= '</merchant-private-item-data>';
  162.  
  163. $xml .= '<digital-content>';
  164. $xml .= '<display-disposition>PESSIMISTIC</display-disposition>';
  165. $xml .= '<description>' . esc_html (sprintf (_x ('You now have access to:<br />%s<br />(<a href="%s">please log back in now</a>)', "s2member-front", "s2member"), $attr["desc"], esc_attr (wp_login_url ()))) . '</description>';
  166. $xml .= '<url>' . esc_html (wp_login_url ()) . '</url>';
  167. $xml .= '</digital-content>';
  168.  
  169. $xml .= '</item>';
  170.  
  171. $xml .= '</items>';
  172. $xml .= '</shopping-cart>';
  173.  
  174. $xml .= '<checkout-flow-support>';
  175. $xml .= '<merchant-checkout-flow-support>';
  176. $xml .= '<edit-cart-url>' . esc_html (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])) . '</edit-cart-url>';
  177. $xml .= '<continue-shopping-url>' . esc_html (wp_login_url ()) . '</continue-shopping-url>';
  178. $xml .= '</merchant-checkout-flow-support>';
  179. $xml .= '</checkout-flow-support>';
  180.  
  181. $xml .= '</checkout-shopping-cart>';
  182.  
  183. $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_sandbox"]) ? "sandbox.google.com/checkout" : "checkout.google.com";
  184.  
  185. if (($xml = c_ws_plugin__s2member_utils_urls::remote ("https://" . $endpoint . "/api/checkout/v2/merchantCheckout/Merchant/" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_merchant_id"], $xml, array_merge (c_ws_plugin__s2member_pro_google_utilities::google_api_headers (), array ("timeout" => 20)))) && preg_match ("/\<redirect-url\>(.+?)\<\/redirect-url\>/i", preg_replace ("/[\r\n\t]+/", "", $xml), $m) && ($google = $m[1]))
  186. wp_redirect(wp_specialchars_decode ($google, ENT_QUOTES)); // Redirect to Google® Checkout.
  187. else // Display error message.
  188. echo strip_tags ($xml);
  189. }
  190.  
  191. else if ($attr["rr"] === "BN" || (!$attr["tp"] && !$attr["rr"])) // Buy Now.
  192. {
  193. $attr["uniqid"] = uniqid (); // Unique ID.
  194. $attr["referencing"] = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id ();
  195.  
  196. $attr["desc"] = (!$attr["desc"]) ? $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $attr["level"] . "_label"] : $attr["desc"];
  197.  
  198. $attr["level_ccaps_eotper"] = ($attr["rt"] !== "L") ? $attr["level"] . ":" . $attr["ccaps"] . ":" . $attr["rp"] . " " . $attr["rt"] : $attr["level"] . ":" . $attr["ccaps"];
  199. $attr["level_ccaps_eotper"] = rtrim ($attr["level_ccaps_eotper"], ":"); // Right-trim separators from this string so we don't have trailing colons.
  200.  
  201. $attr["register_access_link"] = c_ws_plugin__s2member_register_access::register_link_gen ("google", "s2-" . $attr["uniqid"], $attr["custom"], $attr["level_ccaps_eotper"]);
  202.  
  203. $xml = '<?xml version="1.0" encoding="UTF-8"?>';
  204. $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">';
  205. $xml .= '<shopping-cart>';
  206. $xml .= '<items>';
  207.  
  208. $xml .= '<item>';
  209.  
  210. $xml .= '<quantity>1</quantity>';
  211. $xml .= '<item-name>' . esc_html ($attr["desc"]) . '</item-name>';
  212. $xml .= '<item-description>(TID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (_x ("Grants you immediate access.", "s2member-front", "s2member")) . '</item-description>';
  213. $xml .= '<unit-price currency="' . esc_attr ($attr["cc"]) . '">' . esc_html ($attr["ra"]) . '</unit-price>';
  214.  
  215. $xml .= '<merchant-private-item-data>';
  216. $xml .= '<s2_txn_id>s2-' . esc_html ($attr["uniqid"]) . '</s2_txn_id>';
  217. $xml .= '<s2_custom>' . esc_html ($attr["custom"]) . '</s2_custom>';
  218. $xml .= '<s2_customer_ip>' . esc_html ($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>';
  219. $xml .= '<s2_item_number>' . esc_html ($attr["level_ccaps_eotper"]) . '</s2_item_number>';
  220. $xml .= ($attr["referencing"]) ? '<s2_referencing>' . esc_html ($attr["referencing"]) . '</s2_referencing>' : '';
  221. $xml .= '</merchant-private-item-data>';
  222.  
  223. $xml .= '<digital-content>';
  224. $xml .= '<display-disposition>PESSIMISTIC</display-disposition>';
  225.  
  226. if ($attr["referencing"]) // If we're updating an existing account that is already in the system.
  227. {
  228. $xml .= '<description>' . esc_html (sprintf (_x ('You\'ve been updated to:<br />%s<br />(<a href="%s">please log back in now</a>)', "s2member-front", "s2member"), $attr["desc"], esc_attr (wp_login_url ()))) . '</description>';
  229. $xml .= '<url>' . esc_html (wp_login_url ()) . '</url>';
  230. }
  231. else // Otherwise, this checkout experience will establish a brand new Membership.
  232. {
  233. $xml .= '<description>' . esc_html (sprintf (_x ('%s<br />(the next step is to Register a Username)', "s2member-front", "s2member"), $attr["desc"])) . '</description>';
  234. $xml .= '<url>' . esc_html ($attr["register_access_link"]) . '</url>';
  235. }
  236.  
  237. $xml .= '</digital-content>';
  238.  
  239. $xml .= '</item>';
  240.  
  241. $xml .= '</items>';
  242. $xml .= '</shopping-cart>';
  243.  
  244. $xml .= '<checkout-flow-support>';
  245. $xml .= '<merchant-checkout-flow-support>';
  246. $xml .= '<edit-cart-url>' . esc_html (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])) . '</edit-cart-url>';
  247. $xml .= '<continue-shopping-url>' . esc_html ((($attr["referencing"]) ? wp_login_url () : $attr["register_access_link"])) . '</continue-shopping-url>';
  248. $xml .= '</merchant-checkout-flow-support>';
  249. $xml .= '</checkout-flow-support>';
  250.  
  251. $xml .= '</checkout-shopping-cart>';
  252.  
  253. $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_sandbox"]) ? "sandbox.google.com/checkout" : "checkout.google.com";
  254.  
  255. if (($xml = c_ws_plugin__s2member_utils_urls::remote ("https://" . $endpoint . "/api/checkout/v2/merchantCheckout/Merchant/" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_merchant_id"], $xml, array_merge (c_ws_plugin__s2member_pro_google_utilities::google_api_headers (), array ("timeout" => 20)))) && preg_match ("/\<redirect-url\>(.+?)\<\/redirect-url\>/i", preg_replace ("/[\r\n\t]+/", "", $xml), $m) && ($google = $m[1]))
  256. wp_redirect(wp_specialchars_decode ($google, ENT_QUOTES)); // Redirect to Google® Checkout.
  257. else // Display error message.
  258. echo strip_tags ($xml);
  259. }
  260.  
  261. else // Else, use Membership routines.
  262. {
  263. $attr["uniqid"] = uniqid (); // Unique ID.
  264. $attr["referencing"] = c_ws_plugin__s2member_utils_users::get_user_subscr_or_wp_id ();
  265.  
  266. $attr["desc"] = (!$attr["desc"]) ? $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["level" . $attr["level"] . "_label"] : $attr["desc"];
  267.  
  268. $attr["level_ccaps_eotper"] = $attr["level"] . ":" . $attr["ccaps"]; // Actual Subscriptions will always end on their own.
  269. $attr["level_ccaps_eotper"] = rtrim ($attr["level_ccaps_eotper"], ":"); // Clean any trailing separators from this string.
  270.  
  271. $attr["periodicity"] = c_ws_plugin__s2member_pro_google_utilities::google_periodicity ($attr["rp"] . " " . $attr["rt"]); // Google® periodicity.
  272.  
  273. $attr["register_access_link"] = c_ws_plugin__s2member_register_access::register_link_gen ("google", "s2-" . $attr["uniqid"], $attr["custom"], $attr["level_ccaps_eotper"]);
  274.  
  275. if ($attr["tp"]) // An actual Subscription that includes a Trial Period; which MIGHT also be recurring.
  276. {
  277. $attr["start_time"] = c_ws_plugin__s2member_pro_google_utilities::google_start_time ($attr["tp"] . " " . $attr["tt"]);
  278.  
  279. $xml = '<?xml version="1.0" encoding="UTF-8"?>';
  280. $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">';
  281. $xml .= '<shopping-cart>';
  282. $xml .= '<items>';
  283.  
  284. $xml .= '<item>';
  285.  
  286. $xml .= '<quantity>1</quantity>';
  287. $xml .= '<item-name>' . esc_html ($attr["desc"]) . '</item-name>';
  288. $xml .= ($attr["ta"] < 0.01) ? // This needs to change; depending on whether or not this is a 100% Free Trial offer.
  289. '<item-description>(SID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (_x ("100% free trial. NO charge today.", "s2member-front", "s2member")) . '</item-description>' :
  290. '<item-description>(SID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (_x ("First payment for immediate access.", "s2member-front", "s2member")) . '</item-description>';
  291. $xml .= '<unit-price currency="' . esc_attr ($attr["cc"]) . '">' . esc_html ($attr["ta"]) . '</unit-price>';
  292.  
  293. $xml .= '<merchant-private-item-data>';
  294. $xml .= '<s2_subscr_id>s2-' . esc_html ($attr["uniqid"]) . '</s2_subscr_id>';
  295. $xml .= '<s2_custom>' . esc_html ($attr["custom"]) . '</s2_custom>';
  296. $xml .= '<s2_customer_ip>' . esc_html ($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>';
  297. $xml .= '<s2_item_number>' . esc_html ($attr["level_ccaps_eotper"]) . '</s2_item_number>';
  298. $xml .= '<s2_period1>' . esc_html ($attr["tp"] . " " . $attr["tt"]) . '</s2_period1>';
  299. $xml .= '<s2_period3>' . esc_html ($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>';
  300. $xml .= ($attr["rr"]) ? '<s2_recurring>' . esc_html ($attr["rr"]) . '</s2_recurring>' : '';
  301. $xml .= ($attr["referencing"]) ? '<s2_referencing>' . esc_html ($attr["referencing"]) . '</s2_referencing>' : '';
  302. $xml .= '</merchant-private-item-data>';
  303.  
  304. $xml .= '<digital-content>';
  305. $xml .= '<display-disposition>PESSIMISTIC</display-disposition>';
  306. $xml .= '<description>' . esc_html (_x ("You'll receive an email confirmation within 15 minutes.", "s2member-front", "s2member")) . '</description>';
  307. $xml .= '</digital-content>';
  308.  
  309. $xml .= '</item>';
  310.  
  311. $xml .= '<item>';
  312.  
  313. $xml .= '<quantity>1</quantity>';
  314. $xml .= '<item-name>' . esc_html ($attr["desc"]) . '</item-name>';
  315. $xml .= '<item-description>(SID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (sprintf (_x ("Cancel at any time to avoid %s.", "s2member-front", "s2member"), ((!$attr["rr"]) ? _x ("this charge", "s2member-front", "s2member") : _x ("charges", "s2member-front", "s2member")))) . '</item-description>';
  316. $xml .= '<unit-price currency="' . esc_attr ($attr["cc"]) . '">0.00</unit-price>';
  317.  
  318. $xml .= '<merchant-private-item-data>';
  319. $xml .= '<s2_subscr_id>s2-' . esc_html ($attr["uniqid"]) . '</s2_subscr_id>';
  320. $xml .= '<s2_custom>' . esc_html ($attr["custom"]) . '</s2_custom>';
  321. $xml .= '<s2_customer_ip>' . esc_html ($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>';
  322. $xml .= '<s2_item_number>' . esc_html ($attr["level_ccaps_eotper"]) . '</s2_item_number>';
  323. $xml .= '<s2_period1>' . esc_html ($attr["tp"] . " " . $attr["tt"]) . '</s2_period1>';
  324. $xml .= '<s2_period3>' . esc_html ($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>';
  325. $xml .= ($attr["rr"]) ? '<s2_recurring>' . esc_html ($attr["rr"]) . '</s2_recurring>' : '';
  326. $xml .= ($attr["referencing"]) ? '<s2_referencing>' . esc_html ($attr["referencing"]) . '</s2_referencing>' : '';
  327. $xml .= '</merchant-private-item-data>';
  328.  
  329. $xml .= '<digital-content>';
  330. $xml .= '<display-disposition>PESSIMISTIC</display-disposition>';
  331.  
  332. if ($attr["referencing"]) // If we're updating an existing account; already in the system.
  333. {
  334. $xml .= '<description>' . esc_html (sprintf (_x ('You\'ve been updated to:<br />%s<br />(<a href="%s">please log back in now</a>)', "s2member-front", "s2member"), $attr["desc"], esc_attr (wp_login_url ()))) . '</description>';
  335. $xml .= '<url>' . esc_html (wp_login_url ()) . '</url>';
  336. }
  337. else // Otherwise, this checkout experience will establish a brand new Membership.
  338. {
  339. $xml .= '<description>' . esc_html (sprintf (_x ('%s<br />(the next step is to Register a Username)', "s2member-front", "s2member"), $attr["desc"])) . '</description>';
  340. $xml .= '<url>' . esc_html ($attr["register_access_link"]) . '</url>';
  341. }
  342.  
  343. $xml .= '</digital-content>';
  344.  
  345. $xml .= '<subscription type="google" period="' . esc_attr ($attr["periodicity"]) . '" start-date="' . esc_attr (date ("Y-m-d", $attr["start_time"]) . "T00:00:00Z") . '">';
  346.  
  347. $xml .= '<payments>';
  348. $xml .= '<subscription-payment' . ((!$attr["rr"]) ? ' times="1"' : (($attr["rrt"]) ? ' times="'.esc_attr($attr["rrt"]).'"' : "")) . '>';
  349. $xml .= '<maximum-charge currency="' . esc_attr ($attr["cc"]) . '">' . esc_html ($attr["ra"]) . '</maximum-charge>';
  350. $xml .= '</subscription-payment>';
  351. $xml .= '</payments>';
  352.  
  353. $xml .= '<recurrent-item>';
  354.  
  355. $xml .= '<quantity>1</quantity>';
  356. $xml .= '<item-name>' . esc_html ($attr["desc"]) . '</item-name>';
  357. $xml .= '<item-description>(SID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (_x ("Covers ongoing access.", "s2member-front", "s2member")) . '</item-description>';
  358. $xml .= '<unit-price currency="' . esc_attr ($attr["cc"]) . '">' . esc_html ($attr["ra"]) . '</unit-price>';
  359.  
  360. $xml .= '<merchant-private-item-data>';
  361. $xml .= '<s2_subscr_payment>1</s2_subscr_payment>';
  362. $xml .= '<s2_subscr_id>s2-' . esc_html ($attr["uniqid"]) . '</s2_subscr_id>';
  363. $xml .= '<s2_custom>' . esc_html ($attr["custom"]) . '</s2_custom>';
  364. $xml .= '<s2_customer_ip>' . esc_html ($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>';
  365. $xml .= '<s2_item_number>' . esc_html ($attr["level_ccaps_eotper"]) . '</s2_item_number>';
  366. $xml .= '<s2_period1>' . esc_html ($attr["tp"] . " " . $attr["tt"]) . '</s2_period1>';
  367. $xml .= '<s2_period3>' . esc_html ($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>';
  368. $xml .= ($attr["rr"]) ? '<s2_recurring>' . esc_html ($attr["rr"]) . '</s2_recurring>' : '';
  369. $xml .= ($attr["referencing"]) ? '<s2_referencing>' . esc_html ($attr["referencing"]) . '</s2_referencing>' : '';
  370. $xml .= '</merchant-private-item-data>';
  371.  
  372. $xml .= '<digital-content>';
  373. $xml .= '<display-disposition>PESSIMISTIC</display-disposition>';
  374. $xml .= '<description>' . esc_html ($attr["desc"]) . '</description>';
  375. $xml .= '<url>' . esc_html (home_url ("/")) . '</url>';
  376. $xml .= '</digital-content>';
  377.  
  378. $xml .= '</recurrent-item>';
  379.  
  380. $xml .= '</subscription>';
  381.  
  382. $xml .= '</item>';
  383.  
  384. $xml .= '</items>';
  385. $xml .= '</shopping-cart>';
  386.  
  387. $xml .= '<checkout-flow-support>';
  388. $xml .= '<merchant-checkout-flow-support>';
  389. $xml .= '<edit-cart-url>' . esc_html (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])) . '</edit-cart-url>';
  390. $xml .= '<continue-shopping-url>' . esc_html ((($attr["referencing"]) ? wp_login_url () : $attr["register_access_link"])) . '</continue-shopping-url>';
  391. $xml .= '</merchant-checkout-flow-support>';
  392. $xml .= '</checkout-flow-support>';
  393.  
  394. $xml .= '</checkout-shopping-cart>';
  395. }
  396. else if (!$attr["tp"] && $attr["rr"]) /* This is a Subscription w/o a Trial Period; and it IS associated with multiple recurring charges.
  397. This should ALWAYS be associated with recurring charges, because of the "BN" check above that includes (!$attr["tp"] && !$attr["rr"]).
  398. In other words, we should never have a Subscription w/o a Trial Period, AND no recurring charges. That would make no sense. */
  399. {
  400. $attr["start_time"] = c_ws_plugin__s2member_pro_google_utilities::google_start_time ($attr["rp"] . " " . $attr["rt"]);
  401.  
  402. $xml = '<?xml version="1.0" encoding="UTF-8"?>';
  403. $xml .= '<checkout-shopping-cart xmlns="http://checkout.google.com/schema/2">';
  404. $xml .= '<shopping-cart>';
  405. $xml .= '<items>';
  406.  
  407. $xml .= '<item>';
  408.  
  409. $xml .= '<quantity>1</quantity>';
  410. $xml .= '<item-name>' . esc_html ($attr["desc"]) . '</item-name>';
  411. $xml .= '<item-description>(SID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (_x ("First payment for immediate access.", "s2member-front", "s2member")) . '</item-description>';
  412. $xml .= '<unit-price currency="' . esc_attr ($attr["cc"]) . '">' . esc_html ($attr["ra"]) . '</unit-price>';
  413.  
  414. $xml .= '<merchant-private-item-data>';
  415. $xml .= '<s2_subscr_id>s2-' . esc_html ($attr["uniqid"]) . '</s2_subscr_id>';
  416. $xml .= '<s2_custom>' . esc_html ($attr["custom"]) . '</s2_custom>';
  417. $xml .= '<s2_customer_ip>' . esc_html ($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>';
  418. $xml .= '<s2_item_number>' . esc_html ($attr["level_ccaps_eotper"]) . '</s2_item_number>';
  419. $xml .= '<s2_period1>0 D</s2_period1>'; // There is no Trial Period.
  420. $xml .= '<s2_period3>' . esc_html ($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>';
  421. $xml .= '<s2_recurring>' . esc_html ($attr["rr"]) . '</s2_recurring>';
  422. $xml .= ($attr["referencing"]) ? '<s2_referencing>' . esc_html ($attr["referencing"]) . '</s2_referencing>' : '';
  423. $xml .= '</merchant-private-item-data>';
  424.  
  425. $xml .= '<digital-content>';
  426. $xml .= '<display-disposition>PESSIMISTIC</display-disposition>';
  427. $xml .= '<description>' . esc_html (_x ("You'll receive an email confirmation within 15 minutes.", "s2member-front", "s2member")) . '</description>';
  428. $xml .= '</digital-content>';
  429.  
  430. $xml .= '</item>';
  431.  
  432. $xml .= '<item>';
  433.  
  434. $xml .= '<quantity>1</quantity>';
  435. $xml .= '<item-name>' . esc_html ($attr["desc"]) . '</item-name>';
  436. $xml .= '<item-description>(SID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (_x ("Cancel at any time to avoid charges.", "s2member-front", "s2member")) . '</item-description>';
  437. $xml .= '<unit-price currency="' . esc_attr ($attr["cc"]) . '">0.00</unit-price>';
  438.  
  439. $xml .= '<merchant-private-item-data>';
  440. $xml .= '<s2_subscr_id>s2-' . esc_html ($attr["uniqid"]) . '</s2_subscr_id>';
  441. $xml .= '<s2_custom>' . esc_html ($attr["custom"]) . '</s2_custom>';
  442. $xml .= '<s2_customer_ip>' . esc_html ($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>';
  443. $xml .= '<s2_item_number>' . esc_html ($attr["level_ccaps_eotper"]) . '</s2_item_number>';
  444. $xml .= '<s2_period1>0 D</s2_period1>'; // There is no Trial Period.
  445. $xml .= '<s2_period3>' . esc_html ($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>';
  446. $xml .= '<s2_recurring>' . esc_html ($attr["rr"]) . '</s2_recurring>';
  447. $xml .= ($attr["referencing"]) ? '<s2_referencing>' . esc_html ($attr["referencing"]) . '</s2_referencing>' : '';
  448. $xml .= '</merchant-private-item-data>';
  449.  
  450. $xml .= '<digital-content>';
  451. $xml .= '<display-disposition>PESSIMISTIC</display-disposition>';
  452.  
  453. if ($attr["referencing"]) // If we're updating an existing account that is already in the system.
  454. {
  455. $xml .= '<description>' . esc_html (sprintf (_x ('You\'ve been updated to:<br />%s<br />(<a href="%s">please log back in now</a>)', "s2member-front", "s2member"), $attr["desc"], esc_attr (wp_login_url ()))) . '</description>';
  456. $xml .= '<url>' . esc_html (wp_login_url ()) . '</url>';
  457. }
  458. else // Otherwise, this checkout experience will establish a brand new Membership.
  459. {
  460. $xml .= '<description>' . esc_html (sprintf (_x ('%s<br />(the next step is to Register a Username)', "s2member-front", "s2member"), $attr["desc"])) . '</description>';
  461. $xml .= '<url>' . esc_html ($attr["register_access_link"]) . '</url>';
  462. }
  463.  
  464. $xml .= '</digital-content>';
  465.  
  466. $xml .= '<subscription type="google" period="' . esc_attr ($attr["periodicity"]) . '" start-date="' . esc_attr (date ("Y-m-d", $attr["start_time"]) . "T00:00:00Z") . '">';
  467.  
  468. $xml .= '<payments>';
  469. $xml .= '<subscription-payment'.(($attr["rrt"]) ? ' times="'.esc_attr($attr["rrt"]).'"' : "").'>';
  470. $xml .= '<maximum-charge currency="' . esc_attr ($attr["cc"]) . '">' . esc_html ($attr["ra"]) . '</maximum-charge>';
  471. $xml .= '</subscription-payment>';
  472. $xml .= '</payments>';
  473.  
  474. $xml .= '<recurrent-item>';
  475.  
  476. $xml .= '<quantity>1</quantity>';
  477. $xml .= '<item-name>' . esc_html ($attr["desc"]) . '</item-name>';
  478. $xml .= '<item-description>(SID:s2-' . esc_html ($attr["uniqid"]) . ') ' . esc_html (_x ("Covers ongoing access.", "s2member-front", "s2member")) . '</item-description>';
  479. $xml .= '<unit-price currency="' . esc_attr ($attr["cc"]) . '">' . esc_html ($attr["ra"]) . '</unit-price>';
  480.  
  481. $xml .= '<merchant-private-item-data>';
  482. $xml .= '<s2_subscr_payment>1</s2_subscr_payment>';
  483. $xml .= '<s2_subscr_id>s2-' . esc_html ($attr["uniqid"]) . '</s2_subscr_id>';
  484. $xml .= '<s2_custom>' . esc_html ($attr["custom"]) . '</s2_custom>';
  485. $xml .= '<s2_customer_ip>' . esc_html ($_SERVER["REMOTE_ADDR"]) . '</s2_customer_ip>';
  486. $xml .= '<s2_item_number>' . esc_html ($attr["level_ccaps_eotper"]) . '</s2_item_number>';
  487. $xml .= '<s2_period1>0 D</s2_period1>'; // There is no Trial Period.
  488. $xml .= '<s2_period3>' . esc_html ($attr["rp"] . " " . $attr["rt"]) . '</s2_period3>';
  489. $xml .= '<s2_recurring>' . esc_html ($attr["rr"]) . '</s2_recurring>';
  490. $xml .= ($attr["referencing"]) ? '<s2_referencing>' . esc_html ($attr["referencing"]) . '</s2_referencing>' : '';
  491. $xml .= '</merchant-private-item-data>';
  492.  
  493. $xml .= '<digital-content>';
  494. $xml .= '<display-disposition>PESSIMISTIC</display-disposition>';
  495. $xml .= '<description>' . esc_html ($attr["desc"]) . '</description>';
  496. $xml .= '<url>' . esc_html (home_url ("/")) . '</url>';
  497. $xml .= '</digital-content>';
  498.  
  499. $xml .= '</recurrent-item>';
  500.  
  501. $xml .= '</subscription>';
  502.  
  503. $xml .= '</item>';
  504.  
  505. $xml .= '</items>';
  506. $xml .= '</shopping-cart>';
  507.  
  508. $xml .= '<checkout-flow-support>';
  509. $xml .= '<merchant-checkout-flow-support>';
  510. $xml .= '<edit-cart-url>' . esc_html (get_page_link ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["membership_options_page"])) . '</edit-cart-url>';
  511. $xml .= '<continue-shopping-url>' . esc_html ((($attr["referencing"]) ? wp_login_url () : $attr["register_access_link"])) . '</continue-shopping-url>';
  512. $xml .= '</merchant-checkout-flow-support>';
  513. $xml .= '</checkout-flow-support>';
  514.  
  515. $xml .= '</checkout-shopping-cart>';
  516. }
  517.  
  518. $endpoint = ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_sandbox"]) ? "sandbox.google.com/checkout" : "checkout.google.com";
  519.  
  520. if (($xml = c_ws_plugin__s2member_utils_urls::remote ("https://" . $endpoint . "/api/checkout/v2/merchantCheckout/Merchant/" . $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["pro_google_merchant_id"], $xml, array_merge (c_ws_plugin__s2member_pro_google_utilities::google_api_headers (), array ("timeout" => 20)))) && preg_match ("/\<redirect-url\>(.+?)\<\/redirect-url\>/i", preg_replace ("/[\r\n\t]+/", "", $xml), $m) && ($google = $m[1]))
  521. wp_redirect(wp_specialchars_decode ($google, ENT_QUOTES)); // Redirect to Google® Checkout.
  522. else // Display error message.
  523. echo strip_tags ($xml);
  524. }
  525.  
  526. exit /* Clean exit. */ ();
  527. }
  528. }
  529. }
  530. }
  531. ?>

pro\s2member-pro\includes\classes\gateways\google\google-co-in.inc.php

Source Code Documentation