Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //TODO: Set the following constants. All URLs must be publicly accessible.
- // See http://wyday.com/limelm/help/how-to-generate-product-keys-after-order/
- // to learn how to configure the payment form and set everything up.
- //==== General Config ====
- //TODO: disable debug & sandbox when you're using this on your live site.
- // Enable debug logging
- $debug = true;
- $debug_log = dirname(__FILE__).'/payment_debug.log';
- // api key found in http://wyday.com/limelm/settings/
- $LimeLM_ApiKey = 'API KEY';
- // the version id is found in the url.
- // For example http://wyday.com/limelm/version/100/ the version id is '100'.
- $LimeLM_VersionID = 'ID';
- function debug_log($message, $success, $end = false)
- {
- global $debug, $debug_log;
- if (!$debug || !$debug_log)
- return;
- // Timestamp
- $text = '['.date('m/d/Y g:i A').'] - '.(($success)?'SUCCESS :':'FAILURE :').$message. "\n";
- if ($end)
- $text .= "\n------------------------------------------------------------------\n\n";
- // Write to log
- $fp=fopen($debug_log, 'a');
- fwrite($fp, $text);
- fclose($fp);
- }
- function SendPKeys($quantity, $email, $first, $last, $CompanyName, $AppName)
- {
- //Note: we put LimeLM in this directory. Change it as needed.
- require('LimeLM.php');
- global $LimeLM_VersionID, $LimeLM_ApiKey;
- $errors = false;
- // set your API key
- LimeLM::SetAPIKey($LimeLM_ApiKey);
- try
- {
- // Generate the product key - set the number of activations using the quantity
- $xml = new SimpleXMLElement(LimeLM::GeneratePKeys($LimeLM_VersionID, 1, $quantity, $email));
- if ($xml['stat'] == 'ok')
- {
- foreach ($xml->pkeys->pkey as $pkey)
- {
- // add a newline if you're generating more than one key
- if ($product_keys)
- $product_keys .= "\r\n";
- // set the product key
- $product_keys .= $pkey['key']."\r\n";
- }
- }
- else //failure
- {
- // use the error code & message
- debug_log('Failed to generate product keys: ('.$xml->err['code'].') '.$xml->err['msg'],false);
- }
- }
- catch (Exception $e)
- {
- debug_log('Failed to generate product keys, caught exception: '.$e->getMessage(),false);
- }
- if (empty($product_keys))
- {
- // the product key didn't generate, don't send e-mail to the customer yet.
- $errors = true;
- }
- // form the customer name
- $customerName = $first;
- if (!empty($last))
- // append the last name
- $customerName .= ' '.$last;
- $emailBody = $customerName.',
- Thank you for your order. Your product key is:
- '.$product_keys.'
- This product key is licensed for '.$quantity.( $quantity > 1 ? ' users' : ' user' ).' of '.$AppName.'.
- Thank you,
- '.$CompanyName;
- if (!empty($product_keys))
- {
- // Send Email to the buyer
- $emailSent = mail($email, 'Your '.$AppName.' product key', $emailBody, $headers);
- }
- // generate an array you can insert into your database
- $new_order_info = array(
- 'quantity_licenses' => $quantity,
- 'pkey' => $product_keys,
- 'pkey_emailed' => $emailSent ? '1' : '0', // 0 = no, 1 = yes
- 'first_name' => $first,
- 'last_name' => $last,
- 'email' => $email
- );
- //TODO: delete logging, or log to a safe location (not accessible to outside world)
- debug_log('TODO: Insert array into db: '."\r\n\r\n".print_r($new_order_info, true), true);
- if (!$emailSent)
- {
- $errors = true;
- debug_log('Error sending product Email to '.$email.'.',false);
- }
- LimeLM::CleanUp();
- return $product_keys;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment