Ejemplo n.º 1
0
    function controlForm()
    {
        echo '<style>.wp-editor-wrap{max-width: 700px;}code{display:block}div.even{background:white;margin-top:15px;margin-bottom:15px;padding:10px}div.odd{padding:10px;}</style>';
        $d = get_option("chargify");
        if (isset($_POST['chargify-save-nonce']) && wp_verify_nonce($_POST['chargify-save-nonce'], plugin_basename(__FILE__))) {
            if (isset($_REQUEST['chargifySignupLink']) && $_REQUEST['chargifySignupLink'] == 'auto-create') {
                $signupurl = get_permalink(wp_insert_post(array('post_type' => 'page', 'post_title' => 'Chargify', 'post_status' => 'publish')));
            } elseif (isset($_REQUEST['chargifySignupLink']) && $_REQUEST['chargifySignupLink']) {
                $signupurl = $_REQUEST['chargifySignupLink'];
            } else {
                $signupurl = $d['chargifySignupLink'];
            }
            $d["chargifyApiKey"] = $_REQUEST["chargifyApiKey"];
            $d["chargifyTestApiKey"] = $_REQUEST["chargifyTestApiKey"];
            $d["chargifyDomain"] = $_REQUEST["chargifyDomain"];
            $d["chargifyTestDomain"] = $_REQUEST["chargifyTestDomain"];
            $d["chargifyMode"] = $_REQUEST["chargifyMode"];
            $d["chargifyNoAccessAction"] = $_REQUEST["chargifyNoAccessAction"];
            $d["chargifyDefaultNoAccess"] = $_REQUEST["chargifyDefaultNoAccess"];
            //$d["chargifyThankYou"] = $_REQUEST["chargifyThankYou"];
            $d["chargifySignupLink"] = $signupurl;
            $d["chargifySignupType"] = $_REQUEST["chargifySignupType"];
            $d["chargifyOrderFormPos"] = $_REQUEST["chargifyOrderFormPos"];
            $prods = stripslashes_deep($_REQUEST['chargifyproduct']);
            //foreach($prods as $k=>$v)
            //	$prods[$k]['raw'] = $v['raw'];
            $d["chargifyProducts"] = $prods;
            if (isset($_REQUEST['chargifyproduct']) && is_array($_REQUEST['chargifyproduct'])) {
                $opt = array("api_key" => $d["chargifyApiKey"], "test_api_key" => $d["chargifyTestApiKey"], "domain" => $d["chargifyDomain"], "test_domain" => $d["chargifyTestDomain"], "test_mode" => $d["chargifyMode"] == 'test' ? TRUE : FALSE);
                $connector = new ChargifyConnector($opt);
                foreach ($_REQUEST['chargifyproduct'] as $k => $v) {
                    if ($v['enable'] == 'on') {
                        $product = $connector->updateProduct($k, array('return_url' => $signupurl, 'accounting_code' => $v['acctcode'], 'description' => $v['description'], 'name' => $v['name']));
                        $d['chargifyProducts'][$k]['raw'] = base64_encode(serialize($product));
                    }
                }
            }
            update_option('chargify', $d);
            echo '<div class="updated"><p><strong>Options saved</strong></p></div>';
        }
        echo '<div class="wrap">';
        echo '<form name="chargify" method="post" action="">';
        echo '<input type="hidden" name="chargify-save-nonce" value="' . wp_create_nonce(plugin_basename(__FILE__)) . '" />';
        echo '<h2>Chargify Settings</h2>';
        echo '<h2 class="nav-tab-wrapper">';
        echo '<a href="#" class="nav-tab nav-tab-active" id="account">Chargify Account</a>';
        echo '<a href="#" class="nav-tab" id="products">Products</a>';
        echo '<a href="#" class="nav-tab" id="signup">Order Form</a>';
        echo '<a href="#" class="nav-tab" id="messages">Messages and Pages</a>';
        echo '<a href="#" class="nav-tab" id="help">Help</a>';
        echo '</h2>';
        echo '<div id="account" class="chargify-options-hidden-pane">';
        echo '<h3>Account Settings</h3>';
        echo '<p><em>Get this information from your Chargify account. Unless you have multiple accounts, the test values for the API Key and Test Domain are likely the same as their non-test counterparts.</em></p>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row"><label>API Key:</label></th>
                    <td><input type="text" size="40" name="chargifyApiKey" value="' . $d['chargifyApiKey'] . '"></td>
                </tr>
                <tr valign="top">
                    <th scope="row"><label>Test API Key:</label></th>
                    <td><input type="text" size="40" name="chargifyTestApiKey" value="' . $d['chargifyTestApiKey'] . '"></td>
                </tr>
                <tr valign="top">
                    <th scope="row"><label>Domain:</label></th>
                    <td><input type="text" size="40" name="chargifyDomain" value="' . $d['chargifyDomain'] . '">.chargify.com</td>
                </tr>
                <tr valign="top">
                    <th scope="row"><label>Test Domain:</label></th>
                    <td><input type="text" size="40" name="chargifyTestDomain" value="' . $d['chargifyTestDomain'] . '">.chargify.com</td>
                </tr>
                <tr valign="top">
                    <th scope="row"><label>Mode:</label></th>
                    <td><input type="radio" name="chargifyMode" value="test" ' . ($d['chargifyMode'] == 'test' ? 'checked' : '') . '>Test <input type="radio" name="chargifyMode" value="live" ' . ($d['chargifyMode'] == 'live' ? 'checked' : '') . '>Live</td>
                </tr>
            </table>';
        echo '</div>';
        echo '<div id="products" class="chargify-options-hidden-pane">';
        echo '<h3>Chargify Product Settings</h3>';
        echo '<style>.chargify-product{margin-bottom:25px;border:1px solid #dfdfdf;max-width:700px;padding:10px;background:white}.disabled{background:#333}.enabled{background:green}.chargify-product-title{color:white;margin-left:-10px;margin-right:-10px;margin-top:-10px;font-size:18pt;padding:10px;margin-bottom:10px;overflow:hidden}.chargify-product textarea{width:100%;height:6em}.chargify-product input[type="text"]{width:50%}.enablebox{float:right;}.sync{display:none}.outofsync{margin-right:25px;color:#c00}</style>';
        $products = self::products(true);
        if (is_array($products)) {
            foreach ($products as $p) {
                $sync = 'sync';
                if ($d['chargifyProducts'][$p->id]['raw'] != base64_encode(serialize($p)) && $d['chargifyProducts'][$p->id]['enable'] == 'on') {
                    $sync = 'outofsync';
                }
                $url = $d['chargifySignupLink'] . '?plan=' . strtolower(sanitize_title_with_dashes($p->getName()));
                echo '<input type="hidden" name="chargifyproduct[' . $p->id . '][raw]" value="' . base64_encode(serialize($p)) . '">';
                echo '<div class="chargify-product">';
                echo '<div class="chargify-product-title' . ($d['chargifyProducts'][$p->id]['enable'] ? ' enabled' : ' disabled') . '">' . $p->getName() . '<span class="enablebox"><span class="' . $sync . '">Out of Sync</span><input type="checkbox" name="chargifyproduct[' . $p->id . '][enable]"' . ($d['chargifyProducts'][$p->id]['enable'] ? ' CHECKED' : '') . '>Enable</span></div>';
                echo '<div>Name<br><input type="text" name="chargifyproduct[' . $p->id . '][name]" value="' . $p->getName() . '"></div>';
                echo '<div>Description<br><textarea name="chargifyproduct[' . $p->id . '][description]">' . $p->getDescription() . '</textarea></div>';
                echo '<div>Accounting Code<br><input type="text" name="chargifyproduct[' . $p->id . '][acctcode]" value="' . $p->getAccountCode() . '"></div>';
                echo '<div>Direct Link<br>' . $url . '</div>';
                //echo '<div>Return Parameters<br><input type="text" name="chargifyproduct['.$p->id.'][return_params]" value="'.(strlen($p->getReturnParams())?$p->getReturnParams():'subscription_id={subscription_id}&customer_reference={customer_reference}').'"></div>';
                //echo '<div><strong>Return URL: </strong>'.$p->getReturnUrl().'</div>';
                echo '</div>';
            }
        }
        echo '</div>';
        echo '<div id="signup" class="chargify-options-hidden-pane">';
        echo '<h3>Signup Type</h3>';
        echo '<p><em>How will your site process signups. <strong>NOTE: Most users should leave this set to default</strong>.</em></p>
            <table class="form-table">
                <tr valign="top">
                    <th scope="row"><input type="radio" name="chargifySignupType" value="default" ' . ($d['chargifySignupType'] == 'default' || $d['chargifySignupType'] != 'api' ? 'checked' : '') . '>Default</th>
                    <td>When a user creates a subscription they will go to Chargify to enter their payment information and be redirected back to this site to see the thank you page</td>
                </tr>
                <tr valign="top">
                    <th scope="row"><input type="radio" name="chargifySignupType" value="api" ' . ($d['chargifySignupType'] == 'api' ? 'checked' : '') . '>API Style</th>
                    <td><strong>Advanced Option: </strong>When a user creates a subscription they will enter their payment information on this site and the account will be created without the user ever leaving the site.<strong><br />IMPORTANT: Since you will be collecting credit card information in this mode you shouldn\'t activate this without having an SSL certificate on your site!</stron></td>
				</tr>
<tr valign="top">
            </table>';
        echo '<h3>Order Page</h3>';
        echo '<p><em>Choose the page that will display the Chargify subscription order form</em></p>';
        echo '<table class="form-table">';
        echo '<tr valign="top">
				<th scope="row"><label>Link to order page.</label></th>
				<td>';
        echo '<select name="chargifySignupLink" >';
        echo self::pagelist($d['chargifySignupLink']);
        echo '</select>';
        echo '<span class="description">This will get linked on a protected page when a user doesn\'t have access to the content</span><br>';
        if ($d['chargifySignupLink']) {
            echo '<strong>Currently: </strong>' . get_the_title(url_to_postid($d['chargifySignupLink'])) . '&nbsp;<a href="' . get_edit_post_link(url_to_postid($d['chargifySignupLink'])) . '">Edit Order Page</a>';
        } else {
            echo '<strong>Order Page Not Set</strong>';
        }
        echo '</td>
			</tr>
			<th scope="row">Order Form Position</th>
			<td><select name="chargifyOrderFormPos"><option value="top"' . ($d["chargifyOrderFormPos"] == "top" ? " SELECTED" : "") . '>Top</option><option value="bottom"' . ($d["chargifyOrderFormPos"] == "bottom" ? " SELECTED" : "") . '>Bottom</option></select>';
        echo '<span class="description">If there isn\'t a [chargify] shortcode does the orderform get placed on top or bottom of content</span>';
        echo '</td>
			</tr>
            </table>';
        echo '</div>';
        echo '<div id="messages" class="chargify-options-hidden-pane">';
        echo '<h3>No Access Message</h3>
            <p><em>Message to display if user doesn\'t have correct access to the content</em></p>
			<table class="form-table">';
        echo '<tr valign="top">';
        echo '<th scope="row">No Access Action</th>';
        echo '<td><select name="chargifyNoAccessAction" onChange="jQuery(\'#chargifyNoAccessEditor\').toggle()"><option value="default"' . ($d["chargifyNoAccessAction"] == "default" ? " SELECTED" : "") . '>Show custom message</option><option value="exerpt"' . ($d["chargifyNoAccessAction"] == "excerpt" ? " SELECTED" : "") . '>Show post excerpt</option></td>';
        echo '</tr>';
        echo '<tr valign="top" id="chargifyNoAccessEditor" style="' . ($d['chargifyNoAccessAction'] == 'excerpt' ? 'display:none' : '') . '">';
        echo '<td colspan="2">';
        wp_editor($d['chargifyDefaultNoAccess'], 'chargifyDefaultNoAccess');
        echo '</td>';
        echo '</tr>';
        echo '</table>';
        echo '<hr />';
        /*
                    echo '<h3>Thank You Message</h3>';
                    echo '<table class="form-table">';
        			echo '<tr valign="top">';
        				echo '<td colspan="2">';
        					wp_editor($d['chargifyThankYou'],'chargifyThankYou');
        				echo '</td>';
        			echo '</tr>';
        			echo '</table>';
        */
        echo '</div>';
        echo '<div id="help" class="chargify-options-hidden-pane">';
        echo '<h1>Chargify Plugin Configuration Instructions</h1>';
        echo '<div style="width:50%;display:inline-block">';
        ?>
			<div class="even"><h1>Documentation: <a href="http://chargifywp.com/documentation" target="_blank">View the documentation</a></h1>
				Please use the documentation link for the most up to date and step by step instructions on how to put everything together. For your convenience, we have version 1.0 instructions below in case you find them helpful.
			</div>
			<div class="even"><h2>1. <a id="click-1" class="click-help" href="<?php 
        echo admin_url('admin.php?page=chargify-admin-settings#chargify-signup');
        ?>
" onClick="javascript:jQuery('#signup').click();">Choose or have the plugin create</a> the order page</h2></div>
			<div class="odd"><h2>2. Enter your <a id="click-2" class="click-help" href="https://app.chargify.com/login.html" target="_blank">Chargify API keys</a> into the <a id="click-3" class="click-help" href="<?php 
        echo admin_url('admin.php?page=chargify-admin-settings#chargify-account');
        ?>
" onClick="javascript:jQuery('#account').click();">Chargify Account tab</a></h2></div>
			<div class="even"><h2>3. Setup the <a id="click-4" class="click-help" href="https://app.chargify.com/login.html" target="_blank">Return URL and Return Parameters</a> for each product's public signup page</h2>
			<em>This is important and has to happen in your Chargify account otherwise people will not be redirected back to your site after purchase and their accounts will not be created and everyone will become sad. Copy the Return URL and Return Parameters below into their respective slots on the public signup page's settings page</em><br><br>
			<strong>Return URL after successful signup:</strong><br>
			<code>
			<?php 
        echo site_url();
        ?>
			</code>
			<strong>Return Parameters:</strong><br>
			<code>
			subscription_id={subscription_id}&customer_reference={customer_reference}
			</code></div>
			<div class="odd"><h2>4. Enable the products you want on your site in the <a id="click-5" class="click-help" href="<?php 
        echo admin_url('admin.php?page=chargify-admin-settings#chargify-products');
        ?>
" onClick="javascript:jQuery('#products').click();">Products tab</a></h2></div>
			<div class="even"><h2>5. Protect some <a id="click-6" class="click-help" href="<?php 
        echo admin_url('');
        ?>
">pages or posts</a></h2></div>
			<div class="odd"><h2>6. Test some transactions with CC number of 1, CVV of 123 and any Expiration in the future make sure the subscription_id and customer_reference are passed back as well as <a id="click-7" class="click-help" href="#">making sure we automatically log in</a></h2></div>
			<div class="even"><h2>7. After testing the process set your account from test to live in both the <a id="click-8" class="click-help" href="<?php 
        echo admin_url('admin.php?page=chargify-admin-settings#chargify-account');
        ?>
" onClick="javascript:jQuery('#account').click();">Chargify Account tab</a> as well as the <a id="click-9" class="click-help" href="https://app.chargify.com/login.html" target="_blank">Chargify Dashboard</a></h2></div>
<?php 
        echo '</div>';
        echo '<div id="chargify-help-box" style="width:45%;display:inline-block;position:absolute;">';
        echo '</div>';
        echo '</div>';
        echo '<p class="submit"><input class="button-primary" type="submit" name="Submit" value="Update Options" /></p>';
        echo '</form>';
        echo '</div>';
        $pluginurl = WP_PLUGIN_URL . '/' . plugin_basename(dirname(__FILE__));
        ?>
<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery('.click-help').mouseover(function(){
			var thing = this.id;
			thing = thing.replace('click-','');
			var h = Math.floor(window.innerWidth/2);
			var v = Math.floor(window.innerHeight/2);
			hh = jQuery(document).scrollTop();
			jQuery('#chargify-help-box').css('right','10px');
			//jQuery('#chargify-help-box').css('top',v+hh-250+'px');
			jQuery('#chargify-help-box').css('top',hh+100+'px');
			jQuery('#chargify-help-box').html('<img style="max-width:100%;height:auto" src="<?php 
        echo $pluginurl;
        ?>
/images/'+ thing + '.jpg" />');
		});
		jQuery('.click-help').mouseout(function(){
			jQuery('#chargify-help-box').html('');
		});
	})
