knitting

Author Topic: PayPal Set Up for VirtueMart 1.1  (Read 69110 times)

Soeren

  • Administrator
  • Hero Member
  • *
  • Posts: 3103
  • VirtueMart Starter
    • virtuemart.net
PayPal Set Up for VirtueMart 1.1
« on: May 02, 2008, 02:43:26 am »
Hello,
you might have noticed the hundreds of topics about PayPal IPN and issues with it. As PayPal is one of the most popular payment systems for an online-shop it's important to have a running payment method with it.
How do I install PayPal?
You don't have to install it. PayPal is a part of the official distribution and installed per default.
You just have to go to "Store" => "Payment method list" and click on "PayPal".
If you want to know which files are responsible for PayPal:
VIRTUEMART:
* /site_root/administrator/components/com_virtuemart/notify.php
This is the script where paypal.com should post to when a transaction is made. If the transaction was VERIFIED, the order status is usually update to the oder status you have set in the configuration (you can set that for Confirmed, Pending & Failed payments).
* /site_root/administrator/components/com_virtuemart/classes/payment/ps_paypal.php
This is the main class for the paypal configuration. It actually doesn't play any role on checkout.
* site_root/administrator/components/com_virtuemart/classes/payment/ps_paypal.cfg.php
The configuration file for the paypal settings. Remember that this file must be writable to save changes to the configuration.

How do setup PayPal?
This payment method is to be set up as every other payment method: go to "Store" => "List Payment Methods", then select "PayPal" from the list. Once the payment method form for PayPal has opened, you can activate/deactivate it, rename it (the name of the payment method doesn't really matter!), restrict it to a shopper group, define a discount value and change the method's position in a list with other payment methods (list order).
Please note that there's an important Configuration Panel, which can be reached by clicking on the Tab Heading "Configuration".
Test Mode [yes/no; default=no]This is NOT FOR THE PAYPAL SANDBOX!
When you enable the test mode, you can debug the script using Eliteweaver's ipn testing environment. Last time I used that, i didn't worked and didn't recognize that the script was posting back (I know it did!).

//Edit by Hutson
PayPal Email
For LiveYour business email, which is your login at paypal or
For sandboxYour seller e-mail address if you use paypal sandbox (e.g. seller_12592_biz@xxxx.com). Not your Sandbox login.
//edit end

Order Status for confirmed Payments
Order Status for Pending Payments
Order Status for failed Payments

With these settings you can define, which Order Status should be set when a payment was successful / is pending / has failed.
IMPORTANT: PayPal seems to return "Pending" very often, although the payment will be no problem. A further investigation, why the payment is still pending is not made at this time (we'll have to improve the paypal notify script to check that).
That's why you see "An error occured while processing your transaction. The status of your order could not be updated": You obviously haven't set the Order Status for pending payments to "confirmed".
Payment Extra Info
The textarea is used by each payment method. You can fill in HTML/PHP/Javascript here. It is executed:
* on the "Thankyou" page
* each time the order is viewed by the customer (and it's order status is not "confirmed")
So you can use it to
* process additional affiliate tasks
* show your bank account details
* whatever you want to display to the customer
I have rewritten the Payment Extrainfo Code for PayPal, so i directly redirects the customer to PayPal after clicking on "Confirm" to place the order.

Just copy and paste it into your PayPal Extra info box.

//Edit by Hutson

Comment out one of the URLs from the extra info (below) to connect to either the PayPal live or PayPal sandbox as needed.

Live vs Sandbox

Sandbox testing URL
$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
Live URL
$url = "https://www.paypal.com/cgi-bin/webscr";

You need to change your PayPal Payment e-mail address as well to flip between sandbox and live.

//edit end

CODE FOR USE IN VIRTUEMART - //edit hutson, does not contain line item detail
Code: [Select]
<?php
$db1 
= new ps_DB();
$q "SELECT country_2_code FROM #__vm_country WHERE country_3_code='".$user->country."' ORDER BY country_2_code ASC";
$db1->query($q);

//Edit by hutson Comment out the one you DONT want to connect to, Choose either live or sandbox from below but not both!

$url "https://www.sandbox.paypal.com/cgi-bin/webscr";
$url "https://www.paypal.com/cgi-bin/webscr";

//Edit end end of choice

$tax_total $db->f("order_tax") + $db->f("order_shipping_tax");
$discount_total $db->f("coupon_discount") + $db->f("order_discount");
$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_subtotal")+$tax_total-$discount_total2),
"shipping" => sprintf("%.2f"$db->f("order_shipping")),
"currency_code" => $_SESSION['vendor_currency'],

"address_override" => "1",
"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"),
"notify_url" => SECUREURL ."administrator/components/com_virtuemart/notify.php",
"cancel_return" => SECUREURL ."index.php",
"undefined_quantity" => "0",

"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) ."&";
}
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" border="0" 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>';

}
?>
If you don't want your customer to be redirected after confirmation, but still want him to click on "Pay with PayPal", change
Code: [Select]
if( $page == "checkout.thankyou" ) {to
Code: [Select]
if( false ) {Don't forget to save all your changes.  ::)
Common Questions
My PayPal doesn't work. What's wrong?
It could be anything. Please review your settings and read the other Questions/Answers.
//edit Hutson.

Have you commented out the Paypal link you don't want in the code above:-
Live
//$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
$url = "https://www.paypal.com/cgi-bin/webscr";

Sandbox
$url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
//$url = "https://www.paypal.com/cgi-bin/webscr";

//end edit

How can I use the PayPal Sandbox for debugging my PayPal Payment Method?
Make sure you have commented out the right line in the code above.

I'm getting the message "An error occured while processing your transaction. The status of your order could not be updated." when returning from PayPal.
Please be careful before you blame VirtueMart.
There are many reasons why this message could be displayed.
  • Your script can't be reached from the internet
    It's important that your notify.php is not protected by .htaccess files (which is the case when you secure your /administrator directory).
    Try to point to it with your browser.
  • There's a parsing error in your script.
    If you have no idea why things go wrong, do the following:
    * Enable Debug Mode
    * Go to http://www.eliteweaver.co.uk/testing/ipntest.php and debug your script.
    * Click on "Follow IPN" after you have clicked on "Submit IPN" to see the real debug output of your notify.php script
  • Your Payment returned the payment status "Pending" or "Failed".
    When you have a pending or failed payment, the notify.php script changes the order status to whatever you have set in the paypal configuration for it. BUT: if this isn't "confirmed", you will see this error message.
How can I change the return page?
The file behind that default return page is
/site_root/administrator/components/com_virtuemart/html/checkout.result.php
You can also change the return page in the payment extrainfo in the payment method form for PayPal or set your own Notify URL in your PayPal Account.
I hope that clears it a little bit.

ciao, Soeren
The future of eCommerce: VirtueMart & Joomla!
http://virtuemart.net

VirtueMart Forum

PayPal Set Up for VirtueMart 1.1
« on: May 02, 2008, 02:43:26 am »