MIGS payments in Joomla VirtueMart.

18

A VirtueMart payment method plugin to support MIGS 2-party payments.

on 30/5/10

This is a follow-up post in response to Mike Soden's comment on my post Integrate MIGS 2-party payments in PHP - in which Mike asked for some help getting MIGS 2-party payments working in VirtueMart.

I took a quick look at some of the other attempts at MIGS integration into VirtueMart, but I wasn't convinced about their quality; they looked incomplete and sloppy. So, I decided to gut an existing one and roll my own.

I wrote this one using VirtueMart 1.1.4 stable running on Joomla 1.5.17. It will likely work for other versions of VirtueMart and/or Joomla, but I make no promises.

The VirtueMart MIGS payment method plugin code:

VirtueMart allows developers to add a new payment method in two steps:
Step one, by adding the classes to the following location:
[wwwroot]/administrator/components/com_virtuemart/classes/payment
And step 2, by adding and configuring the payment method in the VirtueMart admin component.

The first half of this post will talk about the payment class (and accompanying config file) that you need to paste into the above location. NOTE: You will also need to chmod the config file with write permission, as the VirtueMart admin component writes to this file from the configuration tab.

VirtueMart payment classes typically have two files:

  • ps_migs.php
  • ps_migs.cfg.php (cfg is an abbreviation for config)

The main file (and class) is called ps_migs. For what it's worth: the "ps_" naming convention is remnants of phpShop, which VirtueMart forked from back in the day.

The ps_migs.php file actually contains a few class definitions, including: ps_migs, Migs, MigsConfig and MigsHtml; this is just about keeping the code split into neat logical chunks, while still maintaining the VirtueMart convention of two files. You really needn't worry too much about this.

My ps_migs class takes inspiration from the other payment classes in the methods it contains, largely because I couldn't find appropriate documentation on what an ideal payment class should look like.

There are 5 methods relating to configuring the payment method. These should not be of too much interest to developers implementing the MIGS payment plugin into their own VirtueMart store, as they are all used by the VirtueMart admin component. Needless to say, they all work and together, allow you to configure your MIGS payment method.

There are 2 methods relating to actually processing payments. At this point, only the process_payment method has a proper implementation (as the projects I have been working on have not required payment capture and processing).

Since we already have such a strong basis for making payments using MIGS payment gateway from my previous post - we'll use the existing classes: Migs and MigsConfig. This is going to be a walk in the park!

The other file ps_migs.cfg.php, defines a series of constants. In our case, the ps_migs.cfg.php file contains four constants. The first two are your Merchant Id and your Access Code. The second two are response codes used in VirtueMart which really need not be changed from 'C' and 'X' respectively - as they indicate what status payments that succeeded or failed should receive.


define('vpc_AccessCode', '80#####7');
define('vpc_Merchant', 'TESTBBL9#####4');
define('MIGS_VERIFIED_STATUS', 'C');
define('MIGS_INVALID_STATUS', 'X');

These values can be edited via the VirtueMart admin component, more on this in the second half of the post.

NOTE: At this point you really should have some familiarity with my previous post Integrate MIGS 2-party payments in PHP - in which the Migs class is first introduced.

Ok, since the Migs class is already written to use the MigsConfig class to read it's values from, we're going to write a quick adapter method to populate the config from VirtueMart's defined constants into the MigsConfig class. This is the exact same technique I demonstrated in my previous post to extract config values from a Joomla admin component's parameters. Cool huh?

So, after creating an instance of the Migs class we populate the config from the VirtueMart ps_migs.cfg.php file.


// Bring in the Virtuemart config.
$configFilepath = CLASSPATH.'payment/'.$this->classname.'.cfg.php';
require_once($configFilepath);

// Use Migs helper class to package, process and un-package the payment.
$migs = new Migs();
$migs->config->readConfigFromVirtuemartFile($configFilepath);

The next step is getting the data we need from VirtueMart into an associative array, ready to pass in to the digitalOrder method of the Migs class.


// Get the data from Virtuemart into the format that MIGS expects.
$data = array(
	'vpc_MerchTxnRef' => $orderNumber,
	'vpc_OrderInfo' => $orderNumber,
	'vpc_Amount' => (int)($amount*100), // Force amount into cents.
	'vpc_CardNum' => $_SESSION['ccdata']['order_payment_number'],
	'vpc_CardExp' => (substr($_SESSION['ccdata']['order_payment_expire_year'],2)) . ($_SESSION['ccdata']['order_payment_expire_month']),
	'vpc_CardSecurityCode' => $_SESSION['ccdata']['credit_card_code']
);

