function ym_render_coupon_edit($coupon_id)
{
    $coupon = ym_get_coupon($coupon_id);
    $this_page = YM_ADMIN_URL . '&ym_page=' . ym_get('ym_page');
    $allowed = str_split($coupon->allowed);
    echo '<div>
			<form method="POST" style="margin: 0px; pading: 0px;">
				<input type="hidden" name="edit" value="1" />
				<table class="widefat form-table">
					<tr>
						<th>' . __('Code', 'ym') . '</th>
						<td><input name="name" style="width: 450px;" value="' . $coupon->name . '" /></td>
					</tr>
					<tr>
						<th>' . __('Cost', 'ym') . '</th>
						<td><input name="value" style="width: 50px;" value="' . $coupon->value . '" /></td>
					</tr>
					<tr>
						<th>' . __('Description', 'ym') . '</th>
						<td><input name="description" style="width: 700px;" value="' . $coupon->description . '"/></td>
					</tr>

					<tr>
						<th>
							<label>' . __('Can be used for New Subscriber', 'ym') . '</label>
						</th><td>
							<input type="checkbox" name="new_sub" ' . ($allowed[0] ? 'checked="checked"' : '') . ' />
						</td>
					</tr>
					<tr>
						<th>
							<label>' . __('Can be used for Subscription Upgrade', 'ym') . '</label>
						</th><td>
							<input type="checkbox" name="upgrade" ' . ($allowed[1] ? 'checked="checked"' : '') . ' />
						</td>
					</tr>
					<tr>
						<th>
							<label>' . __('Can be used for Post Purchase', 'ym') . '</label>
						</th><td>
							<input type="checkbox" name="post" ' . ($allowed[2] ? 'checked="checked"' : '') . ' />
						</td>
					</tr>
					<tr>
						<th>
							<label>' . __('Can be used for Pack Purchase', 'ym') . '</label>
						</th><td>
							<input type="checkbox" name="pack" ' . ($allowed[3] ? 'checked="checked"' : '') . ' />
						</td>
					</tr>

					<tr>
						<th>
							<label>' . __('Coupon Usage Limit (0 for Unlimited)', 'ym') . '</label>
						</th><td>
							<input type="text" name="usage_limit" size="2" value="' . $coupon->usage_limit . '" />
						</td>
					</tr>
					<tr>
						<td>
							<input class="button" type="button" onclick="document.location=\'' . $this_page . '\';" value="' . __('&#0171; Back to coupons', 'ym') . '" />
						</td>
						<td style="text-align: right;">
							<input class="button" type="submit" name="update_coupon" value="' . __('Save', 'ym') . '" />
						</td>
					</tr>				</table>
			</form>
		</div>';
}
<?php

echo '	<div class="wrap" id="poststuff">';
ym_coupon_update();
if ($coupon_id = ym_get('coupon_id')) {
    $coupon = ym_get_coupon($coupon_id);
    if (ym_post('edit')) {
        echo ym_start_box(__('Edit coupon: "', 'ym') . $coupon->name . '"');
        ym_render_coupon_edit($coupon_id);
        echo ym_end_box();
    }
    if (ym_post('view')) {
        echo ym_start_box(__('View Users who used Coupon: "', 'ym') . $coupon->name . '"');
        ym_render_coupon_view($coupon_id);
        echo '<form method="POST">
		<input type="hidden" name="ym_coupon_id" value="' . $coupon_id . '" />
		<input class="button" type="submit" name="ym_start_xls_coupon" value="' . __('Export Data', 'ym') . '" />
		 </form>';
        echo ym_end_box();
    }
} else {
    echo ym_start_box(__('Coupon', 'ym'));
    ym_render_coupons();
    echo ym_end_box();
}
echo '</div>';
예제 #3
0
 private function sync_coupons($coupon_name = FALSE, $type = 'name')
 {
     $r = TRUE;
     $coupons = array();
     if ($coupon_name && $type == 'name') {
         if ($id = ym_get_coupon_id_by_name($coupon_name)) {
             $coupons = array(ym_get_coupon($id));
         }
     } else {
         if ($coupon_name && $type == 'id') {
             $coupons = array(ym_get_coupon($coupon_name));
         } else {
             $coupons = ym_get_coupons();
         }
     }
     foreach ($coupons as $coupon) {
         $value = $coupon->value;
         if (ym_get_coupon_type($value) == 'percent') {
             // only support percentages
             $allowed = str_split($coupon->allowed);
             if ($allowed[0] == 1 || $allowed[1] == 1) {
                 // sub enabled
                 $value = str_replace('%', '', $value);
                 $create = FALSE;
                 $id = 'ym_' . $coupon->id;
                 $mycoupon = array('id' => $id, 'percent_off' => $value, 'duration' => 'once');
                 list($r_code, $response) = $this->stripe_api_request('coupons/' . $id);
                 if ($r_code == 200) {
                     // check ok
                     if ($response->percent_off != $value || $response->duration != 'once') {
                         // update needed
                         list($r_code, $response) = $this->stripe_api_request('coupons', 'DELETE', array('id' => $id));
                         if ($r_code == 200) {
                             $create = TRUE;
                         } else {
                             $r = FALSE;
                         }
                     }
                 } else {
                     $create = TRUE;
                 }
                 if ($create) {
                     // doesn't exist
                     list($r_code, $response) = $this->stripe_api_request('coupons', 'POST', $mycoupon);
                     if ($r_code != 200) {
                         $r = FALSE;
                     }
                 }
             }
         }
     }
     return $r;
 }