Exemple #1
0
 function get_button_code($pack, $user_id)
 {
     get_currentuserinfo();
     global $current_user;
     if ($current_user->ID == 0) {
         $current_user = ym_get_user_by_username(ym_get('username'));
     }
     $currency_codes = array('AUD' => '036', 'CAD' => '124', 'JPY' => '392', 'GBP' => '826', 'USD' => '840', 'EUR' => '978');
     if (array_key_exists(ym_get_currency($pack['id']), $currency_codes)) {
         $code = $currency_codes[ym_get_currency($pack['id'])];
     } else {
         return;
     }
     $data = array('clientAccnum' => $this->clientAccnum, 'clientSubacc' => $this->clientSubacc, 'formName' => $this->formname, 'customer_fname' => get_user_meta($current_user->ID, 'first_name', TRUE), 'customer_lname' => get_user_meta($current_user->ID, 'last_name', TRUE), 'email' => $current_user->user_email);
     if (isset($pack['id']) && $pack['id']) {
         // convert to days
         switch ($pack['duration_type']) {
             case 'y':
                 $duration = $pack['duration'] * 365;
                 break;
             case 'm':
                 $duration = $pack['duration'] * 30;
                 break;
             default:
                 $duration = $pack['duration'];
         }
         $data = array_merge($data, array('formPrice' => $pack['cost'], 'formPeriod' => $duration, 'currencyCode' => $code));
         if ($pack['trial_on']) {
             $data['formPrice'] = $pack['trial_cost'];
             // convert to days
             switch ($pack['trial_duration_type']) {
                 case 'y':
                     $duration = $pack['trial_duration'] * 365;
                     break;
                 case 'm':
                     $duration = $pack['trial_duration'] * 30;
                     break;
                 default:
                     $duration = $pack['trial_duration'];
             }
             $data['formPeriod'] = $duration;
         }
         if (isset($pack['num_cycles']) && $pack['num_cycles'] != 1) {
             // recur
             //				unset($data['formPrice'], $data['formPeriod']);
             $data['formRecurringPrice'] = $pack['cost'];
             $data['formRecurringPeriod'] = $duration;
             $data['formRebills'] = $pack['num_cycles'] == 0 ? 99 : $pack['num_cycles'];
             // gen formdigest
             $data['formDigest'] = md5($data['formPrice'] . $data['formPeriod'] . $data['formRecurringPrice'] . $data['formRecurringPeriod'] . $data['formRebills'] . $code . $this->md5salt);
         } else {
             // gen formdigest
             $data['formDigest'] = md5($data['formPrice'] . $data['formPeriod'] . $code . $this->md5salt);
         }
         $data['custom'] = 'buy_subscription_' . $pack['id'] . '_' . $user_id;
     }
     return $data;
 }
    function getButtonOverride($pack, $user_id, $override_price = FALSE)
    {
        if (!$this->sslcheck()) {
            return;
        }
        $button_code = $this->get_button_code($pack, $user_id, $override_price);
        $button_code = apply_filters('ym_additional_code', $button_code, $this->code, $pack['id']);
        $button_code_html = '';
        foreach ($button_code as $item => $val) {
            $button_code_html .= '<input type="hidden" name="' . $item . '" value="' . $val . '" />' . "\n";
        }
        $r = '
<form action="' . $this->action_url . '" method="post" class="ym_form ' . $this->code . '_form" name="' . $this->code . '_form" id="' . $this->code . '_form" target="ym_pro_iframe">
	<fieldset>
		<strong>' . ym_get_pack_label($pack['id']) . '</strong><br />
		';
        if ($override_price) {
            $r .= '<strong>' . $override_price . ' ' . ym_get_currency($pack['id']) . ' ' . __('First Period', 'ym') . '</strong><br />';
        }
        $r .= '
		' . $button_code_html . '
		<input type="image" src="' . $this->logo . '" border="0" name="submit" alt="' . $this->membership_words . '" id="ym_paypal_pro_button" />
	</fieldset>
</form>
';
        $r .= '
<script type="text/javascript">' . "\n\tjQuery('#ym_paypal_pro_button').click(function() {\n\t\tevent.preventDefault();\n\t\tjQuery('." . $this->code . "_form').submit();\n\t\tjQuery('.ym_form').slideUp();\n\t\tjQuery('#ym_pro_iframe_control').slideDown();\n\t});\n</script>\n";
        $r .= '
<br />
<div id="ym_pro_iframe_control" style="display: none; text-align: center;">
	<iframe name="ym_pro_iframe" id="ym_pro_iframe" style="width: 580px; height: 550px;';
        //	if ($margin) {
        if (defined('subscribe.php')) {
            $r .= ' margin-left: -130px;';
        }
        $r .= ' border: 0px;" scrolling="no">Loading...</iframe>
</div>
<br />
';
        return $r;
    }
Exemple #3
0
 function get_button_code($pack, $user_id, $override_price = FALSE)
 {
     global $ym_sys;
     $cost = $override_price ? $override_price : $pack['cost'];
     $data = array('cmd' => isset($pack['num_cycles']) && $pack['num_cycles'] != 1 ? '_xclick-subscriptions' : '_xclick', 'business' => $this->paypal_handle, 'item_name' => isset($pack['item_name']) && $pack['item_name'] ? $pack['item_name'] : $ym_sys->item_name, 'no_shipping' => 1, 'no_note' => 1, 'currency_code' => esc_html(isset($pack['id']) && $pack['id'] ? ym_get_currency($pack['id']) : ym_get_currency()), 'lc' => $this->locale, 'notify_url' => site_url('?ym_process=' . $this->code), 'cancel_return' => site_url($this->cancel_url), 'rm' => 2);
     if (isset($pack['vat_applicable']) && $pack['vat_applicable'] || $ym_sys->global_vat_applicable) {
         if ($ym_sys->vat_rate) {
             $data['tax_rate'] = $ym_sys->vat_rate;
         }
     }
     if ($vat_rate = apply_filters('ym_vat_override', false, $user_id)) {
         $data['tax_rate'] = $vat_rate;
     }
     // calc redirect
     $data['return'] = esc_html($this->redirectlogic($pack));
     // addition per type
     if (isset($pack['id']) && $pack['id']) {
         if ($pack['num_cycles'] == 1) {
             $data = array_merge($data, array('bn' => 'PP-BuyNowBF', 'item_number' => 'buy_subscription_' . $pack['id'] . '_' . $user_id, 'amount' => $cost, 'src' => 1, 'sra' => 1));
         } else {
             // subscription payment
             $data = array_merge($data, array('item_number' => 'buy_subscription_' . $pack['id'] . '_' . $user_id, 'a3' => $cost, 'p3' => $pack['duration'], 't3' => strtoupper($pack['duration_type']), 'src' => 1, 'sra' => 1));
             if (isset($pack['num_cycles']) && $pack['num_cycles']) {
                 $data['srt'] = $pack['num_cycles'];
             }
             if ($pack['trial_on']) {
                 $data['a1'] = $pack['trial_cost'];
                 $data['p1'] = $pack['trial_duration'];
                 $data['t1'] = strtoupper($pack['trial_duration_type']);
             }
         }
     } else {
         // post
         $data['bn'] = 'PP-BuyNowBF';
         $data['amount'] = $cost;
         // post
         if (isset($pack['ppp_pack_id'])) {
             $data['item_number'] = 'buy_bundle_' . $pack['ppp_pack_id'] . '_' . $user_id;
         } else {
             if (isset($pack['ppp_adhoc_posts'])) {
                 $data['item_number'] = 'buy_post_' . implode(',', $pack['ppp_adhoc_posts']) . '_' . $user_id;
             } else {
                 $data['item_number'] = 'buy_post_' . ($pack['post_id'] ? $pack['post_id'] : get_the_ID()) . '_' . $user_id;
             }
         }
         $data['src'] = 0;
         $data['sra'] = 0;
     }
     if ($this->encrypt_buttons) {
         $data['cert_id'] = $this->cert_id;
         $cmd = $this->openssl_path . " smime -sign -signer " . $this->public_cert . " -inkey " . $this->private_key . ' -outform der -nodetach -binary | ' . $this->openssl_path . " smime -encrypt -des3 -binary -outform pem " . $this->paypal_cert;
         $desc = array(0 => array("pipe", "r"), 1 => array("pipe", "w"));
         $process = proc_open($cmd, $desc, $pipes);
         if (is_resource($process)) {
             foreach ($data as $key => $value) {
                 if ($value) {
                     fwrite($pipes[0], $key . '=' . $value . "/n");
                 }
             }
             fflush($pipes[0]);
             fclose($pipes[0]);
             $string = '';
             while (!feof($pipes[1])) {
                 $string .= fgets($pipes[1]);
             }
             $string = str_replace("\r\n", "\n", $string);
             $string = str_replace("\n", "", $string);
             fclose($pipes[1]);
             proc_close($process);
             $new_data = array('cmd' => '_s-xclick', 'encrypted' => $string);
             return $new_data;
         }
     }
     return $data;
 }
