Page 1 of 1

[TUTORIAL] HOTMART INTEGRATION - ENABLE PAID SUBSCRIPTIONS FOR YOUR APPGINI APP

Posted: 2020-02-18 22:33
by D Oliveira
Hello all, hope this helps the community, in this tutorial we are gonna process subscription payment through hotmart and give the user access to your appgini application once payment approved.

1- Create an account with hotmart: https://app-vlc.hotmart.com/

2- Create a subscription product

3- Go to your product page -> tools - > webhook

4- Create a new setting for 'order approved' make sure the url is yourdomain.com/appfolder/sub_access.php

sub_access.php

Code: Select all

<?php

	$currDir = dirname(__FILE__);
	include("{$currDir}/language.php");
	include("{$currDir}/defaultLang.php");
	include("{$currDir}/lib.php");
	include_once("{$currDir}/header.php");
	 $adminConfig = config('adminConfig');

	print_r($_POST);

	 $name = $_POST["name"];

	 $email = $_POST["email"];

	 $statuss = $_POST["subscription_status"];


	 print_r($data);

	 print($email . '  ' . $statuss);


	 		$date0 = new DateTime();
			$date1 = new DateTime();
			$date1->modify('+'.'34'.' day');
			$date2 = $date1->format('Y-m-d');



		
		$sql = "SELECT memberID FROM membership_users WHERE email = '{$email}'";

			$datos = sqlValue($sql);

				if ( $datos == "" ){

				sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('whateverpass', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name}', custom2='1', custom3='', custom4='{$date2}', comments=''", $eo);


				}else{

					sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date2}' WHERE email = '{$email}'", $eo);

				}


$to = $email;
$subject = $name." - Welcome to my app";

$message = "
<html>
<head>
<title>Welcome</title>
</head>
<body>
<div style='text-align: center'><img style='width: 250px' src='yourlogourl.png' /></div>
<table align='center'>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n"."
<tr>
<td align='center'> Hello ".$name.", welcome to the App!</td>
</tr>
<p><br/></p>". "\n" . "
<tr>
<td align='center'> credentials: </td>
</tr>
<tr>
<td align='center'> (user/pass) </td>
</tr>
<p> </p>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>user</th>
</tr>
<tr>
<td align='center'>".$email."</td>
</tr>
<p> </p>
</table>
<table align='center'>
<tr>
<th align='center'>pass</th>
</tr>
<tr>
<td align='center'>whateverpass</td>
</tr>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Access App</th>
</tr>
<tr>
<td align='center'>https://yourappurl.com</td>
</tr>
<p> </p>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Contact</th>
</tr>
<tr>
<td align='center'>[email protected]</td>
</tr>
</table>
<p> </p>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <[email protected]>' . "\r\n";

mail($to,$subject,$message,$headers);




?>
5- in your home.php place this code under your javascript area:

Code: Select all

var ps2 = '0';

	    $j.ajax({
					url: 'hooks/ajax-ps2.php',
					data: { entidad_id: ps2 },
					success: function(data){
						if (data) {
							console.log(data);
							window.location.replace('hooks/erro_hook.php');

						}else{
							//console.log('no data');
						}
					}
		});

6- Also inside hooks folder create erro_hook.php (this is re-activation page)

Code: Select all

<?php
  define('PREPEND_PATH', '../');
  $hooks_dir = dirname(__FILE__);
  include("$hooks_dir/../defaultLang.php");
  include("$hooks_dir/../language.php");
  include("$hooks_dir/../lib.php");

  include_once("$hooks_dir/../header.php");



  //include_once("$hooks_dir/../footer.php");

  $mi = getMemberInfo();




?>

<style>
  .panel-body-description{
    margin-top: 10px;
    height: 100px;
    overflow: auto;
  }
  .panel-body .btn img{
    margin: 0 0px;
    max-height: 32px;
  }
  .glyphicon {
    font-size: 7px;
}



</style>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
                                    
  <link href="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel="stylesheet" />
                                      
  <script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.js"></script>






            <div id="teste" class="" style="text-align: center;">
            <div style="text-align: center"><img src="../logon2.png" onmouseover="this.src='../logon2.png'" onmouseout="this.src='../logon2.png'" style="width:250px;height:250px;" /></div>

                         

                        <div style="text-align: center"><img src="../spacer.png" style="width:50%;height:85px;" /></div>
                        
                        <div style="text-align: center"><img src="../rc.png" onmouseover="this.src='../rc1.png'" onmouseout="this.src='../rc.png'" style="width:320px;height:64px;" id="img1"/></div>
                




<script type="text/javascript">

  jQuery('#img1').click(function(){

    var lki = '1';

  jQuery.ajax({
  url: 'ajax-email.php',
  data: { entidad_id: lki },
  success: function(data){
    if (data) {
      console.log(data);

         window.location.replace('https://checkout.hotmart.com/HOTMARTPRODUCT_ID?email='+data);


    }else{
      console.log('no data');
    }
  }
  });

  });  
   
    
</script>

7- inside hooks folder add the file ajax-ps2.php:

Code: Select all

<?php
	$currDir = dirname(__FILE__) . '/..';
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");



	/* grant access to all users who have acess to the orders table */

	$mi = getMemberInfo();

	$entidad = makesafe($_REQUEST['entidad_id']);


	$date1 = new DateTime();
	$date3 = $date1->format('Y-m-d');

 	$date2 = $mi['custom'][3];


	if ( $date3 > $date2 ){
	echo $date3.' > '.$date2.' -- '.$mi['username'];

	sql("UPDATE `membership_users` SET `groupID` = '124' WHERE `memberID` = '{$mi['username']}'", $eo);

	};

	


?>
8 - Finally add this ajax-emai.php file to hooks folder:

Code: Select all

<?php
	$currDir = dirname(__FILE__) . '/..';
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");

	/* grant access to all users who have acess to the orders table */


	$entidad = makesafe($_REQUEST['entidad_id']);

	$mi = getMemberInfo();

	echo $mi['email'];


?>

* This is a short summary that really gives you everything you need, the 'order approved' event is fired from hotmart when first subscription payment is made and also for all future recurrent payments, we give the user 34 days of credit because hotmart still tries to process the charge for 3 days after the due date in case it was declined for whatever reason, if user fails to pay, order approved will not be fired, and after the expiration date when user tries to log in he will be redirected to the re-activation page to go through hotmart checkout again, it is important to initiate that checkout with the same email that account was registered look : window.location.replace('https://checkout.hotmart.com/HOTMARTPRO ... ail='+data);

also to note:

active user group ID = 2
inactive = 124

admin email settings must be set for mail script to work


hope it helps :)

Re: [TUTORIAL] HOTMART INTEGRATION - ENABLE PAID SUBSCRIPTIONS FOR YOUR APPGINI APP

Posted: 2020-02-19 03:43
by D Oliveira
D Oliveira wrote:
2020-02-18 22:33
Hello all, hope this helps the community, in this tutorial we are gonna process subscription payment through hotmart and give the user access to your appgini application once payment approved.

1- Create an account with hotmart: https://app-vlc.hotmart.com/

2- Create a subscription product

3- Go to your product page -> tools - > webhook

4- Create a new setting for 'order approved' make sure the url is yourdomain.com/appfolder/sub_access.php

sub_access.php

Code: Select all

