Payment Processor Module for Megasoft (Venezuela) using Post

This forum is for general questions about extensions for Joomla! version 1.5.x.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Locked
federicoblank
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Apr 17, 2012 3:40 am

Payment Processor Module for Megasoft (Venezuela) using Post

Post by federicoblank » Tue Apr 17, 2012 5:01 am

Hello everyone, I've been searching in forums, but haven't found a module or answer that fills my needs, so I decided to come here and ask for some guidance, it'd be great to create this module and give it away as an open source application in Joomla's extension directory!

I'm currently using Joomla 1.5 and Virtuemart 1.1.8 but I'm considering moving to Joomla 2.5 and Virtuemart 2. My dilema here is that there's not that much info and plugins available yet for the latest version of Virtuemat, so I'm not sure if I'd be able to develop the module for Virtuemart 2. In any case, I'd like to know your recommendations in terms of using my current store configuration with Joomla, or if it's better to upgrade everything. The store is so simple in design and content at this point that it is a crucial decision since I just found out about both new versions.

As for Virtuemart 1..1.8 I kind of "know" (sorry for my lack of knowledge of php) what needs to be done in this version, and I think it could be similar in the new version as well.

So I used the PayPal Old module as e2a starting point since the process of Megasoft could be similar to the one used by PayPal. I think there's only need to modify 3 files so the module can send the required data to Megasoft platform.

payment-procesor code inside the module
ps_tarjeta.cfg.php (application/x-httpd-php) 2K it used to be ps_paypalold.cfg.php
ps_tarjeta.php (application/x-httpd-php) 10K it used to be ps_paypalold.php

Virtuemart needs to send the information to Megasoft using php post method (or maybe get?) through an url which looks like this in test mode:

https://paytest.megasoft.com.ve:8443/pa ... ura=123456

These are the details contained in that url sent to Megasoft:

Variables

1- the url contained in in the ps_tarjeta.php which used to be the PayPalold php file
https://paytest.megasoft.com.ve:8443/pa ... sar-compra?

2- cod_afiliacion=1633650
It's an constant field related to the affiliation id number of the company with Megasoft

3- transcode=0141
It's also a constant numeric field which determines that it's a credit card transaction

4- pan=4545130000599075
The credit card number

5- cvv2=638
cvv2 code

6- cid=V123654
The ID (Legal Venezuelan Identification) number of the costumer

7- expdate=0510
Expiration date of the credit card

8- amount=1231
Total amout in VEF form Venezuela without decimals in the number, in this example the amount is 12,34

9- client=Pedro%20Perez
Client's full name

10- factura=123456
Virtuemart's invoice id number

Once Megasoft receives the url with the variables included, it returns 0 or 1 in an xml file with confirmation of approval or rejection of the transaction. (Is it a must to use a SSL to perform this data sending?).

If I'm not wrong, here's the code that need to be modified in order to do the job, the thing is that I don't know how to do it, but I'm really willing to learn.

The first piece of code that needs to be modified is this (I made my coments in UPERCASE to differenciate it from the code author):

1- ps_paypal.cfg.php which I renamed ps_tarjeta.cfg.php
2- ps_paypal.php which I renamed ps_tarjeta.php
3- the crucial piece of code that goes inside the module itself.

Code: Select all


<!-- 

THIS IS THE CODE THAT GOES INSIDE VIRTUEMAT'S PAYMENT METHOD ADMINISTRATOR. I THINK THIS IS THE MAIN CODE THAT NEEDS TO BE MODIFIED SO THE MODULE CAN WORK 

1-url https://paytest.megasoft.com.ve:8443/payment/action/procesar-compra?

2- cod_afiliacion=1633650 (ps_tarjeta COULD BE TWEEKED TO DIPLAY THIS FIELD IN THE PAYMENT METHOD ADMINISTRATOR???)

3- transcode=0141 (COULD BE TWEEKED TO DIPLAY THIS FIELD IN THE PAYMENT METHOD ADMINISTRATOR???)

4-pan=4545130000599075

5- cvv2=638 

6- cid=V123654

7- expdate=0510