function ym_render_subscription_form($predata)
{
    global $ym_formgen, $duration_str, $link, $ym_res, $ym_package_types;
    $data = $predata;
    $data['id'] = isset($data['id']) ? $data['id'] : 0;
    if ($data['id']) {
        echo '<input type="hidden" name="id" value="' . $data['id'] . '" />';
    }
    echo '
	<table class="form-table">';
    $ym_formgen->render_form_table_text_row(__('Admin Name', 'ym'), 'admin_name', $data['admin_name'], __('A Handy Name for the Admin Interface', 'ym'));
    $ym_formgen->render_form_table_text_row(__('Price', 'ym'), 'cost', $data['cost'], __('The Price in digits, no currency symbol needed', 'ym'));
    $types = array();
    if ($ym_package_types) {
        foreach ($ym_package_types->types as $k => $v) {
            $types[$k] = $v;
        }
    }
    $types['new'] = __('Create a New Type', 'ym');
    echo '<tr><th>' . __('Package Type', 'ym') . '</th><td><select name="account_type" class="account_type_selector">';
    foreach ($types as $k => $v) {
        echo '<option value="' . $k . '" ';
        if ($data['account_type'] && strtolower($v) == strtolower($data['account_type'])) {
            echo ' selected="selected" ';
        }
        echo ' >';
        echo $v;
        echo '</option>';
    }
    echo '</select></td></tr>';
    echo '<tr class="new_account_type_entry"><th>' . __('New Package Type', 'ym');
    echo '<div style="color: gray; margin-top: 5px; font-size: 11px;">';
    echo __('Create a new Package Type', 'ym');
    echo '</th><td><input type="text" name="new_account_type" value="" /></td></tr>';
    echo '
<tr>
	<th>' . __('Duration', 'ym') . ':
	<div style="color: gray; margin-top: 5px; font-size: 11px;">' . __('The Length of the Subscription', 'ym') . '</div>
	</th>
	<td>
		<table><tr>
			<td>
				<input class="ym_input" style="width: 50px; font-family:\'Lucida Grande\',Verdana; font-size: 11px; text-align: right;" name="duration" value="' . $data['duration'] . '">
			</td>
			<td>
				<select name="duration_type">
				';
    foreach ($duration_str as $str => $val) {
        echo '<option value="' . $str . '"';
        if ($str == $data['duration_type']) {
            echo ' selected="selected"';
        }
        echo '>' . $val . '</option>';
    }
    echo '
				</select>
			</td>
		</tr></table>
	</td>
</tr>
';
    /**
    Basic with trial
    */
    $trial = ym_packs_gateways_trial_on();
    if ($trial) {
        echo '<tr class="basic_with_trial table_divider"><td></td><th><h4>' . __('Trial Options', 'ym') . '</h4></th></tr>';
        echo '<tr class="basic_with_trial"><th>' . __('Enable Trial Period', 'ym');
        echo '</th><td><input type="checkbox" name="trial_on" value="1" ';
        if (isset($data['trial_on'])) {
            if ($data['trial_on'] == 1) {
                echo 'checked="checked"';
            }
        }
        echo ' /></td></tr>';
        echo '<tr class="basic_with_trial"><th>' . __('Trial Price', 'ym');
        echo '</th><td><input tpye="text" name="trial_cost" value="' . $data['trial_cost'] . '" /></td></tr>';
        echo '
<tr class="basic_with_trial">
	<th>' . __('Trial Duration', 'ym') . ':
	<div style="color: gray; margin-top: 5px; font-size: 11px;">' . __('The Length of the Trial Subscription', 'ym') . '</div>
	</th>
	
	<td>
		<table><tr>
			<td>
				<input class="ym_input" style="width: 50px; font-family:\'Lucida Grande\',Verdana; font-size: 11px; text-align: right;" name="trial_duration" value="' . $data['trial_duration'] . '">
			</td>
			<td>
				<select name="trial_duration_type">
				';
        foreach ($duration_str as $str => $val) {
            echo '<option value="' . $str . '"';
            if (isset($data['trial_duration_type'])) {
                if ($str == $data['trial_duration_type']) {
                    echo ' selected="selected"';
                }
            }
            echo '>' . $val . '</option>';
        }
        echo '
				</select>
			</td>
		</tr></table>
	</td>
</tr>
';
    }
    /**
    Advanced
    */
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Additional Package Options', 'ym') . '</h4></th></tr>';
    $cycles = array(0 => 'Ongoing');
    for ($x = 1; $x <= 59; $x++) {
        $cycles[$x] = $x;
    }
    $ym_formgen->tr_class = 'advanced';
    $ym_formgen->style = 'display: none;';
    $ym_formgen->render_combo_from_array_row(__('Package Reoccurance', 'ym'), 'num_cycles', $cycles, $data['num_cycles'], __('How many times the subscription repeats', 'ym'), $data['num_cycles']);
    $currencies = ym_get_currencies();
    if (!$data['currency']) {
        $data['currency'] = ym_get_currency();
    }
    $ym_formgen->render_combo_from_array_row(__('Payment Currency', 'ym'), 'currency', $currencies, $data['currency'], __('Currency for Package', 'ym'));
    $roles = new WP_Roles();
    $roles_array = array_reverse($roles->role_names);
    $ym_formgen->render_combo_from_array_row(__('WordPress Role', 'ym'), 'role', $roles_array, $data['role'], __('Grant these Role set to the User', 'ym'));
    $ym_formgen->render_form_table_textarea_row(__('Package Description', 'ym'), 'description', $data['description'], __('Only used with the [description] Package Template Argument. Check Advanced -> Messages -> Templates', 'ym'));
    $ym_formgen->render_form_table_checkbox_row(__('Hide Old Content', 'ym'), 'hide_old_content', $data['hide_old_content'], __('Hide content created and protected prior to the member&#39;s current subscription start date', 'ym'));
    $ym_formgen->render_form_table_checkbox_row(__('Hide from Standard Subscription page', 'ym'), 'hide_subscription', $data['hide_subscription'], __('When enabled, this package would only be available directly from ym_register shortcode or from a coupon', 'ym'));
    $ym_formgen->render_form_table_checkbox_row(__('Hide Admin Bar', 'ym'), 'hide_admin_bar', $data['hide_admin_bar']);
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Expire Options', 'ym') . '</h4></th></tr>';
    echo '<tr class="advanced"><th>' . __('Set Subscription Expiry Date', 'ym');
    echo '<div style="color: gray; margin-top: 5px; font-size: 11px;">' . __('Users will expire at the start of this date', 'ym') . '</div></th>';
    $value = $data['force_end_date'] ? $data['force_end_date'] : '';
    if ($value) {
        $value = date('d/m/Y', $value);
    }
    echo '<td>
					<input type="text" name="force_end_date" id="dateclear" value="' . $value . '" class="ym_yearpicker" /> <a href="#nowhere" onclick="ym_clear_target(\'dateclear\');">' . __('Clear Date', 'ym') . '
				</td></tr>';
    echo '<tr class="advanced"><th>' . __('On Expire Drop User to:', 'ym') . '</th>';
    echo '<td>';
    echo '<select name="on_expire_drop_to">';
    echo '<option value="">' . __('Inactive', 'ym') . '</option>';
    foreach (ym_get_packs() as $pack) {
        if ($data['id'] == $pack['id']) {
            continue;
        }
        echo '<option value="' . $pack['id'] . '" ';
        if ($data['on_expire_drop_to'] == $pack['id']) {
            echo 'selected="selected"';
        }
        echo '>';
        echo '(' . $pack['id'] . ') ' . ym_get_pack_label($pack['id']);
        echo '</option>';
    }
    echo '</select>';
    echo '</td></tr>';
    // gateway disable
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Payment Gateway Options', 'ym') . '</h4></th></tr>';
    echo '
	<tr class="advanced">
		<td colspan="2"><p>' . __('This filtering is also subject to Payment Gateway filters, for example, the Free Gateway can never be used to buy a non Free Package (so you do not have to deselect it here if this package is not free)', 'ym') . '</p></td>
	</tr>
	<tr class="advanced"><th>' . __('Allow Gateways', 'ym');
    echo '<div style="color: gray; margin-top: 5px; font-size: 11px;">' . __('You can select gateways to use with this Pack', 'ym') . '</div></th>';
    echo '<td>';
    echo '<ul>';
    global $ym_active_modules;
    foreach ((array) $ym_active_modules as $key => $module) {
        echo '<li>';
        echo '<label for="disable_module_' . $key . '">';
        echo '<input type="checkbox" id="disable_module_' . $key . '" name="gateway_disable[]" value="' . $module . '" ';
        // checked?
        if (FALSE !== array_search($module, $data['gateway_disable'])) {
            echo 'checked="checked"';
        }
        echo ' /> ';
        $way = new $module();
        echo $way->name;
        echo '</label>';
        echo '</li>';
    }
    echo '</ul>';
    echo '</td>';
    echo '</tr>';
    // URLS
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Package Speicifc Redirects', 'ym') . '</h4></th></tr>';
    $ym_formgen->render_form_table_url_row(__('Success URL', 'ym'), 'success_redirect', $data['success_redirect'], __('Where to redirect the user to on Successful Transaction, aka Thank You Page', 'ym'));
    echo '
	<tr class="advanced">
		<td colspan="2"><p>' . __('If you need Pack Specific redirects you can configure these here, you can leave these blank and the default redirects configured under Advanced->Security will be used', 'ym') . '</p></td>
	</tr>
	';
    $ym_formgen->render_form_table_url_row(__('Login Redirect URL', 'ym'), 'login_redirect_url', $data['login_redirect_url'], __('Where to redirect the user to on Login', 'ym'));
    $ym_formgen->render_form_table_url_row(__('WP Admin Block URL', 'ym'), 'wpadmin_disable_redirect_url', $data['wpadmin_disable_redirect_url'], __('Where to redirect the user to on WP Admin Access', 'ym'));
    $ym_formgen->render_form_table_url_row(__('Logout Redirect URL', 'ym'), 'logout_redirect_url', $data['logout_redirect_url'], __('Where to redirect the user to on Logout', 'ym'));
    $ym_formgen->render_form_table_url_row(__('First Login URL', 'ym'), 'first_login', $data['first_login'], __('Where to redirect on the user first login with this package', 'ym'));
    // Group Membership
    echo '<tr class="advanced table_divider"><td></td><th><h4>' . __('Group Membership', 'ym') . '</h4></th></tr>';
    $ym_formgen->render_form_table_text_row(__('Total Allowed Child Accounts', 'ym'), 'child_accounts_allowed', $data['child_accounts_allowed']);
    echo '<tr class="advanced"><td colspan="2"><p>' . __('A Group Leader can create child accounts, these child accounts normally inherit the parents package type, optionally you can allow the group admin to choose which Package Type the child account uses from a subset of the available Package Types (this will exclude the parent package type from being selectable unless you select it below). Further more you can allow Packages to be available, allowing you a Group Leader, to create a child account, which itself can have children. If packages are allowed they are applied to a child account at zero cost', 'ym') . '</p></td></tr>';
    echo '<tr class="advanced"><td>' . __('Use Inherit Mode', 'ym') . '</td><td><input type="checkbox" name="inherit_mode" id="ym_inherit_mode" ';
    $score = 0;
    foreach ($data['child_accounts_package_types'] as $v => $count) {
        $score += $count;
    }
    global $ym_packs;
    foreach ($ym_packs->packs as $pack) {
        if (in_array($pack['id'], $data['child_accounts_packages'])) {
            $score++;
        }
    }
    if (!$score) {
        echo 'checked="checked"';
    }
    echo ' /></td></tr>';
    echo '<tr class="ym_inherit_mode_off"><td>' . __('Available Package Types', 'ym') . '</td><td><table>';
    foreach ($ym_package_types->types as $v) {
        if (strtolower($v) == 'guest') {
            continue;
        }
        echo '<tr><td>';
        echo $v;
        echo '</td><td>';
        echo '<input type="text" name="child_accounts_package_types[' . $v . ']" value="' . (isset($data['child_accounts_package_types'][$v]) ? $data['child_accounts_package_types'][$v] : 0) . '" /> ';
        echo '</td></tr>';
    }
    echo '</table></td></tr>';
    echo '<tr class="ym_inherit_mode_off"><td>' . __('Available Packages', 'ym') . '</td><td><table>';
    foreach ($ym_packs->packs as $pack) {
        echo '<tr><td>';
        echo ym_get_pack_label($pack['id']);
        echo '</td><td>';
        echo '<input type="checkbox" name="child_accounts_packages[]" value="' . $pack['id'] . '" ' . (in_array($pack['id'], $data['child_accounts_packages']) ? 'checked="checked"' : '') . ' /> ';
        echo '</td></tr>';
    }
    echo '</table></td></tr>';
    /**
    ALL
    */
    echo '<tr class="basic table_divider"><td></td><th><h4>' . __('Payment Gateway Specific Fields', 'ym') . '</h4></th></tr>';
    // gateway fields
    ym_packs_gateways_extra_fields_display($data);
    echo '</table>';
}
</form>
</table>