<?php

	$currDir = dirname(__FILE__);
	include("{$currDir}/language.php");
	include("{$currDir}/defaultLang.php");
	include("{$currDir}/lib.php");
	include_once("{$currDir}/header.php");
	 $adminConfig = config('adminConfig');

	print_r($_POST);

	 $name = $_POST["name"];

	 $email = $_POST["email"];

	 $statuss = $_POST["subscription_status"];


	 print_r($data);

	 print($email . '  ' . $statuss);


	 		$date0 = new DateTime();
			$date1 = new DateTime();
			$date1->modify('+'.'34'.' day');
			$date2 = $date1->format('Y-m-d');



		
		$sql = "SELECT memberID FROM membership_users WHERE email = '{$email}'";

			$datos = sqlValue($sql);

				if ( $datos == "" ){

				sql("INSERT INTO `membership_users` set memberID='{$email}', passMD5='" . password_hash('whateverpass', PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID='7', isBanned='0', isApproved='1', custom1='{$name}', custom2='1', custom3='', custom4='{$date2}', comments=''", $eo);


				}else{

					sql("UPDATE `membership_users` SET `groupID` = '7', `custom4` = '{$date2}' WHERE email = '{$email}'", $eo);

				}


$to = $email;
$subject = $name." - Welcome to my app";

$message = "
<html>
<head>
<title>Welcome</title>
</head>
<body>
<div style='text-align: center'><img style='width: 250px' src='yourlogourl.png' /></div>
<table align='center'>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n"."
<tr>
<td align='center'> Hello ".$name.", welcome to the App!</td>
</tr>
<p><br/></p>". "\n" . "
<tr>
<td align='center'> credentials: </td>
</tr>
<tr>
<td align='center'> (user/pass) </td>
</tr>
<p> </p>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>user</th>
</tr>
<tr>
<td align='center'>".$email."</td>
</tr>
<p> </p>
</table>
<table align='center'>
<tr>
<th align='center'>pass</th>
</tr>
<tr>
<td align='center'>whateverpass</td>
</tr>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Access App</th>
</tr>
<tr>
<td align='center'>https://yourappurl.com</td>
</tr>
<p> </p>
</table>
<p><br/></p>". "\n". "\n". "\n". "\n". "\n". "\n". "\n". "\n"."
<table align='center'>
<tr>
<th align='center'>Contact</th>
</tr>
<tr>
<td align='center'>[email protected]</td>
</tr>
</table>
<p> </p>
</body>
</html>
";

// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// More headers
$headers .= 'From: <[email protected]>' . "\r\n";

mail($to,$subject,$message,$headers);




?>
5- in your home.php place this code under your javascript area:

Code: Select all

var ps2 = '0';

	    $j.ajax({
					url: 'hooks/ajax-ps2.php',
					data: { entidad_id: ps2 },
					success: function(data){
						if (data) {
							console.log(data);
							window.location.replace('hooks/erro_hook.php');

						}else{
							//console.log('no data');
						}
					}
		});

6- Also inside hooks folder create erro_hook.php (this is re-activation page)

Code: Select all

<?php
  define('PREPEND_PATH', '../');
  $hooks_dir = dirname(__FILE__);
  include("$hooks_dir/../defaultLang.php");
  include("$hooks_dir/../language.php");
  include("$hooks_dir/../lib.php");

  include_once("$hooks_dir/../header.php");



  //include_once("$hooks_dir/../footer.php");

  $mi = getMemberInfo();




?>

<style>
  .panel-body-description{
    margin-top: 10px;
    height: 100px;
    overflow: auto;
  }
  .panel-body .btn img{
    margin: 0 0px;
    max-height: 32px;
  }
  .glyphicon {
    font-size: 7px;
}



</style>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
                                    
  <link href="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.css" rel="stylesheet" />
                                      
  <script src="https://cdnjs.cloudflare.com/ajax/libs/roundSlider/1.3.2/roundslider.min.js"></script>






            <div id="teste" class="" style="text-align: center;">
            <div style="text-align: center"><img src="../logon2.png" onmouseover="this.src='../logon2.png'" onmouseout="this.src='../logon2.png'" style="width:250px;height:250px;" /></div>

                         

                        <div style="text-align: center"><img src="../spacer.png" style="width:50%;height:85px;" /></div>
                        
                        <div style="text-align: center"><img src="../rc.png" onmouseover="this.src='../rc1.png'" onmouseout="this.src='../rc.png'" style="width:320px;height:64px;" id="img1"/></div>
                




<script type="text/javascript">

  jQuery('#img1').click(function(){

    var lki = '1';

  jQuery.ajax({
  url: 'ajax-email.php',
  data: { entidad_id: lki },
  success: function(data){
    if (data) {
      console.log(data);

         window.location.replace('https://checkout.hotmart.com/HOTMARTPRODUCT_ID?email='+data);


    }else{
      console.log('no data');
    }
  }
  });

  });  
   
    
</script>

7- inside hooks folder add the file ajax-ps2.php:

Code: Select all

<?php
	$currDir = dirname(__FILE__) . '/..';
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");



	/* grant access to all users who have acess to the orders table */

	$mi = getMemberInfo();

	$entidad = makesafe($_REQUEST['entidad_id']);


	$date1 = new DateTime();
	$date3 = $date1->format('Y-m-d');

 	$date2 = $mi['custom'][3];


	if ( $date3 > $date2 ){
	echo $date3.' > '.$date2.' -- '.$mi['username'];

	sql("UPDATE `membership_users` SET `groupID` = '124' WHERE `memberID` = '{$mi['username']}'", $eo);

	};

	


?>
8 - Finally add this ajax-emai.php file to hooks folder:

Code: Select all

<?php
	$currDir = dirname(__FILE__) . '/..';
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");

	/* grant access to all users who have acess to the orders table */


	$entidad = makesafe($_REQUEST['entidad_id']);

	$mi = getMemberInfo();

	echo $mi['email'];


?>

* This is a short summary that really gives you everything you need, the 'order approved' event is fired from hotmart when first subscription payment is made and also for all future recurrent payments, we give the user 34 days of credit because hotmart still tries to process the charge for 3 days after the due date in case it was declined for whatever reason, if user fails to pay, order approved will not be fired, and after the expiration date when user tries to log in he will be redirected to the re-activation page to go through hotmart checkout again, it is important to initiate that checkout with the same email that account was registered look : window.location.replace('https://checkout.hotmart.com/HOTMARTPRO ... ail='+data);

also to note:

active user group ID = 2
inactive = 124

admin email settings must be set for mail script to work


hope it helps :)

**active user group ID = 7

Re: [TUTORIAL] HOTMART INTEGRATION - ENABLE PAID SUBSCRIPTIONS FOR YOUR APPGINI APP

Posted: 2020-02-23 16:09
by ronwill
Good work, thanks for that,
cheers,
Ron

Re: [TUTORIAL] HOTMART INTEGRATION - ENABLE PAID SUBSCRIPTIONS FOR YOUR APPGINI APP

Posted: 2020-03-08 22:16
by D Oliveira
ronwill wrote:
2020-02-23 16:09
Good work, thanks for that,
cheers,
Ron
Thanks =)

