I had a really late night session (although 8am technically is morning and not still “night”, lol) testing out the native PayPal subscription feature in the DotNetNuke CMS platform. I’ve been looking to learn how this subscription service would be implemented and at a first glance there would be some major obstacles:
- This feature is so poorly documented it’s unbelievable.
- On forums and blogs. when people ask about this feature they usually get the reply to go with a 3rd party module. This could probably be a result of 1) above.
- Given the two points above, does the native subscription feature even work, and is it ready for “prime time”?
- How do you actually test a feature like this. As this is my first time working with any type of payment gateway whatsoever, I was clueless about this.
Well, readers.. it turns out that despite points 1 and 2 above, the answer to 3 is “Yes! It does work!”. And the answer to 4 is that PayPal offers a sandboxed environment with fake seller accounts, fake buyer accounts and “playmoney” for you to test your solution. It even has a fake mail inbox where you can see the different type of confirmation and notification emails that the various transactions might produce. Great stuff!
This rather long post with lots of screenshots and is divided into sections:
DNS setup
PayPal setup
DNN Setup
- Pages
- Site Settings
- Security Role Setup
- User subscribing
- User cancelling subscription
- Creating a subscription shortcut
Let’s get to it!
DNS setup
Essential for the PayPal feature to work is that your development site is accessible from the internet. In my case I setup a DNS CNAME (dnntest.devlol.com) record to point to my development host. Also port forwarding in my router to allow traffic into my IIS. This is beyond the scope of this post so you figure it out.
PayPal setup
So what you need to first is to head over to the PayPal
developer siteand create an account there and log in. Then you create at least two Test Accounts. I choose to use their preconfigured types and made two accounts, one of the standard type “Buyer” and one of the type “Seller”. Both test accounts complete with mockup credit cards and bank info. The Buyer account I started of with a small amount of money already (fake) deposited.
Click on the screenshot to the right to see how these accounts are setup.
|
|
 |
DotNetNuke setup
Pages
Next, it’s time to head on over to your DNN site and log in as Admin. The first I did was to set up two pages called Success and Cancel. These will act as the URLs to which PayPal returns the user after having made a transaction at their site. For my purposes I created a Subscribe page at the top menu level and the two child pages under this one leaving me with the following structure:
http://dnntest.devlol.com/Subscribe.aspx
-- http://dnntest.devlol.com/Subscribe/Success.aspx
-- http://dnntest.devlol.com/Subscribe/Cancel.aspx
Site Settings
Then I went into the “Admin / Site Settings / Advanced Settings” and entered the currency to use with PayPal. For Processor UserId I entered the fake email address which the PayPal sandbox created for my Seller account. Password can be left empty (AFAIK). For Return URL enter the address to the Success page and Cancel URL is set to the address of the Cancel page. Then you check the Use Sandbox option and save your settings. Screenshot below illustrates my setup.

|
BUG WARNING AND WORKAROUND!!
I found that the sandbox would never work despite selecting the Use Sandbox setting. After some debugging I found that the two aspx pages that use the feature had the same bug. I have reported this as a bug but as of now it is not yet Resolved. See http://support.dotnetnuke.com/issue/ViewIssue.aspx?ID=17681&PROJID=2 for details.
For now make the workaround by editing the pages,
\admin\Sales\PayPalSubscription.aspx.cs (line 88) \admin\Sales\PayPalIPN.aspx.cs (line 138)
In each file change the line
- // Sandbox mode
- if (settings.ContainsKey("paypalsandbox") && !String.IsNullOrEmpty(settings["paypalsandbox"]) && settings["paypalsandbox"] == "true")
to
- // Sandbox mode
- if (settings.ContainsKey("paypalsandbox") && !String.IsNullOrEmpty(settings["paypalsandbox"]) && settings["paypalsandbox"] == "True")
so that the comparison is on “True” with capital T.
I used DNN 6.0.1 source distribution and this section of the blog post will be removed when this issue is resolved.
|
|
Security Role Setup
Next we need to configure a Role for our paying subscribers. I named this Monthly subscribers and opted to have this as a Public role, so that users can opt-in by themselves from the “Manage Services” tab of the “Edit Profile” page. The Auto assign option should for obvious reasons not be used as we do not wish the users to automatically belong to this Role after self registration.

