Jump to content

How to generate a product key for my program when it it bought


mastergamez

Recommended Posts

Hello, I am using Prestashop for my game company and the way I verify people bought my game is by a mySQL of all the product keys which they need to put in the installation. Here is the format in the database: client_id | user_name | company | email | serial_no | license_no | validations_no

and I want to make it so when people buy the game all of the things (except company if they didn't fill it in in the checkout page) will be in a new row in this table. Also client_id is the number of the buyer, for example, the first person to buy the game has a client id that is 1, the next person 2, the next 3, etc. Also, the format of the product key which I want to be randomly generated is ?????-?????-?????-?????-????? 

? is a random letter or number. I want the product key to be emailed to user, and be on the order page.Any help would be appreciated, thank you

Edited by MasterGameZ (see edit history)
Link to comment
Share on other sites

You could create a simple function like this

public function generateLicense($uppercase = true)
{
	$date = uniqid();
	$hash = Tools::encrypt($date);
	$hash = substr($hash, 0, 25);
	$array = str_split($hash, 5);
	$license = implode('-', $array);

	return $uppercase ? strtoupper($license) : $license;
}

Then call it with result in uppercase

$this->generateLicense();

Or call it with result in lowercase:

$this->generateLicense(false);
Link to comment
Share on other sites

Does this do everything here:

Put the product key on the order page/information

Email the customer the product key

Not allow 2 product keys to be the same

Adds a new row in the table i made thats called "clients2" which is the one that has the format client_id | user_name | company | email | serial_no | license_no | validations_no

Also i never mentioned license_no is the amount of copies the buyer bought and validations_no should just be set to 0 since its handeled in installation.

And if it does do all this, where do i put this code?

Link to comment
Share on other sites

Does this do everything here:

Put the product key on the order page/information

Email the customer the product key

Not allow 2 product keys to be the same

Adds a new row in the table i made thats called "clients2" which is the one that has the format client_id | user_name | company | email | serial_no | license_no | validations_no

Also i never mentioned license_no is the amount of copies the buyer bought and validations_no should just be set to 0 since its handeled in installation.

And if it does do all this, where do i put this code?

Of course this doesn't do all that, this is only an idea how you can generate the codes, to achieve all, you will need to search a module, or maybe you need search for a freelancer/agency to develop a module.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...