GFP_Stripe

GFP_Stripe Class.

Defined (1)

The class is defined in the following location(s).

/includes/class-gfp-stripe.php  
  1. class GFP_Stripe { 
  2.  
  3. /** 
  4. * Instance of this class. 
  5. * @since 1.7.9.1 
  6. * @var object 
  7. */ 
  8. private static $_this = null; 
  9.  
  10. /** 
  11. * @since 0.1.0 
  12. * @var string 
  13. */ 
  14. private static $slug = "gravity-forms-stripe"; 
  15.  
  16. /** 
  17. * @since 0.1.0 
  18. * @var string 
  19. */ 
  20. private static $version = '1.9.2.9'; 
  21.  
  22. /** 
  23. * @since 
  24. * @var string 
  25. */ 
  26. private static $min_gravityforms_version = '1.9'; 
  27.  
  28. /** 
  29. * @since 1.9.2.6 
  30. * @var string 
  31. */ 
  32. private static $min_gravityforms_stripe_more_version = '1.9.2.3'; 
  33.  
  34. /** 
  35. * @since 0.1.0 
  36. * @var string 
  37. */ 
  38. private static $transaction_response = ''; 
  39.  
  40. /** 
  41. * Holds information for mapped fields in Stripe rule, used for Stripe JS 
  42. * @since 1.8.17.1 
  43. * @var array 
  44. */ 
  45. private static $stripe_rule_field_info = array(); 
  46.  
  47. /** 
  48. * @since 1.8.2 
  49. * @var bool 
  50. */ 
  51. public static $do_usage_stats = false; 
  52.  
  53. /** 
  54. * Initialize the plugin by setting localization, filters, and administration functions. 
  55. * @since 1.7.9.1 
  56. * @uses wp_die() 
  57. * @uses __() 
  58. * @uses register_activation_hook() 
  59. * @uses add_action() 
  60. */ 
  61. function __construct() { 
  62.  
  63. if ( isset( self::$_this ) ) { 
  64. wp_die( sprintf( __( 'There is already an instance of %s.',  
  65. 'gravity-forms-stripe' ), get_class( $this ) ) ); 
  66.  
  67. self::$_this = $this; 
  68.  
  69. register_activation_hook( GFP_STRIPE_FILE, array( 'GFP_Stripe', 'activate' ) ); 
  70.  
  71. register_activation_hook( 'gravityforms-stripe-more/more-stripe.php', array( 
  72. 'GFP_Stripe',  
  73. 'more_stripe_activate' 
  74. ) ); 
  75.  
  76. register_activation_hook( 'gravityforms-stripe-more/gravityforms-stripe-more.php', array( 
  77. 'GFP_Stripe',  
  78. 'more_stripe_activate' 
  79. ) ); 
  80.  
  81. add_action( 'init', array( $this, 'init' ) ); 
  82.  
  83. add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) ); 
  84.  
  85. add_filter( 'upgrader_post_install', array( $this, 'upgrader_post_install' ), 10, 2 ); 
  86.  
  87.  
  88. /** 
  89. * Private clone method to prevent cloning of the instance of the 
  90. * *Singleton* instance. 
  91. * @return void 
  92. */ 
  93. private function __clone() { 
  94.  
  95. /** 
  96. * Private unserialize method to prevent unserializing of the *Singleton* 
  97. * instance. 
  98. * @return void 
  99. */ 
  100. private function __wakeup() { 
  101.  
  102. /** 
  103. * @return GFP_Stripe|null|object 
  104. */ 
  105. static function this() { 
  106. return self::$_this; 
  107.  
  108. //------------------------------------------------------ 
  109. //------------- SETUP -------------------------- 
  110. //------------------------------------------------------ 
  111.  
  112. /** 
  113. * Activation 
  114. * @since 0.1.0 
  115. * @uses GFP_Stripe::check_for_gravity_forms() 
  116. * @uses GFP_Stripe::check_server_requirements() 
  117. * @uses GFP_Stripe::add_permissions() 
  118. * @uses GFP_Stripe::redirect_to_settings_page() 
  119. * @uses delete_transient() 
  120. * @return void 
  121. */ 
  122. public static function activate() { 
  123.  
  124. delete_transient( 'gfp_stripe_currency' ); 
  125. delete_transient( 'gfp_stripe_usage_stats_cache_data' ); 
  126.  
  127. self::$_this->check_for_gravity_forms(); 
  128.  
  129. self::$_this->check_for_more_stripe(); 
  130.  
  131. self::$_this->check_server_requirements(); 
  132.  
  133. self::$_this->add_permissions(); 
  134. self::$_this->set_settings_page_redirect(); 
  135.  
  136.  
  137. /** 
  138. * When More Stripe is being activated, deactivate it if it doesn't meet the minimum version for this version of +Stripe 
  139. * @since 1.9.2.6 
  140. */ 
  141. public static function more_stripe_activate() { 
  142.  
  143. if ( ( array_key_exists( 'action', $_POST ) ) && ( 'activate-selected' == $_POST[ 'action' ] ) && ( in_array( 'gravity-forms-stripe/gravity-forms-stripe.php', $_POST[ 'checked' ] ) ) ) { 
  144.  
  145. return; 
  146.  
  147. } else { 
  148.  
  149. $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . 'gravityforms-stripe-more/more-stripe.php' ); 
  150.  
  151. if ( empty( $plugin_data[ 'Version' ] ) ) { 
  152.  
  153. $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . 'gravityforms-stripe-more/gravityforms-stripe-more.php' ); 
  154.  
  155.  
  156. if ( empty( $plugin_data[ 'Version' ] ) ) { 
  157.  
  158. return; 
  159.  
  160. if ( ! version_compare( $plugin_data[ 'Version' ], self::$min_gravityforms_stripe_more_version, '>=' ) ) { 
  161.  
  162. deactivate_plugins( 'gravityforms-stripe-more/more-stripe.php' ); 
  163. deactivate_plugins( 'gravityforms-stripe-more/gravityforms-stripe-more.php' ); 
  164.  
  165. $message = "Your current version of Gravity Forms + Stripe requires at least More Stripe " . self::$min_gravityforms_stripe_more_version . '. You may need to renew your license to get the latest version.'; 
  166. die( $message ); 
  167.  
  168.  
  169. /** 
  170. * If More Stripe is installed, deactivate it when we upgrade +Stripe 
  171. * @since 1.9.2.7 
  172. * @param $return 
  173. * @param $plugin 
  174. * @return bool 
  175. */ 
  176. public function upgrader_post_install( $return, $plugin ) { 
  177.  
  178. if ( $return ) { 
  179.  
  180. $plugin = isset( $plugin[ 'plugin' ] ) ? $plugin[ 'plugin' ] : ''; 
  181.  
  182. if ( 'gravity-forms-stripe/gravity-forms-stripe.php' == $plugin ) { 
  183.  
  184. $more_stripe_options = array( 
  185. 'gravityforms-stripe-more/more-stripe.php',  
  186. 'gravityforms-stripe-more/gravityforms-stripe-more.php' 
  187. ); 
  188.  
  189. foreach ( $more_stripe_options as $more_stripe ) { 
  190.  
  191. if ( is_plugin_active( $more_stripe ) ) { 
  192.  
  193. deactivate_plugins( $more_stripe ); 
  194.  
  195. break; 
  196.  
  197.  
  198.  
  199. delete_transient( 'gfp_stripe_currency' ); 
  200.  
  201.  
  202.  
  203. return $return; 
  204.  
  205. /** 
  206. * Make sure Gravity Forms is installed before activating this plugin 
  207. * @since 1.7.9.1 
  208. * @uses deactivate_plugins() 
  209. * @uses __() 
  210. * @return void 
  211. */ 
  212. public function check_for_gravity_forms() { 
  213. if ( ( array_key_exists( 'action', $_POST ) ) && ( 'activate-selected' == $_POST[ 'action' ] ) && ( in_array( 'gravityforms/gravityforms.php', $_POST[ 'checked' ] ) ) ) { 
  214. return; 
  215. } else if ( ! class_exists( 'GFForms' ) ) { 
  216. deactivate_plugins( basename( GFP_STRIPE_FILE ) ); 
  217. $message = __( 'You must install and activate Gravity Forms first.', 'gravity-forms-stripe' ); 
  218. die( $message ); 
  219.  
  220. /** 
  221. * If More Stripe is installed when activating +Stripe, make sure it's deactivated 
  222. * @since 1.9.2.6 
  223. */ 
  224. public function check_for_more_stripe() { 
  225.  
  226. if ( ( array_key_exists( 'action', $_POST ) ) && ( 'activate-selected' == $_POST[ 'action' ] ) && ( in_array( 'gravityforms-stripe-more/more-stripe.php', $_POST[ 'checked' ] ) || in_array( 'gravityforms-stripe-more/gravityforms-stripe-more.php', $_POST[ 'checked' ] ) ) ) { 
  227.  
  228. return; 
  229.  
  230. } else if ( class_exists( 'GFPMoreStripe' ) ) { 
  231.  
  232. deactivate_plugins( 'gravityforms-stripe-more/more-stripe.php' ); 
  233. deactivate_plugins( 'gravityforms-stripe-more/gravityforms-stripe-more.php' ); 
  234.  
  235.  
  236.  
  237. /** 
  238. * Make sure necessary extensions are available on server 
  239. * The plugin will not work without certain server extensions 
  240. * @since 1.8.2 
  241. * @uses deactivate_plugins() 
  242. * @uses __() 
  243. * @return bool 
  244. */ 
  245. public function check_server_requirements() { 
  246. $server_requirements = array( 'curl', 'mbstring' ); 
  247. $missing_requirements = array(); 
  248. foreach ( $server_requirements as $extension ) { 
  249. if ( ! extension_loaded( $extension ) ) { 
  250. $missing_requirements[ ] = $extension; 
  251.  
  252. if ( ! empty( $missing_requirements ) ) { 
  253. deactivate_plugins( plugin_basename( trim( GFP_STRIPE_FILE ) ) ); 
  254. $missing_requirements = implode( ', ', $missing_requirements ); 
  255. $message = __( "Gravity Forms + Stripe needs {$missing_requirements} to be installed on your server. Please contact your host to enable this.", 'gravity-forms-stripe' ); 
  256. die( $message ); 
  257.  
  258. /** 
  259. * Add permissions 
  260. * @since 0.1.0 
  261. * @uses add_cap() 
  262. * @return void 
  263. */ 
  264. public function add_permissions() { 
  265. global $wp_roles; 
  266. $wp_roles->add_cap( 'administrator', 'gfp_stripe' ); 
  267. $wp_roles->add_cap( 'administrator', 'gfp_stripe_settings' ); 
  268. $wp_roles->add_cap( 'administrator', 'gfp_stripe_form_settings' ); 
  269. $wp_roles->add_cap( 'administrator', 'gfp_stripe_uninstall' ); 
  270.  
  271. /** 
  272. * Set option to redirect to settings page 
  273. * @since 1.7.9.1 
  274. * @uses set_transient() 
  275. * @return void 
  276. */ 
  277. public static function set_settings_page_redirect() { 
  278. set_transient( 'gfp_stripe_settings_page_redirect', true, HOUR_IN_SECONDS ); 
  279.  
  280. public function plugins_loaded() { 
  281.  
  282. $this->load_textdomain(); 
  283.  
  284.  
  285. public function load_textdomain() { 
  286.  
  287. $gfp_stripe_lang_dir = dirname( plugin_basename( GFP_STRIPE_FILE ) ) . '/languages/'; 
  288. $gfp_stripe_lang_dir = apply_filters( 'gfp_stripe_language_dir', $gfp_stripe_lang_dir ); 
  289.  
  290. $locale = apply_filters( 'plugin_locale', get_locale(), 'gravity-forms-stripe' ); 
  291. $mofile = sprintf( '%1$s-%2$s.mo', 'gravity-forms-stripe', $locale ); 
  292.  
  293. $mofile_local = $gfp_stripe_lang_dir . $mofile; 
  294. $mofile_global = WP_LANG_DIR . '/gravity-forms-stripe/' . $mofile; 
  295.  
  296. if ( file_exists( $mofile_global ) ) { 
  297. load_textdomain( 'gravity-forms-stripe', $mofile_global ); 
  298. } elseif ( file_exists( $mofile_local ) ) { 
  299. load_textdomain( 'gravity-forms-stripe', $mofile_local ); 
  300. } else { 
  301. load_plugin_textdomain( 'gravity-forms-stripe', false, $gfp_stripe_lang_dir ); 
  302.  
  303. /** 
  304. * Plugin initialization 
  305. * @since 0.1.0 
  306. * @uses add_action() 
  307. * @uses add_filter() 
  308. * @uses load_plugin_textdomain() 
  309. */ 
  310. public function init() { 
  311.  
  312. if ( ( ! $this->is_gravityforms_supported() ) && ( ! ( isset( $_GET[ 'action' ] ) && ( ( 'upgrade-plugin' == $_GET[ 'action' ] ) || ( 'update-selected' == $_GET[ 'action' ] ) ) ) ) ) { 
  313.  
  314. $message = __( 'Gravity Forms + Stripe requires at least Gravity Forms ' . self::$min_gravityforms_version . '.', 'gravity-forms-stripe' ); 
  315.  
  316. $this->set_admin_notice( $message, 'errors' ); 
  317.  
  318. add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
  319.  
  320. return; 
  321.  
  322. $settings = get_option( 'gfp_stripe_settings' ); 
  323. $do_usage_stats = ! empty( $settings[ 'do_usage_stats' ] ) || ! empty( $settings[ 'do_presstrends' ] ); 
  324.  
  325. self::$do_usage_stats = $do_usage_stats; 
  326.  
  327. if ( $do_usage_stats ) { 
  328. add_action( 'gfp_stripe_usage_event', array( $this, 'gfp_stripe_usage_event' ), 1, 1 ); 
  329.  
  330. add_action( 'admin_notices', array( $this, 'admin_notices' ) ); 
  331. add_action( 'admin_init', array( $this, 'admin_init' ) ); 
  332. add_action( 'admin_menu', array( $this, 'admin_menu' ) ); 
  333. add_action( 'wp_loaded', array( $this, 'wp_loaded' ) ); 
  334.  
  335. register_deactivation_hook( 'gravityforms/gravityforms.php', array( $this, 'deactivate_gravityforms' ) ); 
  336.  
  337. add_filter( 'gform_logging_supported', array( $this, 'gform_logging_supported' ) ); 
  338.  
  339. add_filter( 'gform_currency', array( $this, 'gform_currency' ) ); 
  340. add_filter( 'gform_currencies', array( $this, 'gform_currencies' ), 9 ); 
  341.  
  342. add_action( 'gform_after_delete_form', array( $this, 'gform_after_delete_form' ) ); 
  343.  
  344. if ( ! is_admin() ) { 
  345.  
  346. add_action( 'gform_enqueue_scripts', array( $this, 'gform_enqueue_scripts' ), 10, 2 ); 
  347.  
  348. add_filter( 'gform_field_content', array( $this, 'gform_field_content' ), 10, 5 ); 
  349.  
  350. add_filter( 'gform_field_validation', array( $this, 'gform_field_validation' ), 10, 4 ); 
  351. add_filter( 'gform_validation', array( $this, 'gform_validation' ), 1000, 4 ); 
  352. add_filter( 'gform_save_field_value', array( $this, 'gform_save_field_value' ), 10, 4 ); 
  353. add_filter( 'gform_entry_post_save', array( $this, 'gform_entry_post_save' ), 10, 2 ); 
  354.  
  355.  
  356. public function admin_menu() { 
  357. if ( ( 'gf_edit_forms' == RGForms::get( 'page' ) ) && ( 'settings' == rgget( 'view' ) ) && ( 'stripe' == rgget( 'subview' ) || 'Stripe' == rgget( 'addon' ) ) && ( self::$_this->has_access( 'gfp_stripe_form_settings' ) ) ) { 
  358. add_action( 'load-toplevel_page_gf_edit_forms', array( $this, 'load_toplevel_page_gf_edit_forms' ) ); 
  359.  
  360. /** 
  361. * @since 1.7.9.1 
  362. * @uses add_filter() 
  363. * @uses GFP_Stripe::setup() 
  364. * @uses wp_enqueue_script() 
  365. * @uses GFCommon::get_base_path() 
  366. * @uses RGForms::get() 
  367. * @uses RGForms::add_settings_page() 
  368. * @uses GFP_Stripe::get_base_url() 
  369. * @uses GFCommon::get_base_path() 
  370. * @return void 
  371. */ 
  372. public function admin_init() { 
  373.  
  374. add_filter( 'plugin_action_links_' . plugin_basename( GFP_STRIPE_FILE ), array( 
  375. self::$_this,  
  376. 'plugin_action_links' 
  377. ) ); 
  378.  
  379. add_filter( 'plugin_row_meta', array( self::$_this, 'plugin_row_meta' ), 10, 2 ); 
  380.  
  381. self::$_this->setup(); 
  382. self::$_this->redirect_to_settings_page(); 
  383.  
  384. $settings = get_option( 'gfp_stripe_settings' ); 
  385. $do_usage_stats = ! empty( $settings[ 'do_usage_stats' ] ) || ! empty( $settings[ 'do_presstrends' ] ); 
  386. if ( $do_usage_stats ) { 
  387. self::$_this->do_usage_stats(); 
  388.  
  389. if ( function_exists( 'members_get_capabilities' ) ) { 
  390. add_filter( 'members_get_capabilities', array( self::$_this, 'members_get_capabilities' ) ); 
  391.  
  392. add_filter( 'gform_enable_credit_card_field', '__return_true' ); 
  393.  
  394. add_filter( 'gform_form_settings_menu', array( $this, 'gform_form_settings_menu' ), 10, 2 ); 
  395.  
  396. if ( in_array( RG_CURRENT_PAGE, array( 'admin-ajax.php' ) ) ) { 
  397.  
  398. add_action( 'wp_ajax_gfp_stripe_update_feed_active', array( 
  399. self::$_this,  
  400. 'gfp_stripe_update_feed_active' 
  401. ) ); 
  402. add_action( 'wp_ajax_gfp_select_stripe_form', array( self::$_this, 'gfp_select_stripe_form' ) ); 
  403. add_action( 'wp_ajax_gfp_stripe_updates_sign_up', array( self::$_this, 'gfp_stripe_updates_sign_up' ) ); 
  404.  
  405. } else { 
  406.  
  407. switch ( RGForms::get( 'page' ) ) { 
  408.  
  409. case 'gf_settings': 
  410.  
  411. RGForms::add_settings_page( 'Stripe', array( self::$_this, 'settings_page' ) ); 
  412.  
  413. add_action( 'gform_currency_setting_message', array( 
  414. self::$_this,  
  415. 'gform_currency_setting_message' 
  416. ) ); 
  417.  
  418. if ( 'Stripe' == rgget( 'subview' ) || 'Stripe' == rgget( 'addon' ) ) { 
  419.  
  420. require_once( GFCommon::get_base_path() . '/tooltips.php' ); 
  421.  
  422. add_filter( 'gform_tooltips', array( self::$_this, 'gform_tooltips' ) ); 
  423.  
  424. wp_enqueue_style( 'gfp_stripe_admin', trailingslashit( GFP_STRIPE_URL ) . 'css/admin.css', array(), self::$version ); 
  425. add_filter( 'gform_noconflict_styles', array( $this, 'gform_noconflict_styles' ) ); 
  426. add_filter( 'gform_noconflict_scripts', array( $this, 'gform_noconflict_scripts' ) ); 
  427.  
  428. break; 
  429.  
  430. case 'gf_entries': 
  431.  
  432. add_filter( 'gform_enable_entry_info_payment_details', '__return_false' ); 
  433. add_action( 'gform_entry_detail_sidebar_middle', array( 
  434. $this,  
  435. 'gform_entry_detail_sidebar_middle' 
  436. ), 10, 2 ); 
  437.  
  438. wp_enqueue_style( 'gfp_stripe_admin', trailingslashit( GFP_STRIPE_URL ) . 'css/admin.css', array(), self::$version ); 
  439.  
  440. add_filter( 'gform_noconflict_styles', array( $this, 'gform_noconflict_styles' ) ); 
  441.  
  442. break; 
  443.  
  444. case 'gf_edit_forms': 
  445.  
  446. require_once( GFCommon::get_base_path() . '/tooltips.php' ); 
  447. add_filter( 'gform_tooltips', array( self::$_this, 'gform_tooltips' ) ); 
  448.  
  449. if ( ( 'settings' == rgget( 'view' ) ) && ( 'stripe' == rgget( 'subview' ) || 'Stripe' == rgget( 'addon' ) ) && ( self::$_this->has_access( 'gfp_stripe_form_settings' ) ) ) { 
  450.  
  451. add_action( 'gform_form_settings_page_stripe', array( 
  452. $this,  
  453. 'gform_form_settings_page_stripe' 
  454. ) ); 
  455.  
  456. wp_enqueue_style( 'gfp_stripe_admin', trailingslashit( GFP_STRIPE_URL ) . 'css/admin.css', array(), self::$version ); 
  457.  
  458. add_filter( 'gform_noconflict_styles', array( $this, 'gform_noconflict_styles' ) ); 
  459. add_filter( 'gform_noconflict_scripts', array( $this, 'gform_noconflict_scripts' ) ); 
  460.  
  461. add_action( 'gform_field_standard_settings', array( 
  462. $this,  
  463. 'gform_field_standard_settings' 
  464. ), 10, 2 ); 
  465. add_action( 'gform_editor_js', array( $this, 'gform_editor_js' ) ); 
  466. add_filter( 'gform_noconflict_scripts', array( $this, 'gform_noconflict_scripts' ) ); 
  467.  
  468. break; 
  469.  
  470.  
  471. /** 
  472. * Create or update database tables. 
  473. * Will only run when version changes. 
  474. * @since 0.1.0 
  475. * @uses get_option() 
  476. * @uses GFP_Stripe_Data::update_table() 
  477. * @uses update_option() 
  478. * @return void 
  479. */ 
  480. private function setup() { 
  481.  
  482. if ( ( $current_version = get_option( 'gfp_stripe_version' ) ) != self::$version ) { 
  483.  
  484. if ( GFForms::get_wp_option( 'gfp_stripe_version' ) != self::$version ) { 
  485.  
  486. delete_transient( 'gfp_stripe_currency' ); 
  487.  
  488. delete_transient( 'gfp_stripe_usage_stats_cache_data' ); 
  489.  
  490. GFP_Stripe_Data::update_table( $current_version ); 
  491.  
  492. if ( ( ! empty( $current_version ) ) && ( version_compare( $current_version, '1.8.2', '<' ) ) ) { 
  493.  
  494. delete_transient( 'gfp_stripe_presstrends_cache_data' ); 
  495.  
  496. $message = sprintf( __( 'You need to %supgrade your Stripe API to the latest version%s in your Stripe dashboard', 'gravity-forms-stripe' ), '<a href="https://dashboard.stripe.com/account/apikeys" target="_blank">', '</a>' ); 
  497.  
  498. if ( ! file_exists( dirname( GFP_STRIPE_FILE ) . '/../gravityforms-stripe-more' ) ) { 
  499.  
  500. $message .= '<?php add_thickbox(); ?>'; 
  501.  
  502. ob_start(); 
  503.  
  504. include( trailingslashit( GFP_STRIPE_PATH ) . 'includes/views/update-api-message.php' ); 
  505.  
  506. $message .= ob_get_contents(); 
  507.  
  508. ob_end_clean(); 
  509.  
  510.  
  511. $this->set_admin_notice( $message, 'updates' ); 
  512.  
  513. delete_transient( 'gfp_stripe_settings_page_redirect' ); 
  514.  
  515.  
  516. update_option( 'gfp_stripe_version', self::$version ); 
  517.  
  518.  
  519. /** 
  520. * Redirect to settings page if not activating multiple plugins at once 
  521. * @since 1.7.9.1 
  522. * @uses get_transient() 
  523. * @uses delete_transient() 
  524. * @uses admin_url() 
  525. * @uses wp_redirect() 
  526. * @return void 
  527. */ 
  528. public static function redirect_to_settings_page() { 
  529. if ( true == get_transient( 'gfp_stripe_settings_page_redirect' ) ) { 
  530. delete_transient( 'gfp_stripe_settings_page_redirect' ); 
  531. if ( ! isset( $_GET[ 'activate-multi' ] ) ) { 
  532. wp_redirect( self_admin_url( 'admin.php?page=gf_settings&subview=Stripe' ) ); 
  533.  
  534. /** 
  535. * @return bool|mixed 
  536. */ 
  537. public static function is_gravityforms_supported() { 
  538. if ( class_exists( 'GFCommon' ) ) { 
  539. $is_correct_version = version_compare( GFCommon::$version, self::$min_gravityforms_version, '>=' ); 
  540.  
  541. return $is_correct_version; 
  542. } else { 
  543. return false; 
  544.  
  545. /** 
  546. * @return bool 
  547. */ 
  548. public static function is_gravityforms_stripe_more_supported() { 
  549.  
  550. if ( class_exists( 'GFPMoreStripe' ) ) { 
  551.  
  552. $is_correct_version = version_compare( GFPMoreStripe::get_version(), self::$min_gravityforms_stripe_more_version, '>=' ); 
  553.  
  554. return $is_correct_version; 
  555.  
  556. } else { 
  557.  
  558. return true; 
  559.  
  560.  
  561.  
  562. //------------------------------------------------------ 
  563. //------------- GENERAL ADMIN -------------------------- 
  564. //------------------------------------------------------ 
  565. /** 
  566. * Output admin notices 
  567. * @since 1.7.9.1 
  568. * @uses get_site_transient() 
  569. * @uses get_transient() 
  570. * @uses delete_site_transient() 
  571. * @uses delete_transient() 
  572. * @return void 
  573. */ 
  574. public function admin_notices() { 
  575.  
  576. $admin_notices = function_exists( 'get_site_transient' ) ? get_site_transient( 'gfp-stripe-admin_notices' ) : get_transient( 'gfp-stripe-admin_notices' ); 
  577. if ( $admin_notices ) { 
  578. $message = ''; 
  579. foreach ( $admin_notices as $type => $notices ) { 
  580.  
  581. if ( ( 'errors' == $type ) && ( ! $this->is_gravityforms_supported() ) ) { 
  582. foreach ( $notices as $notice ) { 
  583. $message .= '<div class="error"><p>' . $notice . '</p></div>'; 
  584.  
  585. if ( 'updates' == $type ) { 
  586. foreach ( $notices as $notice ) { 
  587. $message .= '<div class="updated"><p>' . $notice . '</p></div>'; 
  588.  
  589. echo $message; 
  590.  
  591. if ( function_exists( 'delete_site_transient' ) ) { 
  592. delete_site_transient( 'gfp-stripe-admin_notices' ); 
  593. } else { 
  594. delete_transient( 'gfp-stripe-admin_notices' ); 
  595.  
  596. /** 
  597. * Create an admin notice 
  598. * @since 1.7.11.1 
  599. * @uses get_site_transient() 
  600. * @uses get_transient() 
  601. * @uses set_site_transient() 
  602. * @uses set_transient() 
  603. * @param $notice 
  604. * @param $type 
  605. * @return void 
  606. */ 
  607. private function set_admin_notice( $notice, $type ) { 
  608. if ( function_exists( 'get_site_transient' ) ) { 
  609. $notices = get_site_transient( 'gfp-stripe-admin_notices' ); 
  610. } else { 
  611. $notices = get_transient( 'gfp-stripe-admin_notices' ); 
  612.  
  613. if ( ! is_array( $notices ) || ! array_key_exists( $type, $notices ) || ! in_array( $notice, $notices[ $type ] ) ) { 
  614. $notices[ $type ][ ] = $notice; 
  615.  
  616. if ( function_exists( 'set_site_transient' ) ) { 
  617. set_site_transient( 'gfp-stripe-admin_notices', $notices ); 
  618. } else { 
  619. set_transient( 'gfp-stripe-admin_notices', $notices ); 
  620.  
  621. /** 
  622. * Add a link to this plugin's settings page 
  623. * @uses self_admin_url() 
  624. * @uses __() 
  625. * @param $links 
  626. * @return array 
  627. */ 
  628. public function plugin_action_links( $links ) { 
  629. return array_merge( 
  630. array( 
  631. 'settings' => '<a href="' . self_admin_url( 'admin.php?page=gf_settings&subview=Stripe' ) . '">' . __( 'Settings', 'gravity-forms-stripe' ) . '</a>' 
  632. ),  
  633. $links 
  634. ); 
  635.  
  636. /** 
  637. * Add helpful gravity+ links 
  638. * @since 1.8.12.1 
  639. * @param array $plugin_meta 
  640. * @param string $plugin_file 
  641. * @return mixed 
  642. */ 
  643. public function plugin_row_meta( $plugin_meta, $plugin_file ) { 
  644. $plugin = plugin_basename( trim( GFP_STRIPE_FILE ) ); 
  645.  
  646. if ( $plugin == $plugin_file ) { 
  647. if ( ! file_exists( dirname( GFP_STRIPE_FILE ) . '/../gravityforms-stripe-more' ) ) { 
  648. $links[ ] = sprintf( __( '%sGet important updates%s', 'gravity-forms-stripe' ), '<a href="https://gravityplus.pro/gravity-forms-stripe/updates/?utm_source=gravity-forms-stripe&utm_medium=link&utm_content=plugins-list&utm_campaign=gravity-forms-stripe" target="_blank">', '</a>' ); 
  649. $links[ ] = sprintf( __( '%sFollow on Twitter%s', 'gravity-forms-stripe' ), '<a href="https://twitter.com/gravityplus" target="_blank">', '</a>' ); 
  650. $plugin_meta = array_merge( $plugin_meta, $links ); 
  651.  
  652. return $plugin_meta; 
  653.  
  654. /** 
  655. * Disallow Gravity Forms deactivation if this plugin is still active 
  656. * Prevents a fatal error if this plugin is still active when user attempts to deactivate Gravity Forms 
  657. * @since 1.7.9.1 
  658. * @uses plugin_basename() 
  659. * @uses is_plugin_active() 
  660. * @uses __() 
  661. * @uses get_site_transient() 
  662. * @uses get_transient() 
  663. * @uses set_site_transient() 
  664. * @uses set_transient() 
  665. * @uses self_admin_url() 
  666. * @uses wp_redirect() 
  667. * @param $network_deactivating 
  668. * @return void 
  669. */ 
  670. public function deactivate_gravityforms( $network_deactivating ) { 
  671. $plugin = plugin_basename( trim( GFP_STRIPE_FILE ) ); 
  672. if ( ( array_key_exists( 'action', $_POST ) ) && ( 'deactivate-selected' == $_POST[ 'action' ] ) && ( in_array( $plugin, $_POST[ 'checked' ] ) ) ) { 
  673. return; 
  674. } else if ( is_plugin_active( $plugin ) ) { 
  675. if ( $network_deactivating ) { 
  676. add_action( 'update_site_option_active_sitewide_plugins', array( 
  677. $this,  
  678. 'update_site_option_active_sitewide_plugins' 
  679. ) ); 
  680. } else { 
  681. add_action( 'update_option_active_plugins', array( $this, 'update_option_active_plugins' ) ); 
  682.  
  683. public function update_option_active_plugins() { 
  684. remove_action( 'update_option_active_plugins', array( $this, 'update_options_active_plugins' ) ); 
  685. $plugin = plugin_basename( trim( GFP_STRIPE_FILE ) ); 
  686. deactivate_plugins( $plugin ); 
  687. update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); 
  688.  
  689. public function update_site_option_active_sitewide_plugins() { 
  690. remove_action( 'update_site_option_active_sitewide_plugins', array( 
  691. $this,  
  692. 'update_site_option_active_sitewide_plugins' 
  693. ) ); 
  694. $plugin = plugin_basename( trim( GFP_STRIPE_FILE ) ); 
  695. deactivate_plugins( $plugin ); 
  696.  
  697. /** 
  698. * Get version 
  699. * @since 1.8.2 
  700. * @return string 
  701. */ 
  702. public static function get_version() { 
  703. return self::$version; 
  704.  
  705. /** 
  706. * @param $noconflict_scripts 
  707. * @return array 
  708. */ 
  709. function gform_noconflict_scripts( $noconflict_scripts ) { 
  710.  
  711. if ( ( 'gf_settings' == RGForms::get( 'page' ) ) && ( 'Stripe' == rgget( 'subview' ) ) ) { 
  712. $noconflict_scripts = array_merge( $noconflict_scripts, array( 'gfp_stripe_settings_page_js' ) ); 
  713. } else if ( 'gf_edit_forms' == RGForms::get( 'page' ) ) { 
  714.  
  715. if ( ( 'settings' == rgget( 'view' ) ) && ( 'stripe' == rgget( 'subview' ) ) && ( self::$_this->has_access( 'gfp_stripe_form_settings' ) ) ) { 
  716. $noconflict_scripts = array_merge( $noconflict_scripts, array( 
  717. 'gfp_stripe_form_settings_stripe_js',  
  718. 'gfp_stripe_form_settings_edit_feed_js' 
  719. ) ); 
  720. } else { 
  721. $noconflict_scripts = array_merge( $noconflict_scripts, array( 'gfp_stripe_form_editor_card_funding_types' ) ); 
  722.  
  723.  
  724. return $noconflict_scripts; 
  725.  
  726. /** 
  727. * @param $noconflict_styles 
  728. * @return array 
  729. */ 
  730. function gform_noconflict_styles( $noconflict_styles ) { 
  731.  
  732. return array_merge( $noconflict_styles, array( 'gfp_stripe_admin' ) ); 
  733.  
  734. function load_toplevel_page_gf_edit_forms() { 
  735. $screen = get_current_screen(); 
  736.  
  737. if ( 'toplevel_page_gf_edit_forms' == $screen->id ) { 
  738. ob_start(); 
  739.  
  740. include( trailingslashit( GFP_STRIPE_PATH ) . 'includes/views/form-settings-stripe-help-sidebar.php' ); 
  741. $sidebar = ob_get_contents(); 
  742. ob_clean(); 
  743.  
  744. include( trailingslashit( GFP_STRIPE_PATH ) . 'includes/views/form-settings-stripe-help-basic-setup.php' ); 
  745. $setup = ob_get_contents(); 
  746. ob_clean(); 
  747.  
  748. include( trailingslashit( GFP_STRIPE_PATH ) . 'includes/views/form-settings-stripe-help-troubleshooting.php' ); 
  749. $troubleshooting = ob_get_contents(); 
  750. ob_clean(); 
  751.  
  752. ob_end_clean(); 
  753.  
  754. $screen->set_help_sidebar( $sidebar ); 
  755.  
  756. $screen->add_help_tab( array( 
  757. 'id' => 'stripe-settings-basic-setup',  
  758. 'title' => __( 'Basic Setup', 'gravity-forms-stripe' ),  
  759. 'content' => $setup 
  760. ) ); 
  761.  
  762. $screen->add_help_tab( array( 
  763. 'id' => 'stripe-settings-troubleshooting',  
  764. 'title' => __( 'Troubleshooting', 'gravity-forms-stripe' ),  
  765. 'content' => $troubleshooting 
  766. ) ); 
  767.  
  768. do_action( 'gfp_stripe_form_settings_contextual_help', $screen ); 
  769.  
  770. /** 
  771. * Remove Gravity Forms admin_print_scripts hook 
  772. * RGForms::print_scripts calls wp_print_scripts, causing default WordPress JS to break (such as contextual help 
  773. * tabs). It is unnecessary to call wp_print_scripts because it will be called automatically in admin-header.php,  
  774. * and on every page load in wp_head. 
  775. * @since 1.8.2 
  776. */ 
  777. function wp_loaded() { 
  778. if ( ( 'gf_edit_forms' == RGForms::get( 'page' ) ) && ( 'settings' == rgget( 'view' ) ) && ( 'stripe' == rgget( 'subview' ) || 'Stripe' == rgget( 'addon' ) ) && ( self::$_this->has_access( 'gfp_stripe_form_settings' ) ) ) { 
  779. remove_action( 'admin_print_scripts', array( 'RGForms', 'print_scripts' ) ); 
  780. wp_enqueue_script( 'sack' ); 
  781.  
  782. //------------------------------------------------------ 
  783. //------------- MEMBERS PLUGIN INTEGRATION ------------- 
  784. //------------------------------------------------------ 
  785. /** 
  786. * Provide the Members plugin with this plugin's list of capabilities 
  787. * @since 0.1.0 
  788. * @param $caps 
  789. * @return array 
  790. */ 
  791. public function members_get_capabilities( $caps ) { 
  792. return array_merge( $caps, array( 
  793. 'gfp_stripe',  
  794. 'gfp_stripe_settings',  
  795. 'gfp_stripe_form_settings',  
  796. 'gfp_stripe_uninstall' 
  797. ) ); 
  798.  
  799. /** 
  800. * Check if user has the required permission 
  801. * @since 0.1.0 
  802. * @uses current_user_can() 
  803. * @param $required_permission 
  804. * @return bool|string 
  805. */ 
  806. public static function has_access( $required_permission ) { 
  807. $has_members_plugin = function_exists( 'members_get_capabilities' ); 
  808. $has_access = $has_members_plugin ? current_user_can( $required_permission ) : current_user_can( 'level_7' ); 
  809. if ( $has_access ) { 
  810. return $has_members_plugin ? $required_permission : 'level_7'; 
  811. } else { 
  812. return false; 
  813.  
  814. //------------------------------------------------------ 
  815. //------------- CURRENCY -------------------------- 
  816. //------------------------------------------------------ 
  817. /** 
  818. * Get the currency or currencies supported by the Stripe account 
  819. * @since 
  820. * @uses get_transient() 
  821. * @uses GFP_Stripe::include_api() 
  822. * @uses GFP_Stripe::get_api_key() 
  823. * @uses PPP\Stripe\Account::retrieve() 
  824. * @uses set_transient() 
  825. * @param $currency 
  826. * @return mixed 
  827. */ 
  828. public function gform_currency( $currency ) { 
  829.  
  830. $stripe_currency = get_transient( 'gfp_stripe_currency' ); 
  831.  
  832. if ( false === $stripe_currency ) { 
  833.  
  834. self::$_this->include_api(); 
  835.  
  836. $api_key = self::$_this->get_api_key( 'secret' ); 
  837.  
  838. if ( ! empty( $api_key ) ) { 
  839.  
  840. PPP\Stripe\Stripe::setApiKey( $api_key ); 
  841.  
  842. try { 
  843. $account = PPP\Stripe\Account::retrieve(); 
  844. } catch ( Exception $e ) { 
  845. $error_message = GFP_Stripe::gfp_stripe_create_error_message( $e ); 
  846. GFP_Stripe::log_error( "Unable to retrieve account to get default Stripe currency: {$error_message}" ); 
  847.  
  848. return $currency; 
  849.  
  850. $stripe_default_currency = strtoupper( $account[ 'default_currency' ] ); 
  851.  
  852. $stripe_account_country = strtoupper( $account[ 'country' ] ); 
  853.  
  854. $stripe_country_spec = PPP\Stripe\CountrySpec::retrieve( $stripe_account_country ); 
  855.  
  856. $stripe_currencies_supported = array_map( 'strtoupper', $stripe_country_spec[ 'supported_payment_currencies' ] ); 
  857.  
  858. set_transient( 'gfp_stripe_currency',  
  859. array( 
  860. 'default' => $stripe_default_currency,  
  861. 'supported' => $stripe_currencies_supported 
  862. ),  
  863. 24 * HOUR_IN_SECONDS ); 
  864.  
  865. if ( ( $stripe_default_currency !== $currency ) && ( ! in_array( $currency, $stripe_currencies_supported ) ) ) { 
  866. $currency = $stripe_default_currency; 
  867.  
  868. } else { 
  869.  
  870. update_option( 'rg_gforms_currency', 'USD' ); 
  871. $currency = 'USD'; 
  872.  
  873.  
  874. } else if ( ! in_array( $currency, $stripe_currency[ 'supported' ] ) ) { 
  875. $currency = $stripe_currency[ 'default' ]; 
  876.  
  877. return $currency; 
  878.  
  879. /** 
  880. * Currencies supported by Stripe account 
  881. * @since 1.7.9.1 
  882. * @uses get_transient() 
  883. * @uses GFP_Stripe::include_api() 
  884. * @uses GFP_Stripe::get_api_key() 
  885. * @uses PPP\Stripe\Stripe::setApiKey() 
  886. * @uses PPP\Stripe\Account::retrieve() 
  887. * @uses set_transient() 
  888. * @param $currencies 
  889. * @return array 
  890. */ 
  891. public function gform_currencies( $currencies ) { 
  892.  
  893. $currencies = array_merge( $currencies, $this->all_currencies() ); 
  894.  
  895. $current_currency = get_transient( 'gfp_stripe_currency' ); 
  896.  
  897. if ( false === $current_currency ) { 
  898.  
  899. self::$_this->include_api(); 
  900.  
  901. $api_key = self::$_this->get_api_key( 'secret' ); 
  902.  
  903. if ( ! empty( $api_key ) ) { 
  904. PPP\Stripe\Stripe::setApiKey( $api_key ); 
  905.  
  906. try { 
  907. $account = PPP\Stripe\Account::retrieve(); 
  908. } catch ( Exception $e ) { 
  909. $error_message = GFP_Stripe::gfp_stripe_create_error_message( $e ); 
  910. GFP_Stripe::log_error( "Unable to retrieve account to get currencies: {$error_message}" ); 
  911.  
  912. return $currencies; 
  913.  
  914. $default_currency = strtoupper( $account[ 'default_currency' ] ); 
  915.  
  916. $stripe_account_country = strtoupper( $account[ 'country' ] ); 
  917.  
  918. $stripe_country_spec = PPP\Stripe\CountrySpec::retrieve( $stripe_account_country ); 
  919.  
  920. $currencies_supported = array_map( 'strtoupper', $stripe_country_spec[ 'supported_payment_currencies' ] ); 
  921.  
  922. set_transient( 'gfp_stripe_currency',  
  923. array( 
  924. 'default' => $default_currency,  
  925. 'supported' => $currencies_supported 
  926. ),  
  927. 24 * HOUR_IN_SECONDS ); 
  928.  
  929.  
  930.  
  931. if ( ( ! empty( $current_currency ) ) || ( ! empty( $default_currency ) ) && ( ! empty( $currencies_supported ) ) ) { 
  932.  
  933. $new_currencies_list = array_intersect_key( $currencies, ( $current_currency ) ? array_flip( $current_currency[ 'supported' ] ) : array_flip( $currencies_supported ) ); 
  934.  
  935. if ( ! empty( $new_currencies_list ) ) { 
  936.  
  937. ksort( $new_currencies_list ); 
  938.  
  939. $currencies = $new_currencies_list; 
  940.  
  941.  
  942.  
  943. return $currencies; 
  944.  
  945. /** 
  946. * Currency setting message 
  947. * @since 
  948. * @uses GFP_Stripe::get_api_key() 
  949. * @uses GFCommon::get_currency() 
  950. * @uses RGCurrency::get_currency() 
  951. * @uses __() 
  952. * @return void 
  953. */ 
  954. public function gform_currency_setting_message() { 
  955. $api_key = self::$_this->get_api_key( 'secret' ); 
  956. if ( ! empty( $api_key ) ) { 
  957. if ( ! class_exists( 'RGCurrency' ) ) { 
  958. require_once( GFCommon::get_base_path() . '/currency.php' ); 
  959. $currency_name = RGCurrency::get_currency( GFCommon::get_currency() ); 
  960. $currency_name = $currency_name[ 'name' ]; 
  961. echo '<div class=\'gform_currency_message\'>' . __( "Your Stripe account allows these currencies.", 'gravity-forms-stripe' ) . '</div>'; 
  962. } else { 
  963. echo '<div class=\'gform_currency_message\'>' . sprintf( __( "Your %sStripe settings%s are not filled in -- using default currency.", 'gravity-forms-stripe' ), '<a href="admin.php?page=gf_settings&addon=Stripe">', '</a>' ) . '</div>'; 
  964.  
  965. public function all_currencies() { 
  966. return array( 
  967. 'USD' => array( 
  968. 'name' => __( 'United States Dollar', 'gravity-forms-stripe' ),  
  969. 'symbol_left' => '$',  
  970. 'symbol_right' => '',  
  971. 'symbol_padding' => ' ',  
  972. 'thousand_separator' => ', ',  
  973. 'decimal_separator' => '.',  
  974. 'decimals' => 2,  
  975. 'american_express' => true 
  976. ),  
  977. 'AED' => array( 
  978. 'name' => __( 'United Arab Emirates Dirham', 'gravity-forms-stripe' ),  
  979. 'symbol_left' => 'د.إ',  
  980. 'symbol_right' => '',  
  981. 'symbol_padding' => ' ',  
  982. 'thousand_separator' => ', ',  
  983. 'decimal_separator' => '.',  
  984. 'decimals' => 2,  
  985. 'american_express' => true 
  986. ),  
  987. 'AFN' => array( 
  988. 'name' => __( 'Afghan Afghani', 'gravity-forms-stripe' ),  
  989. 'symbol_left' => '',  
  990. 'symbol_right' => '؋',  
  991. 'symbol_padding' => ' ',  
  992. 'thousand_separator' => ', ',  
  993. 'decimal_separator' => '.',  
  994. 'decimals' => 2,  
  995. 'american_express' => false 
  996. ),  
  997. 'ALL' => array( 
  998. 'name' => __( 'Albanian Lek', 'gravity-forms-stripe' ),  
  999. 'symbol_left' => '',  
  1000. 'symbol_right' => 'L',  
  1001. 'symbol_padding' => ' ',  
  1002. 'thousand_separator' => ', ',  
  1003. 'decimal_separator' => '.',  
  1004. 'decimals' => 2,  
  1005. 'american_express' => true 
  1006. ),  
  1007. 'AMD' => array( 
  1008. 'name' => __( 'Armenian Dram', 'gravity-forms-stripe' ),  
  1009. 'symbol_left' => 'AMD',  
  1010. 'symbol_right' => '',  
  1011. 'symbol_padding' => ' ',  
  1012. 'thousand_separator' => ', ',  
  1013. 'decimal_separator' => '.',  
  1014. 'decimals' => 2,  
  1015. 'american_express' => true 
  1016. ),  
  1017. 'ANG' => array( 
  1018. 'name' => __( 'Netherlands Antillean Gulden', 'gravity-forms-stripe' ),  
  1019. 'symbol_left' => 'ƒ',  
  1020. 'symbol_right' => '',  
  1021. 'symbol_padding' => ' ',  
  1022. 'thousand_separator' => ', ',  
  1023. 'decimal_separator' => '.',  
  1024. 'decimals' => 2,  
  1025. 'american_express' => true 
  1026. ),  
  1027. 'AOA' => array( 
  1028. 'name' => __( 'Angolan Kwanza', 'gravity-forms-stripe' ),  
  1029. 'symbol_left' => 'Kz',  
  1030. 'symbol_right' => '',  
  1031. 'symbol_padding' => ' ',  
  1032. 'thousand_separator' => ', ',  
  1033. 'decimal_separator' => '.',  
  1034. 'decimals' => 2,  
  1035. 'american_express' => false 
  1036. ),  
  1037. 'ARS' => array( 
  1038. 'name' => __( 'Argentine Peso', 'gravity-forms-stripe' ),  
  1039. 'symbol_left' => 'ARS$',  
  1040. 'symbol_right' => '',  
  1041. 'symbol_padding' => ' ',  
  1042. 'thousand_separator' => ', ',  
  1043. 'decimal_separator' => '.',  
  1044. 'decimals' => 2,  
  1045. 'american_express' => false 
  1046. ),  
  1047. 'AUD' => array( 
  1048. 'name' => __( 'Australian Dollar', 'gravity-forms-stripe' ),  
  1049. 'symbol_left' => 'A$',  
  1050. 'symbol_right' => '',  
  1051. 'symbol_padding' => ' ',  
  1052. 'thousand_separator' => ', ',  
  1053. 'decimal_separator' => '.',  
  1054. 'decimals' => 2,  
  1055. 'american_express' => false 
  1056. ),  
  1057. 'AWG' => array( 
  1058. 'name' => __( 'Aruban Florin', 'gravity-forms-stripe' ),  
  1059. 'symbol_left' => 'ƒ',  
  1060. 'symbol_right' => '',  
  1061. 'symbol_padding' => ' ',  
  1062. 'thousand_separator' => ', ',  
  1063. 'decimal_separator' => '.',  
  1064. 'decimals' => 2,  
  1065. 'american_express' => true 
  1066. ),  
  1067. 'AZN' => array( 
  1068. 'name' => __( 'Azerbaijani Manat', 'gravity-forms-stripe' ),  
  1069. 'symbol_left' => 'ман',  
  1070. 'symbol_right' => '',  
  1071. 'symbol_padding' => ' ',  
  1072. 'thousand_separator' => ', ',  
  1073. 'decimal_separator' => '.',  
  1074. 'decimals' => 2,  
  1075. 'american_express' => true 
  1076. ),  
  1077. 'BAM' => array( 
  1078. 'name' => __( 'Bosnia & Herzegovina Convertible Mark', 'gravity-forms-stripe' ),  
  1079. 'symbol_left' => 'KM',  
  1080. 'symbol_right' => '',  
  1081. 'symbol_padding' => ' ',  
  1082. 'thousand_separator' => ', ',  
  1083. 'decimal_separator' => '.',  
  1084. 'decimals' => 2,  
  1085. 'american_express' => true 
  1086. ),  
  1087. 'BBD' => array( 
  1088. 'name' => __( 'Barbadian Dollar', 'gravity-forms-stripe' ),  
  1089. 'symbol_left' => 'Bbd$',  
  1090. 'symbol_right' => '',  
  1091. 'symbol_padding' => ' ',  
  1092. 'thousand_separator' => ', ',  
  1093. 'decimal_separator' => '.',  
  1094. 'decimals' => 2,  
  1095. 'american_express' => true 
  1096. ),  
  1097. 'BDT' => array( 
  1098. 'name' => __( 'Bangladeshi Taka', 'gravity-forms-stripe' ),  
  1099. 'symbol_left' => '৳',  
  1100. 'symbol_right' => '',  
  1101. 'symbol_padding' => ' ',  
  1102. 'thousand_separator' => ', ',  
  1103. 'decimal_separator' => '.',  
  1104. 'decimals' => 2,  
  1105. 'american_express' => true 
  1106. ),  
  1107. 'BGN' => array( 
  1108. 'name' => __( 'Bulgarian Lev', 'gravity-forms-stripe' ),  
  1109. 'symbol_left' => 'лв',  
  1110. 'symbol_right' => '',  
  1111. 'symbol_padding' => ' ',  
  1112. 'thousand_separator' => ', ',  
  1113. 'decimal_separator' => '.',  
  1114. 'decimals' => 2,  
  1115. 'american_express' => true 
  1116. ),  
  1117. 'BIF' => array( 
  1118. 'name' => __( 'Burundian Franc', 'gravity-forms-stripe' ),  
  1119. 'symbol_left' => '',  
  1120. 'symbol_right' => 'BIF',  
  1121. 'symbol_padding' => ' ',  
  1122. 'thousand_separator' => ', ',  
  1123. 'decimal_separator' => '.',  
  1124. 'decimals' => 0,  
  1125. 'american_express' => true 
  1126. ),  
  1127. 'BMD' => array( 
  1128. 'name' => __( 'Bermudian Dollar', 'gravity-forms-stripe' ),  
  1129. 'symbol_left' => '',  
  1130. 'symbol_right' => 'BMD',  
  1131. 'symbol_padding' => ' ',  
  1132. 'thousand_separator' => ', ',  
  1133. 'decimal_separator' => '.',  
  1134. 'decimals' => 2,  
  1135. 'american_express' => true 
  1136. ),  
  1137. 'BND' => array( 
  1138. 'name' => __( 'Brunei Dollar', 'gravity-forms-stripe' ),  
  1139. 'symbol_left' => '',  
  1140. 'symbol_right' => 'BND',  
  1141. 'symbol_padding' => ' ',  
  1142. 'thousand_separator' => ', ',  
  1143. 'decimal_separator' => '.',  
  1144. 'decimals' => 2,  
  1145. 'american_express' => true 
  1146. ),  
  1147. 'BOB' => array( 
  1148. 'name' => __( 'Bolivian Boliviano', 'gravity-forms-stripe' ),  
  1149. 'symbol_left' => '',  
  1150. 'symbol_right' => 'BOB',  
  1151. 'symbol_padding' => ' ',  
  1152. 'thousand_separator' => ', ',  
  1153. 'decimal_separator' => '.',  
  1154. 'decimals' => 2,  
  1155. 'american_express' => false 
  1156. ),  
  1157. 'BRL' => array( 
  1158. 'name' => __( 'Brazilian Real', 'gravity-forms-stripe' ),  
  1159. 'symbol_left' => 'R$',  
  1160. 'symbol_right' => '',  
  1161. 'symbol_padding' => ' ',  
  1162. 'thousand_separator' => ', ',  
  1163. 'decimal_separator' => '.',  
  1164. 'decimals' => 2,  
  1165. 'american_express' => false 
  1166. ),  
  1167. 'BSD' => array( 
  1168. 'name' => __( 'Bahamian Dollar', 'gravity-forms-stripe' ),  
  1169. 'symbol_left' => '',  
  1170. 'symbol_right' => 'BSD',  
  1171. 'symbol_padding' => ' ',  
  1172. 'thousand_separator' => ', ',  
  1173. 'decimal_separator' => '.',  
  1174. 'decimals' => 2,  
  1175. 'american_express' => true 
  1176. ),  
  1177. 'BWP' => array( 
  1178. 'name' => __( 'Botswana Pula', 'gravity-forms-stripe' ),  
  1179. 'symbol_left' => '',  
  1180. 'symbol_right' => 'BWP',  
  1181. 'symbol_padding' => ' ',  
  1182. 'thousand_separator' => ', ',  
  1183. 'decimal_separator' => '.',  
  1184. 'decimals' => 2,  
  1185. 'american_express' => true 
  1186. ),  
  1187. 'BZD' => array( 
  1188. 'name' => __( 'Belize Dollar', 'gravity-forms-stripe' ),  
  1189. 'symbol_left' => '',  
  1190. 'symbol_right' => 'BZP',  
  1191. 'symbol_padding' => ' ',  
  1192. 'thousand_separator' => ', ',  
  1193. 'decimal_separator' => '.',  
  1194. 'decimals' => 2,  
  1195. 'american_express' => true 
  1196. ),  
  1197. 'CAD' => array( 
  1198. 'name' => __( 'Canadian Dollar', 'gravity-forms-stripe' ),  
  1199. 'symbol_left' => 'CAD$',  
  1200. 'symbol_right' => 'CAD',  
  1201. 'symbol_padding' => ' ',  
  1202. 'thousand_separator' => ', ',  
  1203. 'decimal_separator' => '.',  
  1204. 'decimals' => 2,  
  1205. 'american_express' => false 
  1206. ),  
  1207. 'CDF' => array( 
  1208. 'name' => __( 'Congolese Franc', 'gravity-forms-stripe' ),  
  1209. 'symbol_left' => '',  
  1210. 'symbol_right' => 'CDF',  
  1211. 'symbol_padding' => ' ',  
  1212. 'thousand_separator' => ', ',  
  1213. 'decimal_separator' => '.',  
  1214. 'decimals' => 2,  
  1215. 'american_express' => true 
  1216. ),  
  1217. 'CHF' => array( 
  1218. 'name' => __( 'Swiss Franc', 'gravity-forms-stripe' ),  
  1219. 'symbol_left' => 'Fr',  
  1220. 'symbol_right' => '',  
  1221. 'symbol_padding' => ' ',  
  1222. 'thousand_separator' => "'",  
  1223. 'decimal_separator' => '.',  
  1224. 'decimals' => 2,  
  1225. 'american_express' => true 
  1226. ),  
  1227. 'CLP' => array( 
  1228. 'name' => __( 'Chilean Peso', 'gravity-forms-stripe' ),  
  1229. 'symbol_left' => '',  
  1230. 'symbol_right' => 'CLP',  
  1231. 'symbol_padding' => ' ',  
  1232. 'thousand_separator' => ', ',  
  1233. 'decimal_separator' => '.',  
  1234. 'decimals' => 0,  
  1235. 'american_express' => false 
  1236. ),  
  1237. 'CNY' => array( 
  1238. 'name' => __( 'Chinese Renminbi Yuan', 'gravity-forms-stripe' ),  
  1239. 'symbol_left' => '',  
  1240. 'symbol_right' => 'CNY',  
  1241. 'symbol_padding' => ' ',  
  1242. 'thousand_separator' => ', ',  
  1243. 'decimal_separator' => '.',  
  1244. 'decimals' => 2,  
  1245. 'american_express' => true 
  1246. ),  
  1247. 'COP' => array( 
  1248. 'name' => __( 'Colombian Peso', 'gravity-forms-stripe' ),  
  1249. 'symbol_left' => '',  
  1250. 'symbol_right' => 'COP',  
  1251. 'symbol_padding' => ' ',  
  1252. 'thousand_separator' => ', ',  
  1253. 'decimal_separator' => '.',  
  1254. 'decimals' => 2,  
  1255. 'american_express' => false 
  1256. ),  
  1257. 'CRC' => array( 
  1258. 'name' => __( 'Costa Rican Coln', 'gravity-forms-stripe' ),  
  1259. 'symbol_left' => '',  
  1260. 'symbol_right' => 'CRC',  
  1261. 'symbol_padding' => ' ',  
  1262. 'thousand_separator' => ', ',  
  1263. 'decimal_separator' => '.',  
  1264. 'decimals' => 2,  
  1265. 'american_express' => false 
  1266. ),  
  1267. 'CVE' => array( 
  1268. 'name' => __( 'Cape Verdean Escudo', 'gravity-forms-stripe' ),  
  1269. 'symbol_left' => '',  
  1270. 'symbol_right' => 'CVE',  
  1271. 'symbol_padding' => ' ',  
  1272. 'thousand_separator' => ', ',  
  1273. 'decimal_separator' => '.',  
  1274. 'decimals' => 2,  
  1275. 'american_express' => false 
  1276. ),  
  1277. 'CZK' => array( 
  1278. 'name' => __( 'Czech Koruna', 'gravity-forms-stripe' ),  
  1279. 'symbol_left' => '',  
  1280. 'symbol_right' => 'Kč',  
  1281. 'symbol_padding' => ' ',  
  1282. 'thousand_separator' => ' ',  
  1283. 'decimal_separator' => ', ',  
  1284. 'decimals' => 2,  
  1285. 'american_express' => false 
  1286. ),  
  1287. 'DJF' => array( 
  1288. 'name' => __( 'Djiboutian Franc', 'gravity-forms-stripe' ),  
  1289. 'symbol_left' => '',  
  1290. 'symbol_right' => 'DJF',  
  1291. 'symbol_padding' => ' ',  
  1292. 'thousand_separator' => ', ',  
  1293. 'decimal_separator' => '.',  
  1294. 'decimals' => 0,  
  1295. 'american_express' => false 
  1296. ),  
  1297. 'DKK' => array( 
  1298. 'name' => __( 'Danish Krone', 'gravity-forms-stripe' ),  
  1299. 'symbol_left' => '',  
  1300. 'symbol_right' => 'kr.',  
  1301. 'symbol_padding' => ' ',  
  1302. 'thousand_separator' => '.',  
  1303. 'decimal_separator' => ', ',  
  1304. 'decimals' => 2,  
  1305. 'american_express' => true 
  1306. ),  
  1307. 'DOP' => array( 
  1308. 'name' => __( 'Dominican Peso', 'gravity-forms-stripe' ),  
  1309. 'symbol_left' => '',  
  1310. 'symbol_right' => 'DOP',  
  1311. 'symbol_padding' => ' ',  
  1312. 'thousand_separator' => ', ',  
  1313. 'decimal_separator' => '.',  
  1314. 'decimals' => 2,  
  1315. 'american_express' => true 
  1316. ),  
  1317. 'DZD' => array( 
  1318. 'name' => __( 'Algerian Dinar', 'gravity-forms-stripe' ),  
  1319. 'symbol_left' => '',  
  1320. 'symbol_right' => 'DZD',  
  1321. 'symbol_padding' => ' ',  
  1322. 'thousand_separator' => ', ',  
  1323. 'decimal_separator' => '.',  
  1324. 'decimals' => 2,  
  1325. 'american_express' => true 
  1326. ),  
  1327. 'EEK' => array( 
  1328. 'name' => __( 'Estonian Kroon', 'gravity-forms-stripe' ),  
  1329. 'symbol_left' => '',  
  1330. 'symbol_right' => 'EEK',  
  1331. 'symbol_padding' => ' ',  
  1332. 'thousand_separator' => ', ',  
  1333. 'decimal_separator' => '.',  
  1334. 'decimals' => 2,  
  1335. 'american_express' => false 
  1336. ),  
  1337. 'EGP' => array( 
  1338. 'name' => __( 'Egyptian Pound', 'gravity-forms-stripe' ),  
  1339. 'symbol_left' => '',  
  1340. 'symbol_right' => 'EGP',  
  1341. 'symbol_padding' => ' ',  
  1342. 'thousand_separator' => ', ',  
  1343. 'decimal_separator' => '.',  
  1344. 'decimals' => 2,  
  1345. 'american_express' => true 
  1346. ),  
  1347. 'ETB' => array( 
  1348. 'name' => __( 'Ethiopian Birr', 'gravity-forms-stripe' ),  
  1349. 'symbol_left' => '',  
  1350. 'symbol_right' => 'ETB',  
  1351. 'symbol_padding' => ' ',  
  1352. 'thousand_separator' => ', ',  
  1353. 'decimal_separator' => '.',  
  1354. 'decimals' => 2,  
  1355. 'american_express' => true 
  1356. ),  
  1357. 'EUR' => array( 
  1358. 'name' => __( 'Euro', 'gravity-forms-stripe' ),  
  1359. 'symbol_left' => '',  
  1360. 'symbol_right' => '€',  
  1361. 'symbol_padding' => '',  
  1362. 'thousand_separator' => '.',  
  1363. 'decimal_separator' => ', ',  
  1364. 'decimals' => 2,  
  1365. 'american_express' => true 
  1366. ),  
  1367. 'FJD' => array( 
  1368. 'name' => __( 'Fijian Dollar', 'gravity-forms-stripe' ),  
  1369. 'symbol_left' => '',  
  1370. 'symbol_right' => 'FJD',  
  1371. 'symbol_padding' => ' ',  
  1372. 'thousand_separator' => ', ',  
  1373. 'decimal_separator' => '.',  
  1374. 'decimals' => 2,  
  1375. 'american_express' => true 
  1376. ),  
  1377. 'FKP' => array( 
  1378. 'name' => __( 'Falkland Islands Pound', 'gravity-forms-stripe' ),  
  1379. 'symbol_left' => '',  
  1380. 'symbol_right' => 'FKP',  
  1381. 'symbol_padding' => ' ',  
  1382. 'thousand_separator' => ', ',  
  1383. 'decimal_separator' => '.',  
  1384. 'decimals' => 2,  
  1385. 'american_express' => false 
  1386. ),  
  1387. 'GBP' => array( 
  1388. 'name' => __( 'British Pound', 'gravity-forms-stripe' ),  
  1389. 'symbol_left' => '£',  
  1390. 'symbol_right' => '',  
  1391. 'symbol_padding' => ' ',  
  1392. 'thousand_separator' => ', ',  
  1393. 'decimal_separator' => '.',  
  1394. 'decimals' => 2,  
  1395. 'american_express' => true 
  1396. ),  
  1397. 'GEL' => array( 
  1398. 'name' => __( 'Georgian Lari', 'gravity-forms-stripe' ),  
  1399. 'symbol_left' => '',  
  1400. 'symbol_right' => 'GEL',  
  1401. 'symbol_padding' => ' ',  
  1402. 'thousand_separator' => ', ',  
  1403. 'decimal_separator' => '.',  
  1404. 'decimals' => 2,  
  1405. 'american_express' => true 
  1406. ),  
  1407. 'GIP' => array( 
  1408. 'name' => __( 'Gibraltar Pound', 'gravity-forms-stripe' ),  
  1409. 'symbol_left' => '',  
  1410. 'symbol_right' => 'GIP',  
  1411. 'symbol_padding' => ' ',  
  1412. 'thousand_separator' => ', ',  
  1413. 'decimal_separator' => '.',  
  1414. 'decimals' => 2,  
  1415. 'american_express' => true 
  1416. ),  
  1417. 'GMD' => array( 
  1418. 'name' => __( 'Gambian Dalasi', 'gravity-forms-stripe' ),  
  1419. 'symbol_left' => '',  
  1420. 'symbol_right' => 'GMD',  
  1421. 'symbol_padding' => ' ',  
  1422. 'thousand_separator' => ', ',  
  1423. 'decimal_separator' => '.',  
  1424. 'decimals' => 2,  
  1425. 'american_express' => true 
  1426. ),  
  1427. 'GNF' => array( 
  1428. 'name' => __( 'Guinean Franc', 'gravity-forms-stripe' ),  
  1429. 'symbol_left' => '',  
  1430. 'symbol_right' => 'GNF',  
  1431. 'symbol_padding' => ' ',  
  1432. 'thousand_separator' => ', ',  
  1433. 'decimal_separator' => '.',  
  1434. 'decimals' => 0,  
  1435. 'american_express' => false 
  1436. ),  
  1437. 'GTQ' => array( 
  1438. 'name' => __( 'Guatemalan Quetzal', 'gravity-forms-stripe' ),  
  1439. 'symbol_left' => '',  
  1440. 'symbol_right' => 'GTQ',  
  1441. 'symbol_padding' => ' ',  
  1442. 'thousand_separator' => ', ',  
  1443. 'decimal_separator' => '.',  
  1444. 'decimals' => 2,  
  1445. 'american_express' => false 
  1446. ),  
  1447. 'GYD' => array( 
  1448. 'name' => __( 'Guyanese Dollar', 'gravity-forms-stripe' ),  
  1449. 'symbol_left' => '',  
  1450. 'symbol_right' => 'GYD',  
  1451. 'symbol_padding' => ' ',  
  1452. 'thousand_separator' => ', ',  
  1453. 'decimal_separator' => '.',  
  1454. 'decimals' => 2,  
  1455. 'american_express' => true 
  1456. ),  
  1457. 'HKD' => array( 
  1458. 'name' => __( 'Hong Kong Dollar', 'gravity-forms-stripe' ),  
  1459. 'symbol_left' => 'HK$',  
  1460. 'symbol_right' => '',  
  1461. 'symbol_padding' => ' ',  
  1462. 'thousand_separator' => ', ',  
  1463. 'decimal_separator' => '.',  
  1464. 'decimals' => 2,  
  1465. 'american_express' => true 
  1466. ),  
  1467. 'HNL' => array( 
  1468. 'name' => __( 'Honduran Lempira', 'gravity-forms-stripe' ),  
  1469. 'symbol_left' => '',  
  1470. 'symbol_right' => 'HNL',  
  1471. 'symbol_padding' => ' ',  
  1472. 'thousand_separator' => ', ',  
  1473. 'decimal_separator' => '.',  
  1474. 'decimals' => 2,  
  1475. 'american_express' => false 
  1476. ),  
  1477. 'HRK' => array( 
  1478. 'name' => __( 'Croatian Kuna', 'gravity-forms-stripe' ),  
  1479. 'symbol_left' => '',  
  1480. 'symbol_right' => 'HRK',  
  1481. 'symbol_padding' => ' ',  
  1482. 'thousand_separator' => ', ',  
  1483. 'decimal_separator' => '.',  
  1484. 'decimals' => 2,  
  1485. 'american_express' => true 
  1486. ),  
  1487. 'HTG' => array( 
  1488. 'name' => __( 'Haitian Gourde', 'gravity-forms-stripe' ),  
  1489. 'symbol_left' => '',  
  1490. 'symbol_right' => 'HTG',  
  1491. 'symbol_padding' => ' ',  
  1492. 'thousand_separator' => ', ',  
  1493. 'decimal_separator' => '.',  
  1494. 'decimals' => 2,  
  1495. 'american_express' => true 
  1496. ),  
  1497. 'HUF' => array( 
  1498. 'name' => __( 'Hungarian Forint', 'gravity-forms-stripe' ),  
  1499. 'symbol_left' => '',  
  1500. 'symbol_right' => 'Ft',  
  1501. 'symbol_padding' => ' ',  
  1502. 'thousand_separator' => '.',  
  1503. 'decimal_separator' => ', ',  
  1504. 'decimals' => 2,  
  1505. 'american_express' => true 
  1506. ),  
  1507. 'IDR' => array( 
  1508. 'name' => __( 'Indonesian Rupiah', 'gravity-forms-stripe' ),  
  1509. 'symbol_left' => '',  
  1510. 'symbol_right' => 'IDR',  
  1511. 'symbol_padding' => ' ',  
  1512. 'thousand_separator' => ', ',  
  1513. 'decimal_separator' => '.',  
  1514. 'decimals' => 2,  
  1515. 'american_express' => true 
  1516. ),  
  1517. 'ILS' => array( 
  1518. 'name' => __( 'Israeli New Sheqel', 'gravity-forms-stripe' ),  
  1519. 'symbol_left' => '₪',  
  1520. 'symbol_right' => '',  
  1521. 'symbol_padding' => ' ',  
  1522. 'thousand_separator' => ', ',  
  1523. 'decimal_separator' => '.',  
  1524. 'decimals' => 2,  
  1525. 'american_express' => true 
  1526. ),  
  1527. 'INR' => array( 
  1528. 'name' => __( 'Indian Rupee', 'gravity-forms-stripe' ),  
  1529. 'symbol_left' => '',  
  1530. 'symbol_right' => 'INR',  
  1531. 'symbol_padding' => ' ',  
  1532. 'thousand_separator' => ', ',  
  1533. 'decimal_separator' => '.',  
  1534. 'decimals' => 2,  
  1535. 'american_express' => false 
  1536. ),  
  1537. 'ISK' => array( 
  1538. 'name' => __( 'Icelandic Krna', 'gravity-forms-stripe' ),  
  1539. 'symbol_left' => '',  
  1540. 'symbol_right' => 'ISK',  
  1541. 'symbol_padding' => ' ',  
  1542. 'thousand_separator' => ', ',  
  1543. 'decimal_separator' => '.',  
  1544. 'decimals' => 2,  
  1545. 'american_express' => true 
  1546. ),  
  1547. 'JMD' => array( 
  1548. 'name' => __( 'Jamaican Dollar', 'gravity-forms-stripe' ),  
  1549. 'symbol_left' => '',  
  1550. 'symbol_right' => 'JMD',  
  1551. 'symbol_padding' => ' ',  
  1552. 'thousand_separator' => ', ',  
  1553. 'decimal_separator' => '.',  
  1554. 'decimals' => 2,  
  1555. 'american_express' => true 
  1556. ),  
  1557. 'JPY' => array( 
  1558. 'name' => __( 'Japanese Yen', 'gravity-forms-stripe' ),  
  1559. 'symbol_left' => '¥',  
  1560. 'symbol_right' => '',  
  1561. 'symbol_padding' => ' ',  
  1562. 'thousand_separator' => ', ',  
  1563. 'decimal_separator' => '',  
  1564. 'decimals' => 0,  
  1565. 'american_express' => true 
  1566. ),  
  1567. 'KES' => array( 
  1568. 'name' => __( 'Kenyan Shilling', 'gravity-forms-stripe' ),  
  1569. 'symbol_left' => '',  
  1570. 'symbol_right' => 'KES',  
  1571. 'symbol_padding' => ' ',  
  1572. 'thousand_separator' => ', ',  
  1573. 'decimal_separator' => '.',  
  1574. 'decimals' => 2,  
  1575. 'american_express' => true 
  1576. ),  
  1577. 'KGS' => array( 
  1578. 'name' => __( 'Kyrgyzstani Som', 'gravity-forms-stripe' ),  
  1579. 'symbol_left' => '',  
  1580. 'symbol_right' => 'KGS',  
  1581. 'symbol_padding' => ' ',  
  1582. 'thousand_separator' => ', ',  
  1583. 'decimal_separator' => '.',  
  1584. 'decimals' => 2,  
  1585. 'american_express' => true 
  1586. ),  
  1587. 'KHR' => array( 
  1588. 'name' => __( 'Cambodian Riel', 'gravity-forms-stripe' ),  
  1589. 'symbol_left' => '',  
  1590. 'symbol_right' => 'KHR',  
  1591. 'symbol_padding' => ' ',  
  1592. 'thousand_separator' => ', ',  
  1593. 'decimal_separator' => '.',  
  1594. 'decimals' => 2,  
  1595. 'american_express' => true 
  1596. ),  
  1597. 'KMF' => array( 
  1598. 'name' => __( 'Comorian Franc', 'gravity-forms-stripe' ),  
  1599. 'symbol_left' => '',  
  1600. 'symbol_right' => 'KMF',  
  1601. 'symbol_padding' => ' ',  
  1602. 'thousand_separator' => ', ',  
  1603. 'decimal_separator' => '.',  
  1604. 'decimals' => 0,  
  1605. 'american_express' => true 
  1606. ),  
  1607. 'KRW' => array( 
  1608. 'name' => __( 'South Korean Won', 'gravity-forms-stripe' ),  
  1609. 'symbol_left' => '',  
  1610. 'symbol_right' => 'KRW',  
  1611. 'symbol_padding' => ' ',  
  1612. 'thousand_separator' => ', ',  
  1613. 'decimal_separator' => '.',  
  1614. 'decimals' => 0,  
  1615. 'american_express' => true 
  1616. ),  
  1617. 'KYD' => array( 
  1618. 'name' => __( 'Cayman Islands Dollar', 'gravity-forms-stripe' ),  
  1619. 'symbol_left' => '',  
  1620. 'symbol_right' => 'KYD',  
  1621. 'symbol_padding' => ' ',  
  1622. 'thousand_separator' => ', ',  
  1623. 'decimal_separator' => '.',  
  1624. 'decimals' => 2,  
  1625. 'american_express' => true 
  1626. ),  
  1627. 'KZT' => array( 
  1628. 'name' => __( 'Kazakhstani Tenge', 'gravity-forms-stripe' ),  
  1629. 'symbol_left' => '',  
  1630. 'symbol_right' => 'KZT',  
  1631. 'symbol_padding' => ' ',  
  1632. 'thousand_separator' => ', ',  
  1633. 'decimal_separator' => '.',  
  1634. 'decimals' => 2,  
  1635. 'american_express' => true 
  1636. ),  
  1637. 'LAK' => array( 
  1638. 'name' => __( 'Lao Kip', 'gravity-forms-stripe' ),  
  1639. 'symbol_left' => '',  
  1640. 'symbol_right' => 'LAK',  
  1641. 'symbol_padding' => ' ',  
  1642. 'thousand_separator' => ', ',  
  1643. 'decimal_separator' => '.',  
  1644. 'decimals' => 2,  
  1645. 'american_express' => false 
  1646. ),  
  1647. 'LBP' => array( 
  1648. 'name' => __( 'Lebanese Pound', 'gravity-forms-stripe' ),  
  1649. 'symbol_left' => '',  
  1650. 'symbol_right' => 'LBP',  
  1651. 'symbol_padding' => ' ',  
  1652. 'thousand_separator' => ', ',  
  1653. 'decimal_separator' => '.',  
  1654. 'decimals' => 2,  
  1655. 'american_express' => true 
  1656. ),  
  1657. 'LKR' => array( 
  1658. 'name' => __( 'Sri Lankan Rupee', 'gravity-forms-stripe' ),  
  1659. 'symbol_left' => '',  
  1660. 'symbol_right' => 'LKR',  
  1661. 'symbol_padding' => ' ',  
  1662. 'thousand_separator' => ', ',  
  1663. 'decimal_separator' => '.',  
  1664. 'decimals' => 2,  
  1665. 'american_express' => true 
  1666. ),  
  1667. 'LRD' => array( 
  1668. 'name' => __( 'Liberian Dollar', 'gravity-forms-stripe' ),  
  1669. 'symbol_left' => '',  
  1670. 'symbol_right' => 'LRD',  
  1671. 'symbol_padding' => ' ',  
  1672. 'thousand_separator' => ', ',  
  1673. 'decimal_separator' => '.',  
  1674. 'decimals' => 2,  
  1675. 'american_express' => true 
  1676. ),  
  1677. 'LSL' => array( 
  1678. 'name' => __( 'Lesotho Loti', 'gravity-forms-stripe' ),  
  1679. 'symbol_left' => '',  
  1680. 'symbol_right' => 'LSL',  
  1681. 'symbol_padding' => ' ',  
  1682. 'thousand_separator' => ', ',  
  1683. 'decimal_separator' => '.',  
  1684. 'decimals' => 2,  
  1685. 'american_express' => true 
  1686. ),  
  1687. 'LTL' => array( 
  1688. 'name' => __( 'Lithuanian Litas', 'gravity-forms-stripe' ),  
  1689. 'symbol_left' => '',  
  1690. 'symbol_right' => 'LTL',  
  1691. 'symbol_padding' => ' ',  
  1692. 'thousand_separator' => ', ',  
  1693. 'decimal_separator' => '.',  
  1694. 'decimals' => 2,  
  1695. 'american_express' => true 
  1696. ),  
  1697. 'LVL' => array( 
  1698. 'name' => __( 'Latvian Lats', 'gravity-forms-stripe' ),  
  1699. 'symbol_left' => '',  
  1700. 'symbol_right' => 'LVL',  
  1701. 'symbol_padding' => ' ',  
  1702. 'thousand_separator' => ', ',  
  1703. 'decimal_separator' => '.',  
  1704. 'decimals' => 2,  
  1705. 'american_express' => true 
  1706. ),  
  1707. 'MAD' => array( 
  1708. 'name' => __( 'Moroccan Dirham', 'gravity-forms-stripe' ),  
  1709. 'symbol_left' => '',  
  1710. 'symbol_right' => 'MAD',  
  1711. 'symbol_padding' => ' ',  
  1712. 'thousand_separator' => ', ',  
  1713. 'decimal_separator' => '.',  
  1714. 'decimals' => 2,  
  1715. 'american_express' => true 
  1716. ),  
  1717. 'MDL' => array( 
  1718. 'name' => __( 'Moldovan Leu', 'gravity-forms-stripe' ),  
  1719. 'symbol_left' => '',  
  1720. 'symbol_right' => 'MDL',  
  1721. 'symbol_padding' => ' ',  
  1722. 'thousand_separator' => ', ',  
  1723. 'decimal_separator' => '.',  
  1724. 'decimals' => 2,  
  1725. 'american_express' => true 
  1726. ),  
  1727. 'MGA' => array( 
  1728. 'name' => __( 'Malagasy Ariary', 'gravity-forms-stripe' ),  
  1729. 'symbol_left' => '',  
  1730. 'symbol_right' => 'MGA',  
  1731. 'symbol_padding' => ' ',  
  1732. 'thousand_separator' => ', ',  
  1733. 'decimal_separator' => '.',  
  1734. 'decimals' => 0,  
  1735. 'american_express' => true 
  1736. ),  
  1737. 'MKD' => array( 
  1738. 'name' => __( 'Macedonian Denar', 'gravity-forms-stripe' ),  
  1739. 'symbol_left' => '',  
  1740. 'symbol_right' => 'MKD',  
  1741. 'symbol_padding' => ' ',  
  1742. 'thousand_separator' => ', ',  
  1743. 'decimal_separator' => '.',  
  1744. 'decimals' => 2,  
  1745. 'american_express' => true 
  1746. ),  
  1747. 'MNT' => array( 
  1748. 'name' => __( 'Mongolian Tgrg', 'gravity-forms-stripe' ),  
  1749. 'symbol_left' => '',  
  1750. 'symbol_right' => 'MNT',  
  1751. 'symbol_padding' => ' ',  
  1752. 'thousand_separator' => ', ',  
  1753. 'decimal_separator' => '.',  
  1754. 'decimals' => 2,  
  1755. 'american_express' => true 
  1756. ),  
  1757. 'MOP' => array( 
  1758. 'name' => __( 'Macanese Pataca', 'gravity-forms-stripe' ),  
  1759. 'symbol_left' => '',  
  1760. 'symbol_right' => 'MOP',  
  1761. 'symbol_padding' => ' ',  
  1762. 'thousand_separator' => ', ',  
  1763. 'decimal_separator' => '.',  
  1764. 'decimals' => 2,  
  1765. 'american_express' => true 
  1766. ),  
  1767. 'MRO' => array( 
  1768. 'name' => __( 'Mauritanian Ouguiya', 'gravity-forms-stripe' ),  
  1769. 'symbol_left' => '',  
  1770. 'symbol_right' => 'MRO',  
  1771. 'symbol_padding' => ' ',  
  1772. 'thousand_separator' => ', ',  
  1773. 'decimal_separator' => '.',  
  1774. 'decimals' => 2,  
  1775. 'american_express' => true 
  1776. ),  
  1777. 'MUR' => array( 
  1778. 'name' => __( 'Mauritian Rupee', 'gravity-forms-stripe' ),  
  1779. 'symbol_left' => '',  
  1780. 'symbol_right' => 'MUR',  
  1781. 'symbol_padding' => ' ',  
  1782. 'thousand_separator' => ', ',  
  1783. 'decimal_separator' => '.',  
  1784. 'decimals' => 2,  
  1785. 'american_express' => false 
  1786. ),  
  1787. 'MVR' => array( 
  1788. 'name' => __( 'Maldivian Rufiyaa', 'gravity-forms-stripe' ),  
  1789. 'symbol_left' => '',  
  1790. 'symbol_right' => 'MVR',  
  1791. 'symbol_padding' => ' ',  
  1792. 'thousand_separator' => ', ',  
  1793. 'decimal_separator' => '.',  
  1794. 'decimals' => 2,  
  1795. 'american_express' => true 
  1796. ),  
  1797. 'MWK' => array( 
  1798. 'name' => __( 'Malawian Kwacha', 'gravity-forms-stripe' ),  
  1799. 'symbol_left' => '',  
  1800. 'symbol_right' => 'MWK',  
  1801. 'symbol_padding' => ' ',  
  1802. 'thousand_separator' => ', ',  
  1803. 'decimal_separator' => '.',  
  1804. 'decimals' => 2,  
  1805. 'american_express' => true 
  1806. ),  
  1807. 'MXN' => array( 
  1808. 'name' => __( 'Mexican Peso', 'gravity-forms-stripe' ),  
  1809. 'symbol_left' => 'MXN$',  
  1810. 'symbol_right' => 'MXN',  
  1811. 'symbol_padding' => ' ',  
  1812. 'thousand_separator' => ', ',  
  1813. 'decimal_separator' => '.',  
  1814. 'decimals' => 2,  
  1815. 'american_express' => false 
  1816. ),  
  1817. 'MYR' => array( 
  1818. 'name' => __( 'Malaysian Ringgit', 'gravity-forms-stripe' ),  
  1819. 'symbol_left' => 'RM',  
  1820. 'symbol_right' => '',  
  1821. 'symbol_padding' => ' ',  
  1822. 'thousand_separator' => ', ',  
  1823. 'decimal_separator' => '.',  
  1824. 'decimals' => 2,  
  1825. 'american_express' => true 
  1826. ),  
  1827. 'MZN' => array( 
  1828. 'name' => __( 'Mozambican Metical', 'gravity-forms-stripe' ),  
  1829. 'symbol_left' => '',  
  1830. 'symbol_right' => 'MZN',  
  1831. 'symbol_padding' => ' ',  
  1832. 'thousand_separator' => ', ',  
  1833. 'decimal_separator' => '.',  
  1834. 'decimals' => 2,  
  1835. 'american_express' => true 
  1836. ),  
  1837. 'NAD' => array( 
  1838. 'name' => __( 'Namibian Dollar', 'gravity-forms-stripe' ),  
  1839. 'symbol_left' => '',  
  1840. 'symbol_right' => 'NAD',  
  1841. 'symbol_padding' => ' ',  
  1842. 'thousand_separator' => ', ',  
  1843. 'decimal_separator' => '.',  
  1844. 'decimals' => 2,  
  1845. 'american_express' => true 
  1846. ),  
  1847. 'NGN' => array( 
  1848. 'name' => __( 'Nigerian Naira', 'gravity-forms-stripe' ),  
  1849. 'symbol_left' => '',  
  1850. 'symbol_right' => 'NGN',  
  1851. 'symbol_padding' => ' ',  
  1852. 'thousand_separator' => ', ',  
  1853. 'decimal_separator' => '.',  
  1854. 'decimals' => 2,  
  1855. 'american_express' => true 
  1856. ),  
  1857. 'NIO' => array( 
  1858. 'name' => __( 'Nicaraguan Crdoba', 'gravity-forms-stripe' ),  
  1859. 'symbol_left' => '',  
  1860. 'symbol_right' => 'NIO',  
  1861. 'symbol_padding' => ' ',  
  1862. 'thousand_separator' => ', ',  
  1863. 'decimal_separator' => '.',  
  1864. 'decimals' => 2,  
  1865. 'american_express' => false 
  1866. ),  
  1867. 'NOK' => array( 
  1868. 'name' => __( 'Norwegian Krone', 'gravity-forms-stripe' ),  
  1869. 'symbol_left' => 'Kr',  
  1870. 'symbol_right' => '',  
  1871. 'symbol_padding' => ' ',  
  1872. 'thousand_separator' => ', ',  
  1873. 'decimal_separator' => '.',  
  1874. 'decimals' => 2,  
  1875. 'american_express' => true 
  1876. ),  
  1877. 'NPR' => array( 
  1878. 'name' => __( 'Nepalese Rupee', 'gravity-forms-stripe' ),  
  1879. 'symbol_left' => '',  
  1880. 'symbol_right' => 'NPR',  
  1881. 'symbol_padding' => ' ',  
  1882. 'thousand_separator' => ', ',  
  1883. 'decimal_separator' => '.',  
  1884. 'decimals' => 2,  
  1885. 'american_express' => true 
  1886. ),  
  1887. 'NZD' => array( 
  1888. 'name' => __( 'New Zealand Dollar', 'gravity-forms-stripe' ),  
  1889. 'symbol_left' => 'NZ$',  
  1890. 'symbol_right' => '',  
  1891. 'symbol_padding' => ' ',  
  1892. 'thousand_separator' => ', ',  
  1893. 'decimal_separator' => '.',  
  1894. 'decimals' => 2,  
  1895. 'american_express' => true 
  1896. ),  
  1897. 'PAB' => array( 
  1898. 'name' => __( 'Panamanian Balboa', 'gravity-forms-stripe' ),  
  1899. 'symbol_left' => '',  
  1900. 'symbol_right' => 'PAB',  
  1901. 'symbol_padding' => ' ',  
  1902. 'thousand_separator' => ', ',  
  1903. 'decimal_separator' => '.',  
  1904. 'decimals' => 2,  
  1905. 'american_express' => false 
  1906. ),  
  1907. 'PEN' => array( 
  1908. 'name' => __( 'Peruvian Nuevo Sol', 'gravity-forms-stripe' ),  
  1909. 'symbol_left' => '',  
  1910. 'symbol_right' => 'PEN',  
  1911. 'symbol_padding' => ' ',  
  1912. 'thousand_separator' => ', ',  
  1913. 'decimal_separator' => '.',  
  1914. 'decimals' => 2,  
  1915. 'american_express' => false 
  1916. ),  
  1917. 'PGK' => array( 
  1918. 'name' => __( 'Papua New Guinean Kina', 'gravity-forms-stripe' ),  
  1919. 'symbol_left' => '',  
  1920. 'symbol_right' => 'PGK',  
  1921. 'symbol_padding' => ' ',  
  1922. 'thousand_separator' => ', ',  
  1923. 'decimal_separator' => '.',  
  1924. 'decimals' => 2,  
  1925. 'american_express' => true 
  1926. ),  
  1927. 'PHP' => array( 
  1928. 'name' => __( 'Philippine Peso', 'gravity-forms-stripe' ),  
  1929. 'symbol_left' => '₱',  
  1930. 'symbol_right' => '',  
  1931. 'symbol_padding' => ' ',  
  1932. 'thousand_separator' => ', ',  
  1933. 'decimal_separator' => '.',  
  1934. 'decimals' => 2,  
  1935. 'american_express' => true 
  1936. ),  
  1937. 'PKR' => array( 
  1938. 'name' => __( 'Pakistani Rupee', 'gravity-forms-stripe' ),  
  1939. 'symbol_left' => '',  
  1940. 'symbol_right' => 'PKR',  
  1941. 'symbol_padding' => ' ',  
  1942. 'thousand_separator' => ', ',  
  1943. 'decimal_separator' => '.',  
  1944. 'decimals' => 2,  
  1945. 'american_express' => true 
  1946. ),  
  1947. 'PLN' => array( 
  1948. 'name' => __( 'Polish Z*oty', 'gravity-forms-stripe' ),  
  1949. 'symbol_left' => 'zł',  
  1950. 'symbol_right' => '',  
  1951. 'symbol_padding' => ' ',  
  1952. 'thousand_separator' => '.',  
  1953. 'decimal_separator' => ', ',  
  1954. 'decimals' => 2,  
  1955. 'american_express' => true 
  1956. ),  
  1957. 'PYG' => array( 
  1958. 'name' => __( 'Paraguayan Guaran', 'gravity-forms-stripe' ),  
  1959. 'symbol_left' => '',  
  1960. 'symbol_right' => 'PYG',  
  1961. 'symbol_padding' => ' ',  
  1962. 'thousand_separator' => ', ',  
  1963. 'decimal_separator' => '.',  
  1964. 'decimals' => 0,  
  1965. 'american_express' => false 
  1966. ),  
  1967. 'QAR' => array( 
  1968. 'name' => __( 'Qatari Riyal', 'gravity-forms-stripe' ),  
  1969. 'symbol_left' => '',  
  1970. 'symbol_right' => 'QAR',  
  1971. 'symbol_padding' => ' ',  
  1972. 'thousand_separator' => ', ',  
  1973. 'decimal_separator' => '.',  
  1974. 'decimals' => 2,  
  1975. 'american_express' => true 
  1976. ),  
  1977. 'RON' => array( 
  1978. 'name' => __( 'Romanian Leu', 'gravity-forms-stripe' ),  
  1979. 'symbol_left' => '',  
  1980. 'symbol_right' => 'RON',  
  1981. 'symbol_padding' => ' ',  
  1982. 'thousand_separator' => ', ',  
  1983. 'decimal_separator' => '.',  
  1984. 'decimals' => 2,  
  1985. 'american_express' => true 
  1986. ),  
  1987. 'RSD' => array( 
  1988. 'name' => __( 'Serbian Dinar', 'gravity-forms-stripe' ),  
  1989. 'symbol_left' => '',  
  1990. 'symbol_right' => 'RSD',  
  1991. 'symbol_padding' => ' ',  
  1992. 'thousand_separator' => ', ',  
  1993. 'decimal_separator' => '.',  
  1994. 'decimals' => 2,  
  1995. 'american_express' => true 
  1996. ),  
  1997. 'RUB' => array( 
  1998. 'name' => __( 'Russian Ruble', 'gravity-forms-stripe' ),  
  1999. 'symbol_left' => '',  
  2000. 'symbol_right' => 'RUB',  
  2001. 'symbol_padding' => ' ',  
  2002. 'thousand_separator' => ', ',  
  2003. 'decimal_separator' => '.',  
  2004. 'decimals' => 2,  
  2005. 'american_express' => true 
  2006. ),  
  2007. 'RWF' => array( 
  2008. 'name' => __( 'Rwandan Franc', 'gravity-forms-stripe' ),  
  2009. 'symbol_left' => '',  
  2010. 'symbol_right' => 'RWF',  
  2011. 'symbol_padding' => ' ',  
  2012. 'thousand_separator' => ', ',  
  2013. 'decimal_separator' => '.',  
  2014. 'decimals' => 0,  
  2015. 'american_express' => true 
  2016. ),  
  2017. 'SAR' => array( 
  2018. 'name' => __( 'Saudi Riyal', 'gravity-forms-stripe' ),  
  2019. 'symbol_left' => '',  
  2020. 'symbol_right' => 'SAR',  
  2021. 'symbol_padding' => ' ',  
  2022. 'thousand_separator' => ', ',  
  2023. 'decimal_separator' => '.',  
  2024. 'decimals' => 2,  
  2025. 'american_express' => true 
  2026. ),  
  2027. 'SBD' => array( 
  2028. 'name' => __( 'Solomon Islands Dollar', 'gravity-forms-stripe' ),  
  2029. 'symbol_left' => '',  
  2030. 'symbol_right' => 'SBD',  
  2031. 'symbol_padding' => ' ',  
  2032. 'thousand_separator' => ', ',  
  2033. 'decimal_separator' => '.',  
  2034. 'decimals' => 2,  
  2035. 'american_express' => true 
  2036. ),  
  2037. 'SCR' => array( 
  2038. 'name' => __( 'Seychellois Rupee', 'gravity-forms-stripe' ),  
  2039. 'symbol_left' => '',  
  2040. 'symbol_right' => 'SCR',  
  2041. 'symbol_padding' => ' ',  
  2042. 'thousand_separator' => ', ',  
  2043. 'decimal_separator' => '.',  
  2044. 'decimals' => 2,  
  2045. 'american_express' => true 
  2046. ),  
  2047. 'SEK' => array( 
  2048. 'name' => __( 'Swedish Krona', 'gravity-forms-stripe' ),  
  2049. 'symbol_left' => '',  
  2050. 'symbol_right' => 'kr',  
  2051. 'symbol_padding' => ' ',  
  2052. 'thousand_separator' => ' ',  
  2053. 'decimal_separator' => ', ',  
  2054. 'decimals' => 2,  
  2055. 'american_express' => true 
  2056. ),  
  2057. 'SGD' => array( 
  2058. 'name' => __( 'Singapore Dollar', 'gravity-forms-stripe' ),  
  2059. 'symbol_left' => 'S$',  
  2060. 'symbol_right' => '',  
  2061. 'symbol_padding' => ' ',  
  2062. 'thousand_separator' => ', ',  
  2063. 'decimal_separator' => '.',  
  2064. 'decimals' => 2,  
  2065. 'american_express' => true 
  2066. ),  
  2067. 'SHP' => array( 
  2068. 'name' => __( 'Saint Helenian Pound', 'gravity-forms-stripe' ),  
  2069. 'symbol_left' => '',  
  2070. 'symbol_right' => 'SHP',  
  2071. 'symbol_padding' => ' ',  
  2072. 'thousand_separator' => ', ',  
  2073. 'decimal_separator' => '.',  
  2074. 'decimals' => 2,  
  2075. 'american_express' => false 
  2076. ),  
  2077. 'SLL' => array( 
  2078. 'name' => __( 'Sierra Leonean Leone', 'gravity-forms-stripe' ),  
  2079. 'symbol_left' => '',  
  2080. 'symbol_right' => 'SLL',  
  2081. 'symbol_padding' => ' ',  
  2082. 'thousand_separator' => ', ',  
  2083. 'decimal_separator' => '.',  
  2084. 'decimals' => 2,  
  2085. 'american_express' => true 
  2086. ),  
  2087. 'SOS' => array( 
  2088. 'name' => __( 'Somali Shilling', 'gravity-forms-stripe' ),  
  2089. 'symbol_left' => '',  
  2090. 'symbol_right' => 'SOS',  
  2091. 'symbol_padding' => ' ',  
  2092. 'thousand_separator' => ', ',  
  2093. 'decimal_separator' => '.',  
  2094. 'decimals' => 2,  
  2095. 'american_express' => true 
  2096. ),  
  2097. 'SRD' => array( 
  2098. 'name' => __( 'Surinamese Dollar', 'gravity-forms-stripe' ),  
  2099. 'symbol_left' => '',  
  2100. 'symbol_right' => 'SRD',  
  2101. 'symbol_padding' => ' ',  
  2102. 'thousand_separator' => ', ',  
  2103. 'decimal_separator' => '.',  
  2104. 'decimals' => 2,  
  2105. 'american_express' => false 
  2106. ),  
  2107. 'STD' => array( 
  2108. 'name' => __( 'So Tom and Prncipe Dobra', 'gravity-forms-stripe' ),  
  2109. 'symbol_left' => '',  
  2110. 'symbol_right' => 'STD',  
  2111. 'symbol_padding' => ' ',  
  2112. 'thousand_separator' => ', ',  
  2113. 'decimal_separator' => '.',  
  2114. 'decimals' => 2,  
  2115. 'american_express' => true 
  2116. ),  
  2117. 'SVC' => array( 
  2118. 'name' => __( 'Salvadoran Coln', 'gravity-forms-stripe' ),  
  2119. 'symbol_left' => '',  
  2120. 'symbol_right' => 'SVC',  
  2121. 'symbol_padding' => ' ',  
  2122. 'thousand_separator' => ', ',  
  2123. 'decimal_separator' => '.',  
  2124. 'decimals' => 2,  
  2125. 'american_express' => false 
  2126. ),  
  2127. 'SZL' => array( 
  2128. 'name' => __( 'Swazi Lilangeni', 'gravity-forms-stripe' ),  
  2129. 'symbol_left' => '',  
  2130. 'symbol_right' => 'SZL',  
  2131. 'symbol_padding' => ' ',  
  2132. 'thousand_separator' => ', ',  
  2133. 'decimal_separator' => '.',  
  2134. 'decimals' => 2,  
  2135. 'american_express' => true 
  2136. ),  
  2137. 'THB' => array( 
  2138. 'name' => __( 'Thai Baht', 'gravity-forms-stripe' ),  
  2139. 'symbol_left' => '฿',  
  2140. 'symbol_right' => '',  
  2141. 'symbol_padding' => ' ',  
  2142. 'thousand_separator' => ', ',  
  2143. 'decimal_separator' => '.',  
  2144. 'decimals' => 2,  
  2145. 'american_express' => true 
  2146. ),  
  2147. 'TJS' => array( 
  2148. 'name' => __( 'Tajikistani Somoni', 'gravity-forms-stripe' ),  
  2149. 'symbol_left' => '',  
  2150. 'symbol_right' => 'TJS',  
  2151. 'symbol_padding' => ' ',  
  2152. 'thousand_separator' => ', ',  
  2153. 'decimal_separator' => '.',  
  2154. 'decimals' => 2,  
  2155. 'american_express' => true 
  2156. ),  
  2157. 'TOP' => array( 
  2158. 'name' => __( 'Tongan Pa*anga', 'gravity-forms-stripe' ),  
  2159. 'symbol_left' => '',  
  2160. 'symbol_right' => 'TOP',  
  2161. 'symbol_padding' => ' ',  
  2162. 'thousand_separator' => ', ',  
  2163. 'decimal_separator' => '.',  
  2164. 'decimals' => 2,  
  2165. 'american_express' => true 
  2166. ),  
  2167. 'TRY' => array( 
  2168. 'name' => __( 'Turkish Lira', 'gravity-forms-stripe' ),  
  2169. 'symbol_left' => '',  
  2170. 'symbol_right' => 'TRY',  
  2171. 'symbol_padding' => ' ',  
  2172. 'thousand_separator' => ', ',  
  2173. 'decimal_separator' => '.',  
  2174. 'decimals' => 2,  
  2175. 'american_express' => true 
  2176. ),  
  2177. 'TTD' => array( 
  2178. 'name' => __( 'Trinidad and Tobago Dollar', 'gravity-forms-stripe' ),  
  2179. 'symbol_left' => '',  
  2180. 'symbol_right' => 'TTD',  
  2181. 'symbol_padding' => ' ',  
  2182. 'thousand_separator' => ', ',  
  2183. 'decimal_separator' => '.',  
  2184. 'decimals' => 2,  
  2185. 'american_express' => true 
  2186. ),  
  2187. 'TWD' => array( 
  2188. 'name' => __( 'New Taiwan Dollar', 'gravity-forms-stripe' ),  
  2189. 'symbol_left' => 'NT$',  
  2190. 'symbol_right' => '',  
  2191. 'symbol_padding' => ' ',  
  2192. 'thousand_separator' => ', ',  
  2193. 'decimal_separator' => '.',  
  2194. 'decimals' => 2,  
  2195. 'american_express' => true 
  2196. ),  
  2197. 'TZS' => array( 
  2198. 'name' => __( 'Tanzanian Shilling', 'gravity-forms-stripe' ),  
  2199. 'symbol_left' => '',  
  2200. 'symbol_right' => 'TZS',  
  2201. 'symbol_padding' => ' ',  
  2202. 'thousand_separator' => ', ',  
  2203. 'decimal_separator' => '.',  
  2204. 'decimals' => 2,  
  2205. 'american_express' => true 
  2206. ),  
  2207. 'UAH' => array( 
  2208. 'name' => __( 'Ukrainian Hryvnia', 'gravity-forms-stripe' ),  
  2209. 'symbol_left' => '',  
  2210. 'symbol_right' => 'UAH',  
  2211. 'symbol_padding' => ' ',  
  2212. 'thousand_separator' => ', ',  
  2213. 'decimal_separator' => '.',  
  2214. 'decimals' => 2,  
  2215. 'american_express' => true 
  2216. ),  
  2217. 'UGX' => array( 
  2218. 'name' => __( 'Ugandan Shilling', 'gravity-forms-stripe' ),  
  2219. 'symbol_left' => '',  
  2220. 'symbol_right' => 'UGX',  
  2221. 'symbol_padding' => ' ',  
  2222. 'thousand_separator' => ', ',  
  2223. 'decimal_separator' => '.',  
  2224. 'decimals' => 2,  
  2225. 'american_express' => true 
  2226. ),  
  2227. 'UYU' => array( 
  2228. 'name' => __( 'Uruguayan Peso', 'gravity-forms-stripe' ),  
  2229. 'symbol_left' => '',  
  2230. 'symbol_right' => 'UYU',  
  2231. 'symbol_padding' => ' ',  
  2232. 'thousand_separator' => ', ',  
  2233. 'decimal_separator' => '.',  
  2234. 'decimals' => 2,  
  2235. 'american_express' => true 
  2236. ),  
  2237. 'UZS' => array( 
  2238. 'name' => __( 'Uzbekistani Som', 'gravity-forms-stripe' ),  
  2239. 'symbol_left' => '',  
  2240. 'symbol_right' => 'UZS',  
  2241. 'symbol_padding' => ' ',  
  2242. 'thousand_separator' => ', ',  
  2243. 'decimal_separator' => '.',  
  2244. 'decimals' => 2,  
  2245. 'american_express' => true 
  2246. ),  
  2247. 'VEF' => array( 
  2248. 'name' => __( 'Venezuelan Bolvar', 'gravity-forms-stripe' ),  
  2249. 'symbol_left' => '',  
  2250. 'symbol_right' => 'VEF',  
  2251. 'symbol_padding' => ' ',  
  2252. 'thousand_separator' => ', ',  
  2253. 'decimal_separator' => '.',  
  2254. 'decimals' => 2,  
  2255. 'american_express' => false 
  2256. ),  
  2257. 'VND' => array( 
  2258. 'name' => __( 'Vietnamese **ng', 'gravity-forms-stripe' ),  
  2259. 'symbol_left' => '',  
  2260. 'symbol_right' => 'VND',  
  2261. 'symbol_padding' => ' ',  
  2262. 'thousand_separator' => ', ',  
  2263. 'decimal_separator' => '.',  
  2264. 'decimals' => 2,  
  2265. 'american_express' => true 
  2266. ),  
  2267. 'VUV' => array( 
  2268. 'name' => __( 'Vanuatu Vatu', 'gravity-forms-stripe' ),  
  2269. 'symbol_left' => '',  
  2270. 'symbol_right' => 'VUV',  
  2271. 'symbol_padding' => ' ',  
  2272. 'thousand_separator' => ', ',  
  2273. 'decimal_separator' => '.',  
  2274. 'decimals' => 0,  
  2275. 'american_express' => true 
  2276. ),  
  2277. 'WST' => array( 
  2278. 'name' => __( 'Samoan Tala', 'gravity-forms-stripe' ),  
  2279. 'symbol_left' => '',  
  2280. 'symbol_right' => 'WST',  
  2281. 'symbol_padding' => ' ',  
  2282. 'thousand_separator' => ', ',  
  2283. 'decimal_separator' => '.',  
  2284. 'decimals' => 2,  
  2285. 'american_express' => true 
  2286. ),  
  2287. 'XAF' => array( 
  2288. 'name' => __( 'Central African Cfa Franc', 'gravity-forms-stripe' ),  
  2289. 'symbol_left' => '',  
  2290. 'symbol_right' => 'XAF',  
  2291. 'symbol_padding' => ' ',  
  2292. 'thousand_separator' => ', ',  
  2293. 'decimal_separator' => '.',  
  2294. 'decimals' => 0,  
  2295. 'american_express' => true 
  2296. ),  
  2297. 'XCD' => array( 
  2298. 'name' => __( 'East Caribbean Dollar', 'gravity-forms-stripe' ),  
  2299. 'symbol_left' => '',  
  2300. 'symbol_right' => 'XCD',  
  2301. 'symbol_padding' => ' ',  
  2302. 'thousand_separator' => ', ',  
  2303. 'decimal_separator' => '.',  
  2304. 'decimals' => 2,  
  2305. 'american_express' => true 
  2306. ),  
  2307. 'XOF' => array( 
  2308. 'name' => __( 'West African Cfa Franc', 'gravity-forms-stripe' ),  
  2309. 'symbol_left' => '',  
  2310. 'symbol_right' => 'XOF',  
  2311. 'symbol_padding' => ' ',  
  2312. 'thousand_separator' => ', ',  
  2313. 'decimal_separator' => '.',  
  2314. 'decimals' => 0,  
  2315. 'american_express' => false 
  2316. ),  
  2317. 'XPF' => array( 
  2318. 'name' => __( 'Cfp Franc', 'gravity-forms-stripe' ),  
  2319. 'symbol_left' => '',  
  2320. 'symbol_right' => 'XPF',  
  2321. 'symbol_padding' => ' ',  
  2322. 'thousand_separator' => ', ',  
  2323. 'decimal_separator' => '.',  
  2324. 'decimals' => 0,  
  2325. 'american_express' => false 
  2326. ),  
  2327. 'YER' => array( 
  2328. 'name' => __( 'Yemeni Rial', 'gravity-forms-stripe' ),  
  2329. 'symbol_left' => '',  
  2330. 'symbol_right' => 'YER',  
  2331. 'symbol_padding' => ' ',  
  2332. 'thousand_separator' => ', ',  
  2333. 'decimal_separator' => '.',  
  2334. 'decimals' => 2,  
  2335. 'american_express' => true 
  2336. ),  
  2337. 'ZAR' => array( 
  2338. 'name' => __( 'South African Rand', 'gravity-forms-stripe' ),  
  2339. 'symbol_left' => '',  
  2340. 'symbol_right' => 'ZAR',  
  2341. 'symbol_padding' => ' ',  
  2342. 'thousand_separator' => ', ',  
  2343. 'decimal_separator' => '.',  
  2344. 'decimals' => 2,  
  2345. 'american_express' => true 
  2346. ),  
  2347. 'ZMW' => array( 
  2348. 'name' => __( 'Zambian Kwacha', 'gravity-forms-stripe' ),  
  2349. 'symbol_left' => '',  
  2350. 'symbol_right' => 'ZMW',  
  2351. 'symbol_padding' => ' ',  
  2352. 'thousand_separator' => ', ',  
  2353. 'decimal_separator' => '.',  
  2354. 'decimals' => 2,  
  2355. 'american_express' => true 
  2356. ); 
  2357.  
  2358. //------------------------------------------------------ 
  2359. //------------- SETTINGS PAGE -------------------------- 
  2360. //------------------------------------------------------ 
  2361.  
  2362. /** 
  2363. * Render settings page 
  2364. * @since 0.1.0 
  2365. * @uses check_admin_referer() 
  2366. * @uses GFP_Stripe::uninstall() 
  2367. * @uses _e() 
  2368. * @uses rgpost() 
  2369. * @uses apply_filters() 
  2370. * @uses update_option() 
  2371. * @uses get_option() 
  2372. * @uses delete_option() 
  2373. * @uses has_filter() 
  2374. * @uses wp_nonce_field() 
  2375. * @uses gform_tooltip() 
  2376. * @uses GFPMoreStripe::get_slug() 
  2377. * @uses GFPMoreStripe::get_version() 
  2378. * @uses GFPMoreStripeUpgrade::get_version_info() 
  2379. * @uses GFCommon::get_base_url() 
  2380. * @uses rgar() 
  2381. * @uses esc_attr() 
  2382. * @uses GFP_Stripe::get_base_url() 
  2383. * @uses do_action() 
  2384. * @uses GFCommon::current_user_can_any() 
  2385. * @uses __() 
  2386. * @return void 
  2387. */ 
  2388. public function settings_page() { 
  2389. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  2390. wp_enqueue_script( 'gfp_stripe_settings_page_js', trailingslashit( GFP_STRIPE_URL ) . "js/settings-page{$suffix}.js", array( 'jquery' ), GFP_Stripe::get_version() ); 
  2391. $js_vars = array( 
  2392. 'baseURL' => GFCommon::get_base_url(),  
  2393. 'status_message' => __( 'Signing Up...', 'gravity-forms-stripe' ),  
  2394. 'nonce' => wp_create_nonce( 'gfp_stripe_updates_sign_up' ),  
  2395. 'blank_email_message' => __( 'Please enter an email address', 'gravity-forms-stripe' ),  
  2396. 'success_message' => __( 'All Set!', 'gravity-forms-stripe' ) 
  2397. ); 
  2398. wp_localize_script( 'gfp_stripe_settings_page_js', 'gfp_stripe_settings_page_vars', $js_vars ); 
  2399.  
  2400. if ( isset( $_POST[ 'uninstall' ] ) ) { 
  2401. check_admin_referer( 'uninstall', 'gfp_stripe_uninstall' ); 
  2402. $this->uninstall(); 
  2403.  
  2404. ?> 
  2405. <div class="updated fade" 
  2406. style="padding:20px;"><?php echo sprintf( __( "Gravity Forms Stripe Add-On has been successfully uninstalled. It can be re-activated from the %splugins page%s.", 'gravity-forms-stripe' ), "<a href='plugins.php'>", "</a>" ); ?></div> 
  2407. <?php 
  2408. return; 
  2409. } else if ( isset( $_POST[ 'gfp_stripe_submit' ] ) ) { 
  2410. check_admin_referer( 'update', 'gfp_stripe_update' ); 
  2411. $settings = array( 
  2412. 'test_secret_key' => trim( rgpost( 'gfp_stripe_test_secret_key' ) ),  
  2413. 'test_publishable_key' => trim( rgpost( 'gfp_stripe_test_publishable_key' ) ),  
  2414. 'live_secret_key' => trim( rgpost( 'gfp_stripe_live_secret_key' ) ),  
  2415. 'live_publishable_key' => trim( rgpost( 'gfp_stripe_live_publishable_key' ) ),  
  2416. 'mode' => rgpost( 'gfp_stripe_mode' ),  
  2417. 'do_usage_stats' => rgpost( 'gfp_stripe_do_usage_stats' ) 
  2418. ); 
  2419. $settings = apply_filters( 'gfp_stripe_save_settings', $settings ); 
  2420.  
  2421.  
  2422. update_option( 'gfp_stripe_settings', $settings ); 
  2423. $usage_event_option = get_option( 'gfp_stripe_usage_events' ); 
  2424. if ( empty( $usage_event_option ) ) { 
  2425. add_option( 'gfp_stripe_usage_events' ); 
  2426.  
  2427. $gfp_support_key = get_option( 'gfp_support_key' ); 
  2428. $key = rgpost( 'gfp_support_key' ); 
  2429. if ( empty( $key ) ) { 
  2430. delete_option( 'gfp_support_key' ); 
  2431. } else if ( $gfp_support_key != $key ) { 
  2432. $key = md5( trim( $key ) ); 
  2433. update_option( 'gfp_support_key', $key ); 
  2434.  
  2435. delete_transient( 'gfp_stripe_currency' ); 
  2436. if ( ! empty( $settings[ 'test_secret_key' ] ) ) { 
  2437. update_option( 'rg_gforms_currency', $this->gform_currency( get_option( 'rg_gforms_currency' ) ) ); 
  2438. } else if ( has_filter( 'gfp_stripe_settings_page_action' ) ) { 
  2439. $do_return = ''; 
  2440. $do_return = apply_filters( 'gfp_stripe_settings_page_action', $do_return ); 
  2441. if ( $do_return ) { 
  2442. return; 
  2443.  
  2444. $settings = get_option( 'gfp_stripe_settings' ); 
  2445. $gfp_support_key = get_option( 'gfp_support_key' ); 
  2446. if ( ! empty( $settings ) ) { 
  2447. $is_valid = $this->is_valid_key(); 
  2448. } else { 
  2449. $is_valid = array(); 
  2450.  
  2451. ?> 
  2452.  
  2453. <form method="post" action=""> 
  2454. <?php wp_nonce_field( 'update', 'gfp_stripe_update' ) ?> 
  2455.  
  2456. <h3><span class="icon-stripe"></span><?php _e( ' Stripe Settings', 'gravity-forms-stripe' ); ?></h3> 
  2457.  
  2458. <!--<div class="hr-divider"></div>--> 
  2459. <table id="support-license-key" class="form-table"> 
  2460. <tbody> 
  2461. <tr valign="top"> 
  2462. <th scope="row"> 
  2463. <label 
  2464. for="gfp_support_key"><?php _e( "gravity+ Support License Key", "gfp-stripe" ); ?></label> <?php gform_tooltip( 'stripe_support_license_key' ) ?> 
  2465. </th> 
  2466. <td> 
  2467. <?php 
  2468.  
  2469. $key_field = '<input type="password" ' . ( class_exists( 'GFPMoreStripeUpgrade' ) ? '' : 'disabled' ) . ' name="gfp_support_key" id="gfp_support_key" value="' . ( empty( $gfp_support_key ) ? '' : $gfp_support_key ) . '" />'; 
  2470. $valid_icon = " <span class='dashicons dashicons-yes gf_keystatus_valid valid_credentials' alt='valid key' title='valid key'></span>"; 
  2471. $invalid_icon = " <span class='dashicons dashicons-no gf_keystatus_invalid invalid_credentials' alt='invalid key' title='invalid key'></span>"; 
  2472. if ( class_exists( 'GFPMoreStripeUpgrade' ) ) { 
  2473. $version_info = GFPMoreStripeUpgrade::get_version_info( GFPMoreStripe::get_slug(), $gfp_support_key, GFPMoreStripe::get_version(), ( isset( $_POST[ "gfp_stripe_submit" ] ) ? false : true ) ); 
  2474. if ( $version_info[ 'is_valid_key' ] ) { 
  2475. $key_field .= $valid_icon; 
  2476. } else if ( ! empty( $gfp_support_key ) ) { 
  2477. $key_field .= $invalid_icon; 
  2478. echo $key_field; 
  2479. ?> 
  2480. <br/> 
  2481. <?php echo sprintf( __( "The license key is used for access to %s+(More) Stripe%s automatic upgrades and support. Activate +(More) Stripe to enter your license key.", 'gravity-forms-stripe' ), "<a href='https://gravityplus.pro' target='_blank'>", "</a>" ); ?> 
  2482. </td> 
  2483. </tr> 
  2484. </tbody> 
  2485. </table> 
  2486.  
  2487. <div class="settings-section account-information setup" data-toggle="account-information-settings"> 
  2488. <h3> 
  2489. <span><i class="fa fa-plus-square-o"></i> 
  2490. <i class="fa fa-plus-square"></i> 
  2491. <i class="fa fa-minus-square"></i> 
  2492. </span> 
  2493. <?php _e( 'Stripe Account Information', 'gravity-forms-stripe' ) ?></h3> 
  2494. </div> 
  2495. <div class="account-information-settings hidden"> 
  2496. <p style="text-align: left;"> 
  2497. <?php echo sprintf( __( "Stripe is a payment gateway for merchants. Use Gravity Forms to collect payment information and automatically integrate to your client's Stripe account. If you don't have a Stripe account, you can %ssign up for one here%s", 'gravity-forms-stripe' ), "<a href='http://www.stripe.com' target='_blank'>", "</a>" ) ?> 
  2498. </p> 
  2499. <table class="form-table"> 
  2500.  
  2501. <tr> 
  2502. <th scope="row" nowrap="nowrap"><label 
  2503. for="gfp_stripe_mode"><?php _e( 'API Mode', 'gravity-forms-stripe' ); ?> <?php gform_tooltip( 'stripe_api' ) ?></label> 
  2504. </th> 
  2505. <td width="88%"> 
  2506. <input type="radio" name="gfp_stripe_mode" id="gfp_stripe_mode_live" 
  2507. value="live" <?php echo rgar( $settings, 'mode' ) != 'test' ? "checked='checked'" : '' ?>/> 
  2508. <label class="inline" 
  2509. for="gfp_stripe_mode_live"><?php _e( 'Live', 'gravity-forms-stripe' ); ?></label> 
  2510.     <input type="radio" name="gfp_stripe_mode" id="gfp_stripe_mode_test" 
  2511. value="test" <?php echo 'test' == rgar( $settings, 'mode' ) ? "checked='checked'" : '' ?>/> 
  2512. <label class="inline" 
  2513. for="gfp_stripe_mode_test"><?php _e( 'Test', 'gravity-forms-stripe' ); ?></label> 
  2514. </td> 
  2515. </tr> 
  2516. <tr> 
  2517. <td colspan='2'> 
  2518. <p><?php echo sprintf( __( "You can find your <strong>Stripe API keys</strong> needed below in your Stripe dashboard 'Account Settings' %shere%s", 'gravity-forms-stripe' ), "<a href='https://dashboard.stripe.com/account/apikeys' target='_blank'>", "</a>" ); ?></p> 
  2519. </td> 
  2520. </tr> 
  2521. <tr> 
  2522. <th scope="row" nowrap="nowrap"><label 
  2523. for="gfp_stripe_test_secret_key"><?php _e( 'Test Secret Key', 'gravity-forms-stripe' ); ?> <?php gform_tooltip( 'stripe_test_secret_key' ) ?></label> 
  2524. </th> 
  2525. <td width="88%"> 
  2526. <input class="size-1" id="gfp_stripe_test_secret_key" name="gfp_stripe_test_secret_key" 
  2527. value="<?php echo trim( esc_attr( rgar( $settings, 'test_secret_key' ) ) ) ?>"/> 
  2528. <?php echo ( array_key_exists( 1, $is_valid ) ) ? ( $is_valid[ 1 ][ 'test_secret_key' ] ? $valid_icon : $invalid_icon ) : $invalid_icon ?> 
  2529. <br/> 
  2530. </td> 
  2531. </tr> 
  2532. <tr> 
  2533. <th scope="row" nowrap="nowrap"><label 
  2534. for="gfp_stripe_test_publishable_key"><?php _e( 'Test Publishable Key', 'gravity-forms-stripe' ); ?> <?php gform_tooltip( 'stripe_test_publishable_key' ) ?></label> 
  2535. </th> 
  2536. <td width="88%"> 
  2537. <input class="size-1" id="gfp_stripe_test_publishable_key" 
  2538. name="gfp_stripe_test_publishable_key" 
  2539. value="<?php echo trim( esc_attr( rgar( $settings, 'test_publishable_key' ) ) ) ?>"/> 
  2540. <?php echo ( array_key_exists( 1, $is_valid ) ) ? ( $is_valid[ 1 ][ 'test_publishable_key' ] ? $valid_icon : $invalid_icon ) : $invalid_icon ?> 
  2541. <br/> 
  2542. </td> 
  2543. </tr> 
  2544. <tr> 
  2545. <th scope="row" nowrap="nowrap"><label 
  2546. for="gfp_stripe_live_secret_key"><?php _e( 'Live Secret Key', 'gravity-forms-stripe' ); ?> <?php gform_tooltip( 'stripe_live_secret_key' ) ?></label> 
  2547. </th> 
  2548. <td width="88%"> 
  2549. <input class="size-1" id="gfp_stripe_live_secret_key" name="gfp_stripe_live_secret_key" 
  2550. value="<?php echo trim( esc_attr( rgar( $settings, 'live_secret_key' ) ) ) ?>"/> 
  2551. <?php echo ( array_key_exists( 1, $is_valid ) ) ? ( $is_valid[ 1 ][ 'live_secret_key' ] ? $valid_icon : $invalid_icon ) : $invalid_icon ?> 
  2552. <?php 
  2553. if ( array_key_exists( 1, $is_valid ) && ! $is_valid[ 1 ][ 'live_secret_key' ] && array_key_exists( 2, $is_valid ) && ! empty( $is_valid[ 2 ] ) ) { 
  2554. if ( 'PPP\Stripe\Error\InvalidRequest' == $is_valid[ 2 ][ 'live_secret_key' ][ 0 ] ) { 
  2555. ?> 
  2556. <span class="invalid_credentials invalid_key_error">*You must activate your Stripe account to use this key</span> 
  2557. <?php 
  2558. } else { 
  2559. ?> 
  2560. <span 
  2561. class="invalid_credentials invalid_key_error"><?php echo "{$is_valid[2]['live_secret_key'][0]}: {$is_valid[2]['live_secret_key'][1]}"; ?></span> 
  2562. <?php 
  2563. ?> 
  2564. <br/> 
  2565. </td> 
  2566. </tr> 
  2567. <tr> 
  2568. <th scope="row" nowrap="nowrap"><label 
  2569. for="gfp_stripe_live_publishable_key"><?php _e( 'Live Publishable Key', 'gravity-forms-stripe' ); ?> <?php gform_tooltip( 'stripe_live_publishable_key' ) ?></label> 
  2570. </th> 
  2571. <td width="88%"> 
  2572. <input class="size-1" id="gfp_stripe_live_publishable_key" 
  2573. name="gfp_stripe_live_publishable_key" 
  2574. value="<?php echo trim( esc_attr( rgar( $settings, 'live_publishable_key' ) ) ) ?>"/> 
  2575. <?php echo ( array_key_exists( 1, $is_valid ) ) ? ( $is_valid[ 1 ][ 'live_publishable_key' ] ? $valid_icon : $invalid_icon ) : $invalid_icon ?> 
  2576. <?php 
  2577. if ( array_key_exists( 1, $is_valid ) && ! $is_valid[ 1 ][ 'live_publishable_key' ] && array_key_exists( 2, $is_valid ) && ! empty( $is_valid[ 2 ] ) ) { 
  2578. if ( 'PPP\Stripe\Error\InvalidRequest' == $is_valid[ 2 ][ 'live_publishable_key' ][ 0 ] ) { 
  2579. ?> 
  2580. <span class="invalid_credentials invalid_key_error">*You must activate your Stripe account to use this key</span> 
  2581. <?php 
  2582. } else { 
  2583. ?> 
  2584. <span 
  2585. class="invalid_credentials invalid_key_error"><?php echo "{$is_valid[2]['live_publishable_key'][0]}: {$is_valid[2]['live_publishable_key'][1]}"; ?></span> 
  2586. <?php 
  2587. ?> 
  2588. <br/> 
  2589. </td> 
  2590. </tr> 
  2591. </table> 
  2592. <br/> 
  2593.  
  2594. <div class="push-alert-green"> 
  2595. <p> 
  2596. <span class="strong"> 
  2597. <?php _e( "Broken and difficult to use plugins suck! ", 'gravity-forms-stripe' ); 
  2598. ?> 
  2599. </span> 
  2600. <?php _e( "But that doesn't have to be your experience. ", 'gravity-forms-stripe' ); 
  2601. ?> 
  2602. </p> 
  2603.  
  2604. <p> 
  2605. <span class="strong"> 
  2606. <?php printf( __( 'Enable completely anonymous usage stats, ', 'gravity-forms-stripe' ) ); 
  2607. ?> 
  2608. </span> 
  2609. <?php _e( "so I know which themes, plugins,  
  2610. and configurations to test with to keep your site working!", 'gravity-forms-stripe' ); 
  2611. ?> 
  2612. </p> 
  2613. </div> 
  2614. <table class="form-table"> 
  2615. <tr> 
  2616. <td width="88%"> 
  2617. <input type="checkbox" name="gfp_stripe_do_usage_stats" id="gfp_stripe_do_usage_stats" 
  2618. value="true" <?php checked( true, rgar( $settings, 'do_usage_stats' ) || rgar( $settings, 'do_presstrends' ), true ) ?>/> 
  2619. <label class="inline" 
  2620. for="gfp_stripe_do_usage_stats"><?php _e( 'Yes, I want to make sure this plugin works on my site (and <span style="color: #07a501; font-weight: bold;">receive 10% off any gravity+ service</span>).', 'gravity-forms-stripe' ); ?></label> 
  2621.     
  2622. </td> 
  2623. </tr> 
  2624. </table> 
  2625. </div> 
  2626. <?php 
  2627. do_action( 'gfp_stripe_settings_page', $settings ); 
  2628. ?> 
  2629. <p class="submit" style="text-align: left;"> 
  2630. <input type="submit" name="gfp_stripe_submit" class="button-primary" 
  2631. value="<?php _e( 'Save Settings', 'gravity-forms-stripe' ) ?>"/> 
  2632. </p> 
  2633. </form> 
  2634. <?php if ( ! class_exists( 'GFPMoreStripe' ) ) { ?> 
  2635. <div class="settings-section review setup"> 
  2636. <h3> 
  2637. <div class="dashicons dashicons-star-filled"></div> 
  2638. <?php echo sprintf( __( '%sRate this plugin%s', 'gravity-forms-stripe' ), "<a href='http://wordpress.org/support/view/plugin-reviews/gravity-forms-stripe' target='_blank'>", '</a>' ) ?> 
  2639. </h3> 
  2640. </div> 
  2641. <div class="settings-section email-updates setup"> 
  2642. <?php add_thickbox(); ?> 
  2643. <h3> 
  2644. <div class="dashicons dashicons-email-alt"></div> 
  2645. <?php echo sprintf( __( '%sGet important updates%s', 'gravity-forms-stripe' ), "<a href='#TB_inline?width=375&inlineId=gfp_stripe_sign_up_container' class='thickbox' title='Send Me Updates'>", '</a>' ) ?> 
  2646. </h3> 
  2647. </div> 
  2648. <div id="gfp_stripe_sign_up_container" style="display:none;"> 
  2649. <form id="gfp_stripe_sign_up"> 
  2650. <div id="email-icon" class="dashicons dashicons-email-alt"></div> 
  2651. <p>From time to time, there are important announcements that accompany a new version of the plugin,  
  2652. such as updating your Stripe API. Don*t miss out on anything that can affect your payments.</p> 
  2653. <input type="text" id="gfp_stripe_update_email" name="gfp_stripe_update_email" 
  2654. value="<?php echo get_option( 'admin_email' ); ?>"/> <input id="gfp_stripe_sign_up_submit" 
  2655. type="button" 
  2656. class="button button-large button-primary" 
  2657. value="<?php _e( 'Send Me Updates', 'gravity-forms-stripe' ); ?>"/> 
  2658.  
  2659. <div id="gfp_stripe_sign_up_error_message"></div> 
  2660. </form> 
  2661. </div> 
  2662. <?php } ?> 
  2663. <br/><br/> 
  2664. <div class="settings-section services"> 
  2665. <h3> 
  2666. <div class="service feature-request"> 
  2667. <div class="dashicons dashicons-pressthis"></div> 
  2668. <?php echo sprintf( __( 'Request a %snew feature%s', 'gravity-forms-stripe' ), "<a href='http://gravityplus.pro/support/gravity-forms-stripe/request-feature?utm_source=gravity-forms-stripe&utm_medium=link&utm_content=settings-page&utm_campaign=gravity-forms-stripe' target='_blank'>", '</a>' ) ?> 
  2669. </div> 
  2670. <div class="service help"> 
  2671. <div class="dashicons dashicons-shield-alt"></div> 
  2672. <?php echo sprintf( __( 'Get %sprofessional support%s', 'gravity-forms-stripe' ), "<a href='http://gravityplus.pro/gravity-forms-stripe/get-help?utm_source=gravity-forms-stripe&utm_medium=link&utm_content=settings-page&utm_campaign=gravity-forms-stripe' target='_blank'>", '</a>' ) ?> 
  2673. </div> 
  2674. <div class="service custom-setup"> 
  2675. <div class="dashicons dashicons-hammer"></div> 
  2676. <?php echo sprintf( __( '%sSetup or customize%s for me', 'gravity-forms-stripe' ), "<a href='http://gravityplus.pro/gravity-forms-stripe/custom-setup?utm_source=gravity-forms-stripe&utm_medium=link&utm_content=settings-page&utm_campaign=gravity-forms-stripe' target='_blank'>", '</a>' ) ?> 
  2677. </div> 
  2678. </h3> 
  2679. </div> 
  2680. <?php 
  2681. do_action( 'gfp_stripe_before_uninstall_button', $settings ); 
  2682.  
  2683. if ( ! class_exists( 'GFPMoreStripe' ) ) { 
  2684. ?> 
  2685. <form action="" method="post"> 
  2686. <?php wp_nonce_field( 'uninstall', 'gfp_stripe_uninstall' ) ?> 
  2687. <?php if ( GFCommon::current_user_can_any( 'gfp_stripe_uninstall' ) ) { ?> 
  2688. <div class="hr-divider"></div> 
  2689.  
  2690. <h3><?php _e( 'Uninstall Stripe Add-On', 'gravity-forms-stripe' ) ?></h3> 
  2691. <div 
  2692. class="delete-alert"><?php _e( 'Warning! This operation deletes ALL Stripe Rules.', 'gravity-forms-stripe' ) ?> 
  2693. <?php 
  2694. $uninstall_button = '<input type="submit" name="uninstall" value="' . __( 'Uninstall Stripe Add-On', 'gravity-forms-stripe' ) . '" class="button" onclick="return confirm(\'' . __( "Warning! ALL Stripe Rules will be deleted. This cannot be undone. \'OK\' to delete, \'Cancel\' to stop", 'gravity-forms-stripe' ) . '\');"/>'; 
  2695. echo apply_filters( 'gfp_stripe_uninstall_button', $uninstall_button ); 
  2696. ?> 
  2697. </div> 
  2698. <?php } ?> 
  2699. </form> 
  2700. <?php 
  2701. do_action( 'gfp_stripe_after_uninstall_button' ); 
  2702. ?> 
  2703.  
  2704. <?php 
  2705.  
  2706. /** 
  2707. * Uninstall 
  2708. * @since 
  2709. * @uses GFP_Stripe::has_access() 
  2710. * @uses do_action() 
  2711. * @uses GFP_Stripe_Data::drop_tables() 
  2712. * @uses delete_option() 
  2713. * @uses delete_transient() 
  2714. * @uses deactivate_plugins() 
  2715. * @uses update_option() 
  2716. * @uses get_option() 
  2717. * @return void 
  2718. */ 
  2719. public function uninstall() { 
  2720.  
  2721. if ( ! self::$_this->has_access( 'gfp_stripe_uninstall' ) ) { 
  2722. die( __( 'You don\'t have adequate permission to uninstall the Stripe Add-On.', 'gravity-forms-stripe' ) ); 
  2723.  
  2724. do_action( 'gfp_stripe_uninstall_condition' ); 
  2725.  
  2726. GFP_Stripe_Data::drop_tables(); 
  2727.  
  2728. delete_option( 'gfp_stripe_version' ); 
  2729. delete_option( 'gfp_stripe_settings' ); 
  2730. delete_option( 'gfp_support_key' ); 
  2731. delete_option( 'gfp_stripe_usage_events' ); 
  2732.  
  2733. delete_transient( 'gfp_stripe_currency' ); 
  2734. delete_transient( 'gfp_stripe_usage_stats_cache_data' ); 
  2735.  
  2736. $plugin = plugin_basename( trim( GFP_STRIPE_FILE ) ); 
  2737. deactivate_plugins( $plugin ); 
  2738. update_option( 'recently_activated', array( $plugin => time() ) + (array) get_option( 'recently_activated' ) ); 
  2739.  
  2740. /** 
  2741. * Add feed & settings page tooltips to the list of tooltips 
  2742. * @since 0.1.0 
  2743. * @uses __() 
  2744. * @param $tooltips 
  2745. * @return array 
  2746. */ 
  2747. public function gform_tooltips( $tooltips ) { 
  2748. $stripe_tooltips = array( 
  2749. 'stripe_rule_name' => '<h6>' . __( 'Rule Name', 'gravity-forms-stripe' ) . '</h6>' . __( 'Enter a name to uniquely identify this Stripe rule.', 'gravity-forms-stripe' ),  
  2750. 'stripe_transaction_type' => '<h6>' . __( 'Transaction Type', 'gravity-forms-stripe' ) . '</h6>' . __( 'Select which Stripe transaction type should be used. One-Time Payments, Subscription, or Billing Info Update.', 'gravity-forms-stripe' ),  
  2751. 'stripe_gravity_form' => '<h6>' . __( 'Gravity Form', 'gravity-forms-stripe' ) . '</h6>' . __( 'Select which Gravity Forms you would like to integrate with Stripe.', 'gravity-forms-stripe' ),  
  2752. 'stripe_customer' => '<h6>' . __( 'Customer', 'gravity-forms-stripe' ) . '</h6>' . __( 'Map your Form Fields to the available Stripe customer information fields.', 'gravity-forms-stripe' ),  
  2753. 'stripe_options' => '<h6>' . __( 'Options', 'gravity-forms-stripe' ) . '</h6>' . __( 'Turn on or off the available Stripe checkout options.', 'gravity-forms-stripe' ),  
  2754. 'stripe_support_license_key' => '<h6>' . __( 'gravity+ Support License Key', 'gravity-forms-stripe' ) . '</h6>' . __( 'Your gravity+ support license key is used to enable automatic updates for +(More) Stripe and receive support.', 'gravity-forms-stripe' ),  
  2755. 'stripe_api' => '<h6>' . __( 'API', 'gravity-forms-stripe' ) . '</h6>' . __( 'Select the Stripe API you would like to use. Select \'Live\' to use your Live API keys. Select \'Test\' to use your Test API keys.', 'gravity-forms-stripe' ),  
  2756. 'stripe_test_secret_key' => '<h6>' . __( 'API Test Secret Key', 'gravity-forms-stripe' ) . '</h6>' . __( 'Enter the API Test Secret Key for your Stripe account.', 'gravity-forms-stripe' ),  
  2757. 'stripe_test_publishable_key' => '<h6>' . __( 'API Test Publishable Key', 'gravity-forms-stripe' ) . '</h6>' . __( 'Enter the API Test Publishable Key for your Stripe account.', 'gravity-forms-stripe' ),  
  2758. 'stripe_live_secret_key' => '<h6>' . __( 'API Live Secret Key', 'gravity-forms-stripe' ) . '</h6>' . __( 'Enter the API Live Secret Key for your Stripe account.', 'gravity-forms-stripe' ),  
  2759. 'stripe_live_publishable_key' => '<h6>' . __( 'API Live Publishable Key', 'gravity-forms-stripe' ) . '</h6>' . __( 'Enter the API Live Publishable Key for your Stripe account.', 'gravity-forms-stripe' ),  
  2760. 'stripe_conditional' => '<h6>' . __( 'Stripe Condition', 'gravity-forms-stripe' ) . '</h6>' . __( 'When the Stripe condition is enabled, form submissions will only be sent to Stripe when the condition is met. When disabled all form submissions will be sent to Stripe.', 'gravity-forms-stripe' ),  
  2761. 'form_field_credit_card_funding_type' => '<h6>' . __( 'Funding Type', 'gravity-forms-stripe' ) . '</h6>' . __( 'Select the funding types you want to accept.', 'gravity-forms-stripe' ) 
  2762.  
  2763. ); 
  2764.  
  2765. return array_merge( $tooltips, $stripe_tooltips ); 
  2766.  
  2767. public function gfp_stripe_updates_sign_up() { 
  2768.  
  2769. check_ajax_referer( 'gfp_stripe_updates_sign_up', 'gfp_stripe_updates_sign_up' ); 
  2770.  
  2771. $email = rgpost( 'email' ); 
  2772. if ( ! is_email( $email ) ) { 
  2773. wp_send_json_error( array( 'error_message' => __( 'Invalid email address', 'gravity-forms-stripe' ) ) ); 
  2774.  
  2775. $api_url = "https://gravityplus.pro/?gpp_action=updates_sign_up&email={$email}"; 
  2776. $user_agent = 'GFP_Stripe/' . self::get_version() . '; ' . get_bloginfo( 'url' ); 
  2777. $args = array( 'user-agent' => $user_agent, 'body' => $email ); 
  2778.  
  2779. $raw_response = wp_remote_post( $api_url, $args ); 
  2780. if ( is_wp_error( $raw_response ) ) { 
  2781. $error_message = $raw_response->get_error_message( $raw_response->get_error_code() ); 
  2782. wp_send_json_error( array( 'error_message' => $error_message ) ); 
  2783. } else { 
  2784. $response = json_decode( wp_remote_retrieve_body( $raw_response ), true ); 
  2785. if ( true == $response[ 'success' ] ) { 
  2786. wp_send_json_success(); 
  2787. } else { 
  2788. wp_send_json_error( array( 'error_message' => $response[ 'error' ] ) ); 
  2789.  
  2790. //------------------------------------------------------ 
  2791. //------------- STRIPE RULES EDIT PAGE ------------------ 
  2792. //------------------------------------------------------ 
  2793.  
  2794. /** 
  2795. */ 
  2796. public function gfp_select_stripe_form() { 
  2797.  
  2798. check_ajax_referer( 'gfp_select_stripe_form', 'gfp_select_stripe_form' ); 
  2799.  
  2800. $type = rgpost( 'type' ); 
  2801. $form_id = intval( rgpost( 'form_id' ) ); 
  2802. $setting_id = intval( rgpost( 'setting_id' ) ); 
  2803.  
  2804. if ( ! empty( $form_id ) ) { 
  2805. $form = RGFormsModel::get_form_meta( $form_id ); 
  2806.  
  2807. $customer_fields = $this->get_customer_information( $form ); 
  2808. $more_endselectform_args = array( 
  2809. 'populate_field_options' => array(),  
  2810. 'post_update_action' => array(),  
  2811. 'show_fields' => array() 
  2812. ); 
  2813. $more_endselectform_args = apply_filters( 'gfp_stripe_feed_endselectform_args', $more_endselectform_args, $form ); 
  2814.  
  2815. $response = array( 
  2816. 'form' => $form,  
  2817. 'customer_fields' => $customer_fields,  
  2818. 'endselectform_args' => $more_endselectform_args 
  2819. ); 
  2820.  
  2821. wp_send_json_success( $response ); 
  2822. } else { 
  2823. wp_send_json_error(); 
  2824.  
  2825. /** 
  2826. */ 
  2827. public function gfp_stripe_update_feed_active() { 
  2828. check_ajax_referer( 'gfp_stripe_update_feed_active', 'gfp_stripe_update_feed_active' ); 
  2829. $feed_id = $_POST[ 'feed_id' ]; 
  2830. $form_id = $_POST[ 'form_id' ]; 
  2831. $is_active = $_POST[ 'is_active' ]; 
  2832.  
  2833. $stripe_form_meta = GFP_Stripe_Data::get_stripe_form_meta( $form_id ); 
  2834. if ( ! isset( $stripe_form_meta[ 'rules' ][ $feed_id ] ) ) { 
  2835. return new WP_Error( 'not_found', __( 'Feed not found', 'gravity-forms-stripe' ) ); 
  2836. $stripe_form_meta[ 'rules' ][ $feed_id ][ 'is_active' ] = (bool) $is_active; 
  2837. $result = GFP_Stripe_Data::update_stripe_form_meta( $form_id, $stripe_form_meta[ 'rules' ], 'rules' ); 
  2838.  
  2839. return $result; 
  2840.  
  2841. /** 
  2842. * @param $form 
  2843. * @param null $feed 
  2844. * @return string 
  2845. */ 
  2846. private function get_customer_information( $form, $feed = null ) { 
  2847.  
  2848. $form_fields = $this->get_form_fields( $form ); 
  2849.  
  2850. $str = "<table cellpadding='0' cellspacing='0'><tr><td class='stripe_col_heading'>" . __( 'Stripe Fields', 'gravity-forms-stripe' ) . "</td><td class='stripe_col_heading'>" . __( 'Form Fields', 'gravity-forms-stripe' ) . '</td></tr>'; 
  2851. $customer_fields = $this->get_customer_fields(); 
  2852. foreach ( $customer_fields as $field ) { 
  2853. $selected_field = $feed ? $feed[ 'meta' ][ 'customer_fields' ][ $field[ 'name' ] ] : ''; 
  2854. $str .= "<tr><td class='stripe_field_cell'>" . $field[ "label" ] . "</td><td class='stripe_field_cell'>" . $this->get_mapped_field_list( $field[ 'name' ], $selected_field, $form_fields ) . '</td></tr>'; 
  2855. $str .= '</table>'; 
  2856.  
  2857. return $str; 
  2858.  
  2859. /** 
  2860. * @return array 
  2861. */ 
  2862. private function get_customer_fields() { 
  2863. return 
  2864. array( 
  2865. array( 
  2866. 'name' => 'first_name',  
  2867. 'label' => __( 'First Name', 'gravity-forms-stripe' ) 
  2868. ),  
  2869. array( 
  2870. 'name' => 'last_name',  
  2871. 'label' => __( 'Last Name', 'gravity-forms-stripe' ) 
  2872. ),  
  2873. array( 
  2874. 'name' => 'email',  
  2875. 'label' => __( 'Email', 'gravity-forms-stripe' ) 
  2876. ),  
  2877. array( 
  2878. 'name' => 'address1',  
  2879. 'label' => __( 'Address', 'gravity-forms-stripe' ) 
  2880. ),  
  2881. array( 
  2882. 'name' => 'address2',  
  2883. 'label' => __( 'Address 2', 'gravity-forms-stripe' ) 
  2884. ),  
  2885. array( 
  2886. 'name' => 'city',  
  2887. 'label' => __( 'City', 'gravity-forms-stripe' ) 
  2888. ),  
  2889. array( 
  2890. 'name' => 'state',  
  2891. 'label' => __( 'State', 'gravity-forms-stripe' ) 
  2892. ),  
  2893. array( 
  2894. 'name' => 'zip',  
  2895. 'label' => __( 'Zip', 'gravity-forms-stripe' ) 
  2896. ),  
  2897. array( 
  2898. 'name' => 'country',  
  2899. 'label' => __( 'Country', 'gravity-forms-stripe' ) 
  2900. ); 
  2901.  
  2902. /** 
  2903. * @param $variable_name 
  2904. * @param $selected_field 
  2905. * @param $fields 
  2906. * @return string 
  2907. */ 
  2908. private function get_mapped_field_list( $variable_name, $selected_field, $fields ) { 
  2909. $field_name = 'stripe_customer_field_' . $variable_name; 
  2910. $str = "<select name='{$field_name}' id='{$field_name}'><option value=''></option>"; 
  2911. foreach ( $fields as $field ) { 
  2912. $field_id = $field[ 0 ]; 
  2913. $field_label = esc_html( GFCommon::truncate_middle( $field[ 1 ], 40 ) ); 
  2914.  
  2915. $selected = $field_id == $selected_field ? "selected='selected'" : ''; 
  2916. $str .= "<option value='{$field_id}' {$selected} >{$field_label}</option>"; 
  2917. $str .= '</select>'; 
  2918.  
  2919. return $str; 
  2920.  
  2921. /** 
  2922. * @param $form 
  2923. * @param $selected_field 
  2924. * @param $field_total 
  2925. * @return string 
  2926. */ 
  2927. public static function get_product_options( $form, $selected_field, $field_total ) { 
  2928. $str = "<option value=''>" . __( 'Select a field', 'gravity-forms-stripe' ) . '</option>'; 
  2929. $fields = GFCommon::get_fields_by_type( $form, array( 'product' ) ); 
  2930. foreach ( $fields as $field ) { 
  2931. $field_id = $field[ "id" ]; 
  2932. $field_label = RGFormsModel::get_label( $field ); 
  2933.  
  2934. $selected = $field_id == $selected_field ? "selected='selected'" : ""; 
  2935. $str .= "<option value='" . $field_id . "' " . $selected . ">" . $field_label . '</option>'; 
  2936.  
  2937. if ( $field_total ) { 
  2938. $selected = $selected_field == 'all' ? "selected='selected'" : ""; 
  2939. $str .= "<option value='all' " . $selected . ">" . __( 'Subscription Field Total', 'gravity-forms-stripe' ) . "</option>"; 
  2940.  
  2941.  
  2942. return $str; 
  2943.  
  2944. /** 
  2945. * @param $form 
  2946. * @return array 
  2947. */ 
  2948. public static function get_form_fields( $form ) { 
  2949. $fields = array(); 
  2950.  
  2951. if ( is_array( $form[ 'fields' ] ) ) { 
  2952. foreach ( $form[ 'fields' ] as $field ) { 
  2953. if ( is_array( rgar( $field, 'inputs' ) ) ) { 
  2954.  
  2955. foreach ( $field[ 'inputs' ] as $input ) { 
  2956. $fields[ ] = array( $input[ 'id' ], GFCommon::get_label( $field, $input[ 'id' ] ) ); 
  2957. } else if ( ! rgar( $field, 'displayOnly' ) ) { 
  2958. $fields[ ] = array( $field[ 'id' ], GFCommon::get_label( $field ) ); 
  2959.  
  2960. return $fields; 
  2961.  
  2962. /** 
  2963. * @since 1.7.9.1 
  2964. * @uses get_transient() 
  2965. * @uses wp_count_posts() 
  2966. * @uses wp_count_comments() 
  2967. * @uses wp_get_theme() 
  2968. * @uses get_stylesheet_directory() 
  2969. * @uses get_plugins() 
  2970. * @uses get_plugin_data 
  2971. * @uses site_url() 
  2972. * @uses get_bloginfo() 
  2973. * @uses get_option() 
  2974. * @uses wp_remote_get() 
  2975. * @uses set_transient 
  2976. * @return void 
  2977. */ 
  2978. private static function do_usage_stats() { 
  2979.  
  2980. global $wpdb; 
  2981.  
  2982. $data = get_transient( 'gfp_stripe_usage_stats_cache_data' ); 
  2983.  
  2984. if ( ! $data || $data == '' ) { 
  2985.  
  2986. $api_url = 'https://gravityplus.pro/?gpp_action=update_usage'; 
  2987. $count_posts = wp_count_posts(); 
  2988. $count_pages = wp_count_posts( 'page' ); 
  2989. $comments_count = wp_count_comments(); 
  2990.  
  2991. if ( function_exists( 'wp_get_theme' ) ) { 
  2992. $theme_data = wp_get_theme(); 
  2993. $theme = array( 
  2994. 'Name' => $theme_data[ 'Name' ],  
  2995. 'ThemeURI' => $theme_data[ 'ThemeURI' ],  
  2996. 'Author' => $theme_data[ 'Author' ],  
  2997. 'AuthorURI' => $theme_data[ 'AuthorURI' ],  
  2998. 'Version' => $theme_data[ 'Version' ] 
  2999. ); 
  3000. } else { 
  3001. $theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' ); 
  3002. $theme = $theme_data[ 'Name' ] . ' ' . $theme_data[ 'Version' ]; 
  3003.  
  3004. if ( ! function_exists( 'get_plugins' ) ) { 
  3005. include ABSPATH . 'wp-admin/includes/plugin.php'; 
  3006.  
  3007. $plugins = array_keys( get_plugins() ); 
  3008. $active_plugins = get_option( 'active_plugins', array() ); 
  3009.  
  3010. foreach ( $plugins as $key => $plugin ) { 
  3011. if ( in_array( $plugin, $active_plugins ) ) { 
  3012. unset( $plugins[ $key ] ); 
  3013.  
  3014. $plugin_data = get_plugin_data( GFP_STRIPE_FILE ); 
  3015. $currency = GFCommon::get_currency(); 
  3016. $form_meta = GFP_Stripe_Data::get_all_feeds(); 
  3017. $feed_count = 0; 
  3018. $feed_types = $feed_options = array(); 
  3019. foreach ( $form_meta as $meta ) { 
  3020. foreach ( $meta[ 'rules' ] as $feed ) { 
  3021. $feed_count ++; 
  3022. if ( empty( $feed_types[ $feed[ 'type' ] ] ) ) { 
  3023. $feed_types[ $feed[ 'type' ] ] = 1; 
  3024. } else { 
  3025. $feed_types[ $feed[ 'type' ] ] ++; 
  3026. foreach ( $feed as $key => $value ) { 
  3027. if ( empty( $feed_options[ $key ] ) ) { 
  3028. $feed_options[ $key ] = ( ! empty( $value ) ); 
  3029. $events = get_option( 'gfp_stripe_usage_events' ); 
  3030. $data = array( 
  3031. 'url' => home_url(),  
  3032. 'posts' => $count_posts->publish,  
  3033. 'pages' => $count_pages->publish,  
  3034. 'comments' => $comments_count->total_comments,  
  3035. 'approved' => $comments_count->approved,  
  3036. 'spam' => $comments_count->spam,  
  3037. 'pingbacks' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),  
  3038. 'plugin' => $plugin_data,  
  3039. 'theme' => $theme,  
  3040. 'active_plugins' => $active_plugins,  
  3041. 'inactive_plugins' => $plugins,  
  3042. 'wpversion' => get_bloginfo( 'version' ),  
  3043. 'multisite' => is_multisite(),  
  3044. 'users' => $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->users" ),  
  3045. 'currency' => $currency,  
  3046. 'feeds' => $feed_count,  
  3047. 'feed_types' => $feed_types,  
  3048. 'feed_options' => $feed_options,  
  3049. 'events' => $events 
  3050. ); 
  3051. $data = apply_filters( 'gfp_stripe_usage_stats', $data ); 
  3052. $user_agent = 'GFP_Stripe/' . self::get_version() . '; ' . get_bloginfo( 'url' ); 
  3053. $args = array( 'user-agent' => $user_agent, 'blocking' => false, 'body' => $data ); 
  3054.  
  3055. wp_remote_post( $api_url, $args ); 
  3056. set_transient( 'gfp_stripe_usage_stats_cache_data', $data, 60 * 60 * 24 ); 
  3057. update_option( 'gfp_stripe_usage_events', array() ); 
  3058.  
  3059. /** 
  3060. * @param $event_name 
  3061. */ 
  3062. public function gfp_stripe_usage_event( $event_name ) { 
  3063. $usage_events = get_option( 'gfp_stripe_usage_events' ); 
  3064. $usage_events[ $event_name ] ++; 
  3065.  
  3066. update_option( 'gfp_stripe_usage_events', $usage_events ); 
  3067.  
  3068. //------------------------------------------------------ 
  3069. //------------- FORM --------------------------- 
  3070. //------------------------------------------------------ 
  3071.  
  3072. /** 
  3073. * Add a Stripe form settings tab 
  3074. * @since 1.8.2 
  3075. * @param $setting_tabs 
  3076. * @param $form_id 
  3077. * @return mixed 
  3078. */ 
  3079. public function gform_form_settings_menu( $setting_tabs, $form_id ) { 
  3080.  
  3081. $setting_tabs[ '15' ] = array( 
  3082. 'name' => 'stripe',  
  3083. 'label' => __( 'Stripe', 'gravity-forms-stripe' ),  
  3084. 'query' => array( 'sid' => null ) 
  3085. ); 
  3086.  
  3087. return $setting_tabs; 
  3088.  
  3089. /** 
  3090. * Stripe form settings page 
  3091. * @since 1.8.2 
  3092. */ 
  3093. public function gform_form_settings_page_stripe() { 
  3094.  
  3095. $form_id = RGForms::get( 'id' ); 
  3096.  
  3097. $stripe_feed_id = rgempty( 'stripe_feed_id' ) ? rgget( 'sid' ) : rgpost( 'stripe_feed_id' ); 
  3098.  
  3099. if ( ! rgblank( $stripe_feed_id ) ) { 
  3100. $this->form_settings_edit_feed_page( $form_id, $stripe_feed_id ); 
  3101. } else { 
  3102. $this->form_settings_page( $form_id ); 
  3103.  
  3104. GFFormSettings::page_footer(); 
  3105.  
  3106. /** 
  3107. * @param $form_id 
  3108. */ 
  3109. private function form_settings_page( $form_id ) { 
  3110. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  3111. wp_enqueue_script( 'gfp_stripe_form_settings_stripe_js', trailingslashit( GFP_STRIPE_URL ) . "js/form-settings-stripe{$suffix}.js", array( 'jquery' ), GFP_Stripe::get_version() ); 
  3112.  
  3113. if ( 'delete' == rgpost( 'action' ) && check_admin_referer( 'gfp_stripe_feeds_list_action', 'gfp_stripe_feeds_list_action' ) ) { 
  3114. $sid = rgpost( 'action_argument' ); 
  3115. if ( ! empty( $sid ) ) { 
  3116. $feed_deleted = GFP_Stripe_Data::delete_feed( $sid, $form_id ); 
  3117. if ( $feed_deleted ) { 
  3118. GFCommon::add_message( __( 'Stripe rule deleted.', 'gravity-forms-stripe' ) ); 
  3119. } else { 
  3120. GFCommon::add_error_message( __( 'There was an issue deleting this rule.', 'gravity-forms-stripe' ) ); 
  3121.  
  3122. if ( rgpost( 'gfp_stripe_save_form_settings' ) ) { 
  3123.  
  3124. check_admin_referer( 'gfp_stripe_save_form_settings', 'gfp_stripe_save_form_settings' ); 
  3125. $form = GFFormsModel::get_form_meta( $form_id ); 
  3126.  
  3127. $updated_form = apply_filters( 'gfp_stripe_pre_form_settings_save', array(), $form ); 
  3128.  
  3129. if ( ! empty( $updated_form ) ) { 
  3130.  
  3131. $form = $updated_form; 
  3132.  
  3133. $update_result = GFFormsModel::update_form_meta( $form_id, $form ); 
  3134.  
  3135. if ( false !== $update_result ) { 
  3136. GFCommon::add_message( __( 'Settings updated', 'gravityforms-stripe-more' ) ); 
  3137. } else { 
  3138. GFCommon::add_error_message( __( 'There was an error while saving your settings', 'gravityforms-stripe-more' ) ); 
  3139.  
  3140. GFFormSettings::page_header( __( 'Stripe', 'gravity-forms-stripe' ) ); 
  3141. $add_new_url = add_query_arg( array( 'sid' => 0 ) ); 
  3142. $form_id = rgget( 'id' ); 
  3143.  
  3144. $stripe_feeds_table = new GFP_Stripe_List_Table( $form_id ); 
  3145. $stripe_feeds_table->prepare_items(); 
  3146.  
  3147. $form_settings_js_data = array( 
  3148. 'inactive_text' => __( 'Inactive', 'gravity-forms-stripe' ),  
  3149. 'active_text' => __( 'Active', 'gravity-forms-stripe' ),  
  3150. 'nonce' => wp_create_nonce( 'gfp_stripe_update_feed_active' ),  
  3151. 'update_feed_error_message' => __( 'Ajax error while updating rule', 'gravity-forms-stripe' ) 
  3152. ); 
  3153. wp_localize_script( 'gfp_stripe_form_settings_stripe_js', 'stripe_form_settings', $form_settings_js_data ); 
  3154.  
  3155. require_once( trailingslashit( GFP_STRIPE_PATH ) . 'includes/views/form-settings-stripe.php' ); 
  3156.  
  3157.  
  3158. /** 
  3159. * @param $form_id 
  3160. * @param $feed_id 
  3161. */ 
  3162. private function form_settings_edit_feed_page( $form_id, $feed_id ) { 
  3163. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  3164. wp_enqueue_script( 'gfp_stripe_form_settings_edit_feed_js', trailingslashit( GFP_STRIPE_URL ) . "js/form-settings-edit-feed{$suffix}.js", array( 'jquery' ), GFP_Stripe::get_version() ); 
  3165. wp_enqueue_script( 'gform_gravityforms' ); 
  3166.  
  3167. if ( ! rgempty( 'stripe_feed_id' ) ) { 
  3168. $feed_id = rgpost( 'stripe_feed_id' ); 
  3169.  
  3170. $stripe_form_meta = GFP_Stripe_Data::get_stripe_form_meta( $form_id ); 
  3171. if ( $stripe_form_meta ) { 
  3172. $current_feed_ids = array_keys( $stripe_form_meta[ 'rules' ] ); 
  3173. ksort( $current_feed_ids ); 
  3174.  
  3175. $feed = ! $feed_id ? array( 
  3176. 'meta' => array(),  
  3177. 'is_active' => true 
  3178. ) : self::get_feed( $stripe_form_meta, $feed_id ); 
  3179.  
  3180. $new_feed = empty( $feed_id ) || empty( $feed ); 
  3181.  
  3182. $form = RGFormsModel::get_form_meta( $form_id ); 
  3183. $list_url = remove_query_arg( 'sid' ); 
  3184.  
  3185. if ( rgpost( 'save' ) ) { 
  3186.  
  3187. check_admin_referer( 'gfp_stripe_save_feed', 'gfp_stripe_save_feed' ); 
  3188.  
  3189. if ( $new_feed ) { 
  3190. if ( ! empty( $current_feed_ids ) ) { 
  3191. $feed_id = (string) ( ( array_pop( $current_feed_ids ) ) + 0.1 ); 
  3192. } else { 
  3193. $feed_id = (string) ( number_format( (float) $form_id, 1, '.', ', ' ) ); 
  3194. $feed[ 'id' ] = $feed_id; 
  3195.  
  3196. $feed[ 'form_id' ] = $form_id; 
  3197. $feed[ 'meta' ][ 'rule_name' ] = rgpost( 'gfp_stripe_rule_name' ); 
  3198. $feed[ 'meta' ][ 'type' ] = rgpost( 'gfp_stripe_type' ); 
  3199. $feed[ 'meta' ][ 'update_post_action' ] = rgpost( 'gfp_stripe_update_action' ); 
  3200.  
  3201. $feed[ 'meta' ][ 'stripe_conditional_enabled' ] = rgpost( 'gfp_stripe_conditional_enabled' ); 
  3202. $feed[ 'meta' ][ 'stripe_conditional_field_id' ] = rgpost( 'gfp_stripe_conditional_field_id' ); 
  3203. $feed[ 'meta' ][ 'stripe_conditional_operator' ] = rgpost( 'gfp_stripe_conditional_operator' ); 
  3204. $feed[ 'meta' ][ 'stripe_conditional_value' ] = rgpost( 'gfp_stripe_conditional_value' ); 
  3205.  
  3206. //----------------- 
  3207.  
  3208. $customer_fields = $this->get_customer_fields(); 
  3209. $feed[ 'meta' ][ 'customer_fields' ] = array(); 
  3210. foreach ( $customer_fields as $field ) { 
  3211. $feed[ 'meta' ][ 'customer_fields' ][ $field[ 'name' ] ] = rgpost( "stripe_customer_field_{$field['name']}" ); 
  3212.  
  3213. $feed = apply_filters( 'gfp_stripe_before_save_feed', $feed, $form ); 
  3214.  
  3215. $is_valid = apply_filters( 'gfp_stripe_feed_validation', true, $feed ); 
  3216.  
  3217. if ( $is_valid ) { 
  3218. $rule = $feed[ 'meta' ]; 
  3219. $rule[ 'id' ] = $feed[ 'id' ]; 
  3220. $rule[ 'is_active' ] = $feed[ 'is_active' ]; 
  3221. $stripe_form_meta[ 'rules' ][ $feed_id ] = $rule; 
  3222.  
  3223. GFP_Stripe_Data::save_feeds( $form_id, $stripe_form_meta[ 'rules' ] ); 
  3224. do_action( 'gfp_stripe_after_save_feed', $feed, $form, $new_feed ); 
  3225. $new_feed = false; 
  3226.  
  3227. GFCommon::add_message( sprintf( __( 'Rule saved successfully. %sBack to list.%s', 'gravity-forms-stripe' ), '<a href="' . $list_url . '">', '</a>' ) ); 
  3228. } else { 
  3229. GFCommon::add_error_message( __( 'There was an issue saving your rule. Please check all required information below.', 'gravity-forms-stripe' ) ); 
  3230. GFFormSettings::page_header( __( 'Stripe', 'gravity-forms-stripe' ) ); 
  3231. $settings = get_option( 'gfp_stripe_settings' ); 
  3232.  
  3233. $post_categories = wp_dropdown_categories( array( 
  3234. 'orderby' => 'name',  
  3235. 'hide_empty' => 0,  
  3236. 'echo' => false,  
  3237. 'hierarchical' => true,  
  3238. 'name' => 'gfp_stripe_conditional_value',  
  3239. 'id' => 'gfp_stripe_conditional_value',  
  3240. 'class' => 'optin_select' 
  3241. ) ); 
  3242. $post_categories = str_replace( "\n", "", str_replace( "'", "\\'", $post_categories ) ); 
  3243. $conditional_value_placeholder = __( 'Enter value', 'gravity-forms-stripe' ); 
  3244. $form_settings_edit_feed_js_data = array( 
  3245. 'form_id' => $form_id,  
  3246. 'form' => $form,  
  3247. 'new_feed' => $new_feed,  
  3248. 'select_form_nonce' => wp_create_nonce( 'gfp_select_stripe_form' ),  
  3249. 'select_form_error_message' => __( 'Ajax error while selecting a form', 'gravity-forms-stripe' ),  
  3250. 'post_categories' => $post_categories,  
  3251. 'conditional_value_placeholder' => $conditional_value_placeholder 
  3252. ); 
  3253. if ( ! $new_feed ) { 
  3254. $form_settings_edit_feed_js_data[ 'reg_condition_selected_field' ] = str_replace( '"', '\"', $feed[ 'meta' ][ 'stripe_conditional_field_id' ] ); 
  3255. $form_settings_edit_feed_js_data[ 'reg_condition_selected_value' ] = str_replace( '"', '\"', $feed[ 'meta' ][ 'stripe_conditional_value' ] ); 
  3256. wp_localize_script( 'gfp_stripe_form_settings_edit_feed_js', 'stripe_edit_feed_settings', apply_filters( 'gfp_stripe_edit_feed_js_data', $form_settings_edit_feed_js_data, $form, $feed ) ); 
  3257. require_once( trailingslashit( GFP_STRIPE_PATH ) . 'includes/views/form-settings-edit-feed.php' ); 
  3258.  
  3259. public static function gform_field_standard_settings( $position, $form_id ) { 
  3260. if ( 1435 == $position ) { 
  3261. require_once( GFP_STRIPE_PATH . '/includes/views/field-setting-card_funding_types.php' ); 
  3262.  
  3263. public static function gform_editor_js() { 
  3264. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  3265. wp_enqueue_script( 'gfp_stripe_form_editor_card_funding_types', GFP_STRIPE_URL . "js/form-editor-card-funding-types{$suffix}.js", array( 'gform_form_editor' ), self::get_version() ); 
  3266.  
  3267. /** 
  3268. * Add Stripe JS 
  3269. * @since 0.1.0 
  3270. * @uses GFCommon::has_credit_card_field() 
  3271. * @uses GFP_Stripe_Data::get_feed_by_form() 
  3272. * @uses enqueue_stripe_js() 
  3273. * @param null $form 
  3274. * @param null $ajax 
  3275. * @return void 
  3276. */ 
  3277. public function gform_enqueue_scripts( $form = null, $ajax = null ) { 
  3278.  
  3279. if ( self::is_stripe_form( $form ) ) { 
  3280. $this->enqueue_stripe_js( $form ); 
  3281.  
  3282.  
  3283. /** 
  3284. * Remove input field name attribute so credit card information is not sent to server 
  3285. * @since 0.1.0 
  3286. * @uses GFP_Stripe_Data::get_feed_by_form() 
  3287. * @param $field_content 
  3288. * @param $field 
  3289. * @param $default_value 
  3290. * @param $lead_id 
  3291. * @param $form_id 
  3292. * @return mixed 
  3293. */ 
  3294. public function gform_field_content( $field_content, $field, $default_value, $lead_id, $form_id ) { 
  3295.  
  3296. if ( 'creditcard' == $field[ 'type' ] ) { 
  3297.  
  3298. $form_feeds = GFP_Stripe_Data::get_feed_by_form( $form_id, true ); 
  3299.  
  3300. if ( ! empty( $form_feeds ) ) { 
  3301.  
  3302. $search = array(); 
  3303. $exp_date_input = $field[ 'id' ] . '.2'; 
  3304. $card_type_input = $field[ 'id' ] . '.4'; 
  3305. foreach ( $field[ 'inputs' ] as $input ) { 
  3306. if ( $card_type_input == $input[ 'id' ] ) { 
  3307. continue; 
  3308. } else { 
  3309. ( $input[ 'id' ] == $exp_date_input ) ? ( $search[ ] = "name='input_" . $input[ 'id' ] . "[]'" ) : ( $search[ ] = "name='input_" . $input[ 'id' ] . "'" ); 
  3310. $field_content = str_ireplace( $search, '', $field_content ); 
  3311.  
  3312. return $field_content; 
  3313.  
  3314.  
  3315. /** 
  3316. * Check to see if ID is an input ID 
  3317. * @since 1.7.9.1 
  3318. * @param $id 
  3319. * @return int 
  3320. */ 
  3321. private function is_input_id( $id ) { 
  3322. $is_input_id = stripos( $id, '.' ); 
  3323.  
  3324. return $is_input_id; 
  3325.  
  3326. /** 
  3327. * Get field ID from the ID saved in Stripe feed 
  3328. * @since 1.7.9.1 
  3329. * @uses GFP_Stripe::is_input_id() 
  3330. * @param $id 
  3331. * @return mixed 
  3332. */ 
  3333. private function get_field_id( $id ) { 
  3334. $input_id = $this->is_input_id( $id ); 
  3335. if ( $input_id ) { 
  3336. $id = substr( $id, 0, $input_id ); 
  3337.  
  3338. return $id; 
  3339.  
  3340. /** 
  3341. * Get rule fields 
  3342. * @since 1.7.9.1 
  3343. * @param $form_rule 
  3344. * @return array 
  3345. */ 
  3346. private function get_rule_fields( $form_rule ) { 
  3347. return array( 
  3348. 'rule_field_address1' => $form_rule[ 'meta' ][ 'customer_fields' ][ 'address1' ],  
  3349. 'rule_field_city' => $form_rule[ 'meta' ][ 'customer_fields' ][ 'city' ],  
  3350. 'rule_field_state' => $form_rule[ 'meta' ][ 'customer_fields' ][ 'state' ],  
  3351. 'rule_field_zip' => $form_rule[ 'meta' ][ 'customer_fields' ][ 'zip' ],  
  3352. 'rule_field_country' => $form_rule[ 'meta' ][ 'customer_fields' ][ 'country' ] 
  3353. ); 
  3354.  
  3355. /** 
  3356. * Get field IDs 
  3357. * @since 1.7.9.1 
  3358. * @uses GFP_Stripe::get_field_id() 
  3359. * @param $feed_fields 
  3360. * @return array 
  3361. */ 
  3362. private function get_field_ids( $feed_fields ) { 
  3363. $feed_field_address1 = $feed_field_city = $feed_field_state = $feed_field_zip = $feed_field_country = ''; 
  3364. extract( $feed_fields ); 
  3365.  
  3366. return array( 
  3367. 'address1_field_id' => $this->get_field_id( $feed_field_address1 ),  
  3368. 'city_field_id' => $this->get_field_id( $feed_field_city ),  
  3369. 'state_field_id' => $this->get_field_id( $feed_field_state ),  
  3370. 'zip_field_id' => $this->get_field_id( $feed_field_zip ),  
  3371. 'country_field_id' => $this->get_field_id( $feed_field_country ) 
  3372. ); 
  3373.  
  3374. /** 
  3375. * Get field input ID 
  3376. * @since 1.7.9.1 
  3377. * @param $field_input_id 
  3378. * @return string 
  3379. */ 
  3380. private function get_field_input_id( $field_input_id ) { 
  3381. $separator_position = stripos( $field_input_id, '.' ); 
  3382. $input_id = substr( $field_input_id, $separator_position + 1 ); 
  3383.  
  3384. return $input_id; 
  3385.  
  3386. /** 
  3387. * Get form input IDs 
  3388. * @since 1.7.9.1 
  3389. * @uses GFP_Stripe::get_field_input_id() 
  3390. * @param $form 
  3391. * @param $rule_fields 
  3392. * @param $rule_field_ids 
  3393. * @return array 
  3394. */ 
  3395. private function get_form_input_ids( $form, $rule_fields, $rule_field_ids ) { 
  3396. $form_input_ids = array( 
  3397. 'street_input_id' => '',  
  3398. 'city_input_id' => '',  
  3399. 'state_input_id' => '',  
  3400. 'zip_input_id' => '',  
  3401. 'country_input_id' => '' 
  3402. ); 
  3403. $rule_field_address1 = $rule_field_city = $rule_field_state = $rule_field_zip = $rule_field_country = ''; 
  3404. extract( $rule_fields ); 
  3405. $address1_field_id = $city_field_id = $state_field_id = $zip_field_id = $country_field_id = ''; 
  3406. extract( $rule_field_ids ); 
  3407.  
  3408. foreach ( $form[ 'fields' ] as $field ) { 
  3409. if ( 'creditcard' == $field[ 'type' ] ) { 
  3410. $form_input_ids[ 'creditcard_field_id' ] = $field[ 'id' ]; 
  3411. } else if ( ! empty( $field[ 'inputs' ] ) ) { 
  3412. foreach ( $field[ 'inputs' ] as $input ) { 
  3413. switch ( $input[ 'id' ] ) { 
  3414. case $rule_field_address1: 
  3415. $input_id = $this->get_field_input_id( $input[ 'id' ] ); 
  3416. $street_input_id = $form[ 'id' ] . '_' . $field[ 'id' ] . '_' . $input_id; 
  3417. $form_input_ids[ 'street_input_id' ] = $street_input_id; 
  3418. break; 
  3419. case $rule_field_city: 
  3420. $input_id = $this->get_field_input_id( $input[ 'id' ] ); 
  3421. $city_input_id = $form[ 'id' ] . '_' . $field[ 'id' ] . '_' . $input_id; 
  3422. $form_input_ids[ 'city_input_id' ] = $city_input_id; 
  3423. break; 
  3424. case $rule_field_state: 
  3425. $input_id = $this->get_field_input_id( $input[ 'id' ] ); 
  3426. $state_input_id = $form[ 'id' ] . '_' . $field[ 'id' ] . '_' . $input_id; 
  3427. $form_input_ids[ 'state_input_id' ] = $state_input_id; 
  3428. break; 
  3429. case $rule_field_zip: 
  3430. $input_id = $this->get_field_input_id( $input[ 'id' ] ); 
  3431. $zip_input_id = $form[ 'id' ] . '_' . $field[ 'id' ] . '_' . $input_id; 
  3432. $form_input_ids[ 'zip_input_id' ] = $zip_input_id; 
  3433. break; 
  3434. case $rule_field_country: 
  3435. $input_id = $this->get_field_input_id( $input[ 'id' ] ); 
  3436. $country_input_id = $form[ 'id' ] . '_' . $field[ 'id' ] . '_' . $input_id; 
  3437. $form_input_ids[ 'country_input_id' ] = $country_input_id; 
  3438. break; 
  3439. } else { 
  3440. switch ( $field[ 'id' ] ) { 
  3441. case $address1_field_id: 
  3442. $form_input_ids[ 'street_input_id' ] = $form[ 'id' ] . '_' . $field[ 'id' ]; 
  3443. break; 
  3444. case $city_field_id: 
  3445. $form_input_ids[ 'city_input_id' ] = $form[ 'id' ] . '_' . $field[ 'id' ]; 
  3446. break; 
  3447. case $state_field_id: 
  3448. $form_input_ids[ 'state_input_id' ] = $form[ 'id' ] . '_' . $field[ 'id' ]; 
  3449. break; 
  3450. case $zip_field_id: 
  3451. $form_input_ids[ 'zip_input_id' ] = $form[ 'id' ] . '_' . $field[ 'id' ]; 
  3452. break; 
  3453. case $country_field_id: 
  3454. $form_input_ids[ 'country_input_id' ] = $form[ 'id' ] . '_' . $field[ 'id' ]; 
  3455. break; 
  3456.  
  3457. return $form_input_ids; 
  3458.  
  3459. /** 
  3460. * Does rule have conditional logic 
  3461. * @since 1.7.9.1 
  3462. * @param $rule 
  3463. * @param $conditional_field_id 
  3464. * @return bool 
  3465. */ 
  3466. private function rule_has_condition( $rule, $conditional_field_id ) { 
  3467.  
  3468. $has_condition = ( ( '1' == $rule[ 'meta' ][ 'stripe_conditional_enabled' ] ) && ( $conditional_field_id == $rule[ 'meta' ][ 'stripe_conditional_field_id' ] ) ); 
  3469.  
  3470. return $has_condition; 
  3471.  
  3472.  
  3473. /** 
  3474. * @param $rule 
  3475. * @return array 
  3476. */ 
  3477. private function get_rule_condition( $rule ) { 
  3478.  
  3479. $rule_condition = array(); 
  3480.  
  3481. $rule_condition[ 'operator' ] = $rule[ 'meta' ][ 'stripe_conditional_operator' ]; 
  3482. $rule_condition[ 'value' ] = $rule[ 'meta' ][ 'stripe_conditional_value' ]; 
  3483.  
  3484. return $rule_condition; 
  3485.  
  3486.  
  3487. /** 
  3488. * Enqueue Stripe JS 
  3489. * @since 1.8.17.1 
  3490. * @uses GFP_Stripe_Data::get_feed_by_form() 
  3491. * @uses rule_has_condition() 
  3492. * @uses wp_enqueue_script() 
  3493. * @uses wp_localize_script() 
  3494. * @uses GFP_Stripe::get_version() 
  3495. * @uses GFP_Stripe::get_api_key() 
  3496. * @uses GFP_Stripe::get_rule_fields() 
  3497. * @uses GFP_Stripe::get_field_ids() 
  3498. * @uses GFP_Stripe::get_form_input_ids() 
  3499. * @uses GFP_Stripe::get_rule_condition() 
  3500. * @uses apply_filters() 
  3501. * @uses GFCommon::get_base_url() 
  3502. * @param $form 
  3503. */ 
  3504. private function enqueue_stripe_js( $form ) { 
  3505.  
  3506. $stripe_rules = GFP_Stripe_Data::get_feed_by_form( $form[ 'id' ], true ); 
  3507.  
  3508. $conditional_field_id = 0; 
  3509.  
  3510. if ( 1 == count( $stripe_rules ) ) { 
  3511.  
  3512. $stripe_rules = $stripe_rules[ 0 ]; 
  3513. $conditional_field_id = $stripe_rules[ 'meta' ][ 'stripe_conditional_field_id' ]; 
  3514.  
  3515. } else if ( 1 < count( $stripe_rules ) ) { 
  3516.  
  3517. $valid_rules = 0; 
  3518. $conditional_field_id = $stripe_rules[ 0 ][ 'meta' ][ 'stripe_conditional_field_id' ]; 
  3519.  
  3520. foreach ( $stripe_rules as $rule ) { 
  3521.  
  3522. if ( $this->rule_has_condition( $rule, $conditional_field_id ) ) { 
  3523. $valid_rules ++; 
  3524.  
  3525.  
  3526. if ( $valid_rules !== count( $stripe_rules ) ) { 
  3527.  
  3528. $stripe_rules = $stripe_rules[ 0 ]; 
  3529. $conditional_field_id = $stripe_rules[ 'meta' ][ 'stripe_conditional_field_id' ]; 
  3530.  
  3531.  
  3532.  
  3533. if ( ! empty( $stripe_rules ) ) { 
  3534.  
  3535. $form_id = $form[ 'id' ]; 
  3536.  
  3537. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  3538.  
  3539. $creditcard_field_id = ''; 
  3540.  
  3541. $multiple_rules = isset( $valid_rules ) && ( 1 < $valid_rules ); 
  3542.  
  3543. if ( $multiple_rules ) { 
  3544.  
  3545. $num_of_rules = count( $stripe_rules ); 
  3546. $rule_field_info = array(); 
  3547.  
  3548. foreach ( $stripe_rules as $rule ) { 
  3549.  
  3550. $rule_fields = $this->get_rule_fields( $rule ); 
  3551. $rule_field_ids = $this->get_field_ids( $rule_fields ); 
  3552. $form_input_ids = $this->get_form_input_ids( $form, $rule_fields, $rule_field_ids ); 
  3553. $rule_condition = $this->get_rule_condition( $rule ); 
  3554.  
  3555. $rule_field_info[ ] = array_merge( $form_input_ids, $rule_condition ); 
  3556.  
  3557.  
  3558. foreach ( $rule_field_info as $field_info ) { 
  3559.  
  3560. if ( ! empty( $field_info[ 'creditcard_field_id' ] ) ) { 
  3561.  
  3562. $creditcard_field_id = $field_info[ 'creditcard_field_id' ]; 
  3563.  
  3564. break; 
  3565.  
  3566.  
  3567. unset( $field_info ); 
  3568.  
  3569.  
  3570. } else { 
  3571.  
  3572. $num_of_rules = 1; 
  3573.  
  3574. $rule_field_info = array(); 
  3575.  
  3576. $rule_fields = $this->get_rule_fields( $stripe_rules ); 
  3577. $rule_field_ids = $this->get_field_ids( $rule_fields ); 
  3578. $street_input_id = $city_input_id = $state_input_id = $zip_input_id = $country_input_id = ''; 
  3579.  
  3580. extract( $this->get_form_input_ids( $form, $rule_fields, $rule_field_ids ) ); 
  3581.  
  3582. if ( ! empty( $creditcard_field_id ) ) { 
  3583. $rule_field_info[ 'creditcard_field_id' ] = $creditcard_field_id; 
  3584.  
  3585. $rule_field_info[ 'street_input_id' ] = $street_input_id; 
  3586. $rule_field_info[ 'city_input_id' ] = $city_input_id; 
  3587. $rule_field_info[ 'state_input_id' ] = $state_input_id; 
  3588. $rule_field_info[ 'zip_input_id' ] = $zip_input_id; 
  3589. $rule_field_info[ 'country_input_id' ] = $country_input_id; 
  3590.  
  3591. $rule_field_info = apply_filters( 'gfp_stripe_gform_get_form_filter', $rule_field_info, $stripe_rules, $form ); 
  3592. self::$stripe_rule_field_info = $rule_field_info = apply_filters( 'gfp_stripe_rule_field_info', $rule_field_info, $stripe_rules, $form ); 
  3593.  
  3594. $rule_has_condition = false; 
  3595.  
  3596. if ( array_key_exists( 0, $rule_field_info ) && ( is_array( $rule_field_info[ 0 ] ) ) ) { 
  3597.  
  3598. $rule_has_condition = true; 
  3599.  
  3600. wp_enqueue_script( 'gform_conditional_logic', GFCommon::get_base_url() . '/js/conditional_logic.js', array( 
  3601. 'jquery',  
  3602. 'gforms_gravityforms' 
  3603. ), GFCommon::$version ); 
  3604.  
  3605. } else if ( ( $conditional_field_id ) && ( $this->rule_has_condition( $stripe_rules, $conditional_field_id ) ) ) { 
  3606.  
  3607. $rule_field_info = array_merge( $rule_field_info, $this->get_rule_condition( $stripe_rules ) ); 
  3608.  
  3609. if ( array_key_exists( 'operator', $rule_field_info ) ) { 
  3610.  
  3611. $rule_has_condition = true; 
  3612.  
  3613. wp_enqueue_script( 'gform_conditional_logic', GFCommon::get_base_url() . '/js/conditional_logic.js', array( 
  3614. 'jquery',  
  3615. 'gforms_gravityforms' 
  3616. ), GFCommon::$version ); 
  3617.  
  3618.  
  3619.  
  3620. if ( ! empty( $creditcard_field_id ) ) { 
  3621.  
  3622. wp_enqueue_script( 'stripe-js', 'https://js.stripe.com/v2/', array( 'jquery' ), self::get_version() ); 
  3623.  
  3624. $publishable_key = apply_filters( 'gfp_stripe_get_publishable_key', self::$_this->get_api_key( 'publishable' ), $form_id ); 
  3625.  
  3626. wp_enqueue_script( 'gfp_stripe_js', trailingslashit( GFP_STRIPE_URL ) . "js/form-display{$suffix}.js", array( 
  3627. 'jquery',  
  3628. 'stripe-js' 
  3629. ), self::get_version() ); 
  3630.  
  3631. $creditcard_field = GFFormsModel::get_field( $form, $creditcard_field_id ); 
  3632. $allowed_funding_types = rgar( $creditcard_field, 'creditCardFundingTypes' ); 
  3633.  
  3634. if ( empty( $allowed_funding_types ) ) { 
  3635. $allowed_funding_types = array( 'credit', 'debit', 'prepaid', 'unknown' ); 
  3636.  
  3637. $gfp_stripe_js_vars = array( 
  3638. 'form_id' => $form_id,  
  3639. 'publishable_key' => $publishable_key,  
  3640. 'creditcard_field_id' => $creditcard_field_id,  
  3641. 'allowed_funding_types' => $allowed_funding_types,  
  3642. 'num_of_rules' => $num_of_rules,  
  3643. 'rule_field_info' => $rule_field_info,  
  3644. 'rule_has_condition' => $rule_has_condition,  
  3645. 'conditional_field_id' => $conditional_field_id,  
  3646. 'error_messages' => array( 
  3647. 'funding' => __( ' cards are not accepted.', 'gravity-forms-stripe' ),  
  3648. 'card_number' => __( 'Invalid card number.', 'gravity-forms-stripe' ),  
  3649. 'expiration' => __( ' Invalid expiration date.', 'gravity-forms-stripe' ),  
  3650. 'security_code' => __( ' Invalid security code.', 'gravity-forms-stripe' ),  
  3651. 'cardholder_name' => __( ' Invalid cardholder name.', 'gravity-forms-stripe' ),  
  3652. 'no_card_info' => __( 'Unable to read card information', 'gravity-forms-stripe' ) 
  3653. ); 
  3654.  
  3655. wp_localize_script( 'gfp_stripe_js', 'gfp_stripe_js_vars', $gfp_stripe_js_vars ); 
  3656.  
  3657.  
  3658.  
  3659.  
  3660. /** 
  3661. * @param $form_id 
  3662. */ 
  3663. public function gform_after_delete_form( $form_id ) { 
  3664. GFP_Stripe_Data::delete_stripe_form_meta( $form_id ); 
  3665.  
  3666.  
  3667. public static function get_stripe_rule_field_info() { 
  3668. return self::$stripe_rule_field_info; 
  3669.  
  3670. //------------------------------------------------------ 
  3671. //------------- PROCESSING --------------------------- 
  3672. //------------------------------------------------------ 
  3673.  
  3674. /** 
  3675. * @param $validation_result 
  3676. * @param $value 
  3677. * @param $form 
  3678. * @param $field 
  3679. * @return mixed 
  3680. */ 
  3681. public function gform_field_validation( $validation_result, $value, $form, $field ) { 
  3682.  
  3683. $form_feeds = GFP_Stripe_Data::get_feed_by_form( $form[ 'id' ], true ); 
  3684.  
  3685. if ( ! empty( $form_feeds ) ) { 
  3686.  
  3687. if ( 'creditcard' == $field[ 'type' ] ) { 
  3688.  
  3689. $token = rgpost( 'stripeToken' ); 
  3690.  
  3691. if ( empty( $token ) ) { 
  3692. $validation_result[ 'is_valid' ] = false; 
  3693. $validation_result[ 'message' ] = __( 'This form cannot process your payment. Please contact the site owner.', 'gravity-forms-stripe' ); 
  3694. self::log_error( __( 'Empty token', 'gravity-forms-stripe' ) ); 
  3695. } else { 
  3696. $validation_result[ 'is_valid' ] = true; 
  3697. unset( $validation_result[ 'message' ] ); 
  3698.  
  3699. $validation_result = apply_filters( 'gfp_stripe_gform_field_validation', $validation_result, $value, $field ); 
  3700.  
  3701.  
  3702. return $validation_result; 
  3703.  
  3704. /** 
  3705. * @param $validation_result 
  3706. * @return mixed|void 
  3707. */ 
  3708. public function gform_validation( $validation_result ) { 
  3709.  
  3710. $feed = $this->is_ready_for_capture( $validation_result ); 
  3711.  
  3712. if ( ! $feed ) { 
  3713. return $validation_result; 
  3714.  
  3715. if ( ( 'product' == $feed[ 'meta' ][ 'type' ] ) && ( ! class_exists( 'GFPMoreStripe' ) ) ) { 
  3716.  
  3717. $validation_result = $this->make_product_payment( $feed, $validation_result ); 
  3718.  
  3719. } else { 
  3720. $validation_result = apply_filters( 'gfp_stripe_gform_validation', $validation_result, $feed ); 
  3721.  
  3722. return $validation_result; 
  3723.  
  3724. /** 
  3725. * @param $validation_result 
  3726. * @return bool 
  3727. */ 
  3728. private function is_ready_for_capture( $validation_result ) { 
  3729.  
  3730. $is_ready_for_capture = true; 
  3731. $reason = ''; 
  3732.  
  3733. if ( false == $validation_result[ 'is_valid' ] || ! $this->is_last_page( $validation_result[ 'form' ] ) ) { 
  3734. $is_ready_for_capture = false; 
  3735. $reason = 'form'; 
  3736.  
  3737. if ( $is_ready_for_capture ) { 
  3738.  
  3739. $feed = self::$_this->get_feed_that_meets_condition( $validation_result[ 'form' ] ); 
  3740.  
  3741. if ( ! $feed ) { 
  3742. $is_ready_for_capture = false; 
  3743. $reason = 'feed'; 
  3744. } else { 
  3745. $is_ready_for_capture = $feed; 
  3746.  
  3747.  
  3748. if ( false !== $is_ready_for_capture ) { 
  3749.  
  3750. $creditcard_field = self::$_this->get_creditcard_field( $validation_result[ 'form' ] ); 
  3751.  
  3752. if ( $creditcard_field && RGFormsModel::is_field_hidden( $validation_result[ 'form' ], $creditcard_field, array() ) ) { 
  3753. $is_ready_for_capture = false; 
  3754. $reason = 'creditcard'; 
  3755.  
  3756.  
  3757. return apply_filters( 'gfp_stripe_is_ready_for_capture', $is_ready_for_capture, $reason, $validation_result ); 
  3758.  
  3759. /** 
  3760. * @param $form 
  3761. * @return bool 
  3762. */ 
  3763. public static function is_last_page( $form ) { 
  3764.  
  3765. $current_page = GFFormDisplay::get_source_page( $form[ "id" ] ); 
  3766. $target_page = GFFormDisplay::get_target_page( $form, $current_page, rgpost( 'gform_field_values' ) ); 
  3767.  
  3768. return ( $target_page == 0 ); 
  3769.  
  3770. /** 
  3771. * @param $stripe_form_meta 
  3772. * @param $feed_id 
  3773. * @return array 
  3774. */ 
  3775. public static function get_feed( $stripe_form_meta, $feed_id ) { 
  3776.  
  3777. $feed = array(); 
  3778.  
  3779. foreach ( $stripe_form_meta[ 'rules' ] as $id => $rule ) { 
  3780.  
  3781. if ( $id == $feed_id ) { 
  3782.  
  3783. $feed = array( 
  3784. 'id' => $rule[ 'id' ],  
  3785. 'meta' => $rule,  
  3786. 'form_id' => stristr( $rule[ 'id' ], '.', true ) 
  3787. ); 
  3788.  
  3789. if ( isset( $rule[ 'is_active' ] ) ) { 
  3790. $feed[ 'is_active' ] = $rule[ 'is_active' ]; 
  3791.  
  3792. break; 
  3793.  
  3794.  
  3795.  
  3796. return $feed; 
  3797.  
  3798. /** 
  3799. * @param $form 
  3800. * @return bool 
  3801. */ 
  3802. public static function get_feed_that_meets_condition( $form ) { 
  3803.  
  3804. $feeds = GFP_Stripe_Data::get_feed_by_form( $form[ 'id' ], true ); 
  3805.  
  3806. if ( ! $feeds ) { 
  3807. return false; 
  3808.  
  3809. foreach ( $feeds as $feed ) { 
  3810.  
  3811. if ( self::$_this->has_stripe_condition( $form, $feed ) ) { 
  3812. return $feed; 
  3813.  
  3814.  
  3815. return false; 
  3816.  
  3817. /** 
  3818. * @param $form 
  3819. * @param $feed 
  3820. * @return bool 
  3821. */ 
  3822. public function has_stripe_condition( $form, $feed ) { 
  3823.  
  3824. $feed = $feed[ 'meta' ]; 
  3825.  
  3826. $operator = $feed[ 'stripe_conditional_operator' ]; 
  3827. $field = RGFormsModel::get_field( $form, $feed[ 'stripe_conditional_field_id' ] ); 
  3828.  
  3829. if ( empty( $field ) || ! $feed[ 'stripe_conditional_enabled' ] ) { 
  3830. return true; 
  3831.  
  3832. $is_visible = ! RGFormsModel::is_field_hidden( $form, $field, array() ); 
  3833.  
  3834. $field_value = RGFormsModel::get_field_value( $field, array() ); 
  3835.  
  3836. $is_value_match = RGFormsModel::is_value_match( $field_value, $feed[ 'stripe_conditional_value' ], $operator ); 
  3837. $do_stripe = $is_value_match && $is_visible; 
  3838.  
  3839. return $do_stripe; 
  3840.  
  3841. /** 
  3842. * Get credit card field 
  3843. * @since 
  3844. * @uses GFCommon::get_fields_by_type() 
  3845. * @param $form 
  3846. * @return bool 
  3847. */ 
  3848. public static function get_creditcard_field( $form ) { 
  3849.  
  3850. $fields = GFCommon::get_fields_by_type( $form, array( 'creditcard' ) ); 
  3851.  
  3852. return empty( $fields ) ? false : $fields[ 0 ]; 
  3853.  
  3854.  
  3855. /** 
  3856. * Process payment 
  3857. * @since 0.1.0 
  3858. * @uses GFP_Stripe::log_debug() 
  3859. * @uses GFP_Stripe::get_form_data() 
  3860. * @uses GFP_Stripe::is_last_page() 
  3861. * @uses GFP_Stripe::get_creditcard_field() 
  3862. * @uses GFP_Stripe::has_visible_products() 
  3863. * @uses GFP_Stripe::include_api() 
  3864. * @uses GFP_Stripe::get_api_key() 
  3865. * @uses PPP\Stripe\Stripe::setApiKey() 
  3866. * @uses PPP\Stripe\Customer::create() 
  3867. * @uses apply_filters() 
  3868. * @uses GFP_Stripe::log_error() 
  3869. * @uses GFP_Stripe::gfp_stripe_create_error_message() 
  3870. * @uses GFP_Stripe::set_validation_result() 
  3871. * @uses PPP\Stripe\Charge::create( 
  3872. * @uses GFCommon::get_currency() 
  3873. * @param $feed 
  3874. * @param $validation_result 
  3875. * @return mixed 
  3876. */ 
  3877. private function make_product_payment( $feed, $validation_result ) { 
  3878.  
  3879. $form = $validation_result[ 'form' ]; 
  3880.  
  3881. self::$_this->log_debug( "Starting to make a product payment for form: {$form['id']}" ); 
  3882.  
  3883. $form_data = self::$_this->get_form_data( $form, $feed ); 
  3884.  
  3885. if ( $form_data[ 'amount' ] < 0.5 ) { 
  3886.  
  3887. self::$_this->log_debug( 'Amount is less than $0.50. No need to process payment, but act as if transaction was successful' ); 
  3888.  
  3889. if ( $this->is_last_page( $form ) ) { 
  3890.  
  3891. $card_field = self::$_this->get_creditcard_field( $form ); 
  3892. $_POST[ "input_{$card_field["id"]}_1" ] = ''; 
  3893.  
  3894.  
  3895. if ( $this->has_visible_products( $form ) ) { 
  3896.  
  3897. self::$transaction_response = array( 
  3898. 'transaction_id' => 'N/A',  
  3899. 'amount' => $form_data[ 'amount' ],  
  3900. 'transaction_type' => 1 
  3901. ); 
  3902.  
  3903.  
  3904. return $validation_result; 
  3905.  
  3906. self::$_this->include_api(); 
  3907.  
  3908. $secret_api_key = self::$_this->get_api_key( 'secret' ); 
  3909.  
  3910. self::$_this->log_debug( 'Creating the customer' ); 
  3911.  
  3912. try { 
  3913.  
  3914. $customer = PPP\Stripe\Customer::create( array( 
  3915. 'description' => apply_filters( 'gfp_stripe_customer_description', $form_data[ 'name' ], $form_data, $form ),  
  3916. 'source' => $form_data[ 'credit_card' ],  
  3917. 'email' => $form_data[ 'email' ],  
  3918. 'expand' => array( 'default_source' ) 
  3919. ), $secret_api_key ); 
  3920.  
  3921. } catch ( Exception $e ) { 
  3922.  
  3923. self::$_this->log_error( 'Customer creation failed' ); 
  3924.  
  3925. $error_message = self::$_this->gfp_stripe_create_error_message( $e ); 
  3926.  
  3927. return self::$_this->set_validation_result( $validation_result, $_POST, $error_message ); 
  3928.  
  3929.  
  3930. if ( ! class_exists( 'RGCurrency' ) ) { 
  3931. require_once( GFCommon::get_base_path() . '/currency.php' ); 
  3932.  
  3933. $currency_info = RGCurrency::get_currency( GFCommon::get_currency() ); 
  3934.  
  3935. try { 
  3936.  
  3937. self::$_this->log_debug( 'Creating the charge, using the customer ID' ); 
  3938.  
  3939. $response = PPP\Stripe\Charge::create( array( 
  3940. 'amount' => ( 0 == $currency_info[ 'decimals' ] ) ? round( floatval( $form_data[ 'amount' ] ), 0 ) : ( $form_data[ 'amount' ] * 100 ),  
  3941. 'currency' => GFCommon::get_currency(),  
  3942. 'customer' => $customer[ 'id' ],  
  3943. 'description' => apply_filters( 'gfp_stripe_customer_charge_description', implode( '\n', $form_data[ 'line_items' ] ), $form ) 
  3944. ), $secret_api_key ); 
  3945.  
  3946. self::$_this->log_debug( "Charge successful. ID: {$response['id']} - Amount: {$response['amount']}" ); 
  3947.  
  3948. self::$transaction_response = array( 
  3949. 'transaction_id' => $response[ 'id' ],  
  3950. 'amount' => $response[ 'amount' ] / 100,  
  3951. 'transaction_type' => 1,  
  3952. 'customer' => $customer 
  3953. ); 
  3954.  
  3955. $validation_result[ 'is_valid' ] = true; 
  3956.  
  3957. return $validation_result; 
  3958.  
  3959. } catch ( Exception $e ) { 
  3960.  
  3961. self::$_this->log_error( 'Charge failed' ); 
  3962.  
  3963. $error_message = self::$_this->gfp_stripe_create_error_message( $e ); 
  3964.  
  3965. return self::$_this->set_validation_result( $validation_result, $_POST, $error_message ); 
  3966.  
  3967.  
  3968. /** 
  3969. * Get form data 
  3970. * @since 
  3971. * @uses RGFormsModel::create_lead() 
  3972. * @uses GFCommon::get_product_fields() 
  3973. * @uses rgpost() 
  3974. * @uses apply_filters() 
  3975. * @uses GFP_Stripe::get_order_info() 
  3976. * @param $form 
  3977. * @param $feed 
  3978. * @return mixed|void 
  3979. */ 
  3980. public static function get_form_data( $form, $feed ) { 
  3981.  
  3982. $tmp_lead = RGFormsModel::create_lead( $form ); 
  3983. $products = GFCommon::get_product_fields( $form, $tmp_lead ); 
  3984. $form_data = array(); 
  3985.  
  3986. $form_data[ 'form_title' ] = $form[ 'title' ]; 
  3987. $form_data[ 'name' ] = rgpost( 'input_' . str_replace( '.', '_', $feed[ 'meta' ][ 'customer_fields' ][ 'first_name' ] ) ) . ' ' . rgpost( 'input_' . str_replace( '.', '_', $feed[ 'meta' ][ 'customer_fields' ][ 'last_name' ] ) ); 
  3988. $form_data[ 'email' ] = rgpost( 'input_' . str_replace( '.', '_', $feed[ 'meta' ][ 'customer_fields' ][ 'email' ] ) ); 
  3989. $form_data[ 'address1' ] = rgpost( 'input_' . str_replace( '.', '_', $feed[ 'meta' ][ 'customer_fields' ][ 'address1' ] ) ); 
  3990. $form_data[ 'address2' ] = rgpost( 'input_' . str_replace( '.', '_', $feed[ 'meta' ][ 'customer_fields' ][ 'address2' ] ) ); 
  3991. $form_data[ 'city' ] = rgpost( 'input_' . str_replace( '.', '_', $feed[ 'meta' ][ 'customer_fields' ][ 'city' ] ) ); 
  3992. $form_data[ 'state' ] = rgpost( 'input_' . str_replace( '.', '_', $feed[ 'meta' ][ 'customer_fields' ][ 'state' ] ) ); 
  3993. $form_data[ 'zip' ] = rgpost( 'input_' . str_replace( '.', '_', $feed[ 'meta' ][ 'customer_fields' ][ 'zip' ] ) ); 
  3994. $form_data[ 'country' ] = rgpost( 'input_' . str_replace( '.', '_', $feed[ 'meta' ][ 'customer_fields' ][ 'country' ] ) ); 
  3995. $form_data[ 'credit_card' ] = rgpost( 'stripeToken' ); 
  3996.  
  3997. $form_data = apply_filters( 'gfp_stripe_get_form_data', $form_data, $feed, $products, $form, $tmp_lead ); 
  3998. $order_info_args = ''; 
  3999. $order_info = self::$_this->get_order_info( $products, apply_filters( 'gfp_stripe_get_form_data_order_info', $order_info_args, $feed ), $form_data ); 
  4000.  
  4001. $form_data[ 'line_items' ] = $order_info[ 'line_items' ]; 
  4002. $form_data[ 'amount' ] = $order_info[ 'amount' ]; 
  4003.  
  4004. return $form_data; 
  4005.  
  4006. /** 
  4007. * Get order info 
  4008. * @since 
  4009. * @uses apply_filters() 
  4010. * @uses GFCommon::to_number() 
  4011. * @uses __() 
  4012. * @uses has_action() 
  4013. * @param $products 
  4014. * @param $additional_fields 
  4015. * @param $form_data 
  4016. * @return array 
  4017. */ 
  4018. private function get_order_info( $products, $additional_fields, $form_data ) { 
  4019.  
  4020. $amount = 0; 
  4021. $line_items = array(); 
  4022. $item = 1; 
  4023. $continue_flag = 0; 
  4024. $new_line_item = ''; 
  4025.  
  4026. foreach ( $products[ 'products' ] as $field_id => $product ) { 
  4027.  
  4028. $continue_flag = apply_filters( 'gfp_stripe_get_order_info', $continue_flag, $field_id, $additional_fields ); 
  4029.  
  4030. if ( $continue_flag ) { 
  4031. continue; 
  4032.  
  4033. $quantity = $product[ 'quantity' ] ? $product[ 'quantity' ] : 1; 
  4034.  
  4035. $product_price = GFCommon::to_number( $product[ 'price' ], ( ! empty ( $form_data[ 'currency' ] ) ) ? $form_data[ 'currency' ] : '' ); 
  4036.  
  4037. $options = array(); 
  4038.  
  4039. if ( isset( $product[ 'options' ] ) && is_array( $product[ 'options' ] ) ) { 
  4040.  
  4041. foreach ( $product[ 'options' ] as $option ) { 
  4042.  
  4043. $options[ ] = $option[ 'option_label' ]; 
  4044. $product_price += $option[ 'price' ]; 
  4045.  
  4046.  
  4047.  
  4048. $amount += $product_price * $quantity; 
  4049.  
  4050. $description = ''; 
  4051.  
  4052. if ( ! empty( $options ) ) { 
  4053. $description = __( 'options: ', 'gravity-forms-stripe' ) . ' ' . implode( ', ', $options ); 
  4054.  
  4055. if ( has_action( 'gfp_stripe_get_order_info_line_items' ) ) { 
  4056.  
  4057. $new_line_item = apply_filters( 'gfp_stripe_get_order_info_line_items', $line_items, $product_price, $field_id, $quantity, $product, $description, $item, $form_data ); 
  4058.  
  4059. if ( ! empty( $new_line_item ) ) { 
  4060.  
  4061. $line_items[ ] = $new_line_item; 
  4062. $new_line_item = ''; 
  4063.  
  4064. $item ++; 
  4065.  
  4066.  
  4067. } else if ( ( $product_price >= 0 ) ) { 
  4068.  
  4069. $line_items[ ] = "(" . $quantity . ")\t" . $product[ "name" ] . "\t" . $description . "\tx\t" . GFCommon::to_money( $product_price, ( ! empty ( $form_data[ 'currency' ] ) ) ? $form_data[ 'currency' ] : '' ); 
  4070.  
  4071. $item ++; 
  4072.  
  4073.  
  4074.  
  4075. if ( has_action( 'gfp_stripe_get_order_info_shipping' ) ) { 
  4076.  
  4077. $shipping_info = apply_filters( 'gfp_stripe_get_order_info_shipping', $line_items, $products, $amount, $item, $additional_fields, $form_data ); 
  4078.  
  4079. if ( ! empty( $shipping_info ) ) { 
  4080.  
  4081. $line_items = $shipping_info[ 'line_items' ]; 
  4082. $amount = $shipping_info[ 'amount' ]; 
  4083.  
  4084. $shipping_info = ''; 
  4085.  
  4086.  
  4087. } else if ( ! empty( $products[ 'shipping' ][ 'name' ] ) ) { 
  4088.  
  4089. $line_items[ ] = $item . "\t" . $products[ 'shipping' ][ 'name' ] . "\t" . "1" . "\t" . $products[ 'shipping' ][ 'price' ]; 
  4090.  
  4091. $amount += $products[ 'shipping' ][ 'price' ]; 
  4092.  
  4093.  
  4094. return array( 
  4095. 'amount' => $amount,  
  4096. 'line_items' => $line_items 
  4097. ); 
  4098.  
  4099. /** 
  4100. * @param $product 
  4101. * @return mixed 
  4102. */ 
  4103. public static function get_product_unit_price( $product ) { 
  4104.  
  4105. $product_total = $product[ 'price' ]; 
  4106.  
  4107. foreach ( $product[ 'options' ] as $option ) { 
  4108.  
  4109. $options[ ] = $option[ 'option_label' ]; 
  4110.  
  4111. $product_total += $option[ 'price' ]; 
  4112.  
  4113.  
  4114. return $product_total; 
  4115.  
  4116. /** 
  4117. * Has visible products 
  4118. * @since 
  4119. * @uses RGFormsModel::is_field_hidden() 
  4120. * @param $form 
  4121. * @return bool 
  4122. */ 
  4123. public static function has_visible_products( $form ) { 
  4124.  
  4125. foreach ( $form[ 'fields' ] as $field ) { 
  4126.  
  4127. if ( $field[ 'type' ] == 'product' && ! RGFormsModel::is_field_hidden( $form, $field, '' ) ) { 
  4128. return true; 
  4129.  
  4130.  
  4131. return false; 
  4132.  
  4133. /** 
  4134. * @param $validation_result 
  4135. * @param $post 
  4136. * @param $error_message 
  4137. * @return mixed 
  4138. */ 
  4139. public static function set_validation_result( $validation_result, $post, $error_message ) { 
  4140.  
  4141. $credit_card_page = 0; 
  4142.  
  4143. foreach ( $validation_result[ 'form' ][ 'fields' ] as &$field ) { 
  4144.  
  4145. if ( 'creditcard' == $field[ 'type' ] ) { 
  4146.  
  4147. $field[ 'failed_validation' ] = true; 
  4148. $field[ 'validation_message' ] = $error_message; 
  4149.  
  4150. $credit_card_page = $field[ 'pageNumber' ]; 
  4151.  
  4152. break; 
  4153.  
  4154.  
  4155.  
  4156. $validation_result[ 'is_valid' ] = false; 
  4157.  
  4158. GFFormDisplay::set_current_page( $validation_result[ 'form' ][ 'id' ], $credit_card_page ); 
  4159.  
  4160. $validation_result = apply_filters( 'gfp_stripe_set_validation_result', $validation_result, $post, $error_message ); 
  4161.  
  4162.  
  4163. return $validation_result; 
  4164.  
  4165. /** 
  4166. * @param $e 
  4167. * @param bool $mode 
  4168. * @return mixed|void 
  4169. */ 
  4170. public static function gfp_stripe_create_error_message( $e, $mode = false ) { 
  4171.  
  4172. $error_class = get_class( $e ); 
  4173. $error_message = $e->getMessage(); 
  4174. $response = $error_class . ': ' . $error_message; 
  4175.  
  4176. self::$_this->log_error( print_r( $response, true ) ); 
  4177.  
  4178. if ( ! $mode ) { 
  4179. $settings = get_option( 'gfp_stripe_settings' ); 
  4180. $mode = rgar( $settings, 'mode' ); 
  4181.  
  4182. if ( 'live' === $mode ) { 
  4183.  
  4184. switch ( $error_class ) { 
  4185.  
  4186. case 'PPP\Stripe\Error\InvalidRequest': 
  4187. $error_message = 'This form cannot process your payment. Please contact site owner.'; 
  4188. break; 
  4189. case 'PPP\Stripe\Error\ApiConnection': 
  4190. $error_message = 'There was a temporary network communication error and while we try to make sure these never happen, sometimes they do. Please try your payment again in a few minutes and if this continues, please contact site owner.'; 
  4191. break; 
  4192. case 'PPP\Stripe\Error\Card': 
  4193. break; 
  4194. default: 
  4195. $error_message = 'This form cannot process your payment. Please contact site owner.'; 
  4196.  
  4197.  
  4198.  
  4199. return apply_filters( 'gfp_stripe_error_message', $error_message, $e ); 
  4200.  
  4201. //------------------------------------------------------ 
  4202. //------------- ENTRY --------------------------- 
  4203. //------------------------------------------------------ 
  4204.  
  4205. /** 
  4206. * @param $value 
  4207. * @param $lead 
  4208. * @param $field 
  4209. * @param $form 
  4210. * @return mixed|string 
  4211. */ 
  4212. public function gform_save_field_value( $value, $lead, $field, $form ) { 
  4213.  
  4214. if ( ! empty( self::$transaction_response ) ) { 
  4215.  
  4216. $input_type = RGFormsModel::get_input_type( $field ); 
  4217.  
  4218. if ( ( 'creditcard' == $input_type ) && ( rgpost( "input_{$field['id']}_4" ) !== $value ) ) { 
  4219.  
  4220. $transaction_type = self::$transaction_response[ 'transaction_type' ]; 
  4221.  
  4222. if ( 1 == $transaction_type ) { 
  4223.  
  4224. $value = self::$transaction_response[ 'customer' ]->default_source[ 'id' ]; 
  4225.  
  4226.  
  4227.  
  4228. return $value; 
  4229.  
  4230. /** 
  4231. * Save payment information to DB 
  4232. * @since 1.7.9.1 
  4233. * @uses rgar() 
  4234. * @uses GFCommon::get_currency() 
  4235. * @uses rgpost() 
  4236. * @uses RGFormsModel::get_lead_details_table_name() 
  4237. * @uses wpdb->prepare() 
  4238. * @uses wpdb->get_results() 
  4239. * @uses RGFormsModel::get_lead_detail_id() 
  4240. * @uses wpdb->update() 
  4241. * @uses wpdb->insert() 
  4242. * @uses RGFormsModel::update_lead() 
  4243. * @uses apply_filters() 
  4244. * @uses GFP_Stripe::get_feed_that_meets_condition() 
  4245. * @uses gform_update_meta() 
  4246. * @uses GFP_Stripe_Data::insert_transaction() 
  4247. * @param $entry 
  4248. * @param $form 
  4249. * @return $entry 
  4250. */ 
  4251. public function gform_entry_post_save( $entry, $form ) { 
  4252.  
  4253. global $wpdb; 
  4254.  
  4255. $entry_id = rgar( $entry, 'id' ); 
  4256.  
  4257. if ( ! empty( self::$transaction_response ) ) { 
  4258.  
  4259. $transaction_id = self::$transaction_response[ 'transaction_id' ]; 
  4260. $transaction_type = self::$transaction_response[ 'transaction_type' ]; 
  4261.  
  4262. $amount = array_key_exists( 'amount', self::$transaction_response ) ? self::$transaction_response[ 'amount' ] : null; 
  4263.  
  4264. $payment_date = gmdate( 'Y-m-d H:i:s' ); 
  4265.  
  4266. $entry[ 'currency' ] = array_key_exists( 'currency', self::$transaction_response ) ? self::$transaction_response[ 'currency' ] : null; 
  4267.  
  4268. if ( '1' == $transaction_type ) { 
  4269.  
  4270. $entry[ 'payment_status' ] = 'Paid'; 
  4271. $entry[ 'payment_amount' ] = $amount; 
  4272. $entry[ 'is_fulfilled' ] = true; 
  4273. $entry[ 'transaction_id' ] = $transaction_id; 
  4274. $entry[ 'payment_date' ] = $payment_date; 
  4275.  
  4276.  
  4277. $entry[ 'transaction_type' ] = $transaction_type; 
  4278.  
  4279. $entry = apply_filters( 'gfp_stripe_entry_post_save_update_lead', $entry ); 
  4280.  
  4281. GFAPI::update_entry( $entry ); 
  4282.  
  4283. $feed = self::$_this->get_feed_that_meets_condition( $form ); 
  4284. gform_update_meta( $entry_id, 'stripe_feed_id', $feed[ 'id' ] ); 
  4285.  
  4286. gform_update_meta( $entry_id, 'payment_gateway', 'stripe' ); 
  4287.  
  4288. $settings = get_option( 'gfp_stripe_settings' ); 
  4289. $mode = rgar( $settings, 'mode' ); 
  4290.  
  4291. $transaction = apply_filters( 'gfp_stripe_entry_post_save_insert_transaction', array( 
  4292. 'entry_id' => $entry[ 'id' ],  
  4293. 'user_id' => null,  
  4294. 'type' => 'payment',  
  4295. 'id' => $transaction_id,  
  4296. 'amount' => $amount,  
  4297. 'mode' => $mode,  
  4298. 'meta' => '' 
  4299. ) ); 
  4300.  
  4301. GFP_Stripe_Data::insert_transaction( $transaction[ 'entry_id' ], $transaction[ 'user_id' ], $transaction[ 'type' ], $transaction[ 'id' ], $transaction[ 'amount' ], $entry[ 'currency' ], $transaction[ 'mode' ], $transaction[ 'meta' ] ); 
  4302.  
  4303. do_action( 'gfp_stripe_entry_post_save', $entry ); 
  4304.  
  4305. if ( 1 == $transaction_type || 2 == $transaction_type ) { 
  4306.  
  4307. do_action( 'gform_post_payment_completed', $entry, array( 
  4308. 'type' => 'complete_payment',  
  4309. 'amount' => $transaction[ 'amount' ],  
  4310. 'transaction_type' => $transaction[ 'type' ],  
  4311. 'transaction_id' => $transaction[ 'id' ],  
  4312. 'subscription_id' => ( 2 == $transaction_type ) ? self::$transaction_response[ 'subscription' ][ 'id' ] : false,  
  4313. 'entry_id' => $transaction[ 'entry_id' ],  
  4314. 'payment_status' => $entry[ 'payment_status' ],  
  4315. 'payment_date' => $payment_date,  
  4316. 'payment_method' => ( 2 == $transaction_type ) ? self::$transaction_response[ 'subscription' ][ 'customer' ]->default_source[ 'brand' ] : self::$transaction_response[ 'customer' ]->default_source[ 'brand' ] 
  4317. ) ); 
  4318.  
  4319.  
  4320.  
  4321. return $entry; 
  4322.  
  4323.  
  4324. /** 
  4325. * @since 1.8.2 
  4326. * @param $form_id 
  4327. * @param $entry 
  4328. */ 
  4329. public function gform_entry_detail_sidebar_middle( $form, $entry ) { 
  4330.  
  4331. if ( self::is_stripe_entry( $entry[ 'id' ] ) ) { 
  4332.  
  4333. $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; 
  4334.  
  4335. wp_enqueue_script( 'gfp_stripe_entries_page_js', trailingslashit( GFP_STRIPE_URL ) . "js/entries-page{$suffix}.js", array( 'jquery' ), GFP_Stripe::get_version() ); 
  4336.  
  4337. require_once( trailingslashit( GFP_STRIPE_PATH ) . 'includes/views/entry-detail-stripe-payment-details.php' ); 
  4338.  
  4339.  
  4340.  
  4341. //------------------------------------------------------ 
  4342. //------------- HELPERS -------------------------- 
  4343. //------------------------------------------------------ 
  4344.  
  4345. /** 
  4346. * Validate Stripe API keys 
  4347. * @since 0.1.0 
  4348. * @uses GFP_Stripe::include_api() 
  4349. * @uses get_option() 
  4350. * @uses PPP\Stripe\Stripe::setApiKey() 
  4351. * @uses PPP\Stripe\Token::create() 
  4352. * @return array 
  4353. */ 
  4354. private function is_valid_key() { 
  4355.  
  4356. self::$_this->include_api(); 
  4357. $settings = get_option( 'gfp_stripe_settings' ); 
  4358.  
  4359. $year = date( 'Y' ) + 1; 
  4360.  
  4361. $valid_keys = array( 
  4362. 'test_secret_key' => false,  
  4363. 'test_publishable_key' => false,  
  4364. 'live_secret_key' => false,  
  4365. 'live_publishable_key' => false 
  4366. ); 
  4367. $valid = false; 
  4368. $flag_false = 0; 
  4369.  
  4370. foreach ( $valid_keys as $key => $value ) { 
  4371.  
  4372. if ( ! empty( $settings[ $key ] ) ) { 
  4373.  
  4374. try { 
  4375.  
  4376. PPP\Stripe\Stripe::setApiKey( $settings[ $key ] ); 
  4377. PPP\Stripe\Token::create( array( 
  4378. 'card' => array( 
  4379. 'number' => '4242424242424242',  
  4380. 'exp_month' => 3,  
  4381. 'exp_year' => $year,  
  4382. 'cvc' => 314 
  4383. ),  
  4384. ) ); 
  4385. $valid_keys[ $key ] = true; 
  4386.  
  4387. } catch ( Exception $e ) { 
  4388.  
  4389. $class = get_class( $e ); 
  4390. $message = $e->getMessage(); 
  4391.  
  4392. if ( 'PPP\Stripe\Error\Card' == $class ) { 
  4393. $valid_keys[ $key ] = true; 
  4394. } else { 
  4395. $flag_false ++; 
  4396.  
  4397. $errors[ $key ] = array( $class, $message ); 
  4398.  
  4399.  
  4400. } else { 
  4401. $flag_false ++; 
  4402.  
  4403.  
  4404. if ( 0 == $flag_false ) { 
  4405. $valid = true; 
  4406.  
  4407. return array( $valid, $valid_keys ); 
  4408. } else { 
  4409. return array( $valid, $valid_keys, isset( $errors ) ? $errors : null ); 
  4410.  
  4411.  
  4412. /** 
  4413. * Return the desired API key from the database 
  4414. * @since 
  4415. * @uses get_option() 
  4416. * @uses rgar() 
  4417. * @uses esc_attr() 
  4418. * @param $type 
  4419. * @param bool $mode 
  4420. * @return string 
  4421. */ 
  4422. public static function get_api_key( $type, $mode = false ) { 
  4423. $settings = get_option( 'gfp_stripe_settings' ); 
  4424. if ( ! $mode ) { 
  4425. $mode = rgar( $settings, 'mode' ); 
  4426. $key = $mode . '_' . $type . '_key'; 
  4427.  
  4428. return trim( esc_attr( rgar( $settings, $key ) ) ); 
  4429.  
  4430.  
  4431.  
  4432. /** 
  4433. * Include the Stripe library 
  4434. * @since 0.1.0 
  4435. * @return void 
  4436. */ 
  4437. public static function include_api() { 
  4438.  
  4439. if ( ! class_exists( 'PPP\\Stripe\\Stripe' ) ) { 
  4440. require_once( GFP_STRIPE_PATH . '/includes/api/stripe-php/init.php' ); 
  4441.  
  4442.  
  4443. /** 
  4444. * Return the url of the plugin's root folder 
  4445. * @since 
  4446. * @uses plugins_url() 
  4447. * @return string 
  4448. */ 
  4449. public static function get_base_url() { 
  4450.  
  4451. return plugins_url( null, GFP_STRIPE_FILE ); 
  4452.  
  4453.  
  4454. /** 
  4455. * Return the physical path of the plugin's root folder 
  4456. * @since 
  4457. * @return string 
  4458. */ 
  4459. private static function get_base_path() { 
  4460. $folder = basename( dirname( GFP_STRIPE_FILE ) ); 
  4461.  
  4462. return WP_PLUGIN_DIR . '/' . $folder; 
  4463.  
  4464. /** 
  4465. * @param $form 
  4466. * @return bool 
  4467. */ 
  4468. public static function is_stripe_form( $form ) { 
  4469. $is_stripe_form = false; 
  4470.  
  4471. if ( is_numeric( $form ) ) { 
  4472. $form = RGFormsModel::get_form_meta( $form ); 
  4473. if ( ( ! $form == null ) && ( GFCommon::has_credit_card_field( $form ) ) ) { 
  4474. $form_feeds = GFP_Stripe_Data::get_feed_by_form( $form[ 'id' ], true ); 
  4475.  
  4476. if ( ! empty( $form_feeds ) ) { 
  4477. $is_stripe_form = true; 
  4478.  
  4479. return $is_stripe_form; 
  4480.  
  4481. /** 
  4482. * Set transaction response 
  4483. * @since 
  4484. * @param $response 
  4485. * @return void 
  4486. */ 
  4487. public static function set_transaction_response( $response ) { 
  4488. self::$transaction_response = $response; 
  4489.  
  4490. /** 
  4491. * @return string 
  4492. */ 
  4493. public static function get_transaction_response() { 
  4494. return self::$transaction_response; 
  4495.  
  4496. public static function is_stripe_entry( $entry_id ) { 
  4497. $is_stripe_entry = false; 
  4498. $transaction = GFP_Stripe_Data::get_transaction_by( 'entry', $entry_id ); 
  4499.  
  4500. if ( ! empty( $transaction ) ) { 
  4501. $is_stripe_entry = true; 
  4502.  
  4503. return $is_stripe_entry; 
  4504.  
  4505. //------------------------------------------------------ 
  4506. //------------- LOGGING -------------------------- 
  4507. //------------------------------------------------------ 
  4508.  
  4509. /** 
  4510. * Add this plugin to Gravity Forms Logging Add-On 
  4511. * @since 
  4512. * @param $plugins 
  4513. * @return mixed 
  4514. */ 
  4515. function gform_logging_supported( $plugins ) { 
  4516.  
  4517. $plugins[ self::$slug ] = 'Gravity Forms + Stripe'; 
  4518.  
  4519. return $plugins; 
  4520.  
  4521.  
  4522. /** 
  4523. * Log an error message 
  4524. * @since 
  4525. * @uses GFLogging::include_logger() 
  4526. * @uses GFLogging::log_message 
  4527. * @param $message 
  4528. * @return void 
  4529. */ 
  4530. public static function log_error( $message ) { 
  4531.  
  4532. if ( class_exists( 'GFLogging' ) ) { 
  4533.  
  4534. GFLogging::include_logger(); 
  4535.  
  4536. GFLogging::log_message( self::$slug, $message, KLogger::ERROR ); 
  4537.  
  4538.  
  4539.  
  4540. /** 
  4541. * Log a debug message 
  4542. * @since 
  4543. * @uses GFLogging::include_logger() 
  4544. * @uses GFLogging::log_message 
  4545. * @param $message 
  4546. * @return void 
  4547. */ 
  4548. public static function log_debug( $message ) { 
  4549.  
  4550. if ( class_exists( 'GFLogging' ) ) { 
  4551.  
  4552. GFLogging::include_logger(); 
  4553.  
  4554. GFLogging::log_message( self::$slug, $message, KLogger::DEBUG ); 
  4555.