<?php 
echo ym_end_box();
echo ym_start_box(__('Global Payment Settings', 'ym'));
global $ym_sys, $ym_res, $ym_formgen;
if (isset($_POST['settings_update']) && !empty($_POST['settings_update'])) {
    // currency is in here
    $ym_res->update_from_post();
    // sys
    $ym_sys->update_from_post();
    update_option('ym_sys', $ym_sys);
    ym_display_message(__('System Updated', 'ym'));
}
$sel_currency = ym_get_currency();
$currencies = ym_get_currencies();
echo '
<form action="" method="post">
<table class="form-table">
';
$ym_formgen->render_form_table_text_row(__('The Name that Appears on Customer Reciepts', 'ym'), 'item_name', $ym_sys->item_name, __('The name of the membership to display on the order form', 'ym'));
$ym_formgen->render_combo_from_array_row(__('Payment Currency', 'ym'), 'currency', $currencies, $sel_currency, __('The Currency used for all payments', 'ym'));
$ym_formgen->render_form_table_radio_row(__('Apply sales Tax?', 'ym'), 'global_vat_applicable', $ym_sys->global_vat_applicable);
$ym_formgen->render_form_table_text_row(__('Sales Tax', 'ym'), 'vat_rate', (int) $ym_sys->vat_rate);
$ym_formgen->render_form_table_radio_row(__('Enable Members to Extend Subscription prior to expiry date?', 'ym'), 'allow_upgrade_to_same', (int) $ym_sys->allow_upgrade_to_same, __('Valid only for non-reoccuring package subscriptions', 'ym'));
$ym_formgen->render_form_table_radio_row(__('Enable end of Subscription Grace Period', 'ym'), 'grace_enable', (int) $ym_sys->grace_enable, __('Tip: Useful for pending payments, does not trigger on cancelled/failed payments', 'ym'));
$ym_formgen->render_form_table_text_row(__('Grace Limit (Days)', 'ym'), 'grace_limit', (int) $ym_sys->grace_limit);
echo '<tr>';
echo '<td><label for="tod">' . __('What time of Day should a User Expire?', 'ym') . '</label></td>';
echo '<td>';
Exemple #6
0
 function pack_cost_inc_tax($pack_id, $cost)
 {
     // get sys tax
     global $ym_sys;
     $rate = $ym_sys->vat_rate / 100;
     //eg 17.5 / 100 = 0.175
     $cost = number_format($cost, 2, '.', '');
     $amount = $cost * $rate;
     $total = $amount + $cost;
     $total = number_format($total, 2, '.', '') . ' ' . ym_get_currency($pack_id);
     return $total;
 }
    function getButton($packID, $override_price = FALSE)
    {
        $test = apply_filters('ym_filter_gateway', $this->code, 'getbutton', $packID);
        if ($test != $this->code) {
            return;
        }
        $pack = ym_get_pack_by_id($packID);
        if (method_exists($this, 'pack_filter')) {
            $packs = array($pack);
            $packs = $this->pack_filter($packs);
            $pack = isset($packs[0]) ? $packs[0] : FALSE;
        }
        if ($pack && FALSE !== array_search($this->code, $pack['gateway_disable'])) {
            // remove
            return;
        }
        $r = '';
        if ($pack) {
            if (method_exists($this, 'getButtonOverride')) {
                return $this->getButtonOverride($pack, ym_get_user_id(), $override_price);
            }
            $button_code = $this->get_button_code($pack, ym_get_user_id(), $override_price);
            $button_code = apply_filters('ym_additional_code', $button_code, $this->code, 'buy_subscription_' . $packID . '_' . ym_get_user_id());
            $button_code_html = '';
            foreach ($button_code as $item => $val) {
                $button_code_html .= '<input type="hidden" name="' . $item . '" value="' . $val . '" />' . "\n";
            }
            $r = '
<form action="' . $this->action_url . '" method="post" class="ym_form ' . $this->code . '_form" name="' . $this->code . '_form" id="' . $this->code . '_form">
	<fieldset>
		<strong>' . ym_get_pack_label($pack['id']) . '
		';
            if ($override_price) {
                $r .= '<br />' . $override_price . ' ' . ym_get_currency($pack['id']) . ' ' . __('First Period', 'ym');
            }
            $r .= '</strong><br />';
            $r .= '
		' . $button_code_html . '
		<input type="image" class="' . $this->code . '_button" src="' . $this->logo . '" border="0" name="submit" alt="' . $this->membership_words . '" />
	</fieldset>
</form>
';
        }
        return $r;
    }
