forked from tylerhall/Shine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fastspring.php
57 lines (48 loc) · 1.98 KB
/
fastspring.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?PHP
require 'includes/master.inc.php';
$app = new Application();
$app->select($_POST['item_number']); // custom
if (!$app->ok()) {
error_log("Application {$_POST['item_name']} {$_POST['item_number']} not found!");
exit;
}
// FastSpring security check...
if(md5($_REQUEST['security_data'] . $app->fs_security_key) != $_REQUEST['security_hash'])
die('Security check failed.');
# check by transaction ID and add/update
$o = new Order();
$o->select($_POST['OrderReference'], 'txn_id');
if (!$o->ok()) $o = new Order();
$o->payer_email = $_POST['CustomerEmail'];
$o->first_name = $_POST['CustomerFirstName'];
$o->last_name = $_POST['CustomerLastName'];
$o->txn_id = $_POST['OrderReference'];
$o->item_name = $_POST['item_name']; // custom
$o->residence_country = $_POST['AddressCountry'];
$o->quantity = $_POST['quantity']; // custom
$o->mc_currency = $_POST['mc_currency']; // custom
$o->payment_gross = preg_replace('/[^0-9.]/', '', $_POST['payment_gross']); // custom
$o->mc_gross = $o->payment_gross;
$o->app_id = $app->id;
$o->dt = dater();
$o->type = 'FastSpring';
$o->save();
# Online or immediate activation
if ($app->activation_online != '1') {
$o->generateLicense();
if(isset($_POST['sendEmail']) && ($_POST['sendEmail'] == 1)) {
$o->emailLicense();
}
}
// These are the fields and values you'll need to setup in FastSpring's
// remote notification fulfillment option.
// AddressCountry #{order.address.country}
// CustomerEmail #{order.customer.email}
// CustomerFirstName #{order.customer.firstName}
// CustomerLastName #{order.customer.lastName}
// OrderReference #{order.reference}
// item_name #{orderItem.productName}
// item_number 3 <-- this is the Shine ID number of your product
// mc_currency #{order.currency}
// payment_gross #{orderItem.priceTotalUSD.value}
// quantity #{orderItem.quantity}