PHP

Stripe Credit Card Processing : Thoughts?

If you don’t know, now you know:

https://stripe.com/

Stripe is, or rather states, that they do online processing for a flat fee and act as your gateway interfacing directly with your bank. AWESOME! I think Stripe is pretty new right now; and unfortunately I haven’t used them to know how great it really is. But, I’ve built enough online stores to know that online transactions are cumbersome. You can push for one gateway over the other but ultimately you’re going to deal with several over the course of your career.

PAYPAL!?

Ever tried using PayPal to accept money? Of course you have. Have you ever tried to build a store around PayPal? No, you haven’t. Because if you have then you’ve surely jumped off a cliff by now. I can’t seem to test in the developer sandbox of PayPal’s without having their service go down at least twice. Now the live gateway is reliable, but testing is a nightmare!

OTHER GATEWAYS

So there are a ton of other gateways. And I’ve used several in combination with dozens of merchants. I definitely favor some over others. And, I’m not trying to knock any one of them or say what anyone should or shouldn’t use. But, I do want to hear from people out there.

Have you used Stripe? If so, how was/is it. How good is it for larger scale store type systems? How do you handle refunds, escrow, or customer data? If you haven’t used Stripe do you think you would? I’m going to give it a try next chance I get. The fees are right and I’m excited for a service like this to be available and I think it’s a long time coming. Kudos.

 

Chop A String On a Whole Word With PHP

I’ve been slacking an not writing anything so I’m going to start trying to write much smaller posts starting with this one. A common need for template developers is chopping a string at a whole word. There’s a lot of functions out there on the web to tackle this problem and I went searching for one quickly today rather than just writing one. What I found was a bunch of functions that either a) didn’t work or b) didn’t work well enough. So most of the time you want to chop a string down to 35 characters or so right? For instance, you want to display a post title but you want it to display only on one line but some of the titles are going to break that line.

This function breaks a string on a whole word and makes sure that the string doesn’t go over the set amount of characters you set. This means you always get a string that fits where you want it to; ALWAYS.

function neat_trim($str, $n, $delim='…') {
  $len = strlen($str);
   if ($len > $n) {
       	preg_match('/(.{'.$n.'}).*?\b/', $str, $matches);
		if(strlen( trim( $matches[0] ) ) > $n)
			return substr( $matches[0],0, strrpos( trim( $matches[0] )," ") ) . $delim;
		else
			return $matches[0] . $delim;
   }else {
       return $str;
   }
}

It’s pretty straightforward I hope. You pass the string, the maximum characters your string can be, and a delimiter to display at the end of the string if you chop it. By default it displays … but if you don’t want anything just pass an empty string. I didn’t do all this myself (not that there’s much there). This is based off a broken example I found on the web. The word boundary in the regular expression was mis-used in the example I found so I fixed it, then made it so that the string never goes over n characters. The original would chop it at the next whole word it found which meant our string could be anywhere between n characters and n*E-10. You get the picture. I’m not a math wizard so that’s probably wrong ha ha. I mean what if you wanted to catch 30 characters on one line and the string you chopped was:

“this is my string of existentialism”

My function returns “this is my string of…” whereas most return “this is my string of existentialism” which can completely ruin a layout. Anyway, no need to beat this dead horse back to life. I hope this helps people. If you have a better, cooler, faster, shorter (or longer) way of doing this post it in the comments!

Sending Emails That Don’t Suck With WordPress

I’ve wondered about emailing in WordPress for a while but never did anything about it. How does WordPress send emails? What functions can we hook to for emails? What if I want to setup a template with a form and email someone? And, what if I want to send nice html emails and not just plain-text formatted ones? These are all good questions and definitely what I have been wondering. Let me start out by answering the first question. WordPress doesn’t do anything fancy for sending emails. Nope, no SMTP connections, no html headers, nothing. WordPress just uses the mail function like any PHP application would and sends a regular old plain-text email. Well that’s cool for WordPress, but sometimes that sucks!

Read More

Password Protecting HTML Files

The other day I was doing some work on a back-end system for a client and ran into the problem of having a ton of html files that needed to be accessible only by administrators. Why would I have a bunch of html files you ask? For practical reasons you may have any number of files you don’t want displayed on the web to just anyone. I happened to have a large library of code documented with ASDoc. Anyone who has used, or is interested in using ASDoc knows it creates a large number of html files. My particular project has been one spanning several years and consists of thousands of lines of code and a hundred or more classes across dozens of packages. But, that’s sort of irrelevant. What is important is that I had a hundred or so html files I suddenly needed to protect online.

Read More