For my testing purposes I set 5 GBP per month and a 1 GBP one day trial period.

User subscribing
So now we are ready to test the subscribing procedure. Using an existing or newly created (regular user) account go to the “Manage profile / Manage services” page. There your “monthly subscriber” role should be visible with a Subscribe link. It also displays the billing details for both trial and reoccurring payment.

When the user clicks on Subscribe Monthly subscriber he/she will be taken to the (sandbox) PayPal login page. In our case we will log in using the fake Buyer email that was created for our test account. Then we complete and approve the transaction.

Note that is says “Test Site” to indicate that we are using the sandbox. Also the browser URL is https://www.sandbox.paypal.com/xxxxxx
Here is the thing! I see many people complain that in their testing the transaction is completed, the Seller test account receives money from the Buyer test account. But when returning to the DNN the user has not been added to the appropriate Role. I do not experience this per se, but one issue I had is that I have to either, as the Buyer, manually Accept the payment or have configured my PayPal profile to automatically do so. Before I have done this.. the PayPal IPN (Instant Payment Notification) service will call the page http://dnntest.devlol.com/Admin/Sales/PayPalIPN.aspx in the background to let your site know about the transaction. But if the Seller hasn’t accepted the payment manually or automatically the IPN will post your site a message about the transaction status being Pending. Not until the IPN message indicates status is Completed the RoleController.UpdateUserRole() function will be called and the user should now belong to the new Role. I do not know if this is the problem the forum people are having but perhaps it is!
When the user clicks the “Return” button on the PayPal site he/she is returned to the Success page we defined earlier in out Site Settings.
If we as Admin examine the test user we should se that he/she should be added to the Monthly subscriber role as below. The expiry date in this case is set to the end of the trial period.

And in the subscribed User’s control panel the subscription is also visible.

Nice huh!!!
If we login to our sandbox account and examine the Buyer and Seller accounts we can see that some money have been transferred.

User subscription cancellation
In the unlikely event that our User is unsatisfied with our service, and he/she wants to end the subscription this can be done from the Manage Services page and the Unsubscribe link. This will again take the User to the PayPal site and there the Recurring Payment can be cancelled from his “My pre-approved payments” settings.. Of course the Seller can also cancel the Recurring Payment from his side. When a cancellation is performed, the PayPal IPN will again call our http://dnntest.devlol.com/Admin/Sales/PayPalIPN.aspx page to notify our site.
ISSUE: When a user has cancelled the subscription and then renews, it seems to back into Trial mode and only £1 GBP is transferred from Buyer to Seller. I need to do some more testing for this to see if I did something wrong or if there is a bug. In any case I’m sure this can be worked around by creating separate Trial and “full subscriber” Roles. Side effect of this would be that the User isn’t automatically upped to the regular fee when the Trial is over and has to Subscribe to a new Role.
Creating a shortcut subscription link
I do not know if the following is a “supported” feature or if it just works by accident. But you can create a HTML link anywhere on the site. First you need to find the id of the Role which the subscription is for. I did this by simply looking it up in the dnn_Roles table in our database. You can also look at the Security Roles page Under Admin and examine the Manage Users link for the role, which will contain the correct number.
Example xxxxxx/RoleId/4/mid/373/Default.aspx In this case the RoleId for Monthly subscriber is 4. So I simply create a link to http://dnntest.devlol.com/Admin/Sales/PayPalSubscription.aspx?roleId=4 and when this link is clicked the User is taken immediately to the PayPal site!