Newer
Older
Import / applications / MakePDF / Website / payment / impl / licensing.php
<?php

function sign_license($cleartext, $keyfile)
{
    $private_key = openssl_pkey_get_private('file://' . $keyfile);
    openssl_sign($cleartext, $sig, $private_key, OPENSSL_ALGO_SHA256);
    $signature = str_split(base64_encode($sig), 40);
    foreach ($signature as $k => $v) {
    	$cleartext .= "Signature$k = " . $signature[$k]  . "\r\n";
    }
    return $cleartext;
}

function make_license_from_ipn($keyfile)
{
    $license_text  = "";
    if ($_POST["test_ipn"] == 1) {
        $license_text .= "Test       = true\r\n";
    }
    $license_text .= "LicenseId  = " . $_POST["txn_id"]          . "\r\n";
    $license_text .= "Date       = " . $_POST["payment_date"]    . "\r\n";
    $license_text .= "Product    = " . $_POST["item_name"]       . "\r\n";
    $license_text .= "Version    = " . $_POST["item_number"]     . "\r\n";
    $license_text .= "Users      = " . $_POST["quantity"]        . "\r\n";
    $license_text .= "Other      = " . $_POST["custom"]          . "\r\n";
    $license_text .= "Name       = " . $_POST["address_name"]    . "\r\n";
    $license_text .= "Email      = " . $_POST["payer_email"]     . "\r\n";
    $license_text .= "Address1   = " . $_POST["address_street"]  . "\r\n";
    $license_text .= "Address2   = " . $_POST["address_city"] . " " . $_POST["address_state"] . " " . $_POST["address_zip"] . "\r\n";
    $license_text .= "Address3   = " . $_POST["address_country"] . "\r\n";
    $license_text .= "KeyVersion = 1.0\r\n";

    $signed_license  = "----------------------------------\r\n";
    $signed_license .= sign_license($license_text, $keyfile);
    $signed_license .= "----------------------------------\r\n";
    return $signed_license;
}

?>