Added debug mode for paypal payments
authorMarcel Werk <burntime@woltlab.com>
Fri, 3 Oct 2014 20:28:21 +0000 (22:28 +0200)
committerMarcel Werk <burntime@woltlab.com>
Fri, 3 Oct 2014 20:28:21 +0000 (22:28 +0200)
wcfsetup/install/files/lib/action/PaypalCallbackAction.class.php
wcfsetup/install/files/lib/system/payment/method/PaypalPaymentMethod.class.php

index 747be579d0f0f85973a0e6260fae6a5d2e0c2021..d5af4a4a3e06a4e4a56f09ac4f43d74e5c3bdc5b 100644 (file)
@@ -29,13 +29,19 @@ class PaypalCallbackAction extends AbstractAction {
                        // post back to paypal to validate 
                        $content = '';
                        try {
-                               $request = new HTTPRequest('http://www.paypal.com', array(), array_merge(array('cmd' => '_notify-validate'), $_POST));
+                               $url = 'https://www.paypal.com/cgi-bin/webscr';
+                               if (!empty($_POST['test_ipn'])) {
+                                       // IPN simulator notification
+                                       $url = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
+                               }
+                               
+                               $request = new HTTPRequest($url, array(), array_merge(array('cmd' => '_notify-validate'), $_POST));
                                $request->execute();
                                $reply = $request->getReply();
                                $content = $reply['body'];
                        }
                        catch (SystemException $e) {
-                               throw new SystemException('connection to paypal.com failed');
+                               throw new SystemException('connection to paypal.com failed: ' . $e->getMessage());
                        }
                
                        if (strstr($content, "VERIFIED") === false) {
index bf2b11b2276eda509b393a73e7cef6e972062b78..487582a3adb92876d00cbfe178ae8a01550308c7 100644 (file)
@@ -61,7 +61,7 @@ class PaypalPaymentMethod extends AbstractPaymentMethod {
        public function getPurchaseButton($cost, $currency, $name, $token, $returnURL, $cancelReturnURL, $isRecurring = false, $subscriptionLength = 0, $subscriptionLengthUnit = '') {
                if ($isRecurring) {
                        // subscribe button
-                       return '<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
+                       return '<form method="post" action="https://www.' . (ENABLE_DEBUG_MODE ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr">
                                        <input type="hidden" name="a3" value="'.$cost.'" />
                                        <input type="hidden" name="p3" value="'.$subscriptionLength.'" />
                                        <input type="hidden" name="t3" value="'.$subscriptionLengthUnit.'" />
@@ -85,7 +85,7 @@ class PaypalPaymentMethod extends AbstractPaymentMethod {
                                </form>';
                }
                else {
-                       return '<form method="post" action="https://www.paypal.com/cgi-bin/webscr">
+                       return '<form method="post" action="https://www.' . (ENABLE_DEBUG_MODE ? 'sandbox.' : '') . 'paypal.com/cgi-bin/webscr">
                                        <input type="hidden" name="amount" value="'.$cost.'" />
                                        <input type="hidden" name="business" value="'.StringUtil::encodeHTML(PAYPAL_EMAIL_ADDRESS).'" />
                                        <input type="hidden" name="cancel_return" value="'.StringUtil::encodeHTML($cancelReturnURL).'" />