1

Appologies but new to PHP...

Need to pass a value for 'state' to payment gateway which can be any string for non USA customers but must be two character code for USA (based on drop down list).

'State'=> $billingaddress->getData('region'),

'State'=> $billingaddress->getData('region_id'),

are the two variable.

Not sure of the if else syntax for setting 'state' as 'region_id' if country is USA and 'region' for all other countries. Thanks

1 Answer 1

0

You can try something like this, notice that I added a call to isRegionTwoCharFormat() which you would have to implement, so the sintax could be like this:

if(isRegionTwoCharFormat($billingaddress->getData('region'))) {
    $state = 'US';
} else {
    $state = 'SomethingElse';
}

Or you can also use ternary operator:

$state = isRegionTwoCharFormat($billingaddress->getData('region')) ? 'US' : 'SomethingElse';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.