First of all thanks for creating this module! Stripe seems like a great service and to already have a drupal module that actually works is awesome!

So, what I'd really like to do with this module is manage my site's subscriptions (in addition to the checkout). Since Stripe can handle the recurring payments, prorating of plan changes, cancellations, etc. it seems like a great all in one solution.

Basically I've made some modifications/additions to the module that I'll be happy to share (although my coding is pretty sloppy). Here's what I've done thus far:

•Duplicated, then altered the payment method so there is now a "Stripe Subscription" payment method that passes the Stripe Customer ID and Plan info to the Drupal User on checkout. (I'm using Rules to switch between the payment methods depending on cart contents, but there's probably a more elegant way to combine the functionality of both payment methods).
•Started working on a user tab to change the users plan (still very rough, no admin UI yet)
•Setup a user tab for the user to change their credit card on file (mostly finished)

So all of that works well enough (just need to finish/polish things), and I'm 99% of the way there, but I just can't figure out how to integrate webhooks.

Ideally when a customer is charged their monthly (or yearly) charge, drupal would receive that info via a webhook event and then fire off a rule (in my case awarding the user credits).

If anyone can help me out with the initial setup (the receiving of the webhook / parsing of the info) I think I can handle it from there, but thus far I'm stumped. I've tried the simple example from Stripe's documentation, but that alone isn't working for me.

Comments

bradhawkins’s picture

I think I might have figured it out. I gleaned some ideas from the recurly module and ended up creating a "listener" page. Thus far I've only got it posting log messages, but the basic functionality is working.

So next I'll try create rules for each possible Stripe Event type.

I'll be happy to post all my modifications (possible contributions) once I've had a chance to finish, test and clean up my messy code.

iler’s picture

Great that you have found this module as useful one :) And even more great if you are willing to contribute your modifications to the project! So when you get the modifications ready please post a patch to this thread and I'll have a look at it.

bradhawkins’s picture

I'll definitely post a patch once I've got everything working/cleaned up. Probably about a month or more from now.

Thanks again for creating this module, it's got us really close to finishing our site! : )

BenK’s picture

I'm also really interested in this... any developments on the recurring payments front?

--Ben

bradhawkins’s picture

I did have some success setting up webhooks and rules "events" that could be triggered when a webhook was sent from Stripe. However, I found that the webhooks from Stripe aren't as detailed as I would have liked, thus I've since decided to explore using the drupal recurring framework module to setup recurring payments.

Sorry for the delayed response, honestly for the past couple of months I've been snowed under with other work (freelance VFX is still my day job), but hopefully that will be finishing up this week (or next) and I can start working on drupal stuff again. : )

A little off topic, but, I'm ashamed to admit that I don't even know how to use github. Where's the best place to learn how to make patches, so that I can share anything I come up with?

greggles’s picture

There's instructions on creating patches at http://drupal.org/node/707484

Looking forward to it.

bradhawkins’s picture

Finishing up some work on this now. Hopefully I'll have something to post this next week - although I've made a ton of changes and it might be unwieldy as a patch, we'll see. Basically at this point I've got webhooks -> rules working and integration with Commerce Recurring Frameworks, hopefully it'll be some useful updates for everyone. :)

bradhawkins’s picture

Status: Active » Needs review
StatusFileSize
new17.17 KB
new55.09 KB

Okay, here's the patch that I've created, I'll also upload a zip of the entire folder in case I've made any errors in my patching (first patch yay!).

There's a ton of stuff in this patch (probably should've split it up somehow), I'll do my best to explain everything. But honestly this may be enough of a departure from the original to constitute a new branch, not my place to say though. Either way, here's what we've got in this patch…

1 - Webhooks

In the settings page you can define your Webhooks "listener page" this needs to match whatever you've also setup in the Stripe.com admin settings.

Next you have a bunch of new rules events for the webhooks. When a webhook is sent the corresponding event is triggered, you can use these as you like.

