Quote:
Originally Posted by BCSE
|
Updated to version 3
did you forget an important element? accounting for coupons, reward points
I had to remove these lines from api.php
'ITEMAMT' => $cart['subtotal'],
'TAXAMT' => $cart['tax_cost'],
'FREIGHTAMT' => $cart['shipping_cost'],
in the post array because kept getting this error:
Field format error: 10413-The totals of the cart item amounts do not match order amounts.
Orders without coupon codes processed fine.. now after removing those three items and telling paypal only the AMT, orders with coupons work.
also got 'not finished' orders again so the new version doesn't seem to fix that either..
--special characters need to be handled when posting to paypal (address, name, city, etc).
-- there was also an ssl issue.. forcing curl to use tls1.2 might fix that one..
--- added a check in finish-order for not-finished orders:
first I had to make it so the module used SECURETOKEN instead of SECURETOKENID in the token.php file
then I added a function to api.php to return the array of secure tokens and orderids
then put a check in finish_order.php in the event the getPaymentRepsonse() returns a blank value.
here's some code..
Code:
require_once $xcart_dir . '/include/payment_wait.php';
$api = bcse_pp_get_api();
//bcse_pp_log_error("api get token\n".print_r ($api->getSecureTokenOrders2(),true));
//bcse_pp_log_error("orderid: $orderid token: $token ids $orderids");
//exit;
$response = $api->getPaymentResponse();
//bcse_pp_log_error("RESPONSE:\n".print_r ($api->getPaymentResponse(),true)."setting to blank!\n"); //for testing
//$response=''; //for testing
if (empty($response)) { //matt add - if response is empty perform an inquiry using the secure token or custref
bcse_pp_log_error("Empty response found in finish_order.php\n");
$tokens=$api->getSecureTokenOrders2(); //new function
foreach ($tokens as $k=>$v) {
$token=$k;
$orderid=addslashes($v[0]);
break;
}
bcse_pp_log_error("acquired token: $token and orderid: $orderid\n");
//perform inquiry on token
if ($token!='' && $orderid!='' && is_numeric($orderid)) {
$orderids=array();
$orderids[]=$orderid;
$response = $api->tokenInquire($token); //new function
bcse_pp_log_error("Token-Inquire RESPONSE:\n".print_r ($response,true)."\n");
if ($response['RESULT']==99){
$response = $api->custRefInquire($orderid); //new function requires CUSTREF to be set in the orderdetails POST
bcse_pp_log_error("custRef-Inquire RESPONSE:\n".print_r ($response,true)."\n");
}
.
.
.
comparison code to check silent post .. I use some custom-code and a dbase table to handle silentposts..
.
.
.
if (isset($silent['amount']) && isset($response['AMT']) && $silent['orderid']==$response['CUSTREF'] && $silent['amount']==$response['AMT'] && $silent['transaction']==$response['ORIGPNREF']) {
$response['RESULT']=$response['ORIGRESULT'];
$response['PNREF']=$response['ORIGPNREF'];
if (!isset($response['AUTHCODE'])) {
$response['AUTHCODE']='';
}
} else {
$response='';
bcse_pp_log_error("ERROR: could not match inquiry with empty response!\n");
}
$api->clearSecureTokenOrders($token); //cleanup - new function
} else { //done with an empty result
$orderids = $api->getSecureTokenOrders($response['SECURETOKEN']); //changed to use securetoken - normalshit
}
in this case, the module will now perform an inquiry on the SECURETOKEN and compare results with silent post values..
if it fails to get anything from the securetoken it'll perform an inquiry on CUSTREF
was a bi*tch to setup and took many hours but I feel as this should solve a majority of the "not finished" errors.
hope that helps someone..
please send tips:
BTC: 17jAfPFZ9waexTbGdtCZM4LgAn56qZ7bZh