Solved

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

Posted on 2013-12-17
13
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 31

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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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 110

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
 
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 110

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

729 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