function ym_ppp_meta_box($post)
{
    global $ym_sys;
    if (isset($post->ID) && $post->ID > 0 && $post->post_status != 'auto-draft') {
        $post_purchasable = get_post_meta($post->ID, '_ym_post_purchasable', true);
        $post_purchasable_cost = get_post_meta($post->ID, '_ym_post_purchasable_cost', true);
        $post_purchasable_expiry = get_post_meta($post->ID, '_ym_post_purchasable_expiry', true);
        $post_purchasable_limit = get_post_meta($post->ID, '_ym_post_purchasable_limit', true);
        $post_purchasable_duration = get_post_meta($post->ID, '_ym_post_purchasable_duration', true);
        $post_purchasable_featured = get_post_meta($post->ID, '_ym_post_purchasable_featured', true);
        $ppp_index = get_post_meta($post->ID, '_ym_post_purchasable_index', true);
    } else {
        $post_purchasable = $ym_sys->default_ppp;
        $post_purchasable_cost = $ym_sys->default_ppp_cost;
        $post_purchasable_expiry = '';
        $post_purchasable_limit = '';
        $post_purchasable_duration = '';
        $post_purchasable_featured = 0;
        $ppp_index = '';
    }
    $post_purchasable_no = $post_purchasable ? '' : 'checked="checked"';
    $post_purchasable_yes = $post_purchasable ? 'checked="checked"' : '';
    $post_rest_show = $post_purchasable_yes ? 'show' : 'none';
    $post_purchasable_featured_no = $post_purchasable_featured ? '' : 'checked="checked"';
    $post_purchasable_featured_yes = $post_purchasable_featured ? 'checked="checked"' : '';
    $post_type = substr($_SERVER['SCRIPT_FILENAME'], strrpos($_SERVER['SCRIPT_FILENAME'], '/')) == '/page-new.php' ? 'Page' : 'Post';
    echo '
<table style="width: 100%;">
	<tr>
		<td><label for="post_purchasable" style="width: 50%">' . sprintf(__('Is this %s available to buy?', 'ym'), $post_type) . '</label></td>
		<td>
<label for="post_purchasable_no" onclick="jQuery(\'.post_purchasable_rest\').hide();"><input type="radio" name="post_purchasable" id="post_purchasable_no" value="0" ' . $post_purchasable_no . ' /> ' . __('No', 'ym') . '</label>
<label for="post_purchasable_yes" onclick="jQuery(\'.post_purchasable_rest\').show();"><input type="radio" name="post_purchasable" id="post_purchasable_yes" value="1" ' . $post_purchasable_yes . ' />' . __('Yes', 'ym') . '</label>
		</td>
	</tr>

';
    $class = ' class="post_purchasable_rest" style="display: ' . $post_rest_show . ';"';
    echo '
	<tr ' . $class . '>
		<td>' . sprintf(__('%s Cost (Leave blank for Bundle Only):', 'ym'), $post_type) . '</td>
		<td><input type="text" class="ym_text" name="post_purchasable_cost" value="' . $post_purchasable_cost . '" size="2" /> ' . ym_get_currency() . '</td>
	</tr>
	<tr ' . $class . '>
		<td>' . sprintf(__('Purchase Expiry (date %s stops being Purchasable)', 'ym'), $post_type) . '</td>
		<td><input type="text" class="ym_text ym_datepicker" name="post_purchasable_expiry" id="post_purchasable_expiry" value="' . $post_purchasable_expiry . '" size="12" /> 
				<a href="#nowhere" onclick="ym_clear_target(\'post_purchasable_expiry\');">' . __('Clear Date', 'ym') . '</a></td>
	</tr>
	<tr ' . $class . '>
		<td>' . sprintf(__('Number of %s Available, blank for unlimited', 'ym'), $post_type) . '</td>
		<td><input type="text" class="ym_text" name="post_purchasable_limit" value="' . $post_purchasable_limit . '" size="4" /></td>
	</tr>
	<tr ' . $class . '>
		<td>' . sprintf(__('Buyer can see %s for, blank for forever', 'ym'), $post_type) . '</td>
		<td><input type="text" class="ym_text" name="post_purchasable_duration" value="' . $post_purchasable_duration . '" size="2" /> ' . __('Day(s)', 'ym') . '</td>
	</tr>

	<tr ' . $class . '>
		<td>' . sprintf(__('Make a Featured Purchasable %s', 'ym'), $post_type) . '</td>
		<td>
<label for="post_purchasable_featured_no"><input type="radio" name="post_purchasable_featured" id="post_purchasable_featured_no" value="0" ' . $post_purchasable_featured_no . ' /> ' . __('No', 'ym') . '</label>
<label for="post_purchasable_featured_yes"><input type="radio" name="post_purchasable_featured" id="post_purchasable_featured_yes" value="1" ' . $post_purchasable_featured_yes . ' />' . __('Yes', 'ym') . '</label>
		</td>
	</tr>
	<tr ' . $class . '>
		<td>' . sprintf(__('PPP Index, for Grouping Posts, blank for no grouping')) . '</td>
		<td><input type="text" class="ym_text" name="ppp_index" value="' . $ppp_index . '" size="2" /></td>
	</tr>
	';
    $gateways = ym_spawn_gateways();
    foreach ($gateways as $gateway) {
        if (method_exists($gateway, 'additional_pack_fields')) {
            $fields = $gateway->additional_pack_fields();
            foreach ($fields as $field) {
                $val = get_post_meta($post->ID, '_ym_post_purchasable_' . $field['name'], true);
                echo '
	<tr ' . $class . '>
		<td>' . $field['label'];
                if ($field['caption']) {
                    echo ' - ' . $field['caption'];
                }
                echo '</td>
		<td>' . '<input type="text" class="ym_text" name="' . $field['name'] . '" value="' . $val . '" />
	</tr>';
            }
        }
    }
    echo '
</table>
';
}
 function pack_filter($packs)
 {
     if (ym_get_currency() != 'USD') {
         return array();
     }
     foreach ($packs as $key => $pack) {
         $cost_test = $pack['cost'];
         if (strpos($cost_test, '.')) {
             $cost_test = $cost_test * 100;
         }
         if (strtolower($pack['account_type']) == 'free') {
             unset($packs[$key]);
         } else {
             if ($cost_test == 0) {
                 unset($packs[$key]);
             }
         }
     }
     $new_packs = array();
     foreach ($packs as $key => $pack) {
         // allow
         // $pack['num_cycles'] == 1
         if ($pack['num_cycles'] == 1) {
             $new_packs[$key] = $pack;
         } else {
             if (isset($pack['braintree_plan_id']) && $pack['braintree_plan_id']) {
                 $new_packs[$key] = $pack;
             }
         }
     }
     return $new_packs;
 }
