Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * @package ClubTrips_Payments
- * @version 1.0
- */
- /*
- Plugin Name: Club-Trips - Payments
- Description: This allows you to take payments from your website for trips
- Author: Victor Macko
- Version: 1.0
- Author URI: http://www.victor.com.au
- */
- function clubtrips_makepayment($args = array()) {
- $account_bank = get_option('clubtrips_account_bank');
- $account_name = get_option('clubtrips_account_name');
- $account_bsb = get_option('clubtrips_account_bsb');
- $account_number = get_option('clubtrips_account_number');
- $paypal_email = get_option('clubtrips_paypal_email');
- $paypal_additional_percent = get_option('clubtrips_paypal_additional_percent');
- $siteurl = get_option('siteurl');
- $dir = basename(dirname(__FILE__));
- if(!get_option('clubtrips_url') || !get_option('clubtrips_username') || !get_option('clubtrips_password')) {
- return "<p>Oops! The ClubTrips Pluggin isn't setup just yet - your site administrator needs to fill in the settings page to get it going!</p>";
- }
- ob_start();
- // Use nonce for verification
- wp_nonce_field( plugin_basename( __FILE__ ), 'member_noncename' );
- ?>
- <script type="text/javascript">
- jQuery(function($) {
- var $form = $('form.clubtrips');
- $form.validate({
- 'submitHandler': function(form) {
- $thisForm = $(form);
- $thisForm.find('#submitButton').prop('disabled', true).after('<img src="<?php echo $siteurl ?>/wp-content/plugins/<?php echo $dir ?>/loading.gif" class="loading" style="padding-left: 5px;" />');
- $.post($form.prop('action'), $(form).serialize(), function(data) {
- if(data.result == 'ok') {
- if(data.data) {
- var text = '<div class="clubtrips-tx-complete"><p><strong>Thankyou</strong>, your transaction has been recorded. Your reference for this transaction is <strong>' + data.data.transactionReference + '</strong>. ';
- if($form.find('input[name=paymentMethod]:checked').val() == 'direct-debit') {
- text += 'Now all that\'s left to do is visit your internet banking site, and use the following reference number in the transaction to us.</p><p>Our bank account details are:<br />Bank Account <strong><?php echo $account_name ?> (<?php echo $account_bank ?>)</strong>, BSB <strong><?php echo $account_bsb ?></strong>, Account No. <strong><?php echo $account_number ?></strong><br />Transaction Reference: <strong>' + data.data.transactionReference + '</strong>';
- } else {
- text += 'Now all that\'s left to do is click the following link to PayPal, to complete the transaction.';
- }
- text += '</p></div>';
- $thisForm.hide().after(text);
- } else {
- alert('Oops - it looks like something\'s gone wrong ... please try again and let us know if it continues to happen.');
- $thisForm.find('#submitButton').prop('disabled', false);
- $thisForm.find('img.loading').remove();
- }
- } else if(data.result == 'fields-not-completed') {
- alert('Oops - you need to complete all the fields to process your transaction! Please complete as much as you can, and try again.');
- $thisForm.find('#submitButton').prop('disabled', false);
- $thisForm.find('img.loading').remove();
- } else {
- alert('Oops - it looks like something\'s gone wrong ... please try again and let us know if it continues to happen.');
- $thisForm.find('#submitButton').prop('disabled', false);
- $thisForm.find('img.loading').remove();
- }
- }, 'json');
- return false;
- }
- });
- $form.find('input[name=paymentMethod]').change(function() {
- $form.find('div.direct-debit-message').toggle(this.checked && this.value == 'direct-debit');
- $form.find('div.credit-card-message').toggle(this.checked && this.value == 'paypal');
- if(this.value == 'paypal' && this.checked) {
- var amount = parseFloat($('input.amount').val());
- var surchargeAmount = 0;
- var paypalSurchargePercent = <?php echo $paypal_additional_percent ? $paypal_additional_percent : 0 ?>;
- if(this.value == 'paypal' && this.checked) {
- surchargeAmount = amount * (paypalSurchargePercent/100);
- }
- $('span.amountSubTotal').html(' (+ $' + surchargeAmount.toFixed(2) + ' surcharge = $' + (amount + surchargeAmount).toFixed(2) + ')');
- $('.paypalSurchargeAmount').html((surchargeAmount > 0 ? '($' + surchargeAmount.toFixed(2) + ')' : '-'));
- }
- });
- $form.find('input[name=paymentMethod]:checked').change();
- });
- </script>
- <!--
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
- Click <input type="image" src="./images/site/paypal_button.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> to pay
- <input type="hidden" name="cmd" value="_xclick">
- <input type="hidden" name="business" value="<?php echo $paypal_email ?>">
- <input type="hidden" name="item_name" value="SUSS Payment - # 4513-NM-5806">
- <input type="hidden" name="item_number" value="4513-NM-5806">
- <input type="hidden" name="currency_code" value="AUD">
- <input type="hidden" name="amount" value="10.30">
- <input type="hidden" name="cancel_return" value="http://www.suss.org.au/payments.php?paid_cancel&t=4513-NM-5806">
- <input type="hidden" name="return" value="http://www.suss.org.au/payments.php?complete">
- <input type="hidden" name="no_shipping" value="1">
- <input type="hidden" name="no_note" value="1">
- <input type="hidden" name="invoice" value="4513-NM-5806">
- <input type="hidden" name="email" value="asd">
- </form>
- -->
- <h3>Make a payment</h3>
- <p>To make a payment, <strong>please complete the following form and then click submit</strong>. You will then be directed to pay via your preferred payment method with a <strong>transaction reference</strong> so we know who's paying for what!<br />If you are paying on behalf of someone else, please complete each person's payment in a separate transaction, with their details completed (feel free to make a note than you're paying for them in the details box if you like).</p>
- <form action="<?php echo admin_url('admin-ajax.php') ?>?action=ct_make_payment" method="post" class="clubtrips">
- <?php wp_nonce_field( plugin_basename( __FILE__ ), 'ct_nonce' ); ?>
- <?php if(!empty($args['accountid'])) { ?><input type="hidden" name="accountId" value="<?php echo $args['accountid'] ?>" /><? } ?>
- <table class="form-table">
- <tbody>
- <tr>
- <th><label for="name">Your Name</label></th>
- <td><input type="text" name="name" id="name" value="" class="regular-text required"></td>
- </tr>
- <tr>
- <th><label for="memberNumber">Member Number</label></th>
- <td><input type="text" name="memberNumber" id="memberNumber" value="" class="regular-text"></td>
- </tr>
- <tr>
- <th><label for="first_name">Contact Number</label></th>
- <td><input type="text" name="contactNumber" id="contactNumber" value="" class="regular-text required"></td>
- </tr>
- <tr>
- <th><label for="last_name">Email</label></th>
- <td><input type="text" name="email" id="email" value="" class="regular-text required"></td>
- </tr>
- <tr>
- <th><label for="details">Payment Method</label></th>
- <td>
- <label><input type="radio" name="paymentMethod" value="direct-debit" checked="checked" /> Direct Debt</label><br />
- <div class="direct-debit-message">You will be given a reference number to include in your bank transfer so we can tell who's given us money, and for what.</div>
- <!-- <label><input type="radio" name="paymentMethod" value="paypal" /> PayPal or Credit Card</label>
- <div class="credit-card-message">You will be directed to PayPal to complete the transaction. Note: a <strong><?php echo $paypal_additional_percent ?>% charge <span class="paypalSurchargeAmount"></span></strong> applies to all credit-card & PayPal transactions.</div> -->
- </td>
- </tr>
- <tr>
- <th><label for="what">What are you paying for?</label></th>
- <td><?php if(!empty($args['payingfor'])) { echo $args['payingfor']; ?><input type="hidden" name="payingFor" value="<?php echo $args['payingfor'] ?>" /><?php } else { ?><select name="payingFor" id="payingFor"><option>Trips</option><option>Membership</option><option>Social</option><option>Merchandise</option></select><?php } ?></td>
- </tr>
- <tr>
- <th><label for="nickname">Amount</label></th>
- <td>$ <?php if(!empty($args['amount'])) { echo number_format($args['amount'], 2); ?><input type="hidden" name="amount" value="<?php echo $args['amount'] ?>" class="amount" /><?php } else { ?><input type="text" name="amount" id="amount" value="" class="regular-text"><?php } ?><span class="amountSubTotal"></span></td>
- </tr>
- <tr>
- <th><label for="details">Additional Details / Comments</label></th>
- <td><textarea name="comment" id="details" class="regular-text"></textarea></td>
- </tr>
- <tr>
- <th></th>
- <td><input type="submit" id="submitButton" value="Submit details" /></td>
- </tr>
- </tbody></table>
- </form>
- <?php
- $html = ob_get_clean();
- return $html;
- }
- add_shortcode( 'ct-make-payment', 'clubtrips_makepayment' );
- function clubtrips_process_payment() {
- if ( !isset($_POST['ct_nonce']) || !wp_verify_nonce( $_POST['ct_nonce'], plugin_basename( __FILE__ ) ) ) {
- echo json_encode(array('status' => 200, 'result' => 'form-error'));
- exit;
- }
- // get vars
- $details = array(
- 'name' => isset($_POST['name']) ? stripslashes($_POST['name']) : null,
- 'memberNumber' => isset($_POST['memberNumber']) ? stripslashes($_POST['memberNumber']) : null,
- 'contactNumber' => isset($_POST['contactNumber']) ? stripslashes($_POST['contactNumber']) : null,
- 'email' => isset($_POST['email']) ? stripslashes($_POST['email']) : null,
- 'amount' => isset($_POST['amount']) ? stripslashes($_POST['amount']) : null,
- 'comment' => isset($_POST['comment']) ? stripslashes($_POST['description']) : null,
- 'payingFor' => isset($_POST['payingFor']) ? stripslashes($_POST['payingFor']) : null,
- 'paymentMethod' => isset($_POST['paymentMethod']) ? stripslashes($_POST['payment_method']) : null,
- 'distributions' => array()
- );
- if(isset($_POST['accountId']) && !empty($_POST['accountId'])) {
- $details['distributions'][] = array('account' => stripslashes($_POST['accountId']), 'amount' => $details['amount']);
- }
- // if paying via paypal, add the paypal account ID
- if($details['paymentMethod'] == 'paypal') {
- $paypal_additional_percent = get_option('clubtrips_paypal_additional_percent');
- $paypal_account_id = get_option('clubtrips_paypal_account_id');
- if($paypal_account_id && $paypal_additional_percent > 0) {
- $details['distributions'][] = array('account' => $paypal_account_id, 'amount' => $details['amount'] * $paypal_additional_percent);
- }
- }
- if(empty($details['name']) || empty($details['contactNumber']) ||
- empty($details['email']) || empty($details['amount']) || empty($details['payingFor'])) {
- echo json_encode(array('status' => 200, 'result' => 'fields-not-completed'));
- exit;
- }
- $ch = curl_init();
- $timeout = 5;
- curl_setopt($ch, CURLOPT_URL, get_option('clubtrips_url') . '/api/transactions/add.json');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,$timeout);
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_USERPWD, get_option('clubtrips_username') . ':' . get_option('clubtrips_password'));
- //curl_setopt($ch, CURLOPT_C, true);
- //curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array('tx' => $details)));
- $data = curl_exec($ch);
- curl_close($ch);
- // get receipt / transaction #
- $result = json_decode($data);
- // send details back to user
- echo json_encode(array('status' => 200, 'result' => 'ok', 'data' => $result));
- exit;
- }
- add_action('wp_ajax_ct_make_payment', 'clubtrips_process_payment');
- add_action('wp_ajax_nopriv_ct_make_payment', 'clubtrips_process_payment'); // need this to serve non logged in users
- function clubtrips_addJs() {
- //$siteurl = get_option('siteurl');
- //$dir = basename(dirname(__FILE__));
- wp_register_script('jquery.validate', 'https://ajax.aspnetcdn.com/ajax/jquery.validate/1.8.1/jquery.validate.min.js', array('jquery'));
- wp_register_script('akismet.js', plugin_dir_url(__FILE__) . 'clubtrips.js', array('jquery', 'jquery.validate'));
- wp_enqueue_script('akismet.js');
- }
- add_action('init', 'clubtrips_addJs');
- add_action('admin_menu', 'clubtrips_settings_menu');
- function clubtrips_settings_menu() {
- // Add a new submenu under Settings:
- add_options_page(__('ClubTrips Settings','menu-ct'), __('ClubTrips Settings','menu-ct'), 'manage_options', 'ct_settings', 'clubtrips_settings_page');
- }
- function clubtrips_settings_page() {
- //must check that the user has the required capability
- if (!current_user_can('manage_options'))
- {
- wp_die( __('You do not have sufficient permissions to access this page.') );
- }
- $url = get_option('clubtrips_url');
- $username = get_option('clubtrips_username');
- $password = get_option('clubtrips_password');
- $account_bank = get_option('clubtrips_account_bank');
- $account_name = get_option('clubtrips_account_name');
- $account_bsb = get_option('clubtrips_account_bsb');
- $account_number = get_option('clubtrips_account_number');
- $paypal_email = get_option('clubtrips_paypal_email');
- $paypal_account_id = get_option('clubtrips_paypal_account_id');
- $paypal_additional_percent = get_option('clubtrips_paypal_additional_percent');
- if(count($_POST) > 0) {
- if(isset($_POST['url'])) {
- $url = stripslashes($_POST['url']);
- }
- if(isset($_POST['username'])) {
- $username = stripslashes($_POST['username']);
- }
- if(isset($_POST['password']) && !empty($_POST['password'])) {
- $password = stripslashes($_POST['password']);
- }
- if(isset($_POST['account_bank'])) {
- $account_bank = stripslashes($_POST['account_bank']);
- }
- if(isset($_POST['account_name'])) {
- $account_name = stripslashes($_POST['account_name']);
- }
- if(isset($_POST['account_bsb'])) {
- $account_bsb = stripslashes($_POST['account_bsb']);
- }
- if(isset($_POST['account_number'])) {
- $account_number = stripslashes($_POST['account_number']);
- }
- if(isset($_POST['paypal_email'])) {
- $paypal_email = stripslashes($_POST['paypal_email']);
- }
- if(isset($_POST['paypal_account_id'])) {
- $paypal_account_id = stripslashes($_POST['paypal_account_id']);
- }
- if(isset($_POST['paypal_additional_percent'])) {
- $paypal_additional_percent = stripslashes($_POST['paypal_additional_percent']);
- }
- // save settings
- update_option('clubtrips_url', $url);
- update_option('clubtrips_username', $username);
- update_option('clubtrips_password', $password);
- update_option('clubtrips_account_bank', $account_bank);
- update_option('clubtrips_account_name', $account_name);
- update_option('clubtrips_account_bsb', $account_bsb);
- update_option('clubtrips_account_number', $account_number);
- update_option('clubtrips_paypal_email', $paypal_email);
- update_option('clubtrips_paypal_account_id', $paypal_account_id);
- update_option('clubtrips_paypal_additional_percent', $paypal_additional_percent);
- }
- // get list of accounts to select from when selecting paypal account
- ?>
- <div class="wrap">
- <h2>ClubTrips Settings</h2>
- <form name="form" method="post" action="">
- <table class="form-table">
- <tr valign="top">
- <th scope="row"><label for="url"><?php _e("ClubTrips URL:", 'url' ); ?></label></th>
- <td><input name="url" type="text" id="url" value="<?php echo $url ?>" class="regular-text code"></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="username"><?php _e("Username:", 'username' ); ?></label></th>
- <td><input name="username" type="text" id="username" value="<?php echo $username ?>" class="regular-text"></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="password"><?php _e("Password:", 'password' ); ?></label></th>
- <td><input name="password" type="password" id="password" value="" class="regular-text"></td>
- </tr>
- </table>
- <h3>Your bank account details</h3>
- <p>These are shown to your members when making a deposit via Direct Debit.</p>
- <table class="form-table">
- <tr valign="top">
- <th scope="row"><label for="account_bank"><?php _e("Bank:", 'account_name' ); ?></label></th>
- <td><input name="account_bank" type="text" id="account_bank" value="<?php echo $account_bank ?>" class="regular-text"></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="account_name"><?php _e("Account Name:", 'account_name' ); ?></label></th>
- <td><input name="account_name" type="text" id="account_name" value="<?php echo $account_name ?>" class="regular-text"></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="account_bsb"><?php _e("Account BSB:", 'account_bsb' ); ?></label></th>
- <td><input name="account_bsb" type="text" id="account_bsb" value="<?php echo $account_bsb ?>" class="regular-text code"></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="account_number"><?php _e("Account Number:", 'account_number' ); ?></label></th>
- <td><input name="account_number" type="text" id="account_number" value="<?php echo $account_number ?>" class="regular-text code"></td>
- </tr>
- </table>
- <h3>PayPal details</h3>
- <p>These are used when your members pay for transactions via PayPal.</p>
- <table class="form-table">
- <tr valign="top">
- <th scope="row"><label for="paypal_email"><?php _e("PayPal Email Address:", 'paypal_email' ); ?></label></th>
- <td><input name="paypal_email" type="text" id="paypal_email" value="<?php echo $paypal_email ?>" class="regular-text"></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="paypal_account_id"><?php _e("PayPal Account:", 'paypal_account_id' ); ?></label></th>
- <td><input name="paypal_account_id" type="text" id="paypal_account_id" value="<?php echo $paypal_account_id ?>" class="regular-text"></td>
- </tr>
- <tr valign="top">
- <th scope="row"><label for="paypal_additional_percent"><?php _e("PayPal Additional Fee (%):", 'paypal_additional_percent' ); ?></label></th>
- <td><input name="paypal_additional_percent" type="text" id="paypal_additional_percent" value="<?php echo $paypal_additional_percent ?>" class="regular-text"></td>
- </tr>
- </table>
- <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes"></p>
- </form>
- </div>
- <?php
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement