PayPal Integration

In this example I have integrated the AO API and the Paypal API via PHP so that you can now charge for access to a course.

You can see what this would look like as a customers in the video below:

Requirements for this to work:

How it works:

  • A user is directed to PayPal to purchase a course.
  • The user pays you via PayPal
  • PayPal automatically forwards the user back to your site
  • Behind the scenes my code validates the transaction was successful (verifies they paid you)
  • My code then creates a user in your AO account and adds them to the specified group
  • My code then forwards the user an email with login instructions to access the course
  • The user is given a nice status message telling them about the transaction

Here is what we are going to do:

  1. Create a Paypal business account (it is free)
  2. Enable the AO API on your account
  3. Configure your Paypal business account
  4. Setup your courses in AO
  5. Configure the sample code I have provided to work with your account
  6. Setup Buy Now links for your content items
  7. Test everything

Notes About Paypal:

I am not the biggest fan of PayPal’s fee structure.  They make it overly complex to figure out what the actual fee is that they charge and seems arbitrary that they charge based on a percent of the transaction, but as a general rule, each transaction will cost you (the seller) $0.30 up front, and then %3 of the total transaction.  All the charges for using Paypal go to the seller, so you will be paying for any fees.  You can find a detailed fee structure description on Paypals site.

Some of the code I use in this example is actually code given by Paypal.  I have noted in each of my files if the code comes from me, or Paypal.

1. Creating a Paypal business account

First thing you need to do is create a PayPal Business account.

  1. Create a Paypal account at www.paypal.com if you have not already created one
  2. When setting up the account create a ‘Business’ account or if you already have a personal account, convert it to a Business account.  Business accounts are free to setup.

2. Enable the AO API on your account

  1. Contact your Articulate sales representative to have the AO API feature added to your account.  You can contact your sales represntative here.
  2. Once it is enabled on your account, turn it on. (Go to Settings> Other Settings>Enable API Access in your Articulate Online account.)

3. Configure your paypal business account:

In order to use my method, you will need to enable Payment Data Transfer (PDT) on your Paypal account.  PDT allows you to recieve notification of successful payments as they are made.

Follow these steps to configure your account in PayPal

  1. Log in to your PayPal account.
  2. Click the Profile subtab.
  3. Click Website Payment Preferences in the Seller Preferences column.
  4. Under Auto Return for Website Payments, click the On radio button.
  5. For the Return URL, enter the URL on your site that will receive the transaction ID posted by PayPal after a customer payment.  You want to point this to the “return.php” page that I have included in this sample.  So remember this location for later.
  6. Under Payment Data Transfer, click the On radio button.
  7. Click Save.
  8. Click Website Payment Preferences in the Seller Preferences column.
  9. Important: Scroll down to the Payment Data Transfer section of the page to view your PDT identity token.  Note this for later.

4. Setup your courses in Articulate Online

I have setup the sample code to automatically add a user to a specified group on your account, you can then setup your content so only specified groups have access to the content you specify.

Here is what you need to do on the Articulate Online side to get this working:

  1. Create a group in Articulate Online (People>Groups tab)
  2. Upload your content to Articulate Online
  3. Set the Permissions on that content is Private and select the group you created in step 1
  4. Save your Permissions changes
  5. Now you need to get the GroupID of the group that you created so you can configure the sample code:

  6. Go to the People tab
  7. Select the Groups tab
  8. Select the group you created
  9. Click the “View activity report for this group”
  10. In the URL field of the browser, you should see a URL like this:

    http://blah.articulate-online.com/Reports/GroupActivity.aspx?Cust=89134&GroupID=846dd7a2-bc35-4fa6-957c-7d1dea56599b&Range=all+time

    The GroupID is the letter/number combination between the “GroupID=” and the “&Range=all+time”, so in this example it is:
    846dd7a2-bc35-4fa6-957c-7d1dea56599b
    Note the GroupID for later

5. Configure the sample code I have provided to work with your account

The sample code that I provided comes with 5 files:

  • config.php – this contains your configuration options.  This is the only file that you need to edit.
  • findUser.php – checks to see if the user already exists on the account.
  • createuser.php – creates the user on the account if they don’t already exist as a user
  • addToGroup.php – adds the user to the group that you created.
  • return.php – This is the page that you specify as the return URL.  This will handle the verification of the transaction, then will call findUser.php, createuser.php, addToGroup.php to add the user to your account.

The only file that you need to edit is the config.php file:

Once you install NuSoap, change this the soapLoc to point to the location you installed NuSoap:
$soapLoc = ‘../../lib/nusoap.php’;

Replace the “hRUxKv_GCIFIASioHVFuG4DEJ97kUwdEWIuqhxh1U8z7B1pHbg-n8-xWMJLq” with the authorization token from your account (from Step 3.8 above):
$auth_token = “hRUxKv_GCIFIASioHVFuG4DEJ97kUwdEWIuqhxh1U8z7B1pHbg-n8-xWMJLq”;

Replace the email address, password, and CustomerID with the Customer ID from your Articulate Online account.  Your customer ID can be found by looking at the URL in your browser’s address bar after logging in to Articulate Online. The numeric value specified in the title bar for CustID is your customer id. For example, if the URL in your address bar is https://training.articulate-online.com/Content/Manage.aspx?CustID=12345, your customer id is 12345.

$AOemail = ‘dmozealous@articulate.com’;
$AOpassword = ‘apple’;
$AOCustomerID = ‘89134′;