function ym_render_all_posts_purchased($admin = false, $limit = false, $author_id = false)
{
    global $wpdb;
    $this_page = YM_ADMIN_URL . (isset($_GET['ym_page']) ? '&ym_page=' . $_GET['ym_page'] : '');
    $totals = 0;
    echo '<script>
			function ym_confirm_ppp_delete(id) {
				if (confirm("' . __('Are you sure you want to delete this purchase?', 'ym') . '")) {
					document.location="' . $this_page . '&delete="+id;
				}
			}

		</script>';
    $results = ym_get_all_posts_purchased($limit, $author_id);
    echo '<table class="form-table widefat" cellspacing="0" style="width:100%;">';
    echo '<tr>
				<td style="border-bottom: 1px solid #EFEFEF; font-weight:bold;">' . __('Member', 'ym') . '</td>
				<td style="border-bottom: 1px solid #EFEFEF; font-weight:bold;">' . __('Post Title', 'ym') . '</td>
				<td style="border-bottom: 1px solid #EFEFEF; font-weight:bold;">' . __('Purchase Expiry', 'ym') . '</td>
				<td style="border-bottom: 1px solid #EFEFEF; font-weight:bold;">' . __('Price', 'ym') . '</td>
				<td style="border-bottom: 1px solid #EFEFEF; font-weight:bold;">' . __('Post Author', 'ym') . '</td>
				<td style="border-bottom: 1px solid #EFEFEF; font-weight:bold; text-align: right; width:20%;">' . __('Date Purchased', 'ym') . '</td>
				<td style="border-bottom: 1px solid #EFEFEF; font-weight:bold;">' . __('Payment Method', 'ym') . '</td>
				';
    if ($admin) {
        echo '<td style="border-bottom: 1px solid #EFEFEF; font-weight:bold; text-align: right;">' . __('Delete', 'ym') . '</td>';
    }
    echo '</tr>';
    if (isset($results[0])) {
        $last_user = 0;
        $last_post = 0;
        $last_time = 0;
        foreach ($results as $result) {
            if ($result['user_id']) {
                if ($last_user == $result['user_id']) {
                    if ($last_post == $result['post_id']) {
                        $sql = 'DELETE FROM ' . $wpdb->prefix . 'posts_purchased
							WHERE id = ' . $result['id'];
                        $wpdb->query($sql);
                        continue;
                    } else {
                        $last_post = $result['post_id'];
                    }
                } else {
                    $last_user = $result['user_id'];
                    $last_post = $result['post_id'];
                }
            } else {
                if (!$last_user) {
                    if ($last_post == $result['post_id']) {
                        if ($last_time) {
                            if ($result['unixtime'] >= $last_time - 30) {
                                $result['post_title'] = '<span style="color: red;">Duplicate?: ' . $result['post_title'] . '</div>';
                            }
                        }
                    }
                    $last_time = $result['unixtime'];
                    $last_post = $result['post_id'];
                } else {
                    $last_user = 0;
                    $last_time = $result['unixtime'];
                    $last_post = $result['post_id'];
                }
            }
            $expiry = (int) get_post_meta($result['post_id'], '_ym_post_purchasable_duration', 1);
            if (!$expiry) {
                $expiry = __('Indefinite', 'ym');
            } else {
                $expiry = date('d/m/Y', 86400 * $expiry + $result['unixtime']) . " (" . $expiry . ")";
            }
            if (!$result['user_login']) {
                $result['user_login'] = '******' . __('Non Registered User', 'ym') . '</em>';
            }
            $price = (int) get_post_meta($result['post_id'], '_ym_post_purchasable_cost', true);
            $totals += $price;
            $method = $result['payment_method'] ? $result['payment_method'] : '<em>Unknown</em>';
            echo '<tr>
					<td style="border-bottom: 1px solid #EFEFEF;">' . $result['user_login'] . '</td>
					<td style="border-bottom: 1px solid #EFEFEF;">' . $result['post_title'] . '</td>
					<td style="border-bottom: 1px solid #EFEFEF;">' . $expiry . '</td>
					<td style="border-bottom: 1px solid #EFEFEF;">' . number_format($price, 2) . ' ' . ym_get_currency() . '</td>
					<td style="border-bottom: 1px solid #EFEFEF;">' . $result['author_login'] . '</td>
					<td style="border-bottom: 1px solid #EFEFEF; text-align:right;">' . date(YM_DATE, $result['unixtime'] + get_option('gmt_offset') * 3600) . '</td>
					<td style="border-bottom: 1px solid #EFEFEF;">' . $method . '</td>';
            if ($admin) {
                echo '<td style="border-bottom: 1px solid #EFEFEF; text-align: right;">
						<a onclick="ym_confirm_ppp_delete(' . $result['id'] . ');" style="cursor:pointer;">
							<img src="' . YM_IMAGES_DIR_URL . 'cross.png" alt="' . __('Delete', 'ym') . '"/>
						</a>
					</td>';
            }
            echo '</tr>';
        }
        echo '<tr>
				<td class="ym_admin_ppp_totals">&nbsp;</td>
				<td class="ym_admin_ppp_totals">&nbsp;</td>
				<td class="ym_admin_ppp_totals">&nbsp;</td>
				<td class="ym_admin_ppp_totals">' . number_format($totals, 2) . ' ' . ym_get_currency() . '</td>
				<td class="ym_admin_ppp_totals">&nbsp;</td>
				<td class="ym_admin_ppp_totals">&nbsp;</td>
				<td class="ym_admin_ppp_totals">&nbsp;</td>';
        echo '</tr>';
    } else {
        echo '<tr>
					<td colspan=2>No posts have been sold yet</td>
				</tr>';
    }
    echo '</table>';
}
Exemple #11
0
 function get_button_code($pack, $user_id, $override_price = FALSE)
 {
     get_currentuserinfo();
     global $current_user, $ym_sys;
     $data = array('pay_to_email' => $this->pay_to_email, 'cancel_url' => site_url($this->cancel_url), 'status_url' => site_url('?ym_process=' . $this->code), 'language' => $this->language, 'hide_login' => $this->slim_gateway, 'pay_from_email' => $current_user->user_email, 'currency' => esc_html(ym_get_currency($pack['id'])), 'merchant_fields' => 'packdata');
     $data['rec_status_url'] = $data['status_url'];
     $cost = $override_price ? $override_price : $pack['cost'];
     if ($this->gateway_logo) {
         $data['logo_url'] = site_url($this->gateway_logo);
     }
     // calc redirect
     $data['return_url'] = esc_html($this->redirectlogic($pack));
     // pricing
     $vat = FALSE;
     if (isset($pack['vat_applicable']) && $pack['vat_applicable'] || $ym_sys->global_vat_applicable) {
         if ($ym_sys->vat_rate) {
             $vat = $ym_sys->vat_rate;
         }
     }
     if ($vat_rate = apply_filters('ym_vat_override', false, $user_id)) {
         $vat = $vat_rate;
     }
     if ($vat) {
         $vat = $data['amount'] / 100 * $vat;
         $cost = $cost + $vat;
         $data = array_merge($data, array('amount2' => $vat, 'amount2_description' => __('Tax/VAT', 'ym')));
     }
     // addition per type
     if (isset($pack['id']) && $pack['id']) {
         $types = array('d' => 'day', 'm' => 'month', 'y' => 'year');
         // subscription payment
         $start = time();
         $dt = getdate($start);
         if (strtolower($pack['duration_type']) == 'm') {
             $end = mktime(0, 0, 0, $dt['mon'] + $pack['duration'] * $pack['num_cycles'], $dt['mday'], $dt['year']);
         } elseif (strtolower($pack['duration_type']) == 'd') {
             $end = mktime(0, 0, 0, $dt['mon'], $dt['mday'] + $pack['duration'] * $pack['num_cycles'], $dt['year']);
         } else {
             $end = mktime(0, 0, 0, $dt['mon'], $dt['mday'], $dt['year'] + $pack['duration'] * $pack['num_cycles']);
         }
         if ($pack['trial_on']) {
             $data['amount'] = $pack['trial_cost'];
             $dtstart = getdate($start);
             $dtend = getdate($end);
             if (strtolower($pack['trial_duration_type']) == 'm') {
                 $start = mktime(0, 0, 0, $dtstart['mon'] + $pack['trial_duration'], $dtstart['mday'], $dtstart['year']);
                 $end = mktime(0, 0, 0, $dtend['mon'] + $pack['trial_duration'], $dtend['mday'], $dtend['year']);
             } elseif (strtolower($pack['trial_duration_type']) == 'd') {
                 $start = mktime(0, 0, 0, $dtstart['mon'], $dtstart['mday'] + $pack['trial_duration'], $dtstart['year']);
                 $end = mktime(0, 0, 0, $dtend['mon'], $dtend['mday'] + $pack['trial_duration'], $dtend['year']);
             } else {
                 $start = mktime(0, 0, 0, $dtstart['mon'], $dtstart['mday'], $dtstart['year'] + $pack['trial_duration']);
                 $end = mktime(0, 0, 0, $dtend['mon'], $dtend['mday'], $dtend['year'] + $pack['trial_duration']);
             }
         }
         $data = array_merge($data, array('detail1_description' => __('Subscription:', 'ym'), 'detail1_text' => isset($pack['item_name']) && $pack['item_name'] ? $pack['item_name'] : $ym_sys->item_name, 'packdata' => 'buy_subscription_' . $pack['id'] . '_' . $user_id));
         if ($pack['num_cycles']) {
             // it has end date
             $data['rec_end_date'] = date('d/m/Y', $end);
         }
         if ($pack['num_cycles'] != 1) {
             // it recurs
             //				$data['amount'] = $override_price ? $override_price ? $data['amount'];
             $data = array_merge($data, array('rec_amount' => $cost, 'rec_start_date' => date('d/m/Y', $start), 'rec_period' => $pack['duration'], 'rec_cycle' => $types[$pack['duration_type']]));
         } else {
             $data['amount'] = $cost;
         }
     } else {
         $data['amount'] = $cost;
         // post
         $data = array_merge($data, array('detail1_description' => __('Post:', 'ym'), 'detail1_text' => isset($pack['item_name']) && $pack['item_name'] ? $pack['item_name'] : $ym_sys->item_name));
         if (isset($pack['ppp_pack_id'])) {
             $data['packdata'] = 'buy_bundle_' . $pack['ppp_pack_id'] . '_' . $user_id;
         } else {
             if (isset($pack['ppp_adhoc_posts'])) {
                 $data['packdata'] = 'buy_post_' . implode(',', $pack['ppp_adhoc_posts']) . '_' . $user_id;
             } else {
                 $data['packdata'] = 'buy_post_' . ($pack['post_id'] ? $pack['post_id'] : get_the_ID()) . '_' . $user_id;
             }
         }
     }
     return $data;
 }