quick note, to create a subscription product it needs necessarily to be in this category: Online Courses, Members Area, Subscription Services

Re: [TUTORIAL] HOTMART INTEGRATION - ENABLE PAID SUBSCRIPTIONS FOR YOUR APPGINI APP

Posted: 2020-04-10 05:22
by D Oliveira
Alright y'all, lets enable a 7 day trial =) ,

1- enable 7 day trial at product page in hotmart
2 - webhook 'subscription cancellation' point to file trial.php


explanation: if user fires cancellation event during the 7 days of trial he will only be allowed access till the 8th day, if he cancels after the 7 day trial nothing happens because he has already been charged and credited the days (approved event fired). MODIFY YOUR CODE FROM ABOVE with makeSafe() as I used in the trial.php file, you dont want sql injection vunerabilities, happy coding.

trial.php

Code: Select all


<?php
	$currDir = dirname(__FILE__);
	include("{$currDir}/language.php");
	include("{$currDir}/defaultLang.php");
	include("{$currDir}/lib.php");
	include_once("{$currDir}/header.php");
	$adminConfig = config('adminConfig');

	print_r($_POST);

	$email = makesafe($_POST["email"]);
	
	$sql = "SELECT memberID FROM membership_users WHERE email = '{$email}'";

	$datos = sqlValue($sql);

		if ( $datos == "" ){

		
		}else{

			$sql2 = "SELECT signupDate FROM membership_users WHERE email = '{$email}'";

			$datos2 = sqlValue($sql2);

			$date0 = new DateTime();
			$date0x = $date0->format('Y-m-d');
			$date1 = new DateTime($datos2);
			$date1->modify('+'.'7'.' day');
			$date2 = $date1->format('Y-m-d');


			if($date0x<=$date2){

			$date1x = new DateTime($datos2);
			$date1x->modify('+'.'8'.' day');
			$date2x = $date1x->format('Y-m-d');

				sql("UPDATE `membership_users` SET `custom4` = '{$date2x}' WHERE email = '{$email}'", $eo);

			}

				

		}


?>


Re: [TUTORIAL] HOTMART INTEGRATION - ENABLE PAID SUBSCRIPTIONS FOR YOUR APPGINI APP

Posted: 2020-04-10 05:33
by D Oliveira
*small fix , for the trial php use 'userEmail' instead of 'email', they annoyingly changed the handler name and also JSON format

Code: Select all


	$data = json_decode(file_get_contents('php://input'), true);
	print_r($data);

	$email = makesafe($data["userEmail"]);

Re: [TUTORIAL] HOTMART INTEGRATION - ENABLE PAID SUBSCRIPTIONS FOR YOUR APPGINI APP

Posted: 2020-05-12 01:46
by dharbitindy
Wow, impressive! Thanks for sharing.

David

Re: [TUTORIAL] HOTMART INTEGRATION - ENABLE PAID SUBSCRIPTIONS FOR YOUR APPGINI APP

Posted: 2020-05-14 04:17
by D Oliveira
dharbitindy wrote:
2020-05-12 01:46
Wow, impressive! Thanks for sharing.

David

Glad I helped you :D