PayPal redirect, adding some custom code.

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
12/22/2010 9:13:55 AM
Gravatar
Total Posts 4

PayPal redirect, adding some custom code.

Hi All,

I'm looking at using MojoPortal, as it looks like a great product.

When it comes to the commerce part and PayPal, I see 2 redirect links that PayPal can possibly call (PDT and IPN).

How would I go about doing some custom work when those are called?

I'm mainly looking at finding out who the order is for, and generating some license keys and emailing them off.  I saw in another forum thread, that Joe (the guru) mentioned that it could be done via code, and also he may have another solution.

I have no problem writing C# code, but would prefer not to hack at the MojoPortal code itself.

Can anyone point me in the right direction?

1/26/2011 7:05:27 PM
Gravatar
Total Posts 18

Re: PayPal redirect, adding some custom code.

I'm looking for the same info...I'd like to execute a small amount of custom code when the IPN comes back to create a row in a table in the database. Nothing fancy...just looking for information on where to put the code from someone who may have already tried it. Let me know if you find anything out. Thanks =)

1/26/2011 9:22:32 PM
Gravatar
Total Posts 4

Re: PayPal redirect, adding some custom code.

Hi philip,

I'll definitely let you if I ever figure it out.  It's an important thing I need, before I move forward with this part of mojo.

1/27/2011 12:14:52 PM
Gravatar
Total Posts 18439

Re: PayPal redirect, adding some custom code.

I've added a wish list item to our project tracker for the WebStore to implement a provider model for OrderCompleteHandlers so that one could plug in their own provider to do this kind of post order processing. Not sure when I will get to it but at some point for sure.

It won't be specific to PayPal, it will be designed to fire this event once payment has been posted no matter whether it comes from PayPal IPN or PDT or Google Checkout or other payment gateways.

Best,

Joe

1/27/2011 12:18:43 PM
Gravatar
Total Posts 4

Re: PayPal redirect, adding some custom code.

Hi Joe,

that would be an awesome feature.  Especially for things like generating on the fly licenses and emailing them out.

Thanks for looking into it, and great product btw.

Cheers,

VT

1/27/2011 12:27:41 PM
Gravatar
Total Posts 18

Re: PayPal redirect, adding some custom code.

That sounds great Joe!

I downloaded the source code using TortoiseHg and I'm looking at the IPN handler to see if there's anything I can do with that. It's pretty simple as far as the logic goes, so I think I should be able to tie something in to the HandleRequest() method under the

if (response.StartsWith("VERIFIED"))

just need to figure out how to pull specifics from the order itself so I can write a couple of things to the database.

1/27/2011 12:36:03 PM
Gravatar
Total Posts 18439

Re: PayPal redirect, adding some custom code.

See, the problem is if you make changes to the mojoPortal code it will be difficult for you to upgrade, so its best not to modify that code and wait until I make a plugin system that makes it easier for you to plugin custom code for post order processing without touching the mojoPortal code.

Best,

Joe

1/27/2011 12:42:27 PM
Gravatar
Total Posts 4

Re: PayPal redirect, adding some custom code.

I'd prefer not to touch the MojoPortal code just for that reason. 

But for Philip, if he needs his stuff done in the short term, if he was to write it in such a way that it was modular, when it comes to MojoPortal being upgraded, he would have minimal work to do to create his own plugin as the core of it will be done.

But yeah... I'd limit my changes to the MojoPortal code itself, and instead make it into a module that you could just modify the interface for to cater for when MojoPortal supports plugins for that part of it.

1/27/2011 12:44:40 PM
Gravatar
Total Posts 18

Re: PayPal redirect, adding some custom code.

I'll hold out on implementing any changes to that file for as long as I can, but I'm thinking I'll only need to add about 10 lines of code. I'll just keep it in a separate file somewhere and if I have to upgrade, I can just add it back in and recompile. I'll definitely try to wait for your plugin system though...I'm sure it's a much better idea than me changing the code. Thanks =)

I'm definitely not making changes to any other code...I just like seeing where everything is coming from and a lot of it gives me ideas on how to implement things in my custom user controls.

1/27/2011 12:56:18 PM
Gravatar
Total Posts 18439

Re: PayPal redirect, adding some custom code.

The only way you could get away with it now without touching mojo code would be to implement the WebStorePayPalIPNHandler and WebStorePayPalPDTHandler in your own project with a different namespace in your own assembly/project.

The provider is loaded from config files in /Setup/ProviderConfig/paypalipnhandlers and  paypalpdthandlers folders. They are loaded by name but they point to a class and assembly, if you edit those files to point to your assembly using the same provider names then it would load your version instead of the WebStore version. So you would want to copy the whole implementation from the corresponding webstore classes and then  modify them in your own project to add your logic. That would be a decent temporary solution, the only thing you'd have to keep in mind is that on upgrades it would replace those provider config files so you would need to restore yours after upgrades.

Basically the way it works with PayPal is that the cart is serialized into the mp_PayPalLog table and the log id is passed to PayPal as a custom variable and is returned to us by PayPal, so we lookup the log and the log has the name of the IPNHandler and PDTHandler to load, so as long as you use the same name it will load your custom one.

As a side note part of the reason it is implemented that way with the cart being serialized into the log is so that we have a record of the cart as it was before we sent the user to PayPal. Nothing stops the user form using 2 browser tabs and adding more items to the cart after they have been redirected to PayPal, so to prevent them from getting things they did not pay for we can't just go by the cart id. ie we don't want them adding more stuff to the cart then paying for just the item that was in the cart before we sent them to paypal and getting more items for the price. So each time an item is added or removed from the cart a new record is created in mp_PayPal log with a new id, and we restore the cart to as it was before they went to PayPal when we process the notification of payment from paypal using the log id we sent with the original request.

Hope it helps,

Joe

1/27/2011 1:03:50 PM
Gravatar
Total Posts 18

Re: PayPal redirect, adding some custom code.

Thanks for the info Joe...that definitely helps.

I'm wondering if I'd be better off at this point writing a custom user control that just looks at the mp_PayPalLog table and performs my logic based off what it finds there. I think that might be simpler and cleaner at this point than trying to add my code to the source.

I'll play around with things, but will stay away from modifying the source if at all possible.

You must sign in to post in the forums. This thread is closed to new posts.