// 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) {
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.'" />
</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).'" />