Skip to content

@ryanj /discount_upload.php
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Create N unique Eventbrite discount codes for an event
<?php
// load the API Client library
// https://github.com/ryanjarvinen/eventbrite.php
include "Eventbrite.php";
// -------------- APPLICATION CONFIG ----------------- //
// Eventbrite API key (REQUIRED)
// http://www.eventbrite.com/api/key/
$app_key = 'YOUR_APP_KEY_HERE';
// Eventbrite user_key, required for reading/writing data
// http://www.eventbrite.com/userkeyapi
$user_key = 'YOUR_USER_KEY_HERE';
// PLEASE RUN A TEST BEFORE CREATING YOUR DISCOUNT CODES
// "$test_mode = true" will do a test-run, new discount codes will be
// printed to the screen without being created.
// Running the script with "$test_mode = false" will create your discounts
$test_mode = true;
// DEFAULT DISCOUNT SETTINGS
// See http://developer.eventbrite.com/doc/discount/discount_new/
// for more information about these parameters
$discount_options = array(
// The event_id that the discount applies toward
'event_id' => 1905947770,
// amount OR percent off
'amount_off' => 25,
// ticket_ids that the discount will apply toward
'tickets' => '10206191,10206201,10206209,10207185',
// quantity of discounts available
'quantity_available' => '2'
);
// Generate random codes, or read codes in from a csv file?
// for random codes, set "$csv_filename = false;" and adjust the variables in the next section,
// to read in discount codes from a file, supply the filename here:
$csv_filename = false;
// VARIABLES FOR GENERATING N UNIQUE RANDOM DISCOUNT CODES
// (skip this section and supply a filename above if you want codes from a csv file)
$total_discount_codes = 1000;
$discount_prefix = 'DISC-';
$initial_offset = 5555;
$discount_increment = 667;
// ------------------ End of Config ------------------ //
// create, or simulate the creation of discount codes:
function create_discount( $eb_client, $discount_options, $test_mode ){
print('adding code: ' . $discount_options['code'] . "\n");
//create your discount codes -
// BE CAREFUL!
if($test_mode != true){
$resp = $eb_client->discount_new($discount_options);
var_dump($resp);
}
}
// Initialize the API client
$eb_client = new Eventbrite( $app_key, $user_key );
// Generate random codes based on a pattern, or read codes in from a CSV file:
if( $csv_filename ){
if (($handle = fopen($csv_filename, "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// Read each discount code number in from a csv file:
$discount_options['code'] = $data[0];
create_discount($eb_client, $discount_options, $test_mode);
}
fclose($handle);
}
}else{
for ( $i = $initial_offset; $i < $total_discount_codes + $initial_offset; $i++ ) {
// generate a semi-unique discount code -
// you may want to tweak the $initial_offset or $base_discount_increment
// to make sure that your pattern is less guessable
$random_num = $i * $discount_increment;
//generate discount_new API params
$discount_options['code'] = $discount_prefix . $random_num;
create_discount($eb_client, $discount_options, $test_mode);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.