Now, it's time to reap the benefits of good software development practices... reusability. Yep, it's the Migs class from my previous post, looking like a champ! These next two lines of code handle all the integration with the MIGS payment gateway.


$response = $migs->digitalOrder($data);
$errors = $migs->validateResponse($response);

Lastly, it's just a matter of handling the response - pushing the appropriate data we got back from the MIGS gateway into our VirtueMart data variable to be saved.


// Validate/Verify the response succeeded.
if (sizeof($errors) == 0) {
	$d['order_payment_log'] = var_export($response, true);
	$d['order_payment_trans_id'] = $response['vpc_TransactionNo'];

	// Update the order status to 'C' as per the config.
	$d['order_status'] = MIGS_VERIFIED_STATUS;

	return true;
}
else {
// some code removed ...
}

Install the ps_migs files to the filesystem:

That's the first half taken care of - at this point we should have extracted the two ps_migs files and copied them into the [wwwroot]/administrator/components/com_virtuemart/classes/payment directory. You should also give the ps_migs.cfg.php file write permission if you intend on configuring your MIGS payment method from the VirtueMart admin component.

On to the second half of the post... In brief, we're going to log into Joomla and install/configure your brand-spanking-new MIGS payment method in the VirtueMart admin component.

Add and configure the MIGS payment method:

The following steps should help you through:

  1. Log into the Joomla admin, and head to the VirtueMart component.
  2. On the left hand side, click the Store link (in the accordion menu).
  3. Click Add Payment Method.
  4. Enter details along the lines of:
    Active?: Checked
    Payment Method Name: Credit Card (MIGS) *** NOTE: you can rename this as you please. ***
    Code: MIGS
    Payment class name: ps_migs
    Payment method type: Use Payment Processor
    Accepted Credit Card Types: Visa, MasterCard, American Express, Diners Club, etc.
    [...]
    The rest you can just leave as per their defaults (unless you know what you're doing).

  5. Save the new payment method and return into editing it by clicking it's name in the list.
  6. Click the Configuration tab and enter your MIGS Merchant Id and Access Code.
  7. Ensure the Verified Status Code is C and the Invalid Status Code is X.

  8. Save the configuration.
  9. [Optional] Set other payment methods to un-active if they are not needed.
  10. Give it a test - you're done! :D

NOTE: As I mentioned in my previous post, when testing: the payment amount is translated to cents and needs to be divisible by 100 to be valid. E.g. an amount of $23.00 would work, but $23.50 would return an error response (when using the test payment server).

If everything went correctly, you should be able to select an item from your store, add it to the cart, check out and see something similar in your VirtueMart store.

Download the MIGS VirtueMart payment method plugin:

ps_migs.zip [8kb]

Please note: This code is provided as is, use it at your own discretion.
That said, if you do notice anything that you think is potentially unsecure, or that you think could be improved upon - feel free to let me know.

I'd also be interested in hearing if you have success using this class in any of your own projects.

Professional quality MIGS implementations by Inlight Media.

If you've got to the end of this post and you're still unsure on how to integrate MIGS in to your VirtueMart, or your PHP site - you should give Inlight Media a call on (03) 9029 3582 or email info@inlight.com.au - Inlight Media are a Melbourne based web development agency who (amongst other things) are experts at PHP based MIGS integration.

on 12/11/10

Error after entering credit card details:
"Error: Failure in Processing the Payment (ps_migs)"

Aman

on 8/12/10

Error: Failure in Processing the Payment (ps_migs)

Tony Milne

  -  http://tonymilne.com.au

on 8/12/10

Aman, you're really not giving me much to work with here. What test data did you enter? What environment are you testing against? What version of Joomla/Virtuemart?

Despite the lack of details, I'm going to go out on a limb here and suggest you didn't read my note about the MIGS test payment server returning an error when your payment amount is not a whole dollar value. This is deliberate functionality of the MIGS test payment server, to enable developers to test error responses in a predictable manner.

It can be difficult simulating a whole dollar checkout amount in VirtueMart (due to GST/Postage costs), so you might try temporarily hard-coding a value into the ps_migs.php file (located in /administrator/components/com_virtuemart/classes/payment/ps_migs.php).

You are looking to make the following change on line 128:

'vpc_Amount' => (int)($amount*100), // Force amount into cents.
to:

'vpc_Amount' => 2000, // Hard-coding $20 as cents for testing.
Give that a try and let me know how you go. Lastly, don't forget to change the code back or you could end up with angry and confused customers!

Marvin Nahmias

  -  http://www.agoten.com

on 14/12/10

HI, Im integrating with ONLY AMEX Mexico, and they happen to use same method. I tried installing plugins in virtuemart to no avail, making sure I configured the HASH code correctly to make sure the system flows. Any ideas what I can do? I was able to dummy the posting directly and it worked, but really want to use a component intead like yours. Can we help everyone as well?

Law

on 29/12/10

Hi, I am getting the same "Error: Failure in Processing the Payment (ps_migs)" message to the test environment as well. I am using Virtuemart 1.1.5 stable with Joomla 1.5.22 stable.

I have hard-coded the amount to 2000 (as shown above). Any clue?

law

on 29/12/10

I believed I might have found the solution to this "Error: Failure in Processing the Payment (ps_migs)" (at least to my case).

If you comment out the optional field vpc_TxSource from the $VPC_CONSTANTS array at around line 206, then resubmit the order, you will not get this error message.

All my test orders have since captured successfully by the MIGS testing environment :)

