VirtueMart Forum

VirtueMart 2 + 3 + 4 => Plugins: Payment, Shipment and others => Topic started by: Mojo78 on June 30, 2015, 07:06:34 AM

Title: amazon payment: no billto adress in order
Post by: Mojo78 on June 30, 2015, 07:06:34 AM
Hello,
today i installed the amazon payments plugin (VirtueMart 3.0.8 / Joomla! 3.4.1).

Unfortunately i have to test in my real shop, because amazon refuses to communicate with the unsecure certificate of my local development-server and my online testshop has no ssl at all.

The cart itself seems to work nice, but
-   there is no billto address in my testorder (all fields in billto section are empty) .
-   in the e-mail order confirmation there is address-data from my vm-account, not from amazon sandbox account
-   There is ,,unknown order status" in my testorder.


Testing circumstances:
-   It's a german shop
-   The plugin is in sandbox and debug mode.
-   For testing I log in with a virtuemart test-user (because i have restricted amazon pm for testing-shopper-group only)
-   In the first- / lastname field in amazon sandbox i had only ,,Joe"
-   debug updateBuyerInOrder BT:
array (
  'last_name' ⇒ 'Joe',
  'first_name' ⇒ '',
  'email' ⇒ 'j.oe@mydomain.de',
  'virtuemart_order_id' ⇒ '2909',
  'address_type' ⇒ 'BT',
)

-   options in amazon payment plugin: i only inserted amazon sandbox credentials and restricted access to my testing-shopper-group, everything else is default

Perhaps s.o. here has an idea how this can be solved?

Bye, Mojo
Title: Re: amazon payment: no billto adress in order
Post by: alatak on July 02, 2015, 09:26:40 AM
Hello

Can you give me the exact configuration of Amazon (not the credentials) and the order status you have for emails in the virtuemart configuration . And i will try to reproduce it.
Thank you.
Title: Re: amazon payment: no billto adress in order
Post by: Mojo78 on July 02, 2015, 20:02:41 PM
Hi alatak,
thank you for your help.
Here the information:

Default Order Status to send email to shopper: U, C, X, R, S

Tab Information
name: amazon payments
sef alias: amazon-payments
description: empty
pament: VM Payment - Pay with Amazon
customer group: Tester
ordering: empty

Tab Configuration
Account Param:
Environment: Sandbox
Region: Germany

Account Options:
ERP Modus: On
authorization_mode_erp: async
Capture: delayed
IPN: ON

Order Status:
confirmed: c
capture:: s
refunded: r
cancel: x

Advanced Workflow ssettings:
soft decline: on
sb error sim authorize: no
sb error sim capture: no
sb error refund: no

restirctions:
min amount: empty
max amount: empty
exclude categories: empty
supported lands: empty
ip whitelist: empty
sells digital goods: no

template:
button size: medium
button colour: orange

widget adressbook:
width: 400
height: 260

widget payment:
width: 400
height: 260

virtuemart template:
sign-in button: .payments-signin-button
default css: yes

debug:
debug: yes
debug log to file: no

Title: Re: amazon payment: no billto adress in order
Post by: Mojo78 on July 11, 2015, 08:40:02 AM
i managed to get the plugin to work in my  local development environment with xDebug.

problem: amazon orders without bt-address in table order_user_infos -> broken orders

if i comment out in amazon.php updateBuyerInOrder()...

/*if (!$order_userinfosTable->bindChecknStore($ST, true)) {
vmError($order_userinfosTable->getError());
return false;
}*/

...i have a billto address, but no ST-Address.

I believe bindChecknStore updates the BT-Address to an ST address but it should create a new dataset for ST-address. 

have a look at the line before ->bindChecknStore($ST, true)

$mm=$order_userinfosTable->load($order['details']['BT']->virtuemart_order_id, 'virtuemart_order_id', " AND address_type='ST'");


i believe the reason is, that on order creaton vm stores no st address. so the ->load(..." AND address_type='ST'") does not fetch data. $order_userinfosTable remains the dataset of bt address and so is updated to an st-address -> the order is broken

could that be?
Bye, Mojo

EDIT:
it seems to be as i thougt:
if you execute $order_userinfosTable->load(..." AND address_type='ST'") and there is no ST-data in the order, $order_userinfosTable preserves the BT data incl. the primary key value. So $order_userinfosTable->bindChecknStore($BTFromAmazon, true) updates the BT-dataset to ST.

my solution is to fetch a fresh vmTable from ordermodel:

from line 1137 (updateBuyerInOrder ($client, $cart, $order))

if ($physicalDestination) {
$ST = $this->getUserInfoFromAmazon($physicalDestination);
$ST['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id;
$ST['address_type'] = 'ST';
$order_userinfosTableST=$orderModel->getTable('order_userinfos');
$order_userinfosTableST->load($order['details']['BT']->virtuemart_order_id, 'virtuemart_order_id', " AND address_type='ST'");
if (!$order_userinfosTableST->bindChecknStore($ST, true)) {
vmError($order_userinfosTableST->getError());
return false;
}
$this->debugLog("<pre>" . var_export($ST, true) . "</pre>", __FUNCTION__ . ' ST', 'debug');
}


if there is a better solution please let me know.
Title: Re: amazon payment: no billto adress in order
Post by: alatak on July 28, 2015, 08:25:31 AM
Hello
Yes, you are rigth. There is a problem due to some changes in the VM core with selecting the ST address.
Your fix is almost correct. I am working on this issue today.
Title: Re: amazon payment: no billto adress in order
Post by: alatak on July 28, 2015, 11:40:05 AM
Hello

The reason of the bug is that you are testing connected .
When you are not connected, the ST is there. When you are connected, there was some changes in the VM core: it looks also for the "shipto selected" now.

Please try this code in the function updateBuyerInOrder. It only loads the table if the ST address is not there.

if (!$onlyDigitalGoods) {

$physicalDestination = $orderReferenceDetails->getDestination()->getPhysicalDestination();

if ($physicalDestination) {
$ST = $this->getUserInfoFromAmazon($physicalDestination);
$ST['virtuemart_order_id'] = $order['details']['BT']->virtuemart_order_id;
$ST['address_type'] = 'ST';
$order_userinfosTable->emptyCache();
// check if ST is there
$query="SELECT `#__virtuemart_order_userinfos`.*  FROM `#__virtuemart_order_userinfos`  WHERE `#__virtuemart_order_userinfos`.`virtuemart_order_id` = ".$order['details']['BT']->virtuemart_order_id."  AND address_type='ST'";
$db = JFactory::getDBO();
$db->setQuery($query);
if(!$db->loadResult()) {
$order_userinfosTable=$orderModel->getTable('order_userinfos');
}

$order_userinfosTable->load($order['details']['BT']->virtuemart_order_id, 'virtuemart_order_id', " AND address_type='ST'");
if (!$order_userinfosTable->bindChecknStore($ST, true)) {
vmError($order_userinfosTable->getError());
return false;
}
$this->debugLog("<pre>" . var_export($ST, true) . "</pre>", __FUNCTION__ . ' ST', 'debug');
}
}
Title: Re: amazon payment: no billto adress in order
Post by: alatak on July 28, 2015, 11:57:18 AM
Hello

You can also test without being connected . There is a parameter "IP white list" where you can add your IP. The Pay with amazon button should only be displayed for you in that case;