Author Topic: zero order value - how to stop the handover to Sagepay payment gateway  (Read 5623 times)

Christopher

  • Jr. Member
  • **
  • Posts: 93
    • CDTi
Hello

I'm integrating Sagepay with VM 1.1.x / J1.5.x and all is going well, except...

My clients sell fabric and want their customers to be able to order free samples. If an order comprises ONLY free samples, the shipping is also free (I've set this up with "ShipValue" under Store / Shipping Module List and it works).

The trouble is, VM passes the customer through to the Sagepay payment gateway which throws the following error:

Status: INVALID
Status Detail: 4009 : The Amount is outside the allowed range.
 
...Because Sagepay (understandably) expects the transaction value to be at least £0.01.

Does anyone know what code or settings I need to change to interrupt this process and 'catch' any order value which equals £0.00 before it goes to the final step? I am using Sagepay Form (Previously known as Protx VSP Form)

Thanks for your help

Christopher
There are 10 types of people in the world:
Those who understand binary and those who don't

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10400
  • VirtueMart Version: 3+
enable the purchase order/pickup option. RE_name it to "Fabric Sample Order"

J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Christopher

  • Jr. Member
  • **
  • Posts: 93
    • CDTi
Hi BanquetTables

It kind of works, and thank you for suggesting it, but we're concerned that customers will either not spot what that option does, or use it in error and think they've placed an order (I know - customers should realise they haven't entered their card details, etc but you'd be amazed at how dumb people can be...)

I've attached the file I think need adapting at around line 377 to place a statement like:

If ($order_total = 0) then
echo 'Thank you for your order';

else{

...then follow on with the call to the Sagepay system

That way, the customer just adds whatever they want to their basket and the system decides whether they get fired through to the payment gateway or stop on the 'Thank you for your order' part - the system generates the emails at this stage anyway, so my client would see that an order for samples had been placed

If you could take a look at the attached file (my PHP coding ain't up to much I'm afraid) then I would be very grateful - I seem to be within a cat's whisker of fixing this, but every time I try, something seems to break

If it helps, please take a look at the following site - I've left in place your solution using the renamed Purchase Order:

www.fabricandco.co.uk/index.php

Many thanks

Christopher

[attachment cleanup by admin]
There are 10 types of people in the world:
Those who understand binary and those who don't

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10400
  • VirtueMart Version: 3+
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Christopher

  • Jr. Member
  • **
  • Posts: 93
    • CDTi
Hi BanquetTables

That's great - Thank you very much indeed - will implement the code changes detailed in that forum post tomorrow with a fresh head on my shoulders and see what happens

Kind regards

Christopher
There are 10 types of people in the world:
Those who understand binary and those who don't

Christopher

  • Jr. Member
  • **
  • Posts: 93
    • CDTi
Unfortunately those code changes are for a much older version of VM (I'm using 1.1.8) and a search for the files and code snippets in my version yields no results.

Back to the drawing board.

Thanks for you helps, BanquetTables

Christopher
There are 10 types of people in the world:
Those who understand binary and those who don't

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10400
  • VirtueMart Version: 3+
You wont be able to use that exact hack, but it can help
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Christopher

  • Jr. Member
  • **
  • Posts: 93
    • CDTi
I see code in ps_checkout.php at around line 860:

Code: [Select]
        // Redirect to the last step when there's only one payment method
if( $VM_CHECKOUT_MODULES['CHECK_OUT_GET_PAYMENT_METHOD']['order'] != $VM_CHECKOUT_MODULES['CHECK_OUT_GET_FINAL_CONFIRMATION']['order'] ) {
if ($count <= 1 && $cc_payments==false && $pp_payment==false) {
vmRedirect($sess->url(SECUREURL.basename($_SERVER['PHP_SELF'])."?page=checkout.index&payment_method_id=$first_payment_method_id&ship_to_info_id=$ship_to_info_id&shipping_rate_id=".urlencode($shipping_rate_id)."&checkout_stage=".$VM_CHECKOUT_MODULES['CHECK_OUT_GET_FINAL_CONFIRMATION']['order'], false, false ),"");
}
elseif( isset($order_total) && $order_total <= 0.00 ) {
// In case the order total is less than or equal zero, we don't need a payment method
vmRedirect($sess->url(SECUREURL.basename($_SERVER['PHP_SELF'])."?page=checkout.index&ship_to_info_id=$ship_to_info_id&shipping_rate_id=".urlencode($shipping_rate_id)."&checkout_stage=".$VM_CHECKOUT_MODULES['CHECK_OUT_GET_FINAL_CONFIRMATION']['order'], false, false),"");
}
}

...which would seem to indicate that the function already exists but as with much of Virtuemart, just doesn't bloody work properly!

<sigh>
There are 10 types of people in the world:
Those who understand binary and those who don't

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10400
  • VirtueMart Version: 3+
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Christopher

  • Jr. Member
  • **
  • Posts: 93
    • CDTi
Hi BanquetTables

Thanks for that.

Its interesting but the instructions run out of steam when I get to the final snippet of code - I don't know where to place this code (Have tried in my 'ps_protx_cpi.php' file and it doesn't seem to do anything), or what to put in place of "EXAMPLE_CFG_ORDER_TOTAL_MIN" and "EXAMPLE_CFG_ORDER_TOTAL_MAX"

Now losing the will to live and getting pig-sick of VM, in spite of your best efforts which I do appreciate

Thanks

Christopher
There are 10 types of people in the world:
Those who understand binary and those who don't

Christopher

  • Jr. Member
  • **
  • Posts: 93
    • CDTi
After much head scratching, have managed to get this working.

The third snippet of code needs to be added to EACH of the payment classes you intend to use.

BUT the biggest single f***-up was caused because, when I chose to modify the "Cash On Delivery" payment class to create my 'No Payment Required Option' for the free samples being 'sold' through the system, the 'Payment Class Name' listbox for 'Cash on Delivery' wasn't set to 'ps_cashondel.php' but instead to 'ps_payment.php'.

Stupidly, I edited 'ps_cashondel.php' (and re-edited it about 20 times thinking I'd made a schoolboy error) before deciding to check the admin suite's setup meticulously and discovered that the payment method was calling the wrong <insert expletive here> class file. Genius - thank you VM!

Thanks BaquetTables - Got there in the end!!

To the creators of VM - I've wasted 3 days trying to find a fix for this - who do I send my bill to??
There are 10 types of people in the world:
Those who understand binary and those who don't