Solved

String replace abbr "St." with whole word "Saint"

Posted on 2013-12-17
13
274 Views
Last Modified: 2016-03-24
I am using a paypal express payment gateway on a wordpress shopping cart install, and recently, some of my client's customers have had trouble with paypal returning an error page when they try to check out.  Apparently, the problem has to do with address matching against how we very often use "St. Louis" and "St. Charles"  Either paypal or the shopping cart plugin don't like the abbreviated versions, and will only work if the user enters "Saint Louis" or "Saint Charles" instead.  Can anyone help me come up with an easy validation script or something to convert "St." if entered into "Saint" before passing the transaction on to paypal, or even better, checking for it when the user leaves the city field.

The website is jdvirginhair.com
0
Comment
Question by:Trenton Knew
  • 2
  • 2
  • 2
  • +3
13 Comments
 
LVL 11

Expert Comment

by:Andrew Angell
ID: 39725771
That's not something I've ever run into using PayPal.  The only thing I can think of is that it's possible the credit card company has Saint instead of St. so then AVS fails.  You could simply adjust how your AVS is handled to stop the error from happening, potentially.  

On that note, are you getting a specific error code and message back?  You mention that it's either PayPal or the shopping cart...I guess you're not even sure of the source of the error..??

That's the first step.  Track down exactly what's causing it.  You can probably fix it without having to replace it.  If that's what you decide you want to do, though, here's some PHP that would do it.

str_replace('St.','Saint',$street_address);

Open in new window


That's very basic, of course.  You may want to handle St. vs. st. vs. ST. accordingly, for example.  

Again, though, you shouldn't have to validate like that, so I'd figure out where the problem really lies and adjust it there so you don't have to do such validation.  Just my opinion.
0
 
LVL 9

Author Comment

by:Trenton Knew
ID: 39725782
Well, I'm not sure if the error is pre or post paypal.  What happens is, you enter all the information on the checkout page, then click "checkout with paypal" button, and then I THINK the shopping cart plugin throws an error, but then sends the transaction to paypal anyway, as pressing back button on the browser will return you to the checkout page with an Error message about "couldn't match address" or something like that.
0
 
LVL 30

Expert Comment

by:Marco Gasi
ID: 39726030
The nature of the problem remains obscure, but a workaround could be a javascript. Change the following code accordingly to your form input names:

function validateForm()
{
   var cityName = document.forms["myForm"]["city"].value;
   var newCityName = cityName.replace("St.", "Saint");
   document.forms["myForm"]["city"].value = newCityName;
}

<form name="myForm" action="paypal_address" onsubmit="validateForm()" method="post">
First name: <input type="text" name="city">
<input type="submit" value="CheckOut">
</form>

Open in new window

0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39726093
I would suggest also to include a test that checks if the first 3 characters are the abbreviation of Saint, like:
if (str.substr(0,3)=="St.") {var newStr=str.replace("St.","Saint"); ........; }
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39726674
There may be even deeper problems than the abbreviations.  I went to this page:
http://jdvirginhair.com/shop/

I clicked "add to cart" for the Virgin Brazilian Natural Wave, which is listed for $80.  The price shown in the cart is $90.  A few more shopping clicks and the cart summary on the right sidebar shows two items, but the cart detail in the main body of the page shows three items.

I went to this page:
http://jdvirginhair.com/shop/brazillian-natural-wavy/

There I found two select controls for Length and Quantity.  Neither one worked when I clicked on them, but an attempt to add the product to the cart fails with an alert box telling me I must make a selection.  In addition, there is a prominent red warning about "all sales final" that is so far down the page that it is invisible to anyone who is shopping and just wants to make a purchase.  In the interest of avoiding a customer relations disaster, you might want to move that warning up, just above the Add to Cart button.

I also found that an attempt to change the quantities in the Edit Shopping Cart page failed to change the quantity and did not raise any kind of alert.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Expert Comment

by:Derek Jensen
ID: 39727016
I would side with @marqusG's suggestion to validate on submit; that way it doesn't matter which page or at what point afterwards the error is thrown, because it will be receiving the needed "correct" info to avoid the error.

However, I would caution against checking solely for "St." It doesn't appear relevant for your purposes, since you're specifying your city form field and marqus is using a non-global regex, but a "safer" regex would be something like:

var newCityName = cityName.replace(/^St\. /, "Saint ");

Open in new window

which checks to see if "St." is coming first (and only first), so "St. Mark's St." would become "Saint Mark's St." and not "Saint Mark's Saint".
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39727145
Just a thought for testing, you might want to add a $1 product to the site so you can go through the checkout process a few times and follow all of the variables.  I'd be glad to spend a dollar to help you out but I'm not interested in spending $80 on a hairpiece.
0
 
LVL 11

Accepted Solution

by:
Andrew Angell earned 500 total points
ID: 39728815
You don't need to be running tests (even with $1 products) on live servers.  That's what the sandbox is for.  

If you don't already have one setup, create your own test version of your site running at something like http://sandbox.domain.com.  Then set it up so that your test server hits PayPal's test server and you can go through entire tests of everything without spending any real money.

Even $1 orders add up when you have to test, troubleshoot, fix, rinse and repeat.

If you need more info about testing on the PayPal sandbox let me know.
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39728866
Just to give some references to the replace function:
str.replace("oldtext","newtext"); //replaces the first occurrence
str.replace(/oldtext/g,"newtext"); //replaces each occurrence distinguing between uppercase and lower case
str.replace(/oldtext/gi,"newtext"); //replaces each occurrence with a case-insensitive

Open in new window

0
 
LVL 9

Expert Comment

by:Derek Jensen
ID: 39729419
Indeed @Sar; thanks for the additional explanations. :-)

You can also combine them together (in any order, afaik) like so:

str.replace(/oldtext/sig,"newtext");

Open in new window

which replaces "oldtext" with "newtext" globally, ignores case and enables the . ("any char" wildcard) and \s to capture newlines as well. (no effect w/this regex)
0
 
LVL 9

Author Comment

by:Trenton Knew
ID: 39746763
I haven't forgotten you guys, the holidays have been keeping me BUSY!  I am going to see if I can inject some of this str.replace code somewhere in the plugin where the validation is already (hopefully) occurring.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now