Replace the GroupID with the GroupID noted in Step 4.9 above:
$AOGroupID = ‘9204f95a-a6e4-422c-b9b4-e4ff837a905a’;

Replace the Account URL with the Account URL for your account (must be HTTPS://):
$AOAccountURL = ‘https://blah.articulate-online.com’;

An email will be sent to the purchaser with login instructions on how to access the account, and contain their email address.  You can configure the text of that email by replacing the comment text with your specified text:
$comment = ‘Thank you for purchasing access to this site.  You can login to view your training with the login details below.’;

Now upload the sample content to your website.  Remember that the return.php file location must be at the location that you specified above in step 3.5.

6. Setup Buy Now links for your content items

Now it is time to setup “Buy Now” links for the content items you want to sell.

To do this:

  1. Login to PayPal
  2. Select the Merchant Services tab
  3. Click the “Buy Now” button
  4. Configure the options as you chose
  5. Click Create Button

Tip: Make the Item ID a unique value.  This will help you in the long run in keeping track of what people purchased.

Tip 2: During the testing phase of this as I tried to get it working, I setup my Buy Now links to only charge $.10, this is helpful so you don’t get screwed on the transaction fees during the testing phase.

After you click the Create Button link, it will give you the code to incorporate the Buy Now button in your website.

7. Test Everything

You should now be able to test it out.  If everything works as expected, great, you are ready to roll.  If something went wrong, go back over these instructions and verify that you followed them correctly.  If you still have problems, let me know.

To see this example in action see the following page:

http://www.mozealous.com/samples/Paypal/buy.html

D I S C L A I M E R

WARNING: ANY USE BY YOU OF THE SAMPLE CODE PROVIDED IS AT YOUR OWN RISK.

Mozealous.com provides this code “as is” without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

{ 2 trackbacks }

Integrate Articulate Online with PayPal | Dave Mozealous
April 23, 2009 at 2:24 pm
6 Examples of What’s Possible with the Articulate Online API: E-Commerce & More - Articulate - Word of Mouth Blog
April 24, 2009 at 10:05 am

{ 9 comments… read them below or add one }

Lesley August 6, 2009 at 9:15 am

Dave,
Hello. We are trying to make Paypal work with AO but we keep getting the following error. Can you tell me what we did wrong:

Fatal error: Uncaught SoapFault exception: [Client] Function (“getError”) is not a valid method for this service in /data/18/1/111/111/1600111/user/1724194/htdocs/findUser.php:23 Stack trace: #0 [internal function]: SoapClient->__call(‘getError’, Array) #1 /data/18/1/111/111/1600111/user/1724194/htdocs/findUser.php(23): SoapClient->getError() #2 /data/18/1/111/111/1600111/user/1724194/htdocs/return.php(75): findUser(***I BLANKED THIS OUT****) #3 {main} thrown in /data/18/1/111/111/1600111/user/1724194/htdocs/findUser.php on line 23

mozealou August 10, 2009 at 8:15 am

Hi Lesley,

I am not familiar with that particular error, but initial guess would be that something in your Soap installation might not be correct.

Have you tried any of my other examples and gotten them to work? That is the easiest way I can think of to test. Like try my ListDocuments example. The paypal example relies on several calls to the AO API and ListDocuments only uses one so it is a bit simpler.

Marijan September 29, 2009 at 3:59 am

Hi, Dave
I have problem with trying your example PayPal Integration on http://www.mozealous.com/?page_id=256 in step 3. Configure your paypal business account.

I haven’t “Website Payment Preferences in the Seller Preferences column” in Profile subtab of my Paypal business account.
Are they changed this subtab? What can I do?

Marijan

mozealou September 29, 2009 at 8:31 am

Hi Marijan,

You don’t see an option like this?
http://www.mozealous.com/images/WebSitePaymentPrefs.png

You might want to contact PayPal and see if they know what is up. Not a big PayPal expert so I am not sure why it wouldn’t be enabled on your account.

Marijan October 2, 2009 at 3:53 am

Hi Dave,
I contacted PayPal and they gave me next explanation:

“Paypal isn’t “fully compatible” for Hungary, meaning that you can pay using a Paypal account (on Ebay for example) but you cannot receive money yet and that’s the reason why you don’t have the “Selling preference” column available to you. Sorry about that.”

mozealou October 5, 2009 at 8:29 am

Marijan,

That is a bummer, sorry to hear that.

April December 14, 2009 at 2:01 pm

Hi Dave,

Thanks for putting up all these excellent posts. I have a question. After you clicked the “Buy Now” button, you entered an email address and a password. Does this mean that my customer has to have a PayPal account in order to purchase the training? Or are they creating an account with PayPal during this step? Or is this just a way for the customer to “self register” for my Articulate Online account?

mozealou December 14, 2009 at 2:03 pm

Hi April,

>Does this mean that my customer has to have a PayPal account in order to purchase the training?

Using this example, yeah, the end user would have to have a PayPal account to purchase the training. They could also create a PayPal account during this time too.

I think there are ways using the PayPal API to not require the user to have a PayPal account, but I haven’t really looked into that.

-Dave

Nate May 28, 2010 at 2:31 pm

Lesley:
I was having the same error. I believe it was because I was using PHP5.

I changed $client = new soapclient to:
$client = new nusoap_client
and things seemed to work. PHP5 already has a class called soapclient which causes some issues.

I’m also using nusoap-0.9.5.

Leave a Comment