note: I didn't setup all the webhooks (left out the subscription ones because that is covered by Commerce Recurring Framework), but if you look at the code in the module it would be simple to add the missing webhooks.

2 - Commerce Recurring Framework Integration

There is a new user-field called "Stripe Customer ID" this is where we store the customer ID that is created whenever a charge processed via Stripe. This is important because it allows us to do the recurring charges (via Commerce Recurring Framework) without requiring the user to redo the checkout process.

By default this field is set so that only admins have access to it. However, I'd recommend also installing Field Permissions so that you can really make sure no customer would ever have access to it.

Also included are some more new rules that pertain to recurring orders. These are gleaned directly from the Commerce Recurring Framework module and are meant to directly replace the payment rules used by default in that module. However, they don't require/use the Commerce Card on File module, instead they use the Stripe Token to process charges against the card on file with Stripe.

For example, you can now override the default "Trigger Payments against recurring orders" replacing the action Process payments against recurring orders with the new Process Stripe payments against recurring orders.

3 - User can manage their card on file

There's a simple little form on the user page that allows users (with the proper permissions) to see/edit their credit card on file.

4 - Misc updates

- added "short_title" and "display_title" info to the payment method
- fixed a glitch in commerce_stripe.js file that caused errors when using PayPal or other payment option alongside Stripe (token was being sent regardless of payment choice)
- modified the checkout submission form so that it accounts for the various options (anonymous user, authenticated no Stripe ID, authenticated w/Stripe ID)
- a default rule to add the Stripe Customer ID to new users (for anonymous checkouts)

5 - Caveats:

• I'm a hacker/coder by necessity not training, so please help me discover any errors I've made and most importantly if there are any security issues!

• If a user is setup for recurring orders and then completes an additional checkout with a different credit card their credit card on file will be updated to their most recent card used. This is a limitation of Stripe, they only keep 1 card on file and I don't see what we could do as a workaround, but it shouldn't be a big problem either, just worth noting.

Again, any and all feedback is welcome. Hopefully these updates will be useful to the community!

-Brad

iler’s picture

Thanks for the (huge) patch @bradhawkins! Will see through it very soon but it will take some time :)

jwjoshuawalker’s picture

@bradhawkings

Nice job on this.

I skimmed through your webhooks and did not see anything on the invoice.* hooks. If the intention is information about subscriptions, you probably want to look at invoice.payment_succeeded (charge.succeeded is triggered on any payment, even if not plans). I do apologize if you had other intentions in that area.

@iler,
I'd love to step in and help here any way I can. I recently finished the Stripe -> CiviCRM integration:
http://civicrm.org/extensions/stripe-payment-processor
It has all the required features of Stripe fully implemented: Customers (basically card-on-file), Charging, Plans, Subscriptions, & Webhooks to monitor subscriptions.

Maybe some of the code surrounding plans/subscriptions could be of some use:
https://github.com/drastik/civicrm_stripe

I do have some personal interest here, I'm switching from Auth.net to Stripe.com for my own Commerce integrations and I need recurring :)
This also means that I'm going to make it way or another, and it would be great if it were built into this module you've made already.

bradhawkins’s picture

@drastik

I originally left out the invoice webhooks because Stripe waits 1 full hour after charging a payment to create the invoice. Basically I just found that not very useful (for me) and there are a decent amount of invoice webhooks items, so I was a bit lazy about adding them.

Maybe I misread their documentation on that, but the other problem is that its pretty much impossible to test some of these webhooks quickly. They have the webhooks testing interface in the admin area, but those send out hooks with an event ID of evt_0000000000, which just throws an error on the receiving end.

Regardless of my reasoning, it should be simple enough to add those in. Feel free to add to the patch if you'd like, or maybe we should just wait to see what iler decide's to implement before making any more updates.

iler’s picture

@bradhawkins & @drastik

I added today 7.x-2.x branch where the development of webhooks and subscription/recurring payments features would take place. Would love to have your work included there! So please do provide patches agains the 7.x-2.x dev branch! So basically 7.x-1.x will remain as the basic implementation of Stripe integration to Drupal Commerce while the work with webhooks can be done in 7.x-2.x branch.

