Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

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

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
Trenton Knew
Asked:
Trenton Knew
  • 2
  • 2
  • 2
  • +3
1 Solution
 
Andrew AngellCo-Owner / DeveloperCommented:
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
 
Trenton KnewOwner / Computer WhispererAuthor Commented:
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
 
Marco GasiFreelancerCommented:
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Sar1973Commented:
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
 
Ray PaseurCommented:
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
 
Derek JensenCommented:
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
 
Ray PaseurCommented:
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
 
Andrew AngellCo-Owner / DeveloperCommented:
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
 
Sar1973Commented:
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
 
Derek JensenCommented:
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
 
Trenton KnewOwner / Computer WhispererAuthor Commented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now