</script>
<?php 
    }
Ejemplo n.º 2
0
 public function widgetAccountInfoAction()
 {
     require_once APPPATH . "/src/externals/chargify-client/class.ChargifyConnector.php";
     require_once APPPATH . "/src/externals/chargify-client/class.ChargifyCreditCard.php";
     require_once APPPATH . "/src/externals/chargify-client/class.ChargifyCustomer.php";
     require_once APPPATH . "/src/externals/chargify-client/class.ChargifyProduct.php";
     require_once APPPATH . "/src/externals/chargify-client/class.ChargifySubscription.php";
     $js_module = array();
     $clientId = $this->user->getAccountId();
     if ($clientId == 0) {
         array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Logged in as', 'value' => 'SCALR ADMIN'));
     } else {
         $client = Client::Load($clientId);
         array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Logged in as', 'value' => $client->Email));
         // PayPal users: users without Chargify Client ID property
         if (!$client->GetSettingValue(CLIENT_SETTINGS::BILLING_CGF_CID)) {
             // Billing type
             array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Billing type', 'value' => 'PayPal (Legacy)'));
             $sid = $this->db->GetOne("SELECT subscriptionid FROM subscriptions WHERE clientid=? AND status='Active'", array($clientId));
             if ($sid) {
                 array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Subscription ID', 'value' => $sid));
             }
             $t = strtotime($client->DueDate);
             if ($t) {
                 array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Due date', 'value' => date("M j Y", $t)));
             }
             if ($this->db->GetOne("SELECT amount FROM payments WHERE clientid = ?", array($clientId)) == 50) {
                 $package = 'Beta-legacy';
             } else {
                 $package = 'Production';
             }
             if ($client->GetSettingValue(CLIENT_SETTINGS::BILLING_PACKAGE) == '3') {
                 $package = 'Mission Critical';
             }
             array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Plan', 'value' => $package));
         } else {
             if (!$client->GetSettingValue(CLIENT_SETTINGS::BILLING_CGF_SID)) {
                 array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Plan', 'value' => 'Development'));
             } else {
                 $c = new ChargifyConnector();
                 try {
                     $subs = $c->getCustomerSubscription($client->GetSettingValue(CLIENT_SETTINGS::BILLING_CGF_SID));
                     $color = ucfirst($subs->getState()) != 'Active' ? 'red' : 'green';
                     array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Status', 'value' => "<span style='color:{$color}'>" . ucfirst($subs->getState()) . "</span>"));
                     array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Billing type', 'value' => ucfirst($subs->getCreditCard()->getCardType()) . " (" . $subs->getCreditCard()->getMaskedCardNumber() . ")"));
                     array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Plan', 'value' => ucfirst($subs->getProduct()->getHandle())));
                     array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Due date', 'value' => date("M j Y", strtotime($subs->next_assessment_at))));
                     array_push($js_module, array('xtype' => 'displayfield', 'fieldLabel' => 'Balance', 'value' => "\$" . number_format($subs->getBalanceInCents() / 100, 2)));
                 } catch (Exception $e) {
                     array_push($js_module, array('xtype' => 'displayfield', 'hideLabel' => true, 'value' => "<span style='color:red;'>Billing information is not available at the moment</span>"));
                 }
             }
         }
     }
     $this->response->data(array('module' => $js_module));
 }
 /**
  *
  * @param ChargifyConnector $connector
  *
  * @return void
  */
 public static function setDefault(ChargifyConnector $connector)
 {
     self::$_defaultConnector = $connector;
 }