Home » Categories » Multiple Categories

Create gift subscriptions with Sitelok

For certain sites you may like to have an account created for a user that is not actually the person paying. So for example someone wants to send membership as a gift having the login details emailed directly to that user. Here is a way to do that using Paypal, a registration form and the Paypal plugin. You can access the example pages in the attachments below.

1) We will use a registration form to collect the required details. In this example we will get the name of the payer and a note from them to the actual member (recipient). The payers name will be stored in custom1 and the note in custom2 (these are optional though). We will also collect the name and email address of the recipient.

<?php require_once("slpw/sitelokregister.php"); ?>
<html>
<head>
<title>Gift Subscription Form</title>
</head>
<body>
<hq>Gift Subscription Form</h1>
<?php if ($registermsg!="") print $registermsg; ?><br>
<form name="sitelokregisteruser" action="subscribe-gift.php" method="POST">
<?php registeruser("TEMP","1","subscribe.php?oc=!!!ordercustom!!!","","","Yes","YNYYYY"); ?>
Your Name<br>
<input type="text" name="custom1" id="custom1" value="<?php echo $custom1; ?>"><br>
Note to recipient<br>
<textarea name="custom2" rows="4" wrap="soft" cols="37"><?php echo $custom2; ?></textarea>
<br>
Their Name<br>
<input type="text" name="name" id="name" value="<?php echo $name; ?>"><br>
Their Email<br>
<input type="text" name="email" id="emailemail" value="<?php echo $email; ?>"><br>
<input name="submit" type="submit" value="Pay and Send">
</form>
</body>
</html>

2) The registration form when submitted successfully will create the recipients account in a temporary usergroup called TEMP. This will be updated to the correct usergroup after payment is confirmed. We will pass to the registration thank you page the created username so that can be passed through Paypal. This is all achieved using this line from the above

<?php registeruser("TEMP","1","subscribe.php?oc=!!!ordercustom!!!","","","Yes","YNYYYY"); ?>

The registration thank you page needs to call Paypal using a normal Sitelok Paypal button. So that the user doesn't need to click the button we use javascript to submit it. We also pass the created username through Paypal using the custom field.

<form name="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="paypal@yoursite.com">
<input type="hidden" name="item_name" value="Product Name">
<input type="hidden" name="item_number" value="id1">
<input type="hidden" name="amount" value="9.99">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="http://www.yoursite.com/subscribe-ok.php">
<input type="hidden" name="cancel_return" value="http://www.yoursite.com">
<input type="hidden" name="notify_url" value="http://www.yoursite.com/slpw/pay_paypal/slpaypal.php">
<input type="hidden" name="custom" value="<?php echo $_GET['oc']; ?>">
</form>
<script language="JavaScript">
<!-- JavaScript
document.paypal.submit()
// - JavaScript - -->
</script>

Just replace the above button with your own button remembering to remove the actual button itself and adding the custom field line

<input type="hidden" name="custom" value="<?php echo $_GET['oc']; ?>">

In the rare cases where a user may have javascript disabled you can also add the same button (keeping the button this time) in a <noscript> section (see the example pages).

3) In the Paypal plugin you need to set the product so that it adds the user to the required usergroup(s) as usual and also removes them from the TEMP usergroup. To have a usergroup removed form a usergroup just set the expiry time to -1


Attachments (1) Attachments