8- amount=1231 (I'M NOT SURE HOW TO GET RID OF THE DECIMALS USING PHP)

9- client=Pedro%20Perez (no se a que se refiere el %20 que está entre el nombre y el apellido)

10- factura=123456

FROM THIS POINT I THIK THERE ARE 2 POSSIBLE WAYS:

1 - MODIFY BELOW'S PHP CODE

2 - CREATE A FOR SIMILAR TO THE ONE THAT APPEARS IN THE TUTORIAL http://virtuemart.net/documentation/Developer_Manual/figure/payment_method_form2.png

I BELIVE THAT THIS IS A MORE SIMPLE METHOD TO SEND THE DATA WITH POST METHOD
-->

<?php
$db1 = new ps_DB();

/* 
SHOULD I GET RID OF THE COUNTRY SINCE IT'S ONLY FOR VENEZUELA???
*/
$q = "SELECT country_2_code FROM #__vm_country WHERE country_3_code='".$user->country."' ORDER BY country_2_code ASC";
$db1->query($q);


/* I CHANGED THE PAYPAL'S VARIABLE $url AND USED THIS ONE https://paytest.megasoft.com.ve:8443/payment/action/procesar-compra? BUT I'M NOT SURE IF IT AT THE END SHOULD GO THE ?. I TEST IT AND I GET IN THE BROWSER AN XML FILE

*/

$url = "https://paytest.megasoft.com.ve:8443/payment/action/procesar-compra?";
$tax_total = $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total = $db->f("coupon_discount") + $db->f("order_discount");

/* 

THIS IS A LIST OF VIRTUEMAR VARIABLES NEEDED TO BE SENT TO MEGASOFT

first_name
last_name
address_1
fax   (I USED THIS VARAIBLE TO HOLD THE CLIENT ID NUMBER INSTEAD OF THE FAX NUMBER)
order_number
order_total
ccdata
order_payment_number
credit_card_code
order_payment_expire_month

*/

/* I DON'T UNDERSTAD THIS ARRAY THAT MUCH, BUT I ADDED THE VARIABLES THAT WERE MISSING AND ARE NEEDED TO PROCESS THE PAYMENT */
$post_variables = Array(
"cmd" => "_ext-enter",
"redirect_cmd" => "_xclick",
"upload" => "1",
"business" => PAYPAL_EMAIL,
"receiver_email" => PAYPAL_EMAIL,
"item_name" => $VM_LANG->_('PHPSHOP_ORDER_PRINT_PO_NUMBER').": ". $db->f("order_id"),
"order_id" => $db->f("order_id"),
"invoice" => $db->f("order_number"),
"amount" => round( $db->f("order_total")-$db->f("order_shipping"), 2),
"shipping" => sprintf("%.2f", $db->f("order_shipping")),
"currency_code" => $_SESSION['vendor_currency'],
"address_override" => "1",
"fax" => $dbbt->f('fax'), 
"first_name" => $dbbt->f('first_name'),
"last_name" => $dbbt->f('last_name'),
"address1" => $dbbt->f('address_1'),
"address2" => $dbbt->f('address_2'),
"zip" => $dbbt->f('zip'),
"city" => $dbbt->f('city'),
"state" => $dbbt->f('state'),
"country" => $db1->f('country_2_code'),
"email" => $dbbt->f('user_email'),
"night_phone_b" => $dbbt->f('phone_1'),
"cpp_header_image" => $vendor_image_url,
"return" => SECUREURL ."index.php?option=com_virtuemart&page=checkout.result&order_id=".$db->f("order_id"), /* IS IT A MUST TO USE A SSL FOR SECURE URL?*/
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"undefined_quantity" => "0",
/* I HAVE NO CLUE ABOUT THE DEBUG MODE*/
"test_ipn" => PAYPAL_DEBUG,
"pal" => "NRUBJXESJTY24",
"no_shipping" => "1",
"no_note" => "1"
);
if( $page == "checkout.thankyou" ) {
$query_string = "?";
foreach( $post_variables as $name => $value ) {
$query_string .= $name. "=" . urlencode($value) ."&";
}


/* I GUESS HERE IS WHERE THE PAYPAL BUTTON IS CREATED TO SEND THE VARIABLES TO THE DESIGNATED URL */

vmRedirect( $url . $query_string );
} else {
echo '<form action="'.$url.'" method="post" target="_blank">';

echo '<input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/x-click-but6.gif" alt="Click to pay with PayPal - it is fast, free and secure!" />';

foreach( $post_variables as $name => $value ) {
echo '<input type="hidden" name="'.$name.'" value="'.htmlspecialchars($value).'" />';
}
echo '</form>';

}
?>
So I guess that there's a need to create something like a php function that concatenates all the variables required by Megasoft and send them using post method so the final URL sent looks like the one submitted above.

I don't know how to create that function, that's the core issue of this post, once it is created, Virtuemart should handle the rest of the process.

I think this is something that could be done in a few hours of work of php savvy programmer, I'm willing to pay for this help, but I'm also willing to learn how to do it!

I hope I explained myself clear enough with all the details needed to do this job.

I'm looking forward to your answers.

I'd really appreciate your time and help

Thank you

PS. I'm attaching the following files with comments contained in Archive.zip
1- ps_paypal.cfg.php which I renamed ps_tarjeta.cfg.php
2- ps_paypal.php which I renamed ps_tarjeta.php
You do not have the required permissions to view the files attached to this post.

Locked

Return to “Extensions for Joomla! 1.5”