Kryptronic Software Support Forum

You are viewing this forum as a guest. Login to an existing account, or create a new account, to reply to topics and to create new topics.

#1 10-31-2012 09:54:16

Blitzen
Member
From: USA
Registered: 01-01-2005
Posts: 936

Need Payment Method Dependent on Address

Hi,
Where would I put logic for the payment method(s) to display depending on destination?

That is, if the customer billing address is in the US, they can use either the merchant account (non-PayPal) or PayPal.
If international, then PayPal is the only option that will display.

Thanks!

Offline

 

#2 10-31-2012 11:47:19

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Need Payment Method Dependent on Address

Coding would be done in the cogateways() function in the ECOM_Checkout class ({private}/apps/ecom/ECOM_Checkout/ECOM_Checkout.php).  Look in there and you will see the gateways are pulled via SQL and after the result is formulated you can loop through them and do what you wish.


Nick Hendler

Offline

 

#3 04-03-2016 12:05:17

kpryan
Member
Registered: 02-07-2005
Posts: 69

Re: Need Payment Method Dependent on Address

Hi Nick,
I have been trying to create a mod to restrict Worldpay to certain countries. I am able to pick up the billing address by accessing the cogetaddress sub-routine (the $wpcountry variable). I am using the billing address at the moment. I would prefer to use the delivery address but I am unable to reference it - called ($wpscountry) in my code snippet below. I have tried many statements from the ECOM_Checkout.php module but every one returns a null value. My latest attempt is below.

$address =$this->cogetaddress();
         $wpcountry = ($address['country']);
$info = $this-->globals('ecom.customship');
         $wpscountry = $info['country'];
     foreach ($gateways as $num => $row) {
          if ($row['id'] == 'paypalproe') {
             if ($gateway_select != 'paypalproe') {unset($gateways[$num]);}
          } else {
             if ($gateway_select == 'paypalproe') {unset($gateways[$num]);}
          } // End of if statement.
                   
                                                           
if ($row['id'] == 'worldpaytest') {
if (($wpcountry == "UK - England & Wales")||($wpcountry == "UK - Scotland Mainland")||($wpcountry == "UK - Highlands & Islands Scotland")||($wpcountry == "UK - Isle of Man")||($wpcountry == "UK - Isles of Scilly")||($wpcountry == "UK - Channel Islands")||($wpcountry == "UK - Northern Ireland")){
                         print ($row['id']); print ' is available in ' ;print $wpcountry;
                         continue;
                         }else{
                                 print ($row['id']); print ' is not available in ' ;print $wpcountry;
                                 {unset($gateways[$num]);}
                                            } // end of if statement
                                            }
How do I pick up the delivery address rather than the billing address?

Any help appreciated.

Regards,

Kevin

Offline

 

#4 04-04-2016 06:39:52

webmaster
Administrator
From: York, PA
Registered: 04-20-2001
Posts: 19818
Website

Re: Need Payment Method Dependent on Address

Getting the shipping address in checkout is a bit complicated as it's stored on the item level and could be different, or not there depending on item delivery status.  I'd recommend adding this to your code, and executing it:

Code:

print '<pre>' . print_r($this->cosess,1) . '</pre>';

The checkout session variable ($this->cosess) holds an array of items matched to delivery addresses, which show up in the user's address book, referenced with:

Code:

$this->globals('core_session.addbook');

To pick up the first valid address:

Code:

$addbook = $this->globals('core_session.addbook');
$deladd  = array();

foreach ($this->cosess['items'] as $cartid => $item) {

     if ($item['delgroup'] == 'UNASSIGNED') {continue;}
     if (empty($addbook[$item['deladd']]))  {continue;}

     $deladd = $addbook[$item['deladd']]; break 1;

} // End of foreach statement.

if (!(empty($deladd))) {print '<p>Delivery address is: ' . print_r($deladd,1) . '</p>';}

Nick Hendler

Offline

 

Board footer