bradhawkins’s picture

@Iler - that sounds like a good plan. I'll try to get a new patch out sometime over the next month.

@drastik - I'll add in those invoice webhooks whenever I get around to creating the new patch for the 7.x-2.x branch.

jwjoshuawalker’s picture

@bradhawkins #11

For subscription / recurring product sites, the invoice Webhooks are critical so that Drupal knows if the person is still paying. If the card is declined, or you cancel the subscription from the Stripe interface, Drupal will need to know to revoke the roles or whatever you have users paying a subscription for.

Also if you keep a running history of recurring payments in Drupal, you'll want to act on invoice Webhooks to update that a new payment has successfully gone through.

Anyway, I'll get more involved and start submitting code after the project I'm on is done.

bradhawkins’s picture

I see your point about the invoice webhooks in regards to Stripe's built in subscription service, but keep in mind that my patch does not integrate at all with Stripe's built in subscription/plan functionality. My patch integrate this module with the Commerce Recurring Framework module, so that all charges, updates, cancellations are handled in directly in drupal via Rules. Which makes for a much more flexible & scalable solution.

I found that Stripe's subscription options were very limited (one example, there's no way to do weekly or quarterly subscription), so I contacted them directly and while they do plan to expand the features they suggested that its best to handle subscriptions within Drupal and just use the stripe token to charge recurring payments and the updating of credit cards, etc.

All that said, it'll be easy enough to add in the invoice items and I'll do so with the next patch. Having all the webhooks available could never be a bad thing. But I just wanted to make it clear that it was not my intention with this patch to use Stripe's subscription features, but rather to handle all of that within Drupal.

jwjoshuawalker’s picture

@bradhawkins

That makes sense. More of a pain in the butt, but it definitely lends its way to more features.

cweagans’s picture

Status: Needs review » Needs work

I looked over the code here, and I think that this is the wrong approach.

Here's the basic problem: all of the subscription plans are managed on Stripe. This isn't necessarily a problem until you want to change payment gateways. A better way to do this, IMO, is to leverage commerce_cardonfile and commerce_recurring. An issue was opened about this a while ago (#1541070: Support for tokenized payment gateways), but it was, for some reason, opened in a "Works as designed" state.

Basically, the only thing that needs to happen is that commerce_stripe needs to implement the commerce_cardonfile hooks, as is done with the commerce_authnet module: http://drupalcode.org/project/commerce_authnet.git?a=search&h=HEAD&st=co...

Instead of using Authorize.net's CIM API, though, you'd use Stripe's customer information storage API: https://stripe.com/docs/tutorials/charges#saving-credit-card-details-for...

This way, all subscription charges are completely controlled through Drupal. Using webhooks is (IMO) a pretty hacky solution, especially when you already have all the data you need in your Drupal database. It doesn't make a lot of sense to move the subscription configuration off site.

I really don't want to shoot this down, as I see you've put a lot of work into it, but I really think that this is a suboptimal solution. IMO, further work should happen on #1541074: [meta] Recurring payments/Card on File support. I'm likely going to be coding this up in the coming weeks, so if you're interested, follow that issue!

cweagans’s picture

There's some progress on #1541074: [meta] Recurring payments/Card on File support - commerce_cardonfile is almost all the way supported now and commerce_recurring is next.

markwk’s picture

I'm interested in using Stripe (instead of Authorize.Net) for subscriptions. Can you guys provide any guidance on the progress of subscription integration or even exposing stripe web hooks?

mesch’s picture

I made a patch that supports commerce card on file/recurring integration. It needs testing.

https://drupal.org/node/1541074#comment-7916625

aviindub’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Issue summary: View changes
Status: Needs work » Closed (duplicate)

closing as duplicate because the thread above addresses the same issue. dealing with Stripe subscriptions directly might end up as a feature in the 2.0 branch.