Steve

  -  http://www.webcircle.com.au

on 20/1/11

I'm getting the same result as the above posters the: Error: Failure in Processing the Payment (ps_migs).

I've tried all the suggested fixes above but no luck in getting this sorted.

We're using J1.5.22 with Virtuemart 1.1.5 are you able to provide any other ways I can troubleshoot/fix this? Much appreciated.

Thomas

  -  http://www.globalnutrition.com.au

on 24/3/11

I have the same problem and can't fix it - it doesnt give me a proper error message what's going wrong..i tried it with a fixed amount of 2000 but didn't help, also tried it with commenting the vpc_txsource..

i'm not sure what could be wrong and i would like to implement the MIGS/CommWeb interface..

Andreas

on 11/5/11

Im also getting the error message

"Error: Failure in Processing the Payment (ps_migs)"

The strange thing is that the payment gateway was working and then just stopped working.

I have tested the different payment amounts and all of the return the error message.

We are using VM 1.1.8 and Joomla 1.5.23

Alexandre Silva

on 13/6/11

Hi there,
would it be dificult for you to change the code to make it 3-party (3-way) ?
Thank you very much,

Alex

on 19/7/11

Hello there will it work with bank "Bendigo Bank"?

Thanks in advance.

Rishi

on 19/3/12

Hi Tony,

I implement your plugin in virtumart 1.4 and j1.5. its working perfect and i tested it all testing card. working perfect. thanks for that.

now, i am facing issue in virtumart 2.0.2 as virtumart 2.0.2 removed all ps_ classes and working on MVC structure and have to create joomla install able plug in. i am quite new in that. so it would be great, if you can help me in such case.

Thx in Advanced :-)

Kenny

  -  http://mooksandmellow.com/index.php

on 27/3/12

Hi, Tony,

Thank you so much for the solution. It worked perfectly.

Much appreciated for sharing.

Tarun

on 30/3/12

Hello Tony,

I read all the post and comment from top to end and i have done everything in the Joomla/VM, but still getting the below error. Could you please let me know that does it work with HTML-Form based (e.g. PayPal) payment type. When i used this (HTML-Form based (e.g. PayPal)) payment type then i got the Error:Faliure in Processing error and when i use the Use Payment Processor payment type then i got that credit card number is invalid. So i think in both of the case it is not working with me, if you can please share your technical knowledge with me and can give me any clue that would be great.

Please response me asap and thank you for you any help and for your valuable time. looking forward to hear positive response..

Error: Failure in Processing the Payment (ps_migs)

I am using Joomla 1.5.25 and VM 1.1.9.

Thanks...

Tarun

on 30/3/12

And do we need to put any extra info in Payment Extra Info: for this plugin..?

louai

on 18/4/12

HI Tony
I have VM2 installed and as you know VM2 works different so how I can do it
thanks

darshan

4 weeks ago

Hi Tony,

I am getting the same error as others......'Error: Failure in Processing the Payment (ps_migs)'.

I have changed the amount to 'vpc_Amount' => 2000, but it still doesn't work.

I am using it with CBA migs.

Can you please let me know how to resolve this error?

Anyone have fixed the error??

I am using J 1.5.22 and Virtuemart 1.1.9

Thanks

Claudia

1 day, 7 hours ago

Hi Tony,
would it be dificult for you to change the code to make it 3-party (3-way) ?


I had not been able to make the 2nd party work. I have same error like other ""Error: Failure in Processing the Payment (ps_migs)"

Am using joomla 1.5 and VM 1.1.3

Thanking you in advance.

You should leave a comment:

Some tags are allowed: (a, b, blockquote, code, em, i, u, pre, strong).

who am I?

I live in Melbourne. I work at Inlight Media. I'm passionate about web and software development. I like jQuery, CakePHP, Flex. I can code. I can't draw. I play basketball with the Spiderpigs and the Generals. I love snowboarding in the winter and wakeboarding in the summer. I play computer games too often.