/**
Admin Form
*/
function ym_bundle_form($bundle, $submit)
{
    echo '
<form action="" method="post">
	<input type="hidden" name="bundle_id" value="' . $bundle->id . '" />
<table style="width: 100%;">
	<tr><th>Bundle Name:</th><td><input type="text" name="name" value="' . $bundle->name . '" /></td></tr>
	<tr><th>Bundle Cost:</th><td><input type="text" name="cost" value="' . number_format($bundle->cost, 2) . '" size="6" /> ' . ym_get_currency() . '</td></tr>
	<tr><th>Bundle Description:</th><td><input type="text" name="description" value="' . $bundle->description . '" /></td></tr>

	<tr><th>' . __('Buyer can see Bundle contents for, blank for forever', 'ym') . '</th><td><input type="text" name="purchaseexpire" size="2" value="' . $bundle->purchaseexpire . '" /> ' . __('Day(s)', 'ym') . '</td></tr>
	<tr><th>' . __('Number of Bundles Available, blank for unlimited', 'ym') . '</th><td><input type="text" name="purchaselimit" size="2" value="' . $bundle->purchaselimit . '" /></td></tr>
	<tr><th>' . __('Sale End, date bundle stops being on sale', 'ym') . '</th><td><input type="text" name="saleend" size="8" id="saleend" class="ym_datepicker" value="' . ($bundle->saleend ? date(YM_DATE_ONLY, $bundle->saleend) : '') . '" /> <a href="#nowhere" onclick="ym_clear_target(\'saleend\')">' . __('Clear Date', 'ym') . '</a></td></tr>
';
    $data = unserialize($bundle->additional);
    global $ym_active_modules;
    foreach ($ym_active_modules as $module) {
        $mod = new $module();
        if (method_exists($mod, 'additional_bundle_fields')) {
            $items = $mod->additional_bundle_fields();
            foreach ($items as $item) {
                echo '<tr><th>' . $item['label'] . '</th><td><input type="text" name="' . $item['name'] . '" value="' . $data[$item['name']] . '" /></td></tr>';
            }
        }
    }
    echo '
	<tr><td></td><td><input class="button-primary" type="submit" name="ym_do_bundle" value="' . $submit . '" /></td></tr>
</table>
</form>
';
}
    echo '<td>(' . $purchase->pack_id . ') ' . $purchase->name . '</td>';
    $expires = $purchase->purchaseexpire * 86400 + $purchase->purchasetime;
    echo '<td>' . ($purchase->purchaseexpire ? date(YM_DATE, $expires) : __('No Expire', 'ym')) . '</td>';
    echo '<td>' . date(YM_DATE, $purchase->purchasetime) . '</td>';
    echo '<td>' . $purchase->payment_method . '</td>';
    echo '<td><form action="" method="post">
