If it was paypal, I am not sure you would EVER get one ha ha ha....
To your questions... Yes, that is the code area I am talking about. I believe you will still have issues with attributes with that code because the TOTAL on the dwolla side appears to be calculated by adding up the product prices and is matched against the actual total we are sending in. When there is a difference between the two - which would be the case if an attribute modified the final_price and applied to our local total, dwolla hiccups. However, if you supply the final_price for each of those items, then the total we send will match the total dwolla calculates because they are derived from the same numbers. I didn't get any issues with rounding, so I am not sure if that was ever an issue here, but it never hurts to properly round ;-).
As for the discounts. I think that is going to be a rather simple implementation. It just depends on if we want to go the extra mile and have it in the admin interface for people to set a physical dollar amount or a percentage. But as for the code itself, it should not be a big deal. I was looking at this part for the discount scenario:
// Round off figures
$total = round($order->info['total'], 2);
$subtotal = round($order->info['subtotal'], 2);
$shipping = round($order->info['shipping_cost'], 2);
$tax = round($order->info['tax'], 2);
$adjustments = round(($total - $subtotal - $tax - $shipping), 2);
// This can be discounts, low order fees, etc
// When the value is negative, it means that
// theres a discount(s) applied.
// When the value is positive, there's a
// fee applied.
$discount = '0.00';
if($adjustments > 0) {
$items[] = array(
'Description' => 'Extra Merchant Fees',
'Name' => 'Fee',
'Price' => $adjustments,
'Quantity' => 1
);
} else {
$discount = $adjustments;
}
$dwollaJson = array(
'key' => MODULE_PAYMENT_DWOLLA_API_KEY,
'secret' => MODULE_PAYMENT_DWOLLA_API_CODE,
'redirect' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=dwolla', 'SSL'),
'orderId' => zen_session_id(),
'test' => (MODULE_PAYMENT_DWOLLA_SERVER == 'Test') ? 'true' : 'false',
'purchaseOrder' => array(
'destinationId' => MODULE_PAYMENT_DWOLLA_DESTINATION_ID,
'discount' => $discount,
'shipping' => $shipping,
'tax' => $tax,
'total' => $total,
'orderItems' => $items,
'notes' => 'Order from ZenCart. Session Name ' . zen_session_name() . ' / ID #' . zen_session_id()
)
);
I am taking tha $adjustments and $discounts into consideration here. Basically what happens as the code stands is this: Nothing. In other words, if there are no coupons supplied or a hard coded discount then all is well. If a coupon is added to the order before the checkout confirmation, then it will become the "adjustment" due to the math being performed to populate that var. Example, "$adjustments = round(($total - $subtotal - $tax - $shipping), 2);" <--- this is basically subtracting EVERYTHING from the total EXCEPT the coupon (or any other discount) value.... which would leave the value of such left over, and therefore that becomes the "adjustment". $adjustments is then checked to see if it is positive or negative to determine if it is a discount or a charge. If it is a positive (a charge) it is added to the $items array - if it is a negative number(discount or coupon) then it is added the $discount var.
The trick here is to supply a (either fixed or dynamic) number to the $discounts var and be sure in doing so that we allow for the possibility of a coupon also being used.
So... what we need to do is something like this - I have commented what I am doing in the code:
// Round off figures
$total = round($order->info['total'], 2);
$subtotal = round($order->info['subtotal'], 2);
$shipping = round($order->info['shipping_cost'], 2);
$tax = round($order->info['tax'], 2);
//I am adding this piece for a hard coded 3% discount - but it could be from somewhere dynamic
$dwollaDiscount = 0;
$dwollaDiscount = ((.03)*(round($order->info['subtotal'], 2)));
$adjustments = round(($total - $subtotal - $tax - $shipping), 2);
// This can be discounts, low order fees, etc
// When the value is negative, it means that
// theres a discount(s) applied.
// When the value is positive, there's a
// fee applied.
$discount = 0;
//We then set the discount to rep the one derived above as a numeric value
$discount += $dwollaDiscount;
//This remains the same here to make sure there are no FEES being adding or, more likely, a coupon being added
if($adjustments > 0) {
$items[] = array(
'Description' => 'Extra Merchant Fees',
'Name' => 'Fee',
'Price' => $adjustments,
'Quantity' => 1
);
} else {
//Now we need to take into account that a coupon may also be used and add the dwolla discount to the adjustments coupon.
$discount += $adjustments;
}
$dwollaJson = array(
'key' => MODULE_PAYMENT_DWOLLA_API_KEY,
'secret' => MODULE_PAYMENT_DWOLLA_API_CODE,
'redirect' => zen_href_link(FILENAME_CHECKOUT_PROCESS, 'referer=dwolla', 'SSL'),
'orderId' => zen_session_id(),
'test' => (MODULE_PAYMENT_DWOLLA_SERVER == 'Test') ? 'true' : 'false',
'purchaseOrder' => array(
'destinationId' => MODULE_PAYMENT_DWOLLA_DESTINATION_ID,
//This may need a - in front of $discount to ensure it is represented as a negative number... more on that after a test run
'discount' => $discount,
'shipping' => $shipping,
'tax' => $tax,
'total' => $total,
'orderItems' => $items,
'notes' => 'Order from ZenCart. Session Name ' . zen_session_name() . ' / ID #' . zen_session_id()
)
);
Let me know if that was where you were going with that.