Implementing Paypal Subscription API in PHP

I’m working on implementing Paypal Subscription API in PHP for the past weeks, I thought this was kinda complicated just like the DirectPayment method API. Guess what, it was just a piece of cake, i’ll show you my code:


<form name="_xclick" id="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
		<input type="hidden" name="cmd" value="_xclick-subscriptions">
		<input type="hidden" name="business" value="yourpaypalaccount@samplemail.com">
		<input type="hidden" name="currency_code" value="USD">
		<input type="hidden" name="no_shipping" value="1">
		<input type="hidden" name="a3" value="20">
		<input type="hidden" name="p3" value="1">
		<input type="hidden" name="t3" value="M">
		<input type="hidden" name="src" value="1">
		<input type="hidden" name="sra" value="1">
		<input type="hidden" name="return" value="http://mysite.com/return.php">
		<input type="hidden" name="cancel_return" value="http://mysite.com/cancel.php">
		<input type="hidden" name="item_name" value="Subscription Fee">
		<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="Make payments with PayPal">
</form>';

Here’s an explanation about that code, it’s pretty straightforward though.
a3 – amount to billed each recurrence
p3 – number of time periods between each recurrence
t3 – time period (D=days, W=weeks, M=months, Y=years)
return – Return URL after the user has paid
Cancel – the URL when the user clicks on Cancel on the Paypal Page

On this example, there will be a Subscription Button being displayed, and the user will have to click on the button so that they will be redirected to paypal’s website.

Subscribe Button

 

 

If you want something like there’s no user interaction, like there would be no user clicking, just use javascript in sending the form. Just like this:

<script>document.forms['_xclick'].submit();</script>

And don’t forget to wrap the form code with an echo. So it should look like this:

echo '<form name="_xclick" id="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display:none;">
		<input type="hidden" name="cmd" value="_xclick-subscriptions">
		<input type="hidden" name="business" value="yourpaypalaccount@samplemail.com">
		<input type="hidden" name="currency_code" value="USD">
		<input type="hidden" name="no_shipping" value="1">
		<input type="hidden" name="a3" value="20">
		<input type="hidden" name="p3" value="1">
		<input type="hidden" name="t3" value="M">
		<input type="hidden" name="src" value="1">
		<input type="hidden" name="sra" value="1">
		<input type="hidden" name="return" value="http://mysite.com/return.php">
		<input type="hidden" name="cancel_return" value="http://mysite.com/cancel.php">
		<input type="hidden" name="item_name" value="Subscription Fee">
		<input type="image" src="http://www.paypal.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="Make payments with PayPal">
		</form>';
echo "<script>document.forms['_xclick'].submit();</script>";

Just a piece of cake, right? I hope this helps someone.

Have a happy coding :)

Setup Aweber Email Parser

5ad3izx5tyarjaj I will show you how to setup AWeber Email Parser.
To those of you who do not know what Aweber is, it is an email marketing software that allows you to store email addresses and other important stuffs to people who uses your product or whatever purpose you have.

So my idea here is that everytime a user registers in my website, I will get their email address as well as their name then store it in AWeber.

This is the front end of AWeber

AWeber uses a basic Regular Expression so no need to be rattled ( I was too rattled, so I was forced to learn RegEx :) ).

The default setup of AWeber parse is like this, but I changed it.

Rule 1:: \n[>\s]*Email:\s+(.+?)\n Match:
Store in:
Rule 2:: \n[>\s]*Name:\s+(.+?)\n Match:
Store in:

Looking at the image above(not the table), On the Trigger Rule textinput, change the “aweber” into the email address that you wrote when you created a list. Then change the “myDomain” to your domain name.

Just copy this one as your Rule1:  Name:[ ]*([^\n]+)

Now in your php file:

function SendEmailToAweber( $name, $email_address ) {
      $to = "aweber@elsonsolano.com"; #this is the same email address that you wrote when you created a list
      $subject = "Store Email Address from elsonsolano.com";

     #this is important because we told our regular expression to have a newline above it.
     $message .= "\n";
     $message .= "Name: ".$name;

     $headers = 'MIME-Version: 1.0' . "\r\n";
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     $headers .= 'From: '.$name." <".$email_address."> \r\n";

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

Everytime you run this function, it will send an email to AWeber then it will parse it using the configuration tha we set up. Now you are golden! :) So that’s it! That’s how easy to setup AWeber email parser. Hope this helps someone. Have a happy coding :)