<input type="hidden" name="delete_bundle_purchase" value="' . $purchase->purchase_id . '" />
<input type="image" src="' . YM_PLUGIN_DIR_URL . '/images/cross.png" alt="Delete" class="deletelink" />
</form></td>';
    echo '</tr>';
}
echo '</table>';
echo ym_end_box();
echo ym_start_box(__('Bundles Purchased Count', 'ym'));
echo '<table style="width: 100%;" class="form-table widefat">
	<tr>
		<th>' . __('(ID) Name', 'ym') . '</th>
		<th>' . __('Cost', 'ym') . '</th>
		<th>' . __('Count', 'ym') . '</th>
	</tr>';
foreach ($bundles as $bundle) {
    $count = ym_bundle_purchased_count($bundle->id);
    echo '<tr>';
    echo '<td>(' . $bundle->id . ') ' . $bundle->name . '</td>';
    echo '<td>' . number_format($bundle->cost, 2) . ' ' . ym_get_currency() . '</td>';
    echo '<td>' . $count . '</td>';
    echo '</tr>';
}
echo '</table>';
echo ym_end_box();
echo '</div>';
Exemple #14
0
 function pack_filter($packs)
 {
     if (ym_get_currency() != 'USD') {
         return array();
     }
     if (!$this->api_key) {
         // drop to fail allow render single type to allow error message
         return array(array_pop($packs));
     }
     foreach ($packs as $key => $pack) {
         $cost_test = $pack['cost'];
         if (strpos($cost_test, '.')) {
             $cost_test = $cost_test * 100;
         }
         if (strtolower($pack['account_type']) == 'free') {
             unset($packs[$key]);
         } else {
             if ($cost_test == 0) {
                 unset($packs[$key]);
             } else {
                 if ($pack['duration'] != 1) {
                     unset($packs[$key]);
                 } else {
                     if ($pack['duration_type'] == 'd') {
                         unset($packs[$key]);
                     }
                 }
             }
         }
     }
     return $packs;
 }
function ym_get_pack_label($pack, $cost_override = false, $admin = TRUE)
{
    global $duration_str, $ym_packs;
    if (!is_array($pack)) {
        $pack_id = $pack;
        $pack_data = FALSE;
        $packs = $ym_packs->packs;
        foreach ($packs as $pack) {
            if ($pack['id'] == $pack_id) {
                $pack_data = $pack;
                break;
            }
        }
        if ($pack_data) {
            $pack = $pack_data;
        } else {
            return '';
        }
    }
    if ($admin && is_admin() && (isset($pack['admin_name']) && $pack['admin_name'])) {
        return $pack['admin_name'];
    }
    $cost = $pack['cost'];
    if ($cost_override) {
        $cost = $cost_override;
    }
    // format for diaply
    $cost = number_format($cost, 2, '.', ',');
    $dur_type = $duration_str[$pack['duration_type']];
    $dur_str = $pack['duration'] == 1 ? rtrim($dur_type, 's') : $dur_type;
    return ym_get_pack_string(ucwords($pack['account_type']), $cost, ym_get_currency($pack['id']), $pack['duration'], $dur_str, @$pack['num_cycles'], $pack['trial_on'], $pack['trial_cost'], $pack['trial_duration'], $pack['trial_duration_type'], $pack['description']);
}
Exemple #16
0
 function get_button_code($pack, $user_id, $override_price = FALSE)
 {
     global $ym_sys;
     $cost = $override_price ? $override_price : $pack['cost'];
     $cost = $cost * 100;
     //convert to pence
     $data = array('CpiDirectResultUrl' => site_url('?ym_process=' . $this->code), 'CpiReturnUrl' => site_url('?ym_process=' . $this->code), 'MerchantData' => '', 'Mode' => $this->mode, 'OrderDesc' => isset($pack['item_name']) && $pack['item_name'] ? $pack['item_name'] : $ym_sys->item_name, 'OrderId' => '', 'PurchaseAmount' => $cost, 'PurchaseCurrency' => $this->currency_to_code(ym_get_currency()), 'StorefrontId' => $this->store_front_id, 'TimeStamp' => time() * 1000, 'TransactionType' => 'Capture', 'UserId' => $user_id);
     if ($this->map_billingaddress1) {
         $data = array_merge($data, array('BillingAddress1' => '', 'BillingCity' => '', 'BillingCountry' => '', 'BillingFirstName' => get_user_by('id', $user_id)->user_firstname, 'BillingLastName' => get_user_by('id', $user_id)->user_lastname, 'BillingPostal' => '', 'ShopperEmail' => get_user_by('id', $user_id)->user_email, 'ShippingAddress1' => '', 'ShippingCity' => '', 'ShippingCountry' => '', 'ShippingFirstName' => '', 'ShippingLastName' => '', 'ShippingPostal' => ''));
         $data['ShippingFirstName'] = $data['BillingFirstName'];
         $data['ShippingLastName'] = $data['BillingLastName'];
     }
     // custom
     if (isset($pack['id']) && $pack['id']) {
         $data['MerchantData'] = 'buy_subscription_' . $pack['id'] . '_' . $user_id;
     } else {
         if (isset($pack['ppp_pack_id'])) {
             $data['MerchantData'] = 'buy_bundle_' . $pack['ppp_pack_id'] . '_' . $user_id;
         } else {
             $data['MerchantData'] = 'buy_post_' . ($pack['post_id'] ? $pack['post_id'] : get_the_ID()) . '_' . $user_id;
         }
     }
     $data['OrderId'] = $data['MerchantData'] . '_' . time();
     wp_set_current_user($user_id);
     $customs = ym_get_custom_fields($user_id);
     // MAP
     if ($this->map_billingaddress1) {
         $data['BillingAddress1'] = ym_shortcode_user(array('name' => $this->map_billingaddress1), '', 'ym_user_custom');
         $data['BillingCity'] = ym_shortcode_user(array('name' => $this->map_billingcity), '', 'ym_user_custom');
         $data['BillingCountry'] = ym_shortcode_user(array('name' => $this->map_billingcountry), '', 'ym_user_custom');
         $data['BillingPostal'] = ym_shortcode_user(array('name' => $this->map_billingpostal), '', 'ym_user_custom');
         $data['ShippingAddress1'] = ym_shortcode_user(array('name' => $this->map_shippingaddress1), '', 'ym_user_custom');
         $data['ShippingCity'] = ym_shortcode_user(array('name' => $this->map_shippingcity), '', 'ym_user_custom');
         $data['ShippingCountry'] = ym_shortcode_user(array('name' => $this->map_shippingcountry), '', 'ym_user_custom');
         $data['ShippingPostal'] = ym_shortcode_user(array('name' => $this->map_shippingpostal), '', 'ym_user_custom');
         // code convert
         $data['BillingCountry'] = $this->country_to_code($data['BillingCountry']);
         $data['ShippingCountry'] = $this->country_to_code($data['ShippingCountry']);
     }
     // all fields for hash present
     $data['OrderHash'] = $this->generateHash($data, $this->cpi_hash_key);
     if ($this->map_billingaddress1) {
         // add optional fields
         if ($this->map_billingaddress2) {
             $data['BillingAddress2'] = ym_shortcode_user(array('name' => $this->map_billingaddress2), '', 'ym_user_custom');
         }
         if ($this->map_billingcounty) {
             $data['BillingCounty'] = ym_shortcode_user(array('name' => $this->map_billingcounty), '', 'ym_user_custom');
         }
         if ($this->map_shippingaddress2) {
             $data['ShippingAddress2'] = ym_shortcode_user(array('name' => $this->map_shippingaddress2), '', 'ym_user_custom');
         }
         if ($this->map_shippingcounty) {
             $data['ShippingCounty'] = ym_shortcode_user(array('name' => $this->map_shippingcounty), '', 'ym_user_custom');
         }
     }
     return $data;
 }
Exemple #17
0
 function get_button_code($pack, $user_id, $override_price = FALSE)
 {
     get_currentuserinfo();
     global $current_user, $ym_sys;
     $email = isset($current_user->user_email) ? $current_user->user_email : '';
     if (!$email) {
         if ($user = ym_get('username')) {
             $user = get_user_by('login', $user);
             $email = $user->user_email;
         }
     }
     $data = array('instId' => $this->inst_id, 'cartId' => $user_id, 'amount' => $override_price ? $override_price : $pack['cost'], 'currency' => esc_html(ym_get_currency($pack['id'])), 'email' => $email, 'hideContact' => 0, 'M_payment_type' => 'one-time', 'authMode' => $this->preauth, 'MC_callback' => site_url('?ym_process=' . $this->code));
     if ($this->status == 'test') {
         $data['testMode'] = 100;
     }
     if ($this->md5_sig) {
         $data['signatureFields'] = 'email:cartId:instId';
         $data['signature'] = md5($this->md5_sig . ':' . $data['email'] . ':' . $user_id . ':' . $this->inst_id);
     }
     // addition per type
     if (isset($pack['id'])) {
         // subscription recurring
         $data = array_merge($data, array('M_item_number' => 'buy_subscription_' . $pack['id'] . '_' . $user_id, 'M_payment_type' => 'subscription'));
         $duration_days = $pack['duration'];
         $interval_unit = 1;
         $word = 'days';
         switch ($pack['duration_type']) {
             case 'y':
                 $duration_days = $duration_days * 365;
                 $interval_unit = 4;
                 $word = 'years';
                 break;
             case 'm':
                 $duration_days = $duration_days * 28;
                 $interval_unit = 3;
                 $word = 'months';
         }
         if (isset($pack['num_cycles']) && $pack['num_cycles'] != 1) {
             $data['futurePayType'] = 'regular';
             $time = strtotime('+' . $pack['duration'] . ' ' . $word);
             $data['startDate'] = date('Y-m-d', $time);
             $data['noOfPayments'] = $pack['num_cycles'] ? $pack['num_cycles'] - 1 : 0;
             //don't include initial payment
             $data['intervalUnit'] = $interval_unit;
             $data['intervalMult'] = $pack['duration'];
             $data['normalAmount'] = $pack['cost'];
             $data['option'] = 1;
         }
         if ($pack['trial_on']) {
             $interval_unit = 1;
             $duration_days = $pack['trial_duration'];
             switch ($pack['trial_duration_type']) {
                 case 'y':
                     $duration_days = $duration_days * 365;
                     break;
                 case 'm':
                     $duration_days = $duration_days * 28;
             }
             $data['Amount'] = $pack['trial_cost'];
             $data['startDate'] = date('Y-m-d', time() + $duration_days * 86400);
             $data['noOfPayments'] = $pack['num_cycles'];
             //dont need to not include
         }
     } else {
         // post or post pack
         if (isset($pack['ppp_pack_id'])) {
             $data['M_item_number'] = 'buy_bundle_' . $pack['ppp_pack_id'] . '_' . $user_id;
         } else {
             if (isset($pack['ppp_adhoc_posts'])) {
                 $data['M_item_number'] = 'buy_post_' . implode(',', $pack['ppp_adhoc_posts']) . '_' . $user_id;
             } else {
                 $data['M_item_number'] = 'buy_post_' . ($pack['post_id'] ? $pack['post_id'] : get_the_ID()) . '_' . $user_id;
             }
         }
     }
     $data['M_return'] = esc_html($this->redirectlogic($